aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-12-13 11:34:11 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-12-13 11:34:11 -0500
commit5233c331cfb41433bc167fc7c70ea67c1133ffec (patch)
tree1ab0da40a3069c54e41a2aed8a0ada8ddb325e46
parent58f253d26254b7ec0faa0a67d70912facd6687e4 (diff)
parentff6af28faff53a7389230026b83e543385f7b21d (diff)
Merge tag 'mmc-v4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc
Pull MMC updates from Ulf Hansson: "It's been an busy period for mmc. Quite some changes in the mmc core, two new mmc host drivers, some existing drivers being extended to support new IP versions and lots of other updates. MMC core: - Delete eMMC packed command support - Introduce mmc_abort_tuning() to enable eMMC tuning to fail gracefully - Introduce mmc_can_retune() to see if a host can be retuned - Re-work and improve the sequence when sending a CMD6 for mmc - Enable CDM13 polling when switching to HS and HS DDR mode for mmc - Relax checking for CMD6 errors after switch to HS200 - Re-factoring the code dealing with the mmc block queue - Recognize whether the eMMC card supports CMDQ - Fix 4K native sector check - Don't power off the card when starting the host - Increase MMC_IOC_MAX_BYTES to support bigger firmware binaries - Improve error handling and drop meaningless BUG_ONs() - Lots of clean-ups and changes to improve the quality of the code MMC host: - sdhci: Fix tuning sequence and clean-up the related code - sdhci: Add support to via DT override broken SDHCI cap register bits - sdhci-cadence: Add new driver for Cadence SD4HC SDHCI variant - sdhci-msm: Update clock management - sdhci-msm: Add support for eMMC HS400 mode - sdhci-msm: Deploy runtime/system PM support - sdhci-iproc: Extend driver support to newer IP versions - sdhci-pci: Add support for Intel GLK - sdhci-pci: Add support for Intel NI byt sdio - sdhci-acpi: Add support for 80860F14 UID 2 SDIO bus - sdhci: Lots of various small improvements and clean-ups - tmio: Add support for tuning - sh_mobile_sdhi: Add support for tuning - sh_mobile_sdhi: Extend driver to support SDHI IP on R7S72100 SoC - sh_mobile_sdhi: remove support for sh7372 - davinci: Use mmc_of_parse() to enable generic mmc DT bindings - meson: Add new driver to support GX platforms - dw_mmc: Deploy generic runtime/system PM support - dw_mmc: Lots of various small improvements As a part of the mmc changes this time, I have also pulled in an immutable branch/tag (soc-device-match-tag1) hosted by Geert Uytterhoeven, to share the implementation of the new soc_device_match() interface. This is needed by these mmc related changes: - mmc: sdhci-of-esdhc: Get correct IP version for T4240-R1.0-R2.0 - soc: fsl: add GUTS driver for QorIQ platforms" * tag 'mmc-v4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc: (136 commits) mmc: sdhci-cadence: add Cadence SD4HC support mmc: sdhci: export sdhci_execute_tuning() mmc: sdhci: Tidy tuning loop mmc: sdhci: Simplify tuning block size logic mmc: sdhci: Factor out tuning helper functions mmc: sdhci: Use mmc_abort_tuning() mmc: mmc: Introduce mmc_abort_tuning() mmc: sdhci: Always allow tuning to fall back to fixed sampling mmc: sdhci: Fix tuning reset after exhausting the maximum number of loops mmc: sdhci: Fix recovery from tuning timeout Revert "mmc: sdhci: Reset cmd and data circuits after tuning failure" mmc: mmc: Relax checking for switch errors after HS200 switch mmc: sdhci-acpi: support 80860F14 UID 2 SDIO bus mmc: sdhci-of-at91: remove bogus MMC_SDHCI_IO_ACCESSORS select mmc: sdhci-pci: Use ACPI to get max frequency for Intel NI byt sdio mmc: sdhci-pci: Add PCI ID for Intel NI byt sdio mmc: sdhci-s3c: add spin_unlock_irq() before calling clk_round_rate mmc: dw_mmc: display the clock message only one time when card is polling mmc: dw_mmc: add the debug message for polling and non-removable mmc: dw_mmc: check the "present" variable before checking flags ...
-rw-r--r--Documentation/devicetree/bindings/mmc/amlogic,meson-gx.txt32
-rw-r--r--Documentation/devicetree/bindings/mmc/brcm,sdhci-iproc.txt9
-rw-r--r--Documentation/devicetree/bindings/mmc/renesas,mmcif.txt3
-rw-r--r--Documentation/devicetree/bindings/mmc/sdhci-cadence.txt30
-rw-r--r--Documentation/devicetree/bindings/mmc/sdhci-msm.txt1
-rw-r--r--Documentation/devicetree/bindings/mmc/sdhci.txt13
-rw-r--r--Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt8
-rw-r--r--Documentation/devicetree/bindings/mmc/tmio_mmc.txt2
-rw-r--r--Documentation/devicetree/bindings/soc/fsl/guts.txt (renamed from Documentation/devicetree/bindings/powerpc/fsl/guts.txt)3
-rw-r--r--MAINTAINERS12
-rw-r--r--arch/arm64/boot/dts/freescale/fsl-ls2080a.dtsi6
-rw-r--r--drivers/base/Kconfig1
-rw-r--r--drivers/base/soc.c79
-rw-r--r--drivers/mmc/card/block.c499
-rw-r--r--drivers/mmc/card/mmc_test.c58
-rw-r--r--drivers/mmc/card/queue.c312
-rw-r--r--drivers/mmc/card/queue.h29
-rw-r--r--drivers/mmc/card/sdio_uart.c2
-rw-r--r--drivers/mmc/core/core.c97
-rw-r--r--drivers/mmc/core/debugfs.c6
-rw-r--r--drivers/mmc/core/mmc.c113
-rw-r--r--drivers/mmc/core/mmc_ops.c220
-rw-r--r--drivers/mmc/core/mmc_ops.h7
-rw-r--r--drivers/mmc/core/sd.c14
-rw-r--r--drivers/mmc/core/sd_ops.c27
-rw-r--r--drivers/mmc/core/sdio.c17
-rw-r--r--drivers/mmc/core/sdio_cis.c3
-rw-r--r--drivers/mmc/core/sdio_irq.c12
-rw-r--r--drivers/mmc/core/slot-gpio.c8
-rw-r--r--drivers/mmc/host/Kconfig23
-rw-r--r--drivers/mmc/host/Makefile2
-rw-r--r--drivers/mmc/host/davinci_mmc.c130
-rw-r--r--drivers/mmc/host/dw_mmc-exynos.c52
-rw-r--r--drivers/mmc/host/dw_mmc-k3.c39
-rw-r--r--drivers/mmc/host/dw_mmc-pci.c29
-rw-r--r--drivers/mmc/host/dw_mmc-pltfm.c28
-rw-r--r--drivers/mmc/host/dw_mmc-rockchip.c42
-rw-r--r--drivers/mmc/host/dw_mmc.c181
-rw-r--r--drivers/mmc/host/dw_mmc.h7
-rw-r--r--drivers/mmc/host/jz4740_mmc.c3
-rw-r--r--drivers/mmc/host/meson-gx-mmc.c851
-rw-r--r--drivers/mmc/host/mmci.c128
-rw-r--r--drivers/mmc/host/mmci.h71
-rw-r--r--drivers/mmc/host/mtk-sd.c4
-rw-r--r--drivers/mmc/host/omap_hsmmc.c3
-rw-r--r--drivers/mmc/host/rtsx_pci_sdmmc.c3
-rw-r--r--drivers/mmc/host/rtsx_usb_sdmmc.c3
-rw-r--r--drivers/mmc/host/s3cmci.c15
-rw-r--r--drivers/mmc/host/sdhci-acpi.c1
-rw-r--r--drivers/mmc/host/sdhci-cadence.c283
-rw-r--r--drivers/mmc/host/sdhci-iproc.c35
-rw-r--r--drivers/mmc/host/sdhci-msm.c694
-rw-r--r--drivers/mmc/host/sdhci-of-at91.c1
-rw-r--r--drivers/mmc/host/sdhci-of-esdhc.c20
-rw-r--r--drivers/mmc/host/sdhci-pci-core.c98
-rw-r--r--drivers/mmc/host/sdhci-pci.h3
-rw-r--r--drivers/mmc/host/sdhci-pltfm.h2
-rw-r--r--drivers/mmc/host/sdhci-s3c.c2
-rw-r--r--drivers/mmc/host/sdhci.c362
-rw-r--r--drivers/mmc/host/sdhci.h4
-rw-r--r--drivers/mmc/host/sh_mobile_sdhi.c274
-rw-r--r--drivers/mmc/host/sunxi-mmc.c15
-rw-r--r--drivers/mmc/host/tmio_mmc.h32
-rw-r--r--drivers/mmc/host/tmio_mmc_pio.c119
-rw-r--r--drivers/mmc/host/wbsd.c11
-rw-r--r--drivers/soc/Kconfig3
-rw-r--r--drivers/soc/fsl/Kconfig18
-rw-r--r--drivers/soc/fsl/Makefile1
-rw-r--r--drivers/soc/fsl/guts.c239
-rw-r--r--include/linux/fsl/guts.h125
-rw-r--r--include/linux/mfd/tmio.h5
-rw-r--r--include/linux/mmc/card.h14
-rw-r--r--include/linux/mmc/core.h16
-rw-r--r--include/linux/mmc/dw_mmc.h6
-rw-r--r--include/linux/mmc/host.h17
-rw-r--r--include/linux/mmc/mmc.h17
-rw-r--r--include/linux/mmc/slot-gpio.h1
-rw-r--r--include/linux/sys_soc.h9
-rw-r--r--include/uapi/linux/mmc/ioctl.h2
79 files changed, 4092 insertions, 1574 deletions
diff --git a/Documentation/devicetree/bindings/mmc/amlogic,meson-gx.txt b/Documentation/devicetree/bindings/mmc/amlogic,meson-gx.txt
new file mode 100644
index 000000000000..7f95ec400863
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/amlogic,meson-gx.txt
@@ -0,0 +1,32 @@
1Amlogic SD / eMMC controller for S905/GXBB family SoCs
2
3The MMC 5.1 compliant host controller on Amlogic provides the
4interface for SD, eMMC and SDIO devices.
5
6This file documents the properties in addition to those available in
7the MMC core bindings, documented by mmc.txt.
8
9Required properties:
10- compatible : contains one of:
11 - "amlogic,meson-gx-mmc"
12 - "amlogic,meson-gxbb-mmc"
13 - "amlogic,meson-gxl-mmc"
14 - "amlogic,meson-gxm-mmc"
15- clocks : A list of phandle + clock-specifier pairs for the clocks listed in clock-names.
16- clock-names: Should contain the following:
17 "core" - Main peripheral bus clock
18 "clkin0" - Parent clock of internal mux
19 "clkin1" - Other parent clock of internal mux
20 The driver has an interal mux clock which switches between clkin0 and clkin1 depending on the
21 clock rate requested by the MMC core.
22
23Example:
24
25 sd_emmc_a: mmc@70000 {
26 compatible = "amlogic,meson-gxbb-mmc";
27 reg = <0x0 0x70000 0x0 0x2000>;
28 interrupts = < GIC_SPI 216 IRQ_TYPE_EDGE_RISING>;
29 clocks = <&clkc CLKID_SD_EMMC_A>, <&xtal>, <&clkc CLKID_FCLK_DIV2>;
30 clock-names = "core", "clkin0", "clkin1";
31 pinctrl-0 = <&emmc_pins>;
32 };
diff --git a/Documentation/devicetree/bindings/mmc/brcm,sdhci-iproc.txt b/Documentation/devicetree/bindings/mmc/brcm,sdhci-iproc.txt
index be56d2bd474a..954561d09a8e 100644
--- a/Documentation/devicetree/bindings/mmc/brcm,sdhci-iproc.txt
+++ b/Documentation/devicetree/bindings/mmc/brcm,sdhci-iproc.txt
@@ -7,6 +7,15 @@ Required properties:
7- compatible : Should be one of the following 7- compatible : Should be one of the following
8 "brcm,bcm2835-sdhci" 8 "brcm,bcm2835-sdhci"
9 "brcm,sdhci-iproc-cygnus" 9 "brcm,sdhci-iproc-cygnus"
10 "brcm,sdhci-iproc"
11
12Use brcm2835-sdhci for Rasperry PI.
13
14Use sdhci-iproc-cygnus for Broadcom SDHCI Controllers
15restricted to 32bit host accesses to SDHCI registers.
16
17Use sdhci-iproc for Broadcom SDHCI Controllers that allow standard
188, 16, 32-bit host access to SDHCI register.
10 19
11- clocks : The clock feeding the SDHCI controller. 20- clocks : The clock feeding the SDHCI controller.
12 21
diff --git a/Documentation/devicetree/bindings/mmc/renesas,mmcif.txt b/Documentation/devicetree/bindings/mmc/renesas,mmcif.txt
index ff611fa66871..e4ba92aa035e 100644
--- a/Documentation/devicetree/bindings/mmc/renesas,mmcif.txt
+++ b/Documentation/devicetree/bindings/mmc/renesas,mmcif.txt
@@ -8,11 +8,14 @@ Required properties:
8 8
9- compatible: should be "renesas,mmcif-<soctype>", "renesas,sh-mmcif" as a 9- compatible: should be "renesas,mmcif-<soctype>", "renesas,sh-mmcif" as a
10 fallback. Examples with <soctype> are: 10 fallback. Examples with <soctype> are:
11 - "renesas,mmcif-r8a73a4" for the MMCIF found in r8a73a4 SoCs
11 - "renesas,mmcif-r8a7740" for the MMCIF found in r8a7740 SoCs 12 - "renesas,mmcif-r8a7740" for the MMCIF found in r8a7740 SoCs
13 - "renesas,mmcif-r8a7778" for the MMCIF found in r8a7778 SoCs
12 - "renesas,mmcif-r8a7790" for the MMCIF found in r8a7790 SoCs 14 - "renesas,mmcif-r8a7790" for the MMCIF found in r8a7790 SoCs
13 - "renesas,mmcif-r8a7791" for the MMCIF found in r8a7791 SoCs 15 - "renesas,mmcif-r8a7791" for the MMCIF found in r8a7791 SoCs
14 - "renesas,mmcif-r8a7793" for the MMCIF found in r8a7793 SoCs 16 - "renesas,mmcif-r8a7793" for the MMCIF found in r8a7793 SoCs
15 - "renesas,mmcif-r8a7794" for the MMCIF found in r8a7794 SoCs 17 - "renesas,mmcif-r8a7794" for the MMCIF found in r8a7794 SoCs
18 - "renesas,mmcif-sh73a0" for the MMCIF found in sh73a0 SoCs
16 19
17- clocks: reference to the functional clock 20- clocks: reference to the functional clock
18 21
diff --git a/Documentation/devicetree/bindings/mmc/sdhci-cadence.txt b/Documentation/devicetree/bindings/mmc/sdhci-cadence.txt
new file mode 100644
index 000000000000..750374fc9d94
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/sdhci-cadence.txt
@@ -0,0 +1,30 @@
1* Cadence SD/SDIO/eMMC Host Controller
2
3Required properties:
4- compatible: should be "cdns,sd4hc".
5- reg: offset and length of the register set for the device.
6- interrupts: a single interrupt specifier.
7- clocks: phandle to the input clock.
8
9Optional properties:
10For eMMC configuration, supported speed modes are not indicated by the SDHCI
11Capabilities Register. Instead, the following properties should be specified
12if supported. See mmc.txt for details.
13- mmc-ddr-1_8v
14- mmc-ddr-1_2v
15- mmc-hs200-1_8v
16- mmc-hs200-1_2v
17- mmc-hs400-1_8v
18- mmc-hs400-1_2v
19
20Example:
21 emmc: sdhci@5a000000 {
22 compatible = "cdns,sd4hc";
23 reg = <0x5a000000 0x400>;
24 interrupts = <0 78 4>;
25 clocks = <&clk 4>;
26 bus-width = <8>;
27 mmc-ddr-1_8v;
28 mmc-hs200-1_8v;
29 mmc-hs400-1_8v;
30 };
diff --git a/Documentation/devicetree/bindings/mmc/sdhci-msm.txt b/Documentation/devicetree/bindings/mmc/sdhci-msm.txt
index 485483a63d8c..0576264eab5e 100644
--- a/Documentation/devicetree/bindings/mmc/sdhci-msm.txt
+++ b/Documentation/devicetree/bindings/mmc/sdhci-msm.txt
@@ -17,6 +17,7 @@ Required properties:
17 "iface" - Main peripheral bus clock (PCLK/HCLK - AHB Bus clock) (required) 17 "iface" - Main peripheral bus clock (PCLK/HCLK - AHB Bus clock) (required)
18 "core" - SDC MMC clock (MCLK) (required) 18 "core" - SDC MMC clock (MCLK) (required)
19 "bus" - SDCC bus voter clock (optional) 19 "bus" - SDCC bus voter clock (optional)
20 "xo" - TCXO clock (optional)
20 21
21Example: 22Example:
22 23
diff --git a/Documentation/devicetree/bindings/mmc/sdhci.txt b/Documentation/devicetree/bindings/mmc/sdhci.txt
new file mode 100644
index 000000000000..1c95a1a555c3
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/sdhci.txt
@@ -0,0 +1,13 @@
1The properties specific for SD host controllers. For properties shared by MMC
2host controllers refer to the mmc[1] bindings.
3
4 [1] Documentation/devicetree/bindings/mmc/mmc.txt
5
6Optional properties:
7- sdhci-caps-mask: The sdhci capabilities register is incorrect. This 64bit
8 property corresponds to the bits in the sdhci capabilty register. If the bit
9 is on in the mask then the bit is incorrect in the register and should be
10 turned off, before applying sdhci-caps.
11- sdhci-caps: The sdhci capabilities register is incorrect. This 64bit
12 property corresponds to the bits in the sdhci capability register. If the
13 bit is on in the property then the bit should be turned on.
diff --git a/Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt b/Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt
index bfa461aaac99..7fd17c3da116 100644
--- a/Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt
+++ b/Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt
@@ -59,8 +59,9 @@ Optional properties:
59 is specified and the ciu clock is specified then we'll try to set the ciu 59 is specified and the ciu clock is specified then we'll try to set the ciu
60 clock to this at probe time. 60 clock to this at probe time.
61 61
62* clock-freq-min-max: Minimum and Maximum clock frequency for card output 62* clock-freq-min-max (DEPRECATED): Minimum and Maximum clock frequency for card output
63 clock(cclk_out). If it's not specified, max is 200MHZ and min is 400KHz by default. 63 clock(cclk_out). If it's not specified, max is 200MHZ and min is 400KHz by default.
64 (Use the "max-frequency" instead of "clock-freq-min-max".)
64 65
65* num-slots: specifies the number of slots supported by the controller. 66* num-slots: specifies the number of slots supported by the controller.
66 The number of physical slots actually used could be equal or less than the 67 The number of physical slots actually used could be equal or less than the
@@ -74,11 +75,6 @@ Optional properties:
74* card-detect-delay: Delay in milli-seconds before detecting card after card 75* card-detect-delay: Delay in milli-seconds before detecting card after card
75 insert event. The default value is 0. 76 insert event. The default value is 0.
76 77
77* supports-highspeed (DEPRECATED): Enables support for high speed cards (up to 50MHz)
78 (use "cap-mmc-highspeed" or "cap-sd-highspeed" instead)
79
80* broken-cd: as documented in mmc core bindings.
81
82* vmmc-supply: The phandle to the regulator to use for vmmc. If this is 78* vmmc-supply: The phandle to the regulator to use for vmmc. If this is
83 specified we'll defer probe until we can find this regulator. 79 specified we'll defer probe until we can find this regulator.
84 80
diff --git a/Documentation/devicetree/bindings/mmc/tmio_mmc.txt b/Documentation/devicetree/bindings/mmc/tmio_mmc.txt
index 13df9c2399c3..a1650edfd2b7 100644
--- a/Documentation/devicetree/bindings/mmc/tmio_mmc.txt
+++ b/Documentation/devicetree/bindings/mmc/tmio_mmc.txt
@@ -11,8 +11,8 @@ optional bindings can be used.
11 11
12Required properties: 12Required properties:
13- compatible: "renesas,sdhi-shmobile" - a generic sh-mobile SDHI unit 13- compatible: "renesas,sdhi-shmobile" - a generic sh-mobile SDHI unit
14 "renesas,sdhi-sh7372" - SDHI IP on SH7372 SoC
15 "renesas,sdhi-sh73a0" - SDHI IP on SH73A0 SoC 14 "renesas,sdhi-sh73a0" - SDHI IP on SH73A0 SoC
15 "renesas,sdhi-r7s72100" - SDHI IP on R7S72100 SoC
16 "renesas,sdhi-r8a73a4" - SDHI IP on R8A73A4 SoC 16 "renesas,sdhi-r8a73a4" - SDHI IP on R8A73A4 SoC
17 "renesas,sdhi-r8a7740" - SDHI IP on R8A7740 SoC 17 "renesas,sdhi-r8a7740" - SDHI IP on R8A7740 SoC
18 "renesas,sdhi-r8a7778" - SDHI IP on R8A7778 SoC 18 "renesas,sdhi-r8a7778" - SDHI IP on R8A7778 SoC
diff --git a/Documentation/devicetree/bindings/powerpc/fsl/guts.txt b/Documentation/devicetree/bindings/soc/fsl/guts.txt
index b71b2039e112..07adca914d3d 100644
--- a/Documentation/devicetree/bindings/powerpc/fsl/guts.txt
+++ b/Documentation/devicetree/bindings/soc/fsl/guts.txt
@@ -25,6 +25,9 @@ Recommended properties:
25 - fsl,liodn-bits : Indicates the number of defined bits in the LIODN 25 - fsl,liodn-bits : Indicates the number of defined bits in the LIODN
26 registers, for those SOCs that have a PAMU device. 26 registers, for those SOCs that have a PAMU device.
27 27
28 - little-endian : Indicates that the global utilities block is little
29 endian. The default is big endian.
30
28Examples: 31Examples:
29 global-utilities@e0000 { /* global utilities block */ 32 global-utilities@e0000 { /* global utilities block */
30 compatible = "fsl,mpc8548-guts"; 33 compatible = "fsl,mpc8548-guts";
diff --git a/MAINTAINERS b/MAINTAINERS
index d04335080cdd..ef461e087275 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1052,6 +1052,7 @@ F: arch/arm/mach-meson/
1052F: arch/arm/boot/dts/meson* 1052F: arch/arm/boot/dts/meson*
1053F: arch/arm64/boot/dts/amlogic/ 1053F: arch/arm64/boot/dts/amlogic/
1054F: drivers/pinctrl/meson/ 1054F: drivers/pinctrl/meson/
1055F: drivers/mmc/host/meson*
1055N: meson 1056N: meson
1056 1057
1057ARM/Annapurna Labs ALPINE ARCHITECTURE 1058ARM/Annapurna Labs ALPINE ARCHITECTURE
@@ -5068,9 +5069,18 @@ S: Maintained
5068F: drivers/net/ethernet/freescale/fman 5069F: drivers/net/ethernet/freescale/fman
5069F: Documentation/devicetree/bindings/powerpc/fsl/fman.txt 5070F: Documentation/devicetree/bindings/powerpc/fsl/fman.txt
5070 5071
5072FREESCALE SOC DRIVERS
5073M: Scott Wood <oss@buserror.net>
5074L: linuxppc-dev@lists.ozlabs.org
5075L: linux-arm-kernel@lists.infradead.org
5076S: Maintained
5077F: drivers/soc/fsl/
5078F: include/linux/fsl/
5079
5071FREESCALE QUICC ENGINE LIBRARY 5080FREESCALE QUICC ENGINE LIBRARY
5081M: Qiang Zhao <qiang.zhao@nxp.com>
5072L: linuxppc-dev@lists.ozlabs.org 5082L: linuxppc-dev@lists.ozlabs.org
5073S: Orphan 5083S: Maintained
5074F: drivers/soc/fsl/qe/ 5084F: drivers/soc/fsl/qe/
5075F: include/soc/fsl/*qe*.h 5085F: include/soc/fsl/*qe*.h
5076F: include/soc/fsl/*ucc*.h 5086F: include/soc/fsl/*ucc*.h
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls2080a.dtsi b/arch/arm64/boot/dts/freescale/fsl-ls2080a.dtsi
index 7f0dc13b4087..d058e56db72d 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls2080a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls2080a.dtsi
@@ -216,6 +216,12 @@
216 clocks = <&sysclk>; 216 clocks = <&sysclk>;
217 }; 217 };
218 218
219 dcfg: dcfg@1e00000 {
220 compatible = "fsl,ls2080a-dcfg", "syscon";
221 reg = <0x0 0x1e00000 0x0 0x10000>;
222 little-endian;
223 };
224
219 serial0: serial@21c0500 { 225 serial0: serial@21c0500 {
220 compatible = "fsl,ns16550", "ns16550a"; 226 compatible = "fsl,ns16550", "ns16550a";
221 reg = <0x0 0x21c0500 0x0 0x100>; 227 reg = <0x0 0x21c0500 0x0 0x100>;
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index d02e7c0f5bfd..2abea876c0a0 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -237,6 +237,7 @@ config GENERIC_CPU_AUTOPROBE
237 237
238config SOC_BUS 238config SOC_BUS
239 bool 239 bool
240 select GLOB
240 241
241source "drivers/base/regmap/Kconfig" 242source "drivers/base/regmap/Kconfig"
242 243
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index b63f23e6ad61..dc26e5949a32 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -13,6 +13,7 @@
13#include <linux/spinlock.h> 13#include <linux/spinlock.h>
14#include <linux/sys_soc.h> 14#include <linux/sys_soc.h>
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/glob.h>
16 17
17static DEFINE_IDA(soc_ida); 18static DEFINE_IDA(soc_ida);
18 19
@@ -113,6 +114,12 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
113 struct soc_device *soc_dev; 114 struct soc_device *soc_dev;
114 int ret; 115 int ret;
115 116
117 if (!soc_bus_type.p) {
118 ret = bus_register(&soc_bus_type);
119 if (ret)
120 goto out1;
121 }
122
116 soc_dev = kzalloc(sizeof(*soc_dev), GFP_KERNEL); 123 soc_dev = kzalloc(sizeof(*soc_dev), GFP_KERNEL);
117 if (!soc_dev) { 124 if (!soc_dev) {
118 ret = -ENOMEM; 125 ret = -ENOMEM;
@@ -156,6 +163,78 @@ void soc_device_unregister(struct soc_device *soc_dev)
156 163
157static int __init soc_bus_register(void) 164static int __init soc_bus_register(void)
158{ 165{
166 if (soc_bus_type.p)
167 return 0;
168
159 return bus_register(&soc_bus_type); 169 return bus_register(&soc_bus_type);
160} 170}
161core_initcall(soc_bus_register); 171core_initcall(soc_bus_register);
172
173static int soc_device_match_one(struct device *dev, void *arg)
174{
175 struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
176 const struct soc_device_attribute *match = arg;
177
178 if (match->machine &&
179 (!soc_dev->attr->machine ||
180 !glob_match(match->machine, soc_dev->attr->machine)))
181 return 0;
182
183 if (match->family &&
184 (!soc_dev->attr->family ||
185 !glob_match(match->family, soc_dev->attr->family)))
186 return 0;
187
188 if (match->revision &&
189 (!soc_dev->attr->revision ||
190 !glob_match(match->revision, soc_dev->attr->revision)))
191 return 0;
192
193 if (match->soc_id &&
194 (!soc_dev->attr->soc_id ||
195 !glob_match(match->soc_id, soc_dev->attr->soc_id)))
196 return 0;
197
198 return 1;
199}
200
201/*
202 * soc_device_match - identify the SoC in the machine
203 * @matches: zero-terminated array of possible matches
204 *
205 * returns the first matching entry of the argument array, or NULL
206 * if none of them match.
207 *
208 * This function is meant as a helper in place of of_match_node()
209 * in cases where either no device tree is available or the information
210 * in a device node is insufficient to identify a particular variant
211 * by its compatible strings or other properties. For new devices,
212 * the DT binding should always provide unique compatible strings
213 * that allow the use of of_match_node() instead.
214 *
215 * The calling function can use the .data entry of the
216 * soc_device_attribute to pass a structure or function pointer for
217 * each entry.
218 */
219const struct soc_device_attribute *soc_device_match(
220 const struct soc_device_attribute *matches)
221{
222 int ret = 0;
223
224 if (!matches)
225 return NULL;
226
227 while (!ret) {
228 if (!(matches->machine || matches->family ||
229 matches->revision || matches->soc_id))
230 break;
231 ret = bus_for_each_dev(&soc_bus_type, NULL, (void *)matches,
232 soc_device_match_one);
233 if (!ret)
234 matches++;
235 else
236 return matches;
237 }
238 return NULL;
239}
240EXPORT_SYMBOL_GPL(soc_device_match);
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 709a872ed484..646d1a1fa6ca 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -66,9 +66,6 @@ MODULE_ALIAS("mmc:block");
66 66
67#define mmc_req_rel_wr(req) ((req->cmd_flags & REQ_FUA) && \ 67#define mmc_req_rel_wr(req) ((req->cmd_flags & REQ_FUA) && \
68 (rq_data_dir(req) == WRITE)) 68 (rq_data_dir(req) == WRITE))
69#define PACKED_CMD_VER 0x01
70#define PACKED_CMD_WR 0x02
71
72static DEFINE_MUTEX(block_mutex); 69static DEFINE_MUTEX(block_mutex);
73 70
74/* 71/*
@@ -102,7 +99,6 @@ struct mmc_blk_data {
102 unsigned int flags; 99 unsigned int flags;
103#define MMC_BLK_CMD23 (1 << 0) /* Can do SET_BLOCK_COUNT for multiblock */ 100#define MMC_BLK_CMD23 (1 << 0) /* Can do SET_BLOCK_COUNT for multiblock */
104#define MMC_BLK_REL_WR (1 << 1) /* MMC Reliable write support */ 101#define MMC_BLK_REL_WR (1 << 1) /* MMC Reliable write support */
105#define MMC_BLK_PACKED_CMD (1 << 2) /* MMC packed command support */
106 102
107 unsigned int usage; 103 unsigned int usage;
108 unsigned int read_only; 104 unsigned int read_only;
@@ -126,12 +122,6 @@ struct mmc_blk_data {
126 122
127static DEFINE_MUTEX(open_lock); 123static DEFINE_MUTEX(open_lock);
128 124
129enum {
130 MMC_PACKED_NR_IDX = -1,
131 MMC_PACKED_NR_ZERO,
132 MMC_PACKED_NR_SINGLE,
133};
134
135module_param(perdev_minors, int, 0444); 125module_param(perdev_minors, int, 0444);
136MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device"); 126MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device");
137 127
@@ -139,17 +129,6 @@ static inline int mmc_blk_part_switch(struct mmc_card *card,
139 struct mmc_blk_data *md); 129 struct mmc_blk_data *md);
140static int get_card_status(struct mmc_card *card, u32 *status, int retries); 130static int get_card_status(struct mmc_card *card, u32 *status, int retries);
141 131
142static inline void mmc_blk_clear_packed(struct mmc_queue_req *mqrq)
143{
144 struct mmc_packed *packed = mqrq->packed;
145
146 mqrq->cmd_type = MMC_PACKED_NONE;
147 packed->nr_entries = MMC_PACKED_NR_ZERO;
148 packed->idx_failure = MMC_PACKED_NR_IDX;
149 packed->retries = 0;
150 packed->blocks = 0;
151}
152
153static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk) 132static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk)
154{ 133{
155 struct mmc_blk_data *md; 134 struct mmc_blk_data *md;
@@ -854,7 +833,7 @@ static int get_card_status(struct mmc_card *card, u32 *status, int retries)
854} 833}
855 834
856static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms, 835static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms,
857 bool hw_busy_detect, struct request *req, int *gen_err) 836 bool hw_busy_detect, struct request *req, bool *gen_err)
858{ 837{
859 unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms); 838 unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
860 int err = 0; 839 int err = 0;
@@ -871,7 +850,7 @@ static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms,
871 if (status & R1_ERROR) { 850 if (status & R1_ERROR) {
872 pr_err("%s: %s: error sending status cmd, status %#x\n", 851 pr_err("%s: %s: error sending status cmd, status %#x\n",
873 req->rq_disk->disk_name, __func__, status); 852 req->rq_disk->disk_name, __func__, status);
874 *gen_err = 1; 853 *gen_err = true;
875 } 854 }
876 855
877 /* We may rely on the host hw to handle busy detection.*/ 856 /* We may rely on the host hw to handle busy detection.*/
@@ -902,7 +881,7 @@ static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms,
902} 881}
903 882
904static int send_stop(struct mmc_card *card, unsigned int timeout_ms, 883static int send_stop(struct mmc_card *card, unsigned int timeout_ms,
905 struct request *req, int *gen_err, u32 *stop_status) 884 struct request *req, bool *gen_err, u32 *stop_status)
906{ 885{
907 struct mmc_host *host = card->host; 886 struct mmc_host *host = card->host;
908 struct mmc_command cmd = {0}; 887 struct mmc_command cmd = {0};
@@ -940,7 +919,7 @@ static int send_stop(struct mmc_card *card, unsigned int timeout_ms,
940 (*stop_status & R1_ERROR)) { 919 (*stop_status & R1_ERROR)) {
941 pr_err("%s: %s: general error sending stop command, resp %#x\n", 920 pr_err("%s: %s: general error sending stop command, resp %#x\n",
942 req->rq_disk->disk_name, __func__, *stop_status); 921 req->rq_disk->disk_name, __func__, *stop_status);
943 *gen_err = 1; 922 *gen_err = true;
944 } 923 }
945 924
946 return card_busy_detect(card, timeout_ms, use_r1b_resp, req, gen_err); 925 return card_busy_detect(card, timeout_ms, use_r1b_resp, req, gen_err);
@@ -1014,7 +993,7 @@ static int mmc_blk_cmd_error(struct request *req, const char *name, int error,
1014 * Otherwise we don't understand what happened, so abort. 993 * Otherwise we don't understand what happened, so abort.
1015 */ 994 */
1016static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req, 995static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
1017 struct mmc_blk_request *brq, int *ecc_err, int *gen_err) 996 struct mmc_blk_request *brq, bool *ecc_err, bool *gen_err)
1018{ 997{
1019 bool prev_cmd_status_valid = true; 998 bool prev_cmd_status_valid = true;
1020 u32 status, stop_status = 0; 999 u32 status, stop_status = 0;
@@ -1053,7 +1032,7 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
1053 if ((status & R1_CARD_ECC_FAILED) || 1032 if ((status & R1_CARD_ECC_FAILED) ||
1054 (brq->stop.resp[0] & R1_CARD_ECC_FAILED) || 1033 (brq->stop.resp[0] & R1_CARD_ECC_FAILED) ||
1055 (brq->cmd.resp[0] & R1_CARD_ECC_FAILED)) 1034 (brq->cmd.resp[0] & R1_CARD_ECC_FAILED))
1056 *ecc_err = 1; 1035 *ecc_err = true;
1057 1036
1058 /* Flag General errors */ 1037 /* Flag General errors */
1059 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) 1038 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ)
@@ -1062,7 +1041,7 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
1062 pr_err("%s: %s: general error sending stop or status command, stop cmd response %#x, card status %#x\n", 1041 pr_err("%s: %s: general error sending stop or status command, stop cmd response %#x, card status %#x\n",
1063 req->rq_disk->disk_name, __func__, 1042 req->rq_disk->disk_name, __func__,
1064 brq->stop.resp[0], status); 1043 brq->stop.resp[0], status);
1065 *gen_err = 1; 1044 *gen_err = true;
1066 } 1045 }
1067 1046
1068 /* 1047 /*
@@ -1085,7 +1064,7 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
1085 } 1064 }
1086 1065
1087 if (stop_status & R1_CARD_ECC_FAILED) 1066 if (stop_status & R1_CARD_ECC_FAILED)
1088 *ecc_err = 1; 1067 *ecc_err = true;
1089 } 1068 }
1090 1069
1091 /* Check for set block count errors */ 1070 /* Check for set block count errors */
@@ -1154,7 +1133,7 @@ static inline void mmc_blk_reset_success(struct mmc_blk_data *md, int type)
1154 1133
1155int mmc_access_rpmb(struct mmc_queue *mq) 1134int mmc_access_rpmb(struct mmc_queue *mq)
1156{ 1135{
1157 struct mmc_blk_data *md = mq->data; 1136 struct mmc_blk_data *md = mq->blkdata;
1158 /* 1137 /*
1159 * If this is a RPMB partition access, return ture 1138 * If this is a RPMB partition access, return ture
1160 */ 1139 */
@@ -1166,7 +1145,7 @@ int mmc_access_rpmb(struct mmc_queue *mq)
1166 1145
1167static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req) 1146static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
1168{ 1147{
1169 struct mmc_blk_data *md = mq->data; 1148 struct mmc_blk_data *md = mq->blkdata;
1170 struct mmc_card *card = md->queue.card; 1149 struct mmc_card *card = md->queue.card;
1171 unsigned int from, nr, arg; 1150 unsigned int from, nr, arg;
1172 int err = 0, type = MMC_BLK_DISCARD; 1151 int err = 0, type = MMC_BLK_DISCARD;
@@ -1210,7 +1189,7 @@ out:
1210static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq, 1189static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
1211 struct request *req) 1190 struct request *req)
1212{ 1191{
1213 struct mmc_blk_data *md = mq->data; 1192 struct mmc_blk_data *md = mq->blkdata;
1214 struct mmc_card *card = md->queue.card; 1193 struct mmc_card *card = md->queue.card;
1215 unsigned int from, nr, arg; 1194 unsigned int from, nr, arg;
1216 int err = 0, type = MMC_BLK_SECDISCARD; 1195 int err = 0, type = MMC_BLK_SECDISCARD;
@@ -1276,7 +1255,7 @@ out:
1276 1255
1277static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req) 1256static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req)
1278{ 1257{
1279 struct mmc_blk_data *md = mq->data; 1258 struct mmc_blk_data *md = mq->blkdata;
1280 struct mmc_card *card = md->queue.card; 1259 struct mmc_card *card = md->queue.card;
1281 int ret = 0; 1260 int ret = 0;
1282 1261
@@ -1320,15 +1299,16 @@ static inline void mmc_apply_rel_rw(struct mmc_blk_request *brq,
1320 R1_CC_ERROR | /* Card controller error */ \ 1299 R1_CC_ERROR | /* Card controller error */ \
1321 R1_ERROR) /* General/unknown error */ 1300 R1_ERROR) /* General/unknown error */
1322 1301
1323static int mmc_blk_err_check(struct mmc_card *card, 1302static enum mmc_blk_status mmc_blk_err_check(struct mmc_card *card,
1324 struct mmc_async_req *areq) 1303 struct mmc_async_req *areq)
1325{ 1304{
1326 struct mmc_queue_req *mq_mrq = container_of(areq, struct mmc_queue_req, 1305 struct mmc_queue_req *mq_mrq = container_of(areq, struct mmc_queue_req,
1327 mmc_active); 1306 mmc_active);
1328 struct mmc_blk_request *brq = &mq_mrq->brq; 1307 struct mmc_blk_request *brq = &mq_mrq->brq;
1329 struct request *req = mq_mrq->req; 1308 struct request *req = mq_mrq->req;
1330 int need_retune = card->host->need_retune; 1309 int need_retune = card->host->need_retune;
1331 int ecc_err = 0, gen_err = 0; 1310 bool ecc_err = false;
1311 bool gen_err = false;
1332 1312
1333 /* 1313 /*
1334 * sbc.error indicates a problem with the set block count 1314 * sbc.error indicates a problem with the set block count
@@ -1378,7 +1358,7 @@ static int mmc_blk_err_check(struct mmc_card *card,
1378 pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n", 1358 pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n",
1379 req->rq_disk->disk_name, __func__, 1359 req->rq_disk->disk_name, __func__,
1380 brq->stop.resp[0]); 1360 brq->stop.resp[0]);
1381 gen_err = 1; 1361 gen_err = true;
1382 } 1362 }
1383 1363
1384 err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, false, req, 1364 err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, false, req,
@@ -1419,67 +1399,12 @@ static int mmc_blk_err_check(struct mmc_card *card,
1419 if (!brq->data.bytes_xfered) 1399 if (!brq->data.bytes_xfered)
1420 return MMC_BLK_RETRY; 1400 return MMC_BLK_RETRY;
1421 1401
1422 if (mmc_packed_cmd(mq_mrq->cmd_type)) {
1423 if (unlikely(brq->data.blocks << 9 != brq->data.bytes_xfered))
1424 return MMC_BLK_PARTIAL;
1425 else
1426 return MMC_BLK_SUCCESS;
1427 }
1428
1429 if (blk_rq_bytes(req) != brq->data.bytes_xfered) 1402 if (blk_rq_bytes(req) != brq->data.bytes_xfered)
1430 return MMC_BLK_PARTIAL; 1403 return MMC_BLK_PARTIAL;
1431 1404
1432 return MMC_BLK_SUCCESS; 1405 return MMC_BLK_SUCCESS;
1433} 1406}
1434 1407
1435static int mmc_blk_packed_err_check(struct mmc_card *card,
1436 struct mmc_async_req *areq)
1437{
1438 struct mmc_queue_req *mq_rq = container_of(areq, struct mmc_queue_req,
1439 mmc_active);
1440 struct request *req = mq_rq->req;
1441 struct mmc_packed *packed = mq_rq->packed;
1442 int err, check, status;
1443 u8 *ext_csd;
1444
1445 packed->retries--;
1446 check = mmc_blk_err_check(card, areq);
1447 err = get_card_status(card, &status, 0);
1448 if (err) {
1449 pr_err("%s: error %d sending status command\n",
1450 req->rq_disk->disk_name, err);
1451 return MMC_BLK_ABORT;
1452 }
1453
1454 if (status & R1_EXCEPTION_EVENT) {
1455 err = mmc_get_ext_csd(card, &ext_csd);
1456 if (err) {
1457 pr_err("%s: error %d sending ext_csd\n",
1458 req->rq_disk->disk_name, err);
1459 return MMC_BLK_ABORT;
1460 }
1461
1462 if ((ext_csd[EXT_CSD_EXP_EVENTS_STATUS] &
1463 EXT_CSD_PACKED_FAILURE) &&
1464 (ext_csd[EXT_CSD_PACKED_CMD_STATUS] &
1465 EXT_CSD_PACKED_GENERIC_ERROR)) {
1466 if (ext_csd[EXT_CSD_PACKED_CMD_STATUS] &
1467 EXT_CSD_PACKED_INDEXED_ERROR) {
1468 packed->idx_failure =
1469 ext_csd[EXT_CSD_PACKED_FAILURE_INDEX] - 1;
1470 check = MMC_BLK_PARTIAL;
1471 }
1472 pr_err("%s: packed cmd failed, nr %u, sectors %u, "
1473 "failure index: %d\n",
1474 req->rq_disk->disk_name, packed->nr_entries,
1475 packed->blocks, packed->idx_failure);
1476 }
1477 kfree(ext_csd);
1478 }
1479
1480 return check;
1481}
1482
1483static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq, 1408static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
1484 struct mmc_card *card, 1409 struct mmc_card *card,
1485 int disable_multi, 1410 int disable_multi,
@@ -1488,7 +1413,7 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
1488 u32 readcmd, writecmd; 1413 u32 readcmd, writecmd;
1489 struct mmc_blk_request *brq = &mqrq->brq; 1414 struct mmc_blk_request *brq = &mqrq->brq;
1490 struct request *req = mqrq->req; 1415 struct request *req = mqrq->req;
1491 struct mmc_blk_data *md = mq->data; 1416 struct mmc_blk_data *md = mq->blkdata;
1492 bool do_data_tag; 1417 bool do_data_tag;
1493 1418
1494 /* 1419 /*
@@ -1640,224 +1565,6 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
1640 mmc_queue_bounce_pre(mqrq); 1565 mmc_queue_bounce_pre(mqrq);
1641} 1566}
1642 1567
1643static inline u8 mmc_calc_packed_hdr_segs(struct request_queue *q,
1644 struct mmc_card *card)
1645{
1646 unsigned int hdr_sz = mmc_large_sector(card) ? 4096 : 512;
1647 unsigned int max_seg_sz = queue_max_segment_size(q);
1648 unsigned int len, nr_segs = 0;
1649
1650 do {
1651 len = min(hdr_sz, max_seg_sz);
1652 hdr_sz -= len;
1653 nr_segs++;
1654 } while (hdr_sz);
1655
1656 return nr_segs;
1657}
1658
1659static u8 mmc_blk_prep_packed_list(struct mmc_queue *mq, struct request *req)
1660{
1661 struct request_queue *q = mq->queue;
1662 struct mmc_card *card = mq->card;
1663 struct request *cur = req, *next = NULL;
1664 struct mmc_blk_data *md = mq->data;
1665 struct mmc_queue_req *mqrq = mq->mqrq_cur;
1666 bool en_rel_wr = card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN;
1667 unsigned int req_sectors = 0, phys_segments = 0;
1668 unsigned int max_blk_count, max_phys_segs;
1669 bool put_back = true;
1670 u8 max_packed_rw = 0;
1671 u8 reqs = 0;
1672
1673 /*
1674 * We don't need to check packed for any further
1675 * operation of packed stuff as we set MMC_PACKED_NONE
1676 * and return zero for reqs if geting null packed. Also
1677 * we clean the flag of MMC_BLK_PACKED_CMD to avoid doing
1678 * it again when removing blk req.
1679 */
1680 if (!mqrq->packed) {
1681 md->flags &= (~MMC_BLK_PACKED_CMD);
1682 goto no_packed;
1683 }
1684
1685 if (!(md->flags & MMC_BLK_PACKED_CMD))
1686 goto no_packed;
1687
1688 if ((rq_data_dir(cur) == WRITE) &&
1689 mmc_host_packed_wr(card->host))
1690 max_packed_rw = card->ext_csd.max_packed_writes;
1691
1692 if (max_packed_rw == 0)
1693 goto no_packed;
1694
1695 if (mmc_req_rel_wr(cur) &&
1696 (md->flags & MMC_BLK_REL_WR) && !en_rel_wr)
1697 goto no_packed;
1698
1699 if (mmc_large_sector(card) &&
1700 !IS_ALIGNED(blk_rq_sectors(cur), 8))
1701 goto no_packed;
1702
1703 mmc_blk_clear_packed(mqrq);
1704
1705 max_blk_count = min(card->host->max_blk_count,
1706 card->host->max_req_size >> 9);
1707 if (unlikely(max_blk_count > 0xffff))
1708 max_blk_count = 0xffff;
1709
1710 max_phys_segs = queue_max_segments(q);
1711 req_sectors += blk_rq_sectors(cur);
1712 phys_segments += cur->nr_phys_segments;
1713
1714 if (rq_data_dir(cur) == WRITE) {
1715 req_sectors += mmc_large_sector(card) ? 8 : 1;
1716 phys_segments += mmc_calc_packed_hdr_segs(q, card);
1717 }
1718
1719 do {
1720 if (reqs >= max_packed_rw - 1) {
1721 put_back = false;
1722 break;
1723 }
1724
1725 spin_lock_irq(q->queue_lock);
1726 next = blk_fetch_request(q);
1727 spin_unlock_irq(q->queue_lock);
1728 if (!next) {
1729 put_back = false;
1730 break;
1731 }
1732
1733 if (mmc_large_sector(card) &&
1734 !IS_ALIGNED(blk_rq_sectors(next), 8))
1735 break;
1736
1737 if (req_op(next) == REQ_OP_DISCARD ||
1738 req_op(next) == REQ_OP_SECURE_ERASE ||
1739 req_op(next) == REQ_OP_FLUSH)
1740 break;
1741
1742 if (rq_data_dir(cur) != rq_data_dir(next))
1743 break;
1744
1745 if (mmc_req_rel_wr(next) &&
1746 (md->flags & MMC_BLK_REL_WR) && !en_rel_wr)
1747 break;
1748
1749 req_sectors += blk_rq_sectors(next);
1750 if (req_sectors > max_blk_count)
1751 break;
1752
1753 phys_segments += next->nr_phys_segments;
1754 if (phys_segments > max_phys_segs)
1755 break;
1756
1757 list_add_tail(&next->queuelist, &mqrq->packed->list);
1758 cur = next;
1759 reqs++;
1760 } while (1);
1761
1762 if (put_back) {
1763 spin_lock_irq(q->queue_lock);
1764 blk_requeue_request(q, next);
1765 spin_unlock_irq(q->queue_lock);
1766 }
1767
1768 if (reqs > 0) {
1769 list_add(&req->queuelist, &mqrq->packed->list);
1770 mqrq->packed->nr_entries = ++reqs;
1771 mqrq->packed->retries = reqs;
1772 return reqs;
1773 }
1774
1775no_packed:
1776 mqrq->cmd_type = MMC_PACKED_NONE;
1777 return 0;
1778}
1779
1780static void mmc_blk_packed_hdr_wrq_prep(struct mmc_queue_req *mqrq,
1781 struct mmc_card *card,
1782 struct mmc_queue *mq)
1783{
1784 struct mmc_blk_request *brq = &mqrq->brq;
1785 struct request *req = mqrq->req;
1786 struct request *prq;
1787 struct mmc_blk_data *md = mq->data;
1788 struct mmc_packed *packed = mqrq->packed;
1789 bool do_rel_wr, do_data_tag;
1790 __le32 *packed_cmd_hdr;
1791 u8 hdr_blocks;
1792 u8 i = 1;
1793
1794 mqrq->cmd_type = MMC_PACKED_WRITE;
1795 packed->blocks = 0;
1796 packed->idx_failure = MMC_PACKED_NR_IDX;
1797
1798 packed_cmd_hdr = packed->cmd_hdr;
1799 memset(packed_cmd_hdr, 0, sizeof(packed->cmd_hdr));
1800 packed_cmd_hdr[0] = cpu_to_le32((packed->nr_entries << 16) |
1801 (PACKED_CMD_WR << 8) | PACKED_CMD_VER);
1802 hdr_blocks = mmc_large_sector(card) ? 8 : 1;
1803
1804 /*
1805 * Argument for each entry of packed group
1806 */
1807 list_for_each_entry(prq, &packed->list, queuelist) {
1808 do_rel_wr = mmc_req_rel_wr(prq) && (md->flags & MMC_BLK_REL_WR);
1809 do_data_tag = (card->ext_csd.data_tag_unit_size) &&
1810 (prq->cmd_flags & REQ_META) &&
1811 (rq_data_dir(prq) == WRITE) &&
1812 blk_rq_bytes(prq) >= card->ext_csd.data_tag_unit_size;
1813 /* Argument of CMD23 */
1814 packed_cmd_hdr[(i * 2)] = cpu_to_le32(
1815 (do_rel_wr ? MMC_CMD23_ARG_REL_WR : 0) |
1816 (do_data_tag ? MMC_CMD23_ARG_TAG_REQ : 0) |
1817 blk_rq_sectors(prq));
1818 /* Argument of CMD18 or CMD25 */
1819 packed_cmd_hdr[((i * 2)) + 1] = cpu_to_le32(
1820 mmc_card_blockaddr(card) ?
1821 blk_rq_pos(prq) : blk_rq_pos(prq) << 9);
1822 packed->blocks += blk_rq_sectors(prq);
1823 i++;
1824 }
1825
1826 memset(brq, 0, sizeof(struct mmc_blk_request));
1827 brq->mrq.cmd = &brq->cmd;
1828 brq->mrq.data = &brq->data;
1829 brq->mrq.sbc = &brq->sbc;
1830 brq->mrq.stop = &brq->stop;
1831
1832 brq->sbc.opcode = MMC_SET_BLOCK_COUNT;
1833 brq->sbc.arg = MMC_CMD23_ARG_PACKED | (packed->blocks + hdr_blocks);
1834 brq->sbc.flags = MMC_RSP_R1 | MMC_CMD_AC;
1835
1836 brq->cmd.opcode = MMC_WRITE_MULTIPLE_BLOCK;
1837 brq->cmd.arg = blk_rq_pos(req);
1838 if (!mmc_card_blockaddr(card))
1839 brq->cmd.arg <<= 9;
1840 brq->cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
1841
1842 brq->data.blksz = 512;
1843 brq->data.blocks = packed->blocks + hdr_blocks;
1844 brq->data.flags = MMC_DATA_WRITE;
1845
1846 brq->stop.opcode = MMC_STOP_TRANSMISSION;
1847 brq->stop.arg = 0;
1848 brq->stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
1849
1850 mmc_set_data_timeout(&brq->data, card);
1851
1852 brq->data.sg = mqrq->sg;
1853 brq->data.sg_len = mmc_queue_map_sg(mq, mqrq);
1854
1855 mqrq->mmc_active.mrq = &brq->mrq;
1856 mqrq->mmc_active.err_check = mmc_blk_packed_err_check;
1857
1858 mmc_queue_bounce_pre(mqrq);
1859}
1860
1861static int mmc_blk_cmd_err(struct mmc_blk_data *md, struct mmc_card *card, 1568static int mmc_blk_cmd_err(struct mmc_blk_data *md, struct mmc_card *card,
1862 struct mmc_blk_request *brq, struct request *req, 1569 struct mmc_blk_request *brq, struct request *req,
1863 int ret) 1570 int ret)
@@ -1881,97 +1588,25 @@ static int mmc_blk_cmd_err(struct mmc_blk_data *md, struct mmc_card *card,
1881 ret = blk_end_request(req, 0, blocks << 9); 1588 ret = blk_end_request(req, 0, blocks << 9);
1882 } 1589 }
1883 } else { 1590 } else {
1884 if (!mmc_packed_cmd(mq_rq->cmd_type)) 1591 ret = blk_end_request(req, 0, brq->data.bytes_xfered);
1885 ret = blk_end_request(req, 0, brq->data.bytes_xfered);
1886 } 1592 }
1887 return ret; 1593 return ret;
1888} 1594}
1889 1595
1890static int mmc_blk_end_packed_req(struct mmc_queue_req *mq_rq)
1891{
1892 struct request *prq;
1893 struct mmc_packed *packed = mq_rq->packed;
1894 int idx = packed->idx_failure, i = 0;
1895 int ret = 0;
1896
1897 while (!list_empty(&packed->list)) {
1898 prq = list_entry_rq(packed->list.next);
1899 if (idx == i) {
1900 /* retry from error index */
1901 packed->nr_entries -= idx;
1902 mq_rq->req = prq;
1903 ret = 1;
1904
1905 if (packed->nr_entries == MMC_PACKED_NR_SINGLE) {
1906 list_del_init(&prq->queuelist);
1907 mmc_blk_clear_packed(mq_rq);
1908 }
1909 return ret;
1910 }
1911 list_del_init(&prq->queuelist);
1912 blk_end_request(prq, 0, blk_rq_bytes(prq));
1913 i++;
1914 }
1915
1916 mmc_blk_clear_packed(mq_rq);
1917 return ret;
1918}
1919
1920static void mmc_blk_abort_packed_req(struct mmc_queue_req *mq_rq)
1921{
1922 struct request *prq;
1923 struct mmc_packed *packed = mq_rq->packed;
1924
1925 while (!list_empty(&packed->list)) {
1926 prq = list_entry_rq(packed->list.next);
1927 list_del_init(&prq->queuelist);
1928 blk_end_request(prq, -EIO, blk_rq_bytes(prq));
1929 }
1930
1931 mmc_blk_clear_packed(mq_rq);
1932}
1933
1934static void mmc_blk_revert_packed_req(struct mmc_queue *mq,
1935 struct mmc_queue_req *mq_rq)
1936{
1937 struct request *prq;
1938 struct request_queue *q = mq->queue;
1939 struct mmc_packed *packed = mq_rq->packed;
1940
1941 while (!list_empty(&packed->list)) {
1942 prq = list_entry_rq(packed->list.prev);
1943 if (prq->queuelist.prev != &packed->list) {
1944 list_del_init(&prq->queuelist);
1945 spin_lock_irq(q->queue_lock);
1946 blk_requeue_request(mq->queue, prq);
1947 spin_unlock_irq(q->queue_lock);
1948 } else {
1949 list_del_init(&prq->queuelist);
1950 }
1951 }
1952
1953 mmc_blk_clear_packed(mq_rq);
1954}
1955
1956static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc) 1596static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1957{ 1597{
1958 struct mmc_blk_data *md = mq->data; 1598 struct mmc_blk_data *md = mq->blkdata;
1959 struct mmc_card *card = md->queue.card; 1599 struct mmc_card *card = md->queue.card;
1960 struct mmc_blk_request *brq = &mq->mqrq_cur->brq; 1600 struct mmc_blk_request *brq;
1961 int ret = 1, disable_multi = 0, retry = 0, type, retune_retry_done = 0; 1601 int ret = 1, disable_multi = 0, retry = 0, type, retune_retry_done = 0;
1962 enum mmc_blk_status status; 1602 enum mmc_blk_status status;
1963 struct mmc_queue_req *mq_rq; 1603 struct mmc_queue_req *mq_rq;
1964 struct request *req = rqc; 1604 struct request *req;
1965 struct mmc_async_req *areq; 1605 struct mmc_async_req *areq;
1966 const u8 packed_nr = 2;
1967 u8 reqs = 0;
1968 1606
1969 if (!rqc && !mq->mqrq_prev->req) 1607 if (!rqc && !mq->mqrq_prev->req)
1970 return 0; 1608 return 0;
1971 1609
1972 if (rqc)
1973 reqs = mmc_blk_prep_packed_list(mq, rqc);
1974
1975 do { 1610 do {
1976 if (rqc) { 1611 if (rqc) {
1977 /* 1612 /*
@@ -1981,20 +1616,18 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1981 if (mmc_large_sector(card) && 1616 if (mmc_large_sector(card) &&
1982 !IS_ALIGNED(blk_rq_sectors(rqc), 8)) { 1617 !IS_ALIGNED(blk_rq_sectors(rqc), 8)) {
1983 pr_err("%s: Transfer size is not 4KB sector size aligned\n", 1618 pr_err("%s: Transfer size is not 4KB sector size aligned\n",
1984 req->rq_disk->disk_name); 1619 rqc->rq_disk->disk_name);
1985 mq_rq = mq->mqrq_cur; 1620 mq_rq = mq->mqrq_cur;
1621 req = rqc;
1622 rqc = NULL;
1986 goto cmd_abort; 1623 goto cmd_abort;
1987 } 1624 }
1988 1625
1989 if (reqs >= packed_nr) 1626 mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq);
1990 mmc_blk_packed_hdr_wrq_prep(mq->mqrq_cur,
1991 card, mq);
1992 else
1993 mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq);
1994 areq = &mq->mqrq_cur->mmc_active; 1627 areq = &mq->mqrq_cur->mmc_active;
1995 } else 1628 } else
1996 areq = NULL; 1629 areq = NULL;
1997 areq = mmc_start_req(card->host, areq, (int *) &status); 1630 areq = mmc_start_req(card->host, areq, &status);
1998 if (!areq) { 1631 if (!areq) {
1999 if (status == MMC_BLK_NEW_REQUEST) 1632 if (status == MMC_BLK_NEW_REQUEST)
2000 mq->flags |= MMC_QUEUE_NEW_REQUEST; 1633 mq->flags |= MMC_QUEUE_NEW_REQUEST;
@@ -2015,13 +1648,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
2015 */ 1648 */
2016 mmc_blk_reset_success(md, type); 1649 mmc_blk_reset_success(md, type);
2017 1650
2018 if (mmc_packed_cmd(mq_rq->cmd_type)) { 1651 ret = blk_end_request(req, 0,
2019 ret = mmc_blk_end_packed_req(mq_rq); 1652 brq->data.bytes_xfered);
2020 break;
2021 } else {
2022 ret = blk_end_request(req, 0,
2023 brq->data.bytes_xfered);
2024 }
2025 1653
2026 /* 1654 /*
2027 * If the blk_end_request function returns non-zero even 1655 * If the blk_end_request function returns non-zero even
@@ -2058,8 +1686,7 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
2058 err = mmc_blk_reset(md, card->host, type); 1686 err = mmc_blk_reset(md, card->host, type);
2059 if (!err) 1687 if (!err)
2060 break; 1688 break;
2061 if (err == -ENODEV || 1689 if (err == -ENODEV)
2062 mmc_packed_cmd(mq_rq->cmd_type))
2063 goto cmd_abort; 1690 goto cmd_abort;
2064 /* Fall through */ 1691 /* Fall through */
2065 } 1692 }
@@ -2090,23 +1717,14 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
2090 } 1717 }
2091 1718
2092 if (ret) { 1719 if (ret) {
2093 if (mmc_packed_cmd(mq_rq->cmd_type)) { 1720 /*
2094 if (!mq_rq->packed->retries) 1721 * In case of a incomplete request
2095 goto cmd_abort; 1722 * prepare it again and resend.
2096 mmc_blk_packed_hdr_wrq_prep(mq_rq, card, mq); 1723 */
2097 mmc_start_req(card->host, 1724 mmc_blk_rw_rq_prep(mq_rq, card,
2098 &mq_rq->mmc_active, NULL); 1725 disable_multi, mq);
2099 } else { 1726 mmc_start_req(card->host,
2100 1727 &mq_rq->mmc_active, NULL);
2101 /*
2102 * In case of a incomplete request
2103 * prepare it again and resend.
2104 */
2105 mmc_blk_rw_rq_prep(mq_rq, card,
2106 disable_multi, mq);
2107 mmc_start_req(card->host,
2108 &mq_rq->mmc_active, NULL);
2109 }
2110 mq_rq->brq.retune_retry_done = retune_retry_done; 1728 mq_rq->brq.retune_retry_done = retune_retry_done;
2111 } 1729 }
2112 } while (ret); 1730 } while (ret);
@@ -2114,15 +1732,11 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
2114 return 1; 1732 return 1;
2115 1733
2116 cmd_abort: 1734 cmd_abort:
2117 if (mmc_packed_cmd(mq_rq->cmd_type)) { 1735 if (mmc_card_removed(card))
2118 mmc_blk_abort_packed_req(mq_rq); 1736 req->cmd_flags |= REQ_QUIET;
2119 } else { 1737 while (ret)
2120 if (mmc_card_removed(card)) 1738 ret = blk_end_request(req, -EIO,
2121 req->cmd_flags |= REQ_QUIET; 1739 blk_rq_cur_bytes(req));
2122 while (ret)
2123 ret = blk_end_request(req, -EIO,
2124 blk_rq_cur_bytes(req));
2125 }
2126 1740
2127 start_new_req: 1741 start_new_req:
2128 if (rqc) { 1742 if (rqc) {
@@ -2130,12 +1744,6 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
2130 rqc->cmd_flags |= REQ_QUIET; 1744 rqc->cmd_flags |= REQ_QUIET;
2131 blk_end_request_all(rqc, -EIO); 1745 blk_end_request_all(rqc, -EIO);
2132 } else { 1746 } else {
2133 /*
2134 * If current request is packed, it needs to put back.
2135 */
2136 if (mmc_packed_cmd(mq->mqrq_cur->cmd_type))
2137 mmc_blk_revert_packed_req(mq, mq->mqrq_cur);
2138
2139 mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq); 1747 mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq);
2140 mmc_start_req(card->host, 1748 mmc_start_req(card->host,
2141 &mq->mqrq_cur->mmc_active, NULL); 1749 &mq->mqrq_cur->mmc_active, NULL);
@@ -2148,10 +1756,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
2148int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) 1756int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
2149{ 1757{
2150 int ret; 1758 int ret;
2151 struct mmc_blk_data *md = mq->data; 1759 struct mmc_blk_data *md = mq->blkdata;
2152 struct mmc_card *card = md->queue.card; 1760 struct mmc_card *card = md->queue.card;
2153 struct mmc_host *host = card->host;
2154 unsigned long flags;
2155 bool req_is_special = mmc_req_is_special(req); 1761 bool req_is_special = mmc_req_is_special(req);
2156 1762
2157 if (req && !mq->mqrq_prev->req) 1763 if (req && !mq->mqrq_prev->req)
@@ -2184,11 +1790,6 @@ int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
2184 mmc_blk_issue_rw_rq(mq, NULL); 1790 mmc_blk_issue_rw_rq(mq, NULL);
2185 ret = mmc_blk_issue_flush(mq, req); 1791 ret = mmc_blk_issue_flush(mq, req);
2186 } else { 1792 } else {
2187 if (!req && host->areq) {
2188 spin_lock_irqsave(&host->context_info.lock, flags);
2189 host->context_info.is_waiting_last_req = true;
2190 spin_unlock_irqrestore(&host->context_info.lock, flags);
2191 }
2192 ret = mmc_blk_issue_rw_rq(mq, req); 1793 ret = mmc_blk_issue_rw_rq(mq, req);
2193 } 1794 }
2194 1795
@@ -2266,7 +1867,7 @@ again:
2266 if (ret) 1867 if (ret)
2267 goto err_putdisk; 1868 goto err_putdisk;
2268 1869
2269 md->queue.data = md; 1870 md->queue.blkdata = md;
2270 1871
2271 md->disk->major = MMC_BLOCK_MAJOR; 1872 md->disk->major = MMC_BLOCK_MAJOR;
2272 md->disk->first_minor = devidx * perdev_minors; 1873 md->disk->first_minor = devidx * perdev_minors;
@@ -2318,14 +1919,6 @@ again:
2318 blk_queue_write_cache(md->queue.queue, true, true); 1919 blk_queue_write_cache(md->queue.queue, true, true);
2319 } 1920 }
2320 1921
2321 if (mmc_card_mmc(card) &&
2322 (area_type == MMC_BLK_DATA_AREA_MAIN) &&
2323 (md->flags & MMC_BLK_CMD23) &&
2324 card->ext_csd.packed_event_en) {
2325 if (!mmc_packed_init(&md->queue, card))
2326 md->flags |= MMC_BLK_PACKED_CMD;
2327 }
2328
2329 return md; 1922 return md;
2330 1923
2331 err_putdisk: 1924 err_putdisk:
@@ -2429,8 +2022,6 @@ static void mmc_blk_remove_req(struct mmc_blk_data *md)
2429 */ 2022 */
2430 card = md->queue.card; 2023 card = md->queue.card;
2431 mmc_cleanup_queue(&md->queue); 2024 mmc_cleanup_queue(&md->queue);
2432 if (md->flags & MMC_BLK_PACKED_CMD)
2433 mmc_packed_clean(&md->queue);
2434 if (md->disk->flags & GENHD_FL_UP) { 2025 if (md->disk->flags & GENHD_FL_UP) {
2435 device_remove_file(disk_to_dev(md->disk), &md->force_ro); 2026 device_remove_file(disk_to_dev(md->disk), &md->force_ro);
2436 if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) && 2027 if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
index 3678220964fe..ec1d1c46eb90 100644
--- a/drivers/mmc/card/mmc_test.c
+++ b/drivers/mmc/card/mmc_test.c
@@ -214,7 +214,8 @@ static void mmc_test_prepare_mrq(struct mmc_test_card *test,
214 struct mmc_request *mrq, struct scatterlist *sg, unsigned sg_len, 214 struct mmc_request *mrq, struct scatterlist *sg, unsigned sg_len,
215 unsigned dev_addr, unsigned blocks, unsigned blksz, int write) 215 unsigned dev_addr, unsigned blocks, unsigned blksz, int write)
216{ 216{
217 BUG_ON(!mrq || !mrq->cmd || !mrq->data || !mrq->stop); 217 if (WARN_ON(!mrq || !mrq->cmd || !mrq->data || !mrq->stop))
218 return;
218 219
219 if (blocks > 1) { 220 if (blocks > 1) {
220 mrq->cmd->opcode = write ? 221 mrq->cmd->opcode = write ?
@@ -694,7 +695,8 @@ static int mmc_test_cleanup(struct mmc_test_card *test)
694static void mmc_test_prepare_broken_mrq(struct mmc_test_card *test, 695static void mmc_test_prepare_broken_mrq(struct mmc_test_card *test,
695 struct mmc_request *mrq, int write) 696 struct mmc_request *mrq, int write)
696{ 697{
697 BUG_ON(!mrq || !mrq->cmd || !mrq->data); 698 if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
699 return;
698 700
699 if (mrq->data->blocks > 1) { 701 if (mrq->data->blocks > 1) {
700 mrq->cmd->opcode = write ? 702 mrq->cmd->opcode = write ?
@@ -714,7 +716,8 @@ static int mmc_test_check_result(struct mmc_test_card *test,
714{ 716{
715 int ret; 717 int ret;
716 718
717 BUG_ON(!mrq || !mrq->cmd || !mrq->data); 719 if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
720 return -EINVAL;
718 721
719 ret = 0; 722 ret = 0;
720 723
@@ -736,15 +739,28 @@ static int mmc_test_check_result(struct mmc_test_card *test,
736 return ret; 739 return ret;
737} 740}
738 741
739static int mmc_test_check_result_async(struct mmc_card *card, 742static enum mmc_blk_status mmc_test_check_result_async(struct mmc_card *card,
740 struct mmc_async_req *areq) 743 struct mmc_async_req *areq)
741{ 744{
742 struct mmc_test_async_req *test_async = 745 struct mmc_test_async_req *test_async =
743 container_of(areq, struct mmc_test_async_req, areq); 746 container_of(areq, struct mmc_test_async_req, areq);
747 int ret;
744 748
745 mmc_test_wait_busy(test_async->test); 749 mmc_test_wait_busy(test_async->test);
746 750
747 return mmc_test_check_result(test_async->test, areq->mrq); 751 /*
752 * FIXME: this would earlier just casts a regular error code,
753 * either of the kernel type -ERRORCODE or the local test framework
754 * RESULT_* errorcode, into an enum mmc_blk_status and return as
755 * result check. Instead, convert it to some reasonable type by just
756 * returning either MMC_BLK_SUCCESS or MMC_BLK_CMD_ERR.
757 * If possible, a reasonable error code should be returned.
758 */
759 ret = mmc_test_check_result(test_async->test, areq->mrq);
760 if (ret)
761 return MMC_BLK_CMD_ERR;
762
763 return MMC_BLK_SUCCESS;
748} 764}
749 765
750/* 766/*
@@ -755,7 +771,8 @@ static int mmc_test_check_broken_result(struct mmc_test_card *test,
755{ 771{
756 int ret; 772 int ret;
757 773
758 BUG_ON(!mrq || !mrq->cmd || !mrq->data); 774 if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
775 return -EINVAL;
759 776
760 ret = 0; 777 ret = 0;
761 778
@@ -817,8 +834,9 @@ static int mmc_test_nonblock_transfer(struct mmc_test_card *test,
817 struct mmc_async_req *done_areq; 834 struct mmc_async_req *done_areq;
818 struct mmc_async_req *cur_areq = &test_areq[0].areq; 835 struct mmc_async_req *cur_areq = &test_areq[0].areq;
819 struct mmc_async_req *other_areq = &test_areq[1].areq; 836 struct mmc_async_req *other_areq = &test_areq[1].areq;
837 enum mmc_blk_status status;
820 int i; 838 int i;
821 int ret; 839 int ret = RESULT_OK;
822 840
823 test_areq[0].test = test; 841 test_areq[0].test = test;
824 test_areq[1].test = test; 842 test_areq[1].test = test;
@@ -834,10 +852,12 @@ static int mmc_test_nonblock_transfer(struct mmc_test_card *test,
834 for (i = 0; i < count; i++) { 852 for (i = 0; i < count; i++) {
835 mmc_test_prepare_mrq(test, cur_areq->mrq, sg, sg_len, dev_addr, 853 mmc_test_prepare_mrq(test, cur_areq->mrq, sg, sg_len, dev_addr,
836 blocks, blksz, write); 854 blocks, blksz, write);
837 done_areq = mmc_start_req(test->card->host, cur_areq, &ret); 855 done_areq = mmc_start_req(test->card->host, cur_areq, &status);
838 856
839 if (ret || (!done_areq && i > 0)) 857 if (status != MMC_BLK_SUCCESS || (!done_areq && i > 0)) {
858 ret = RESULT_FAIL;
840 goto err; 859 goto err;
860 }
841 861
842 if (done_areq) { 862 if (done_areq) {
843 if (done_areq->mrq == &mrq2) 863 if (done_areq->mrq == &mrq2)
@@ -851,7 +871,9 @@ static int mmc_test_nonblock_transfer(struct mmc_test_card *test,
851 dev_addr += blocks; 871 dev_addr += blocks;
852 } 872 }
853 873
854 done_areq = mmc_start_req(test->card->host, NULL, &ret); 874 done_areq = mmc_start_req(test->card->host, NULL, &status);
875 if (status != MMC_BLK_SUCCESS)
876 ret = RESULT_FAIL;
855 877
856 return ret; 878 return ret;
857err: 879err:
@@ -2351,6 +2373,7 @@ static int mmc_test_ongoing_transfer(struct mmc_test_card *test,
2351 struct mmc_request *mrq; 2373 struct mmc_request *mrq;
2352 unsigned long timeout; 2374 unsigned long timeout;
2353 bool expired = false; 2375 bool expired = false;
2376 enum mmc_blk_status blkstat = MMC_BLK_SUCCESS;
2354 int ret = 0, cmd_ret; 2377 int ret = 0, cmd_ret;
2355 u32 status = 0; 2378 u32 status = 0;
2356 int count = 0; 2379 int count = 0;
@@ -2378,9 +2401,11 @@ static int mmc_test_ongoing_transfer(struct mmc_test_card *test,
2378 2401
2379 /* Start ongoing data request */ 2402 /* Start ongoing data request */
2380 if (use_areq) { 2403 if (use_areq) {
2381 mmc_start_req(host, &test_areq.areq, &ret); 2404 mmc_start_req(host, &test_areq.areq, &blkstat);
2382 if (ret) 2405 if (blkstat != MMC_BLK_SUCCESS) {
2406 ret = RESULT_FAIL;
2383 goto out_free; 2407 goto out_free;
2408 }
2384 } else { 2409 } else {
2385 mmc_wait_for_req(host, mrq); 2410 mmc_wait_for_req(host, mrq);
2386 } 2411 }
@@ -2413,10 +2438,13 @@ static int mmc_test_ongoing_transfer(struct mmc_test_card *test,
2413 } while (repeat_cmd && R1_CURRENT_STATE(status) != R1_STATE_TRAN); 2438 } while (repeat_cmd && R1_CURRENT_STATE(status) != R1_STATE_TRAN);
2414 2439
2415 /* Wait for data request to complete */ 2440 /* Wait for data request to complete */
2416 if (use_areq) 2441 if (use_areq) {
2417 mmc_start_req(host, NULL, &ret); 2442 mmc_start_req(host, NULL, &blkstat);
2418 else 2443 if (blkstat != MMC_BLK_SUCCESS)
2444 ret = RESULT_FAIL;
2445 } else {
2419 mmc_wait_for_req_done(test->card->host, mrq); 2446 mmc_wait_for_req_done(test->card->host, mrq);
2447 }
2420 2448
2421 /* 2449 /*
2422 * For cap_cmd_during_tfr request, upper layer must send stop if 2450 * For cap_cmd_during_tfr request, upper layer must send stop if
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index 8037f73a109a..cf29809f69e4 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -53,6 +53,7 @@ static int mmc_queue_thread(void *d)
53{ 53{
54 struct mmc_queue *mq = d; 54 struct mmc_queue *mq = d;
55 struct request_queue *q = mq->queue; 55 struct request_queue *q = mq->queue;
56 struct mmc_context_info *cntx = &mq->card->host->context_info;
56 57
57 current->flags |= PF_MEMALLOC; 58 current->flags |= PF_MEMALLOC;
58 59
@@ -63,6 +64,19 @@ static int mmc_queue_thread(void *d)
63 spin_lock_irq(q->queue_lock); 64 spin_lock_irq(q->queue_lock);
64 set_current_state(TASK_INTERRUPTIBLE); 65 set_current_state(TASK_INTERRUPTIBLE);
65 req = blk_fetch_request(q); 66 req = blk_fetch_request(q);
67 mq->asleep = false;
68 cntx->is_waiting_last_req = false;
69 cntx->is_new_req = false;
70 if (!req) {
71 /*
72 * Dispatch queue is empty so set flags for
73 * mmc_request_fn() to wake us up.
74 */
75 if (mq->mqrq_prev->req)
76 cntx->is_waiting_last_req = true;
77 else
78 mq->asleep = true;
79 }
66 mq->mqrq_cur->req = req; 80 mq->mqrq_cur->req = req;
67 spin_unlock_irq(q->queue_lock); 81 spin_unlock_irq(q->queue_lock);
68 82
@@ -115,7 +129,6 @@ static void mmc_request_fn(struct request_queue *q)
115{ 129{
116 struct mmc_queue *mq = q->queuedata; 130 struct mmc_queue *mq = q->queuedata;
117 struct request *req; 131 struct request *req;
118 unsigned long flags;
119 struct mmc_context_info *cntx; 132 struct mmc_context_info *cntx;
120 133
121 if (!mq) { 134 if (!mq) {
@@ -127,19 +140,13 @@ static void mmc_request_fn(struct request_queue *q)
127 } 140 }
128 141
129 cntx = &mq->card->host->context_info; 142 cntx = &mq->card->host->context_info;
130 if (!mq->mqrq_cur->req && mq->mqrq_prev->req) { 143
131 /* 144 if (cntx->is_waiting_last_req) {
132 * New MMC request arrived when MMC thread may be 145 cntx->is_new_req = true;
133 * blocked on the previous request to be complete 146 wake_up_interruptible(&cntx->wait);
134 * with no current request fetched 147 }
135 */ 148
136 spin_lock_irqsave(&cntx->lock, flags); 149 if (mq->asleep)
137 if (cntx->is_waiting_last_req) {
138 cntx->is_new_req = true;
139 wake_up_interruptible(&cntx->wait);
140 }
141 spin_unlock_irqrestore(&cntx->lock, flags);
142 } else if (!mq->mqrq_cur->req && !mq->mqrq_prev->req)
143 wake_up_process(mq->thread); 150 wake_up_process(mq->thread);
144} 151}
145 152
@@ -179,6 +186,82 @@ static void mmc_queue_setup_discard(struct request_queue *q,
179 queue_flag_set_unlocked(QUEUE_FLAG_SECERASE, q); 186 queue_flag_set_unlocked(QUEUE_FLAG_SECERASE, q);
180} 187}
181 188
189#ifdef CONFIG_MMC_BLOCK_BOUNCE
190static bool mmc_queue_alloc_bounce_bufs(struct mmc_queue *mq,
191 unsigned int bouncesz)
192{
193 int i;
194
195 for (i = 0; i < mq->qdepth; i++) {
196 mq->mqrq[i].bounce_buf = kmalloc(bouncesz, GFP_KERNEL);
197 if (!mq->mqrq[i].bounce_buf)
198 goto out_err;
199 }
200
201 return true;
202
203out_err:
204 while (--i >= 0) {
205 kfree(mq->mqrq[i].bounce_buf);
206 mq->mqrq[i].bounce_buf = NULL;
207 }
208 pr_warn("%s: unable to allocate bounce buffers\n",
209 mmc_card_name(mq->card));
210 return false;
211}
212
213static int mmc_queue_alloc_bounce_sgs(struct mmc_queue *mq,
214 unsigned int bouncesz)
215{
216 int i, ret;
217
218 for (i = 0; i < mq->qdepth; i++) {
219 mq->mqrq[i].sg = mmc_alloc_sg(1, &ret);
220 if (ret)
221 return ret;
222
223 mq->mqrq[i].bounce_sg = mmc_alloc_sg(bouncesz / 512, &ret);
224 if (ret)
225 return ret;
226 }
227
228 return 0;
229}
230#endif
231
232static int mmc_queue_alloc_sgs(struct mmc_queue *mq, int max_segs)
233{
234 int i, ret;
235
236 for (i = 0; i < mq->qdepth; i++) {
237 mq->mqrq[i].sg = mmc_alloc_sg(max_segs, &ret);
238 if (ret)
239 return ret;
240 }
241
242 return 0;
243}
244
245static void mmc_queue_req_free_bufs(struct mmc_queue_req *mqrq)
246{
247 kfree(mqrq->bounce_sg);
248 mqrq->bounce_sg = NULL;
249
250 kfree(mqrq->sg);
251 mqrq->sg = NULL;
252
253 kfree(mqrq->bounce_buf);
254 mqrq->bounce_buf = NULL;
255}
256
257static void mmc_queue_reqs_free_bufs(struct mmc_queue *mq)
258{
259 int i;
260
261 for (i = 0; i < mq->qdepth; i++)
262 mmc_queue_req_free_bufs(&mq->mqrq[i]);
263}
264
182/** 265/**
183 * mmc_init_queue - initialise a queue structure. 266 * mmc_init_queue - initialise a queue structure.
184 * @mq: mmc queue 267 * @mq: mmc queue
@@ -193,9 +276,8 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
193{ 276{
194 struct mmc_host *host = card->host; 277 struct mmc_host *host = card->host;
195 u64 limit = BLK_BOUNCE_HIGH; 278 u64 limit = BLK_BOUNCE_HIGH;
196 int ret; 279 bool bounce = false;
197 struct mmc_queue_req *mqrq_cur = &mq->mqrq[0]; 280 int ret = -ENOMEM;
198 struct mmc_queue_req *mqrq_prev = &mq->mqrq[1];
199 281
200 if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask) 282 if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
201 limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT; 283 limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT;
@@ -205,8 +287,13 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
205 if (!mq->queue) 287 if (!mq->queue)
206 return -ENOMEM; 288 return -ENOMEM;
207 289
208 mq->mqrq_cur = mqrq_cur; 290 mq->qdepth = 2;
209 mq->mqrq_prev = mqrq_prev; 291 mq->mqrq = kcalloc(mq->qdepth, sizeof(struct mmc_queue_req),
292 GFP_KERNEL);
293 if (!mq->mqrq)
294 goto blk_cleanup;
295 mq->mqrq_cur = &mq->mqrq[0];
296 mq->mqrq_prev = &mq->mqrq[1];
210 mq->queue->queuedata = mq; 297 mq->queue->queuedata = mq;
211 298
212 blk_queue_prep_rq(mq->queue, mmc_prep_request); 299 blk_queue_prep_rq(mq->queue, mmc_prep_request);
@@ -228,63 +315,29 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
228 if (bouncesz > (host->max_blk_count * 512)) 315 if (bouncesz > (host->max_blk_count * 512))
229 bouncesz = host->max_blk_count * 512; 316 bouncesz = host->max_blk_count * 512;
230 317
231 if (bouncesz > 512) { 318 if (bouncesz > 512 &&
232 mqrq_cur->bounce_buf = kmalloc(bouncesz, GFP_KERNEL); 319 mmc_queue_alloc_bounce_bufs(mq, bouncesz)) {
233 if (!mqrq_cur->bounce_buf) {
234 pr_warn("%s: unable to allocate bounce cur buffer\n",
235 mmc_card_name(card));
236 } else {
237 mqrq_prev->bounce_buf =
238 kmalloc(bouncesz, GFP_KERNEL);
239 if (!mqrq_prev->bounce_buf) {
240 pr_warn("%s: unable to allocate bounce prev buffer\n",
241 mmc_card_name(card));
242 kfree(mqrq_cur->bounce_buf);
243 mqrq_cur->bounce_buf = NULL;
244 }
245 }
246 }
247
248 if (mqrq_cur->bounce_buf && mqrq_prev->bounce_buf) {
249 blk_queue_bounce_limit(mq->queue, BLK_BOUNCE_ANY); 320 blk_queue_bounce_limit(mq->queue, BLK_BOUNCE_ANY);
250 blk_queue_max_hw_sectors(mq->queue, bouncesz / 512); 321 blk_queue_max_hw_sectors(mq->queue, bouncesz / 512);
251 blk_queue_max_segments(mq->queue, bouncesz / 512); 322 blk_queue_max_segments(mq->queue, bouncesz / 512);
252 blk_queue_max_segment_size(mq->queue, bouncesz); 323 blk_queue_max_segment_size(mq->queue, bouncesz);
253 324
254 mqrq_cur->sg = mmc_alloc_sg(1, &ret); 325 ret = mmc_queue_alloc_bounce_sgs(mq, bouncesz);
255 if (ret)
256 goto cleanup_queue;
257
258 mqrq_cur->bounce_sg =
259 mmc_alloc_sg(bouncesz / 512, &ret);
260 if (ret)
261 goto cleanup_queue;
262
263 mqrq_prev->sg = mmc_alloc_sg(1, &ret);
264 if (ret)
265 goto cleanup_queue;
266
267 mqrq_prev->bounce_sg =
268 mmc_alloc_sg(bouncesz / 512, &ret);
269 if (ret) 326 if (ret)
270 goto cleanup_queue; 327 goto cleanup_queue;
328 bounce = true;
271 } 329 }
272 } 330 }
273#endif 331#endif
274 332
275 if (!mqrq_cur->bounce_buf && !mqrq_prev->bounce_buf) { 333 if (!bounce) {
276 blk_queue_bounce_limit(mq->queue, limit); 334 blk_queue_bounce_limit(mq->queue, limit);
277 blk_queue_max_hw_sectors(mq->queue, 335 blk_queue_max_hw_sectors(mq->queue,
278 min(host->max_blk_count, host->max_req_size / 512)); 336 min(host->max_blk_count, host->max_req_size / 512));
279 blk_queue_max_segments(mq->queue, host->max_segs); 337 blk_queue_max_segments(mq->queue, host->max_segs);
280 blk_queue_max_segment_size(mq->queue, host->max_seg_size); 338 blk_queue_max_segment_size(mq->queue, host->max_seg_size);
281 339
282 mqrq_cur->sg = mmc_alloc_sg(host->max_segs, &ret); 340 ret = mmc_queue_alloc_sgs(mq, host->max_segs);
283 if (ret)
284 goto cleanup_queue;
285
286
287 mqrq_prev->sg = mmc_alloc_sg(host->max_segs, &ret);
288 if (ret) 341 if (ret)
289 goto cleanup_queue; 342 goto cleanup_queue;
290 } 343 }
@@ -296,27 +349,16 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
296 349
297 if (IS_ERR(mq->thread)) { 350 if (IS_ERR(mq->thread)) {
298 ret = PTR_ERR(mq->thread); 351 ret = PTR_ERR(mq->thread);
299 goto free_bounce_sg; 352 goto cleanup_queue;
300 } 353 }
301 354
302 return 0; 355 return 0;
303 free_bounce_sg:
304 kfree(mqrq_cur->bounce_sg);
305 mqrq_cur->bounce_sg = NULL;
306 kfree(mqrq_prev->bounce_sg);
307 mqrq_prev->bounce_sg = NULL;
308 356
309 cleanup_queue: 357 cleanup_queue:
310 kfree(mqrq_cur->sg); 358 mmc_queue_reqs_free_bufs(mq);
311 mqrq_cur->sg = NULL; 359 kfree(mq->mqrq);
312 kfree(mqrq_cur->bounce_buf); 360 mq->mqrq = NULL;
313 mqrq_cur->bounce_buf = NULL; 361blk_cleanup:
314
315 kfree(mqrq_prev->sg);
316 mqrq_prev->sg = NULL;
317 kfree(mqrq_prev->bounce_buf);
318 mqrq_prev->bounce_buf = NULL;
319
320 blk_cleanup_queue(mq->queue); 362 blk_cleanup_queue(mq->queue);
321 return ret; 363 return ret;
322} 364}
@@ -325,8 +367,6 @@ void mmc_cleanup_queue(struct mmc_queue *mq)
325{ 367{
326 struct request_queue *q = mq->queue; 368 struct request_queue *q = mq->queue;
327 unsigned long flags; 369 unsigned long flags;
328 struct mmc_queue_req *mqrq_cur = mq->mqrq_cur;
329 struct mmc_queue_req *mqrq_prev = mq->mqrq_prev;
330 370
331 /* Make sure the queue isn't suspended, as that will deadlock */ 371 /* Make sure the queue isn't suspended, as that will deadlock */
332 mmc_queue_resume(mq); 372 mmc_queue_resume(mq);
@@ -340,71 +380,14 @@ void mmc_cleanup_queue(struct mmc_queue *mq)
340 blk_start_queue(q); 380 blk_start_queue(q);
341 spin_unlock_irqrestore(q->queue_lock, flags); 381 spin_unlock_irqrestore(q->queue_lock, flags);
342 382
343 kfree(mqrq_cur->bounce_sg); 383 mmc_queue_reqs_free_bufs(mq);
344 mqrq_cur->bounce_sg = NULL; 384 kfree(mq->mqrq);
345 385 mq->mqrq = NULL;
346 kfree(mqrq_cur->sg);
347 mqrq_cur->sg = NULL;
348
349 kfree(mqrq_cur->bounce_buf);
350 mqrq_cur->bounce_buf = NULL;
351
352 kfree(mqrq_prev->bounce_sg);
353 mqrq_prev->bounce_sg = NULL;
354
355 kfree(mqrq_prev->sg);
356 mqrq_prev->sg = NULL;
357
358 kfree(mqrq_prev->bounce_buf);
359 mqrq_prev->bounce_buf = NULL;
360 386
361 mq->card = NULL; 387 mq->card = NULL;
362} 388}
363EXPORT_SYMBOL(mmc_cleanup_queue); 389EXPORT_SYMBOL(mmc_cleanup_queue);
364 390
365int mmc_packed_init(struct mmc_queue *mq, struct mmc_card *card)
366{
367 struct mmc_queue_req *mqrq_cur = &mq->mqrq[0];
368 struct mmc_queue_req *mqrq_prev = &mq->mqrq[1];
369 int ret = 0;
370
371
372 mqrq_cur->packed = kzalloc(sizeof(struct mmc_packed), GFP_KERNEL);
373 if (!mqrq_cur->packed) {
374 pr_warn("%s: unable to allocate packed cmd for mqrq_cur\n",
375 mmc_card_name(card));
376 ret = -ENOMEM;
377 goto out;
378 }
379
380 mqrq_prev->packed = kzalloc(sizeof(struct mmc_packed), GFP_KERNEL);
381 if (!mqrq_prev->packed) {
382 pr_warn("%s: unable to allocate packed cmd for mqrq_prev\n",
383 mmc_card_name(card));
384 kfree(mqrq_cur->packed);
385 mqrq_cur->packed = NULL;
386 ret = -ENOMEM;
387 goto out;
388 }
389
390 INIT_LIST_HEAD(&mqrq_cur->packed->list);
391 INIT_LIST_HEAD(&mqrq_prev->packed->list);
392
393out:
394 return ret;
395}
396
397void mmc_packed_clean(struct mmc_queue *mq)
398{
399 struct mmc_queue_req *mqrq_cur = &mq->mqrq[0];
400 struct mmc_queue_req *mqrq_prev = &mq->mqrq[1];
401
402 kfree(mqrq_cur->packed);
403 mqrq_cur->packed = NULL;
404 kfree(mqrq_prev->packed);
405 mqrq_prev->packed = NULL;
406}
407
408/** 391/**
409 * mmc_queue_suspend - suspend a MMC request queue 392 * mmc_queue_suspend - suspend a MMC request queue
410 * @mq: MMC queue to suspend 393 * @mq: MMC queue to suspend
@@ -449,41 +432,6 @@ void mmc_queue_resume(struct mmc_queue *mq)
449 } 432 }
450} 433}
451 434
452static unsigned int mmc_queue_packed_map_sg(struct mmc_queue *mq,
453 struct mmc_packed *packed,
454 struct scatterlist *sg,
455 enum mmc_packed_type cmd_type)
456{
457 struct scatterlist *__sg = sg;
458 unsigned int sg_len = 0;
459 struct request *req;
460
461 if (mmc_packed_wr(cmd_type)) {
462 unsigned int hdr_sz = mmc_large_sector(mq->card) ? 4096 : 512;
463 unsigned int max_seg_sz = queue_max_segment_size(mq->queue);
464 unsigned int len, remain, offset = 0;
465 u8 *buf = (u8 *)packed->cmd_hdr;
466
467 remain = hdr_sz;
468 do {
469 len = min(remain, max_seg_sz);
470 sg_set_buf(__sg, buf + offset, len);
471 offset += len;
472 remain -= len;
473 sg_unmark_end(__sg++);
474 sg_len++;
475 } while (remain);
476 }
477
478 list_for_each_entry(req, &packed->list, queuelist) {
479 sg_len += blk_rq_map_sg(mq->queue, req, __sg);
480 __sg = sg + (sg_len - 1);
481 sg_unmark_end(__sg++);
482 }
483 sg_mark_end(sg + (sg_len - 1));
484 return sg_len;
485}
486
487/* 435/*
488 * Prepare the sg list(s) to be handed of to the host driver 436 * Prepare the sg list(s) to be handed of to the host driver
489 */ 437 */
@@ -492,26 +440,12 @@ unsigned int mmc_queue_map_sg(struct mmc_queue *mq, struct mmc_queue_req *mqrq)
492 unsigned int sg_len; 440 unsigned int sg_len;
493 size_t buflen; 441 size_t buflen;
494 struct scatterlist *sg; 442 struct scatterlist *sg;
495 enum mmc_packed_type cmd_type;
496 int i; 443 int i;
497 444
498 cmd_type = mqrq->cmd_type; 445 if (!mqrq->bounce_buf)
499 446 return blk_rq_map_sg(mq->queue, mqrq->req, mqrq->sg);
500 if (!mqrq->bounce_buf) {
501 if (mmc_packed_cmd(cmd_type))
502 return mmc_queue_packed_map_sg(mq, mqrq->packed,
503 mqrq->sg, cmd_type);
504 else
505 return blk_rq_map_sg(mq->queue, mqrq->req, mqrq->sg);
506 }
507
508 BUG_ON(!mqrq->bounce_sg);
509 447
510 if (mmc_packed_cmd(cmd_type)) 448 sg_len = blk_rq_map_sg(mq->queue, mqrq->req, mqrq->bounce_sg);
511 sg_len = mmc_queue_packed_map_sg(mq, mqrq->packed,
512 mqrq->bounce_sg, cmd_type);
513 else
514 sg_len = blk_rq_map_sg(mq->queue, mqrq->req, mqrq->bounce_sg);
515 449
516 mqrq->bounce_sg_len = sg_len; 450 mqrq->bounce_sg_len = sg_len;
517 451
diff --git a/drivers/mmc/card/queue.h b/drivers/mmc/card/queue.h
index 342f1e3f301e..dac8c3d010dd 100644
--- a/drivers/mmc/card/queue.h
+++ b/drivers/mmc/card/queue.h
@@ -11,6 +11,7 @@ static inline bool mmc_req_is_special(struct request *req)
11 11
12struct request; 12struct request;
13struct task_struct; 13struct task_struct;
14struct mmc_blk_data;
14 15
15struct mmc_blk_request { 16struct mmc_blk_request {
16 struct mmc_request mrq; 17 struct mmc_request mrq;
@@ -21,23 +22,6 @@ struct mmc_blk_request {
21 int retune_retry_done; 22 int retune_retry_done;
22}; 23};
23 24
24enum mmc_packed_type {
25 MMC_PACKED_NONE = 0,
26 MMC_PACKED_WRITE,
27};
28
29#define mmc_packed_cmd(type) ((type) != MMC_PACKED_NONE)
30#define mmc_packed_wr(type) ((type) == MMC_PACKED_WRITE)
31
32struct mmc_packed {
33 struct list_head list;
34 __le32 cmd_hdr[1024];
35 unsigned int blocks;
36 u8 nr_entries;
37 u8 retries;
38 s16 idx_failure;
39};
40
41struct mmc_queue_req { 25struct mmc_queue_req {
42 struct request *req; 26 struct request *req;
43 struct mmc_blk_request brq; 27 struct mmc_blk_request brq;
@@ -46,8 +30,6 @@ struct mmc_queue_req {
46 struct scatterlist *bounce_sg; 30 struct scatterlist *bounce_sg;
47 unsigned int bounce_sg_len; 31 unsigned int bounce_sg_len;
48 struct mmc_async_req mmc_active; 32 struct mmc_async_req mmc_active;
49 enum mmc_packed_type cmd_type;
50 struct mmc_packed *packed;
51}; 33};
52 34
53struct mmc_queue { 35struct mmc_queue {
@@ -57,11 +39,13 @@ struct mmc_queue {
57 unsigned int flags; 39 unsigned int flags;
58#define MMC_QUEUE_SUSPENDED (1 << 0) 40#define MMC_QUEUE_SUSPENDED (1 << 0)
59#define MMC_QUEUE_NEW_REQUEST (1 << 1) 41#define MMC_QUEUE_NEW_REQUEST (1 << 1)
60 void *data; 42 bool asleep;
43 struct mmc_blk_data *blkdata;
61 struct request_queue *queue; 44 struct request_queue *queue;
62 struct mmc_queue_req mqrq[2]; 45 struct mmc_queue_req *mqrq;
63 struct mmc_queue_req *mqrq_cur; 46 struct mmc_queue_req *mqrq_cur;
64 struct mmc_queue_req *mqrq_prev; 47 struct mmc_queue_req *mqrq_prev;
48 int qdepth;
65}; 49};
66 50
67extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *, 51extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
@@ -75,9 +59,6 @@ extern unsigned int mmc_queue_map_sg(struct mmc_queue *,
75extern void mmc_queue_bounce_pre(struct mmc_queue_req *); 59extern void mmc_queue_bounce_pre(struct mmc_queue_req *);
76extern void mmc_queue_bounce_post(struct mmc_queue_req *); 60extern void mmc_queue_bounce_post(struct mmc_queue_req *);
77 61
78extern int mmc_packed_init(struct mmc_queue *, struct mmc_card *);
79extern void mmc_packed_clean(struct mmc_queue *);
80
81extern int mmc_access_rpmb(struct mmc_queue *); 62extern int mmc_access_rpmb(struct mmc_queue *);
82 63
83#endif 64#endif
diff --git a/drivers/mmc/card/sdio_uart.c b/drivers/mmc/card/sdio_uart.c
index 5af6fb9a9ce2..491c187744f5 100644
--- a/drivers/mmc/card/sdio_uart.c
+++ b/drivers/mmc/card/sdio_uart.c
@@ -135,8 +135,6 @@ static void sdio_uart_port_remove(struct sdio_uart_port *port)
135{ 135{
136 struct sdio_func *func; 136 struct sdio_func *func;
137 137
138 BUG_ON(sdio_uart_table[port->index] != port);
139
140 spin_lock(&sdio_uart_table_lock); 138 spin_lock(&sdio_uart_table_lock);
141 sdio_uart_table[port->index] = NULL; 139 sdio_uart_table[port->index] = NULL;
142 spin_unlock(&sdio_uart_table_lock); 140 spin_unlock(&sdio_uart_table_lock);
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 2553d903a82b..543eadd230e5 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -306,16 +306,16 @@ static int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
306 mrq->sbc->mrq = mrq; 306 mrq->sbc->mrq = mrq;
307 } 307 }
308 if (mrq->data) { 308 if (mrq->data) {
309 BUG_ON(mrq->data->blksz > host->max_blk_size); 309 if (mrq->data->blksz > host->max_blk_size ||
310 BUG_ON(mrq->data->blocks > host->max_blk_count); 310 mrq->data->blocks > host->max_blk_count ||
311 BUG_ON(mrq->data->blocks * mrq->data->blksz > 311 mrq->data->blocks * mrq->data->blksz > host->max_req_size)
312 host->max_req_size); 312 return -EINVAL;
313
314#ifdef CONFIG_MMC_DEBUG 313#ifdef CONFIG_MMC_DEBUG
315 sz = 0; 314 sz = 0;
316 for_each_sg(mrq->data->sg, sg, mrq->data->sg_len, i) 315 for_each_sg(mrq->data->sg, sg, mrq->data->sg_len, i)
317 sz += sg->length; 316 sz += sg->length;
318 BUG_ON(sz != mrq->data->blocks * mrq->data->blksz); 317 if (sz != mrq->data->blocks * mrq->data->blksz)
318 return -EINVAL;
319#endif 319#endif
320 320
321 mrq->cmd->data = mrq->data; 321 mrq->cmd->data = mrq->data;
@@ -349,8 +349,6 @@ void mmc_start_bkops(struct mmc_card *card, bool from_exception)
349 int timeout; 349 int timeout;
350 bool use_busy_signal; 350 bool use_busy_signal;
351 351
352 BUG_ON(!card);
353
354 if (!card->ext_csd.man_bkops_en || mmc_card_doing_bkops(card)) 352 if (!card->ext_csd.man_bkops_en || mmc_card_doing_bkops(card))
355 return; 353 return;
356 354
@@ -380,7 +378,7 @@ void mmc_start_bkops(struct mmc_card *card, bool from_exception)
380 mmc_retune_hold(card->host); 378 mmc_retune_hold(card->host);
381 379
382 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 380 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
383 EXT_CSD_BKOPS_START, 1, timeout, 381 EXT_CSD_BKOPS_START, 1, timeout, 0,
384 use_busy_signal, true, false); 382 use_busy_signal, true, false);
385 if (err) { 383 if (err) {
386 pr_warn("%s: Error %d starting bkops\n", 384 pr_warn("%s: Error %d starting bkops\n",
@@ -497,32 +495,28 @@ static int __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq)
497 * 495 *
498 * Returns enum mmc_blk_status after checking errors. 496 * Returns enum mmc_blk_status after checking errors.
499 */ 497 */
500static int mmc_wait_for_data_req_done(struct mmc_host *host, 498static enum mmc_blk_status mmc_wait_for_data_req_done(struct mmc_host *host,
501 struct mmc_request *mrq, 499 struct mmc_request *mrq,
502 struct mmc_async_req *next_req) 500 struct mmc_async_req *next_req)
503{ 501{
504 struct mmc_command *cmd; 502 struct mmc_command *cmd;
505 struct mmc_context_info *context_info = &host->context_info; 503 struct mmc_context_info *context_info = &host->context_info;
506 int err; 504 enum mmc_blk_status status;
507 unsigned long flags;
508 505
509 while (1) { 506 while (1) {
510 wait_event_interruptible(context_info->wait, 507 wait_event_interruptible(context_info->wait,
511 (context_info->is_done_rcv || 508 (context_info->is_done_rcv ||
512 context_info->is_new_req)); 509 context_info->is_new_req));
513 spin_lock_irqsave(&context_info->lock, flags);
514 context_info->is_waiting_last_req = false; 510 context_info->is_waiting_last_req = false;
515 spin_unlock_irqrestore(&context_info->lock, flags);
516 if (context_info->is_done_rcv) { 511 if (context_info->is_done_rcv) {
517 context_info->is_done_rcv = false; 512 context_info->is_done_rcv = false;
518 context_info->is_new_req = false;
519 cmd = mrq->cmd; 513 cmd = mrq->cmd;
520 514
521 if (!cmd->error || !cmd->retries || 515 if (!cmd->error || !cmd->retries ||
522 mmc_card_removed(host->card)) { 516 mmc_card_removed(host->card)) {
523 err = host->areq->err_check(host->card, 517 status = host->areq->err_check(host->card,
524 host->areq); 518 host->areq);
525 break; /* return err */ 519 break; /* return status */
526 } else { 520 } else {
527 mmc_retune_recheck(host); 521 mmc_retune_recheck(host);
528 pr_info("%s: req failed (CMD%u): %d, retrying...\n", 522 pr_info("%s: req failed (CMD%u): %d, retrying...\n",
@@ -534,13 +528,12 @@ static int mmc_wait_for_data_req_done(struct mmc_host *host,
534 continue; /* wait for done/new event again */ 528 continue; /* wait for done/new event again */
535 } 529 }
536 } else if (context_info->is_new_req) { 530 } else if (context_info->is_new_req) {
537 context_info->is_new_req = false;
538 if (!next_req) 531 if (!next_req)
539 return MMC_BLK_NEW_REQUEST; 532 return MMC_BLK_NEW_REQUEST;
540 } 533 }
541 } 534 }
542 mmc_retune_release(host); 535 mmc_retune_release(host);
543 return err; 536 return status;
544} 537}
545 538
546void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq) 539void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq)
@@ -611,18 +604,15 @@ EXPORT_SYMBOL(mmc_is_req_done);
611 * mmc_pre_req - Prepare for a new request 604 * mmc_pre_req - Prepare for a new request
612 * @host: MMC host to prepare command 605 * @host: MMC host to prepare command
613 * @mrq: MMC request to prepare for 606 * @mrq: MMC request to prepare for
614 * @is_first_req: true if there is no previous started request
615 * that may run in parellel to this call, otherwise false
616 * 607 *
617 * mmc_pre_req() is called in prior to mmc_start_req() to let 608 * mmc_pre_req() is called in prior to mmc_start_req() to let
618 * host prepare for the new request. Preparation of a request may be 609 * host prepare for the new request. Preparation of a request may be
619 * performed while another request is running on the host. 610 * performed while another request is running on the host.
620 */ 611 */
621static void mmc_pre_req(struct mmc_host *host, struct mmc_request *mrq, 612static void mmc_pre_req(struct mmc_host *host, struct mmc_request *mrq)
622 bool is_first_req)
623{ 613{
624 if (host->ops->pre_req) 614 if (host->ops->pre_req)
625 host->ops->pre_req(host, mrq, is_first_req); 615 host->ops->pre_req(host, mrq);
626} 616}
627 617
628/** 618/**
@@ -658,21 +648,22 @@ static void mmc_post_req(struct mmc_host *host, struct mmc_request *mrq,
658 * is returned without waiting. NULL is not an error condition. 648 * is returned without waiting. NULL is not an error condition.
659 */ 649 */
660struct mmc_async_req *mmc_start_req(struct mmc_host *host, 650struct mmc_async_req *mmc_start_req(struct mmc_host *host,
661 struct mmc_async_req *areq, int *error) 651 struct mmc_async_req *areq,
652 enum mmc_blk_status *ret_stat)
662{ 653{
663 int err = 0; 654 enum mmc_blk_status status = MMC_BLK_SUCCESS;
664 int start_err = 0; 655 int start_err = 0;
665 struct mmc_async_req *data = host->areq; 656 struct mmc_async_req *data = host->areq;
666 657
667 /* Prepare a new request */ 658 /* Prepare a new request */
668 if (areq) 659 if (areq)
669 mmc_pre_req(host, areq->mrq, !host->areq); 660 mmc_pre_req(host, areq->mrq);
670 661
671 if (host->areq) { 662 if (host->areq) {
672 err = mmc_wait_for_data_req_done(host, host->areq->mrq, areq); 663 status = mmc_wait_for_data_req_done(host, host->areq->mrq, areq);
673 if (err == MMC_BLK_NEW_REQUEST) { 664 if (status == MMC_BLK_NEW_REQUEST) {
674 if (error) 665 if (ret_stat)
675 *error = err; 666 *ret_stat = status;
676 /* 667 /*
677 * The previous request was not completed, 668 * The previous request was not completed,
678 * nothing to return 669 * nothing to return
@@ -695,27 +686,27 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host,
695 686
696 /* prepare the request again */ 687 /* prepare the request again */
697 if (areq) 688 if (areq)
698 mmc_pre_req(host, areq->mrq, !host->areq); 689 mmc_pre_req(host, areq->mrq);
699 } 690 }
700 } 691 }
701 692
702 if (!err && areq) 693 if (status == MMC_BLK_SUCCESS && areq)
703 start_err = __mmc_start_data_req(host, areq->mrq); 694 start_err = __mmc_start_data_req(host, areq->mrq);
704 695
705 if (host->areq) 696 if (host->areq)
706 mmc_post_req(host, host->areq->mrq, 0); 697 mmc_post_req(host, host->areq->mrq, 0);
707 698
708 /* Cancel a prepared request if it was not started. */ 699 /* Cancel a prepared request if it was not started. */
709 if ((err || start_err) && areq) 700 if ((status != MMC_BLK_SUCCESS || start_err) && areq)
710 mmc_post_req(host, areq->mrq, -EINVAL); 701 mmc_post_req(host, areq->mrq, -EINVAL);
711 702
712 if (err) 703 if (status != MMC_BLK_SUCCESS)
713 host->areq = NULL; 704 host->areq = NULL;
714 else 705 else
715 host->areq = areq; 706 host->areq = areq;
716 707
717 if (error) 708 if (ret_stat)
718 *error = err; 709 *ret_stat = status;
719 return data; 710 return data;
720} 711}
721EXPORT_SYMBOL(mmc_start_req); 712EXPORT_SYMBOL(mmc_start_req);
@@ -754,8 +745,6 @@ int mmc_interrupt_hpi(struct mmc_card *card)
754 u32 status; 745 u32 status;
755 unsigned long prg_wait; 746 unsigned long prg_wait;
756 747
757 BUG_ON(!card);
758
759 if (!card->ext_csd.hpi_en) { 748 if (!card->ext_csd.hpi_en) {
760 pr_info("%s: HPI enable bit unset\n", mmc_hostname(card->host)); 749 pr_info("%s: HPI enable bit unset\n", mmc_hostname(card->host));
761 return 1; 750 return 1;
@@ -850,7 +839,6 @@ int mmc_stop_bkops(struct mmc_card *card)
850{ 839{
851 int err = 0; 840 int err = 0;
852 841
853 BUG_ON(!card);
854 err = mmc_interrupt_hpi(card); 842 err = mmc_interrupt_hpi(card);
855 843
856 /* 844 /*
@@ -1666,8 +1654,6 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, u32 ocr)
1666 int err = 0; 1654 int err = 0;
1667 u32 clock; 1655 u32 clock;
1668 1656
1669 BUG_ON(!host);
1670
1671 /* 1657 /*
1672 * Send CMD11 only if the request is to switch the card to 1658 * Send CMD11 only if the request is to switch the card to
1673 * 1.8V signalling. 1659 * 1.8V signalling.
@@ -1884,9 +1870,7 @@ void mmc_power_cycle(struct mmc_host *host, u32 ocr)
1884 */ 1870 */
1885static void __mmc_release_bus(struct mmc_host *host) 1871static void __mmc_release_bus(struct mmc_host *host)
1886{ 1872{
1887 BUG_ON(!host); 1873 WARN_ON(!host->bus_dead);
1888 BUG_ON(host->bus_refs);
1889 BUG_ON(!host->bus_dead);
1890 1874
1891 host->bus_ops = NULL; 1875 host->bus_ops = NULL;
1892} 1876}
@@ -1926,15 +1910,12 @@ void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
1926{ 1910{
1927 unsigned long flags; 1911 unsigned long flags;
1928 1912
1929 BUG_ON(!host);
1930 BUG_ON(!ops);
1931
1932 WARN_ON(!host->claimed); 1913 WARN_ON(!host->claimed);
1933 1914
1934 spin_lock_irqsave(&host->lock, flags); 1915 spin_lock_irqsave(&host->lock, flags);
1935 1916
1936 BUG_ON(host->bus_ops); 1917 WARN_ON(host->bus_ops);
1937 BUG_ON(host->bus_refs); 1918 WARN_ON(host->bus_refs);
1938 1919
1939 host->bus_ops = ops; 1920 host->bus_ops = ops;
1940 host->bus_refs = 1; 1921 host->bus_refs = 1;
@@ -1950,8 +1931,6 @@ void mmc_detach_bus(struct mmc_host *host)
1950{ 1931{
1951 unsigned long flags; 1932 unsigned long flags;
1952 1933
1953 BUG_ON(!host);
1954
1955 WARN_ON(!host->claimed); 1934 WARN_ON(!host->claimed);
1956 WARN_ON(!host->bus_ops); 1935 WARN_ON(!host->bus_ops);
1957 1936
@@ -2824,12 +2803,11 @@ void mmc_start_host(struct mmc_host *host)
2824 host->rescan_disable = 0; 2803 host->rescan_disable = 0;
2825 host->ios.power_mode = MMC_POWER_UNDEFINED; 2804 host->ios.power_mode = MMC_POWER_UNDEFINED;
2826 2805
2827 mmc_claim_host(host); 2806 if (!(host->caps2 & MMC_CAP2_NO_PRESCAN_POWERUP)) {
2828 if (host->caps2 & MMC_CAP2_NO_PRESCAN_POWERUP) 2807 mmc_claim_host(host);
2829 mmc_power_off(host);
2830 else
2831 mmc_power_up(host, host->ocr_avail); 2808 mmc_power_up(host, host->ocr_avail);
2832 mmc_release_host(host); 2809 mmc_release_host(host);
2810 }
2833 2811
2834 mmc_gpiod_request_cd_irq(host); 2812 mmc_gpiod_request_cd_irq(host);
2835 _mmc_detect_change(host, 0, false); 2813 _mmc_detect_change(host, 0, false);
@@ -2865,8 +2843,6 @@ void mmc_stop_host(struct mmc_host *host)
2865 } 2843 }
2866 mmc_bus_put(host); 2844 mmc_bus_put(host);
2867 2845
2868 BUG_ON(host->card);
2869
2870 mmc_claim_host(host); 2846 mmc_claim_host(host);
2871 mmc_power_off(host); 2847 mmc_power_off(host);
2872 mmc_release_host(host); 2848 mmc_release_host(host);
@@ -3019,7 +2995,6 @@ void mmc_unregister_pm_notifier(struct mmc_host *host)
3019 */ 2995 */
3020void mmc_init_context_info(struct mmc_host *host) 2996void mmc_init_context_info(struct mmc_host *host)
3021{ 2997{
3022 spin_lock_init(&host->context_info.lock);
3023 host->context_info.is_new_req = false; 2998 host->context_info.is_new_req = false;
3024 host->context_info.is_done_rcv = false; 2999 host->context_info.is_done_rcv = false;
3025 host->context_info.is_waiting_last_req = false; 3000 host->context_info.is_waiting_last_req = false;
diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
index c8451ce557ae..30623b8b86a4 100644
--- a/drivers/mmc/core/debugfs.c
+++ b/drivers/mmc/core/debugfs.c
@@ -321,7 +321,11 @@ static int mmc_ext_csd_open(struct inode *inode, struct file *filp)
321 for (i = 0; i < 512; i++) 321 for (i = 0; i < 512; i++)
322 n += sprintf(buf + n, "%02x", ext_csd[i]); 322 n += sprintf(buf + n, "%02x", ext_csd[i]);
323 n += sprintf(buf + n, "\n"); 323 n += sprintf(buf + n, "\n");
324 BUG_ON(n != EXT_CSD_STR_LEN); 324
325 if (n != EXT_CSD_STR_LEN) {
326 err = -EINVAL;
327 goto out_free;
328 }
325 329
326 filp->private_data = buf; 330 filp->private_data = buf;
327 kfree(ext_csd); 331 kfree(ext_csd);
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index df19777068a6..b61b52f9da3d 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -618,6 +618,24 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd)
618 (ext_csd[EXT_CSD_SUPPORTED_MODE] & 0x1) && 618 (ext_csd[EXT_CSD_SUPPORTED_MODE] & 0x1) &&
619 !(ext_csd[EXT_CSD_FW_CONFIG] & 0x1); 619 !(ext_csd[EXT_CSD_FW_CONFIG] & 0x1);
620 } 620 }
621
622 /* eMMC v5.1 or later */
623 if (card->ext_csd.rev >= 8) {
624 card->ext_csd.cmdq_support = ext_csd[EXT_CSD_CMDQ_SUPPORT] &
625 EXT_CSD_CMDQ_SUPPORTED;
626 card->ext_csd.cmdq_depth = (ext_csd[EXT_CSD_CMDQ_DEPTH] &
627 EXT_CSD_CMDQ_DEPTH_MASK) + 1;
628 /* Exclude inefficiently small queue depths */
629 if (card->ext_csd.cmdq_depth <= 2) {
630 card->ext_csd.cmdq_support = false;
631 card->ext_csd.cmdq_depth = 0;
632 }
633 if (card->ext_csd.cmdq_support) {
634 pr_debug("%s: Command Queue supported depth %u\n",
635 mmc_hostname(card->host),
636 card->ext_csd.cmdq_depth);
637 }
638 }
621out: 639out:
622 return err; 640 return err;
623} 641}
@@ -1003,19 +1021,6 @@ static int mmc_select_bus_width(struct mmc_card *card)
1003 return err; 1021 return err;
1004} 1022}
1005 1023
1006/* Caller must hold re-tuning */
1007static int mmc_switch_status(struct mmc_card *card)
1008{
1009 u32 status;
1010 int err;
1011
1012 err = mmc_send_status(card, &status);
1013 if (err)
1014 return err;
1015
1016 return mmc_switch_status_error(card->host, status);
1017}
1018
1019/* 1024/*
1020 * Switch to the high-speed mode 1025 * Switch to the high-speed mode
1021 */ 1026 */
@@ -1025,13 +1030,8 @@ static int mmc_select_hs(struct mmc_card *card)
1025 1030
1026 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1031 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1027 EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS, 1032 EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS,
1028 card->ext_csd.generic_cmd6_time, 1033 card->ext_csd.generic_cmd6_time, MMC_TIMING_MMC_HS,
1029 true, false, true); 1034 true, true, true);
1030 if (!err) {
1031 mmc_set_timing(card->host, MMC_TIMING_MMC_HS);
1032 err = mmc_switch_status(card);
1033 }
1034
1035 if (err) 1035 if (err)
1036 pr_warn("%s: switch to high-speed failed, err:%d\n", 1036 pr_warn("%s: switch to high-speed failed, err:%d\n",
1037 mmc_hostname(card->host), err); 1037 mmc_hostname(card->host), err);
@@ -1058,10 +1058,12 @@ static int mmc_select_hs_ddr(struct mmc_card *card)
1058 ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ? 1058 ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ?
1059 EXT_CSD_DDR_BUS_WIDTH_8 : EXT_CSD_DDR_BUS_WIDTH_4; 1059 EXT_CSD_DDR_BUS_WIDTH_8 : EXT_CSD_DDR_BUS_WIDTH_4;
1060 1060
1061 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1061 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1062 EXT_CSD_BUS_WIDTH, 1062 EXT_CSD_BUS_WIDTH,
1063 ext_csd_bits, 1063 ext_csd_bits,
1064 card->ext_csd.generic_cmd6_time); 1064 card->ext_csd.generic_cmd6_time,
1065 MMC_TIMING_MMC_DDR52,
1066 true, true, true);
1065 if (err) { 1067 if (err) {
1066 pr_err("%s: switch to bus width %d ddr failed\n", 1068 pr_err("%s: switch to bus width %d ddr failed\n",
1067 mmc_hostname(host), 1 << bus_width); 1069 mmc_hostname(host), 1 << bus_width);
@@ -1104,9 +1106,6 @@ static int mmc_select_hs_ddr(struct mmc_card *card)
1104 if (err) 1106 if (err)
1105 err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330); 1107 err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330);
1106 1108
1107 if (!err)
1108 mmc_set_timing(host, MMC_TIMING_MMC_DDR52);
1109
1110 return err; 1109 return err;
1111} 1110}
1112 1111
@@ -1128,7 +1127,7 @@ static int mmc_select_hs400(struct mmc_card *card)
1128 val = EXT_CSD_TIMING_HS; 1127 val = EXT_CSD_TIMING_HS;
1129 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1128 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1130 EXT_CSD_HS_TIMING, val, 1129 EXT_CSD_HS_TIMING, val,
1131 card->ext_csd.generic_cmd6_time, 1130 card->ext_csd.generic_cmd6_time, 0,
1132 true, false, true); 1131 true, false, true);
1133 if (err) { 1132 if (err) {
1134 pr_err("%s: switch to high-speed from hs200 failed, err:%d\n", 1133 pr_err("%s: switch to high-speed from hs200 failed, err:%d\n",
@@ -1163,7 +1162,7 @@ static int mmc_select_hs400(struct mmc_card *card)
1163 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; 1162 card->drive_strength << EXT_CSD_DRV_STR_SHIFT;
1164 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1163 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1165 EXT_CSD_HS_TIMING, val, 1164 EXT_CSD_HS_TIMING, val,
1166 card->ext_csd.generic_cmd6_time, 1165 card->ext_csd.generic_cmd6_time, 0,
1167 true, false, true); 1166 true, false, true);
1168 if (err) { 1167 if (err) {
1169 pr_err("%s: switch to hs400 failed, err:%d\n", 1168 pr_err("%s: switch to hs400 failed, err:%d\n",
@@ -1206,7 +1205,7 @@ int mmc_hs400_to_hs200(struct mmc_card *card)
1206 /* Switch HS400 to HS DDR */ 1205 /* Switch HS400 to HS DDR */
1207 val = EXT_CSD_TIMING_HS; 1206 val = EXT_CSD_TIMING_HS;
1208 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 1207 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING,
1209 val, card->ext_csd.generic_cmd6_time, 1208 val, card->ext_csd.generic_cmd6_time, 0,
1210 true, false, true); 1209 true, false, true);
1211 if (err) 1210 if (err)
1212 goto out_err; 1211 goto out_err;
@@ -1220,7 +1219,7 @@ int mmc_hs400_to_hs200(struct mmc_card *card)
1220 /* Switch HS DDR to HS */ 1219 /* Switch HS DDR to HS */
1221 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, 1220 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH,
1222 EXT_CSD_BUS_WIDTH_8, card->ext_csd.generic_cmd6_time, 1221 EXT_CSD_BUS_WIDTH_8, card->ext_csd.generic_cmd6_time,
1223 true, false, true); 1222 0, true, false, true);
1224 if (err) 1223 if (err)
1225 goto out_err; 1224 goto out_err;
1226 1225
@@ -1234,14 +1233,19 @@ int mmc_hs400_to_hs200(struct mmc_card *card)
1234 val = EXT_CSD_TIMING_HS200 | 1233 val = EXT_CSD_TIMING_HS200 |
1235 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; 1234 card->drive_strength << EXT_CSD_DRV_STR_SHIFT;
1236 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 1235 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING,
1237 val, card->ext_csd.generic_cmd6_time, 1236 val, card->ext_csd.generic_cmd6_time, 0,
1238 true, false, true); 1237 true, false, true);
1239 if (err) 1238 if (err)
1240 goto out_err; 1239 goto out_err;
1241 1240
1242 mmc_set_timing(host, MMC_TIMING_MMC_HS200); 1241 mmc_set_timing(host, MMC_TIMING_MMC_HS200);
1243 1242
1244 err = mmc_switch_status(card); 1243 /*
1244 * For HS200, CRC errors are not a reliable way to know the switch
1245 * failed. If there really is a problem, we would expect tuning will
1246 * fail and the result ends up the same.
1247 */
1248 err = __mmc_switch_status(card, false);
1245 if (err) 1249 if (err)
1246 goto out_err; 1250 goto out_err;
1247 1251
@@ -1281,16 +1285,23 @@ static int mmc_select_hs400es(struct mmc_card *card)
1281 goto out_err; 1285 goto out_err;
1282 1286
1283 /* Switch card to HS mode */ 1287 /* Switch card to HS mode */
1284 err = mmc_select_hs(card); 1288 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1285 if (err) 1289 EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS,
1290 card->ext_csd.generic_cmd6_time, 0,
1291 true, false, true);
1292 if (err) {
1293 pr_err("%s: switch to hs for hs400es failed, err:%d\n",
1294 mmc_hostname(host), err);
1286 goto out_err; 1295 goto out_err;
1296 }
1287 1297
1288 mmc_set_clock(host, card->ext_csd.hs_max_dtr); 1298 mmc_set_timing(host, MMC_TIMING_MMC_HS);
1289
1290 err = mmc_switch_status(card); 1299 err = mmc_switch_status(card);
1291 if (err) 1300 if (err)
1292 goto out_err; 1301 goto out_err;
1293 1302
1303 mmc_set_clock(host, card->ext_csd.hs_max_dtr);
1304
1294 /* Switch card to DDR with strobe bit */ 1305 /* Switch card to DDR with strobe bit */
1295 val = EXT_CSD_DDR_BUS_WIDTH_8 | EXT_CSD_BUS_WIDTH_STROBE; 1306 val = EXT_CSD_DDR_BUS_WIDTH_8 | EXT_CSD_BUS_WIDTH_STROBE;
1296 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1307 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
@@ -1308,7 +1319,7 @@ static int mmc_select_hs400es(struct mmc_card *card)
1308 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; 1319 card->drive_strength << EXT_CSD_DRV_STR_SHIFT;
1309 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1320 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1310 EXT_CSD_HS_TIMING, val, 1321 EXT_CSD_HS_TIMING, val,
1311 card->ext_csd.generic_cmd6_time, 1322 card->ext_csd.generic_cmd6_time, 0,
1312 true, false, true); 1323 true, false, true);
1313 if (err) { 1324 if (err) {
1314 pr_err("%s: switch to hs400es failed, err:%d\n", 1325 pr_err("%s: switch to hs400es failed, err:%d\n",
@@ -1390,14 +1401,20 @@ static int mmc_select_hs200(struct mmc_card *card)
1390 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; 1401 card->drive_strength << EXT_CSD_DRV_STR_SHIFT;
1391 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1402 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1392 EXT_CSD_HS_TIMING, val, 1403 EXT_CSD_HS_TIMING, val,
1393 card->ext_csd.generic_cmd6_time, 1404 card->ext_csd.generic_cmd6_time, 0,
1394 true, false, true); 1405 true, false, true);
1395 if (err) 1406 if (err)
1396 goto err; 1407 goto err;
1397 old_timing = host->ios.timing; 1408 old_timing = host->ios.timing;
1398 mmc_set_timing(host, MMC_TIMING_MMC_HS200); 1409 mmc_set_timing(host, MMC_TIMING_MMC_HS200);
1399 1410
1400 err = mmc_switch_status(card); 1411 /*
1412 * For HS200, CRC errors are not a reliable way to know the
1413 * switch failed. If there really is a problem, we would expect
1414 * tuning will fail and the result ends up the same.
1415 */
1416 err = __mmc_switch_status(card, false);
1417
1401 /* 1418 /*
1402 * mmc_select_timing() assumes timing has not changed if 1419 * mmc_select_timing() assumes timing has not changed if
1403 * it is a switch error. 1420 * it is a switch error.
@@ -1480,7 +1497,6 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1480 u32 cid[4]; 1497 u32 cid[4];
1481 u32 rocr; 1498 u32 rocr;
1482 1499
1483 BUG_ON(!host);
1484 WARN_ON(!host->claimed); 1500 WARN_ON(!host->claimed);
1485 1501
1486 /* Set correct bus mode for MMC before attempting init */ 1502 /* Set correct bus mode for MMC before attempting init */
@@ -1854,7 +1870,7 @@ static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type)
1854 1870
1855 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1871 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1856 EXT_CSD_POWER_OFF_NOTIFICATION, 1872 EXT_CSD_POWER_OFF_NOTIFICATION,
1857 notify_type, timeout, true, false, false); 1873 notify_type, timeout, 0, true, false, false);
1858 if (err) 1874 if (err)
1859 pr_err("%s: Power Off Notification timed out, %u\n", 1875 pr_err("%s: Power Off Notification timed out, %u\n",
1860 mmc_hostname(card->host), timeout); 1876 mmc_hostname(card->host), timeout);
@@ -1870,9 +1886,6 @@ static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type)
1870 */ 1886 */
1871static void mmc_remove(struct mmc_host *host) 1887static void mmc_remove(struct mmc_host *host)
1872{ 1888{
1873 BUG_ON(!host);
1874 BUG_ON(!host->card);
1875
1876 mmc_remove_card(host->card); 1889 mmc_remove_card(host->card);
1877 host->card = NULL; 1890 host->card = NULL;
1878} 1891}
@@ -1892,9 +1905,6 @@ static void mmc_detect(struct mmc_host *host)
1892{ 1905{
1893 int err; 1906 int err;
1894 1907
1895 BUG_ON(!host);
1896 BUG_ON(!host->card);
1897
1898 mmc_get_card(host->card); 1908 mmc_get_card(host->card);
1899 1909
1900 /* 1910 /*
@@ -1920,9 +1930,6 @@ static int _mmc_suspend(struct mmc_host *host, bool is_suspend)
1920 unsigned int notify_type = is_suspend ? EXT_CSD_POWER_OFF_SHORT : 1930 unsigned int notify_type = is_suspend ? EXT_CSD_POWER_OFF_SHORT :
1921 EXT_CSD_POWER_OFF_LONG; 1931 EXT_CSD_POWER_OFF_LONG;
1922 1932
1923 BUG_ON(!host);
1924 BUG_ON(!host->card);
1925
1926 mmc_claim_host(host); 1933 mmc_claim_host(host);
1927 1934
1928 if (mmc_card_suspended(host->card)) 1935 if (mmc_card_suspended(host->card))
@@ -1979,9 +1986,6 @@ static int _mmc_resume(struct mmc_host *host)
1979{ 1986{
1980 int err = 0; 1987 int err = 0;
1981 1988
1982 BUG_ON(!host);
1983 BUG_ON(!host->card);
1984
1985 mmc_claim_host(host); 1989 mmc_claim_host(host);
1986 1990
1987 if (!mmc_card_suspended(host->card)) 1991 if (!mmc_card_suspended(host->card))
@@ -2114,7 +2118,6 @@ int mmc_attach_mmc(struct mmc_host *host)
2114 int err; 2118 int err;
2115 u32 ocr, rocr; 2119 u32 ocr, rocr;
2116 2120
2117 BUG_ON(!host);
2118 WARN_ON(!host->claimed); 2121 WARN_ON(!host->claimed);
2119 2122
2120 /* Set correct bus mode for MMC before attempting attach */ 2123 /* Set correct bus mode for MMC before attempting attach */
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index ad6e9798e949..b11c3455b040 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -54,21 +54,15 @@ static const u8 tuning_blk_pattern_8bit[] = {
54 0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee, 54 0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee,
55}; 55};
56 56
57static inline int __mmc_send_status(struct mmc_card *card, u32 *status, 57int mmc_send_status(struct mmc_card *card, u32 *status)
58 bool ignore_crc)
59{ 58{
60 int err; 59 int err;
61 struct mmc_command cmd = {0}; 60 struct mmc_command cmd = {0};
62 61
63 BUG_ON(!card);
64 BUG_ON(!card->host);
65
66 cmd.opcode = MMC_SEND_STATUS; 62 cmd.opcode = MMC_SEND_STATUS;
67 if (!mmc_host_is_spi(card->host)) 63 if (!mmc_host_is_spi(card->host))
68 cmd.arg = card->rca << 16; 64 cmd.arg = card->rca << 16;
69 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC; 65 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
70 if (ignore_crc)
71 cmd.flags &= ~MMC_RSP_CRC;
72 66
73 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); 67 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
74 if (err) 68 if (err)
@@ -83,17 +77,10 @@ static inline int __mmc_send_status(struct mmc_card *card, u32 *status,
83 return 0; 77 return 0;
84} 78}
85 79
86int mmc_send_status(struct mmc_card *card, u32 *status)
87{
88 return __mmc_send_status(card, status, false);
89}
90
91static int _mmc_select_card(struct mmc_host *host, struct mmc_card *card) 80static int _mmc_select_card(struct mmc_host *host, struct mmc_card *card)
92{ 81{
93 struct mmc_command cmd = {0}; 82 struct mmc_command cmd = {0};
94 83
95 BUG_ON(!host);
96
97 cmd.opcode = MMC_SELECT_CARD; 84 cmd.opcode = MMC_SELECT_CARD;
98 85
99 if (card) { 86 if (card) {
@@ -109,7 +96,6 @@ static int _mmc_select_card(struct mmc_host *host, struct mmc_card *card)
109 96
110int mmc_select_card(struct mmc_card *card) 97int mmc_select_card(struct mmc_card *card)
111{ 98{
112 BUG_ON(!card);
113 99
114 return _mmc_select_card(card->host, card); 100 return _mmc_select_card(card->host, card);
115} 101}
@@ -181,8 +167,6 @@ int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
181 struct mmc_command cmd = {0}; 167 struct mmc_command cmd = {0};
182 int i, err = 0; 168 int i, err = 0;
183 169
184 BUG_ON(!host);
185
186 cmd.opcode = MMC_SEND_OP_COND; 170 cmd.opcode = MMC_SEND_OP_COND;
187 cmd.arg = mmc_host_is_spi(host) ? 0 : ocr; 171 cmd.arg = mmc_host_is_spi(host) ? 0 : ocr;
188 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR; 172 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR;
@@ -221,9 +205,6 @@ int mmc_all_send_cid(struct mmc_host *host, u32 *cid)
221 int err; 205 int err;
222 struct mmc_command cmd = {0}; 206 struct mmc_command cmd = {0};
223 207
224 BUG_ON(!host);
225 BUG_ON(!cid);
226
227 cmd.opcode = MMC_ALL_SEND_CID; 208 cmd.opcode = MMC_ALL_SEND_CID;
228 cmd.arg = 0; 209 cmd.arg = 0;
229 cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR; 210 cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR;
@@ -241,9 +222,6 @@ int mmc_set_relative_addr(struct mmc_card *card)
241{ 222{
242 struct mmc_command cmd = {0}; 223 struct mmc_command cmd = {0};
243 224
244 BUG_ON(!card);
245 BUG_ON(!card->host);
246
247 cmd.opcode = MMC_SET_RELATIVE_ADDR; 225 cmd.opcode = MMC_SET_RELATIVE_ADDR;
248 cmd.arg = card->rca << 16; 226 cmd.arg = card->rca << 16;
249 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 227 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
@@ -257,9 +235,6 @@ mmc_send_cxd_native(struct mmc_host *host, u32 arg, u32 *cxd, int opcode)
257 int err; 235 int err;
258 struct mmc_command cmd = {0}; 236 struct mmc_command cmd = {0};
259 237
260 BUG_ON(!host);
261 BUG_ON(!cxd);
262
263 cmd.opcode = opcode; 238 cmd.opcode = opcode;
264 cmd.arg = arg; 239 cmd.arg = arg;
265 cmd.flags = MMC_RSP_R2 | MMC_CMD_AC; 240 cmd.flags = MMC_RSP_R2 | MMC_CMD_AC;
@@ -440,7 +415,7 @@ int mmc_spi_set_crc(struct mmc_host *host, int use_crc)
440 return err; 415 return err;
441} 416}
442 417
443int mmc_switch_status_error(struct mmc_host *host, u32 status) 418static int mmc_switch_status_error(struct mmc_host *host, u32 status)
444{ 419{
445 if (mmc_host_is_spi(host)) { 420 if (mmc_host_is_spi(host)) {
446 if (status & R1_SPI_ILLEGAL_COMMAND) 421 if (status & R1_SPI_ILLEGAL_COMMAND)
@@ -455,6 +430,88 @@ int mmc_switch_status_error(struct mmc_host *host, u32 status)
455 return 0; 430 return 0;
456} 431}
457 432
433/* Caller must hold re-tuning */
434int __mmc_switch_status(struct mmc_card *card, bool crc_err_fatal)
435{
436 u32 status;
437 int err;
438
439 err = mmc_send_status(card, &status);
440 if (!crc_err_fatal && err == -EILSEQ)
441 return 0;
442 if (err)
443 return err;
444
445 return mmc_switch_status_error(card->host, status);
446}
447
448int mmc_switch_status(struct mmc_card *card)
449{
450 return __mmc_switch_status(card, true);
451}
452
453static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms,
454 bool send_status, bool retry_crc_err)
455{
456 struct mmc_host *host = card->host;
457 int err;
458 unsigned long timeout;
459 u32 status = 0;
460 bool expired = false;
461 bool busy = false;
462
463 /* We have an unspecified cmd timeout, use the fallback value. */
464 if (!timeout_ms)
465 timeout_ms = MMC_OPS_TIMEOUT_MS;
466
467 /*
468 * In cases when not allowed to poll by using CMD13 or because we aren't
469 * capable of polling by using ->card_busy(), then rely on waiting the
470 * stated timeout to be sufficient.
471 */
472 if (!send_status && !host->ops->card_busy) {
473 mmc_delay(timeout_ms);
474 return 0;
475 }
476
477 timeout = jiffies + msecs_to_jiffies(timeout_ms) + 1;
478 do {
479 /*
480 * Due to the possibility of being preempted while polling,
481 * check the expiration time first.
482 */
483 expired = time_after(jiffies, timeout);
484
485 if (host->ops->card_busy) {
486 busy = host->ops->card_busy(host);
487 } else {
488 err = mmc_send_status(card, &status);
489 if (retry_crc_err && err == -EILSEQ) {
490 busy = true;
491 } else if (err) {
492 return err;
493 } else {
494 err = mmc_switch_status_error(host, status);
495 if (err)
496 return err;
497 busy = R1_CURRENT_STATE(status) == R1_STATE_PRG;
498 }
499 }
500
501 /* Timeout if the device still remains busy. */
502 if (expired && busy) {
503 pr_err("%s: Card stuck being busy! %s\n",
504 mmc_hostname(host), __func__);
505 return -ETIMEDOUT;
506 }
507 } while (busy);
508
509 if (host->ops->card_busy && send_status)
510 return mmc_switch_status(card);
511
512 return 0;
513}
514
458/** 515/**
459 * __mmc_switch - modify EXT_CSD register 516 * __mmc_switch - modify EXT_CSD register
460 * @card: the MMC card associated with the data transfer 517 * @card: the MMC card associated with the data transfer
@@ -463,24 +520,22 @@ int mmc_switch_status_error(struct mmc_host *host, u32 status)
463 * @value: value to program into EXT_CSD register 520 * @value: value to program into EXT_CSD register
464 * @timeout_ms: timeout (ms) for operation performed by register write, 521 * @timeout_ms: timeout (ms) for operation performed by register write,
465 * timeout of zero implies maximum possible timeout 522 * timeout of zero implies maximum possible timeout
523 * @timing: new timing to change to
466 * @use_busy_signal: use the busy signal as response type 524 * @use_busy_signal: use the busy signal as response type
467 * @send_status: send status cmd to poll for busy 525 * @send_status: send status cmd to poll for busy
468 * @ignore_crc: ignore CRC errors when sending status cmd to poll for busy 526 * @retry_crc_err: retry when CRC errors when polling with CMD13 for busy
469 * 527 *
470 * Modifies the EXT_CSD register for selected card. 528 * Modifies the EXT_CSD register for selected card.
471 */ 529 */
472int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, 530int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
473 unsigned int timeout_ms, bool use_busy_signal, bool send_status, 531 unsigned int timeout_ms, unsigned char timing,
474 bool ignore_crc) 532 bool use_busy_signal, bool send_status, bool retry_crc_err)
475{ 533{
476 struct mmc_host *host = card->host; 534 struct mmc_host *host = card->host;
477 int err; 535 int err;
478 struct mmc_command cmd = {0}; 536 struct mmc_command cmd = {0};
479 unsigned long timeout;
480 u32 status = 0;
481 bool use_r1b_resp = use_busy_signal; 537 bool use_r1b_resp = use_busy_signal;
482 bool expired = false; 538 unsigned char old_timing = host->ios.timing;
483 bool busy = false;
484 539
485 mmc_retune_hold(host); 540 mmc_retune_hold(host);
486 541
@@ -522,62 +577,24 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
522 if (!use_busy_signal) 577 if (!use_busy_signal)
523 goto out; 578 goto out;
524 579
525 /* 580 /* Switch to new timing before poll and check switch status. */
526 * CRC errors shall only be ignored in cases were CMD13 is used to poll 581 if (timing)
527 * to detect busy completion. 582 mmc_set_timing(host, timing);
528 */
529 if ((host->caps & MMC_CAP_WAIT_WHILE_BUSY) && use_r1b_resp)
530 ignore_crc = false;
531
532 /* We have an unspecified cmd timeout, use the fallback value. */
533 if (!timeout_ms)
534 timeout_ms = MMC_OPS_TIMEOUT_MS;
535
536 /* Must check status to be sure of no errors. */
537 timeout = jiffies + msecs_to_jiffies(timeout_ms) + 1;
538 do {
539 /*
540 * Due to the possibility of being preempted after
541 * sending the status command, check the expiration
542 * time first.
543 */
544 expired = time_after(jiffies, timeout);
545 if (send_status) {
546 err = __mmc_send_status(card, &status, ignore_crc);
547 if (err)
548 goto out;
549 }
550 if ((host->caps & MMC_CAP_WAIT_WHILE_BUSY) && use_r1b_resp)
551 break;
552 if (host->ops->card_busy) {
553 if (!host->ops->card_busy(host))
554 break;
555 busy = true;
556 }
557 if (mmc_host_is_spi(host))
558 break;
559 583
560 /* 584 /*If SPI or used HW busy detection above, then we don't need to poll. */
561 * We are not allowed to issue a status command and the host 585 if (((host->caps & MMC_CAP_WAIT_WHILE_BUSY) && use_r1b_resp) ||
562 * does'nt support MMC_CAP_WAIT_WHILE_BUSY, then we can only 586 mmc_host_is_spi(host)) {
563 * rely on waiting for the stated timeout to be sufficient. 587 if (send_status)
564 */ 588 err = mmc_switch_status(card);
565 if (!send_status && !host->ops->card_busy) { 589 goto out_tim;
566 mmc_delay(timeout_ms); 590 }
567 goto out;
568 }
569 591
570 /* Timeout if the device never leaves the program state. */ 592 /* Let's try to poll to find out when the command is completed. */
571 if (expired && 593 err = mmc_poll_for_busy(card, timeout_ms, send_status, retry_crc_err);
572 (R1_CURRENT_STATE(status) == R1_STATE_PRG || busy)) {
573 pr_err("%s: Card stuck in programming state! %s\n",
574 mmc_hostname(host), __func__);
575 err = -ETIMEDOUT;
576 goto out;
577 }
578 } while (R1_CURRENT_STATE(status) == R1_STATE_PRG || busy);
579 594
580 err = mmc_switch_status_error(host, status); 595out_tim:
596 if (err && timing)
597 mmc_set_timing(host, old_timing);
581out: 598out:
582 mmc_retune_release(host); 599 mmc_retune_release(host);
583 600
@@ -587,8 +604,8 @@ out:
587int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, 604int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
588 unsigned int timeout_ms) 605 unsigned int timeout_ms)
589{ 606{
590 return __mmc_switch(card, set, index, value, timeout_ms, true, true, 607 return __mmc_switch(card, set, index, value, timeout_ms, 0,
591 false); 608 true, true, false);
592} 609}
593EXPORT_SYMBOL_GPL(mmc_switch); 610EXPORT_SYMBOL_GPL(mmc_switch);
594 611
@@ -661,6 +678,31 @@ out:
661} 678}
662EXPORT_SYMBOL_GPL(mmc_send_tuning); 679EXPORT_SYMBOL_GPL(mmc_send_tuning);
663 680
681int mmc_abort_tuning(struct mmc_host *host, u32 opcode)
682{
683 struct mmc_command cmd = {0};
684
685 /*
686 * eMMC specification specifies that CMD12 can be used to stop a tuning
687 * command, but SD specification does not, so do nothing unless it is
688 * eMMC.
689 */
690 if (opcode != MMC_SEND_TUNING_BLOCK_HS200)
691 return 0;
692
693 cmd.opcode = MMC_STOP_TRANSMISSION;
694 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
695
696 /*
697 * For drivers that override R1 to R1b, set an arbitrary timeout based
698 * on the tuning timeout i.e. 150ms.
699 */
700 cmd.busy_timeout = 150;
701
702 return mmc_wait_for_cmd(host, &cmd, 0);
703}
704EXPORT_SYMBOL_GPL(mmc_abort_tuning);
705
664static int 706static int
665mmc_send_bus_test(struct mmc_card *card, struct mmc_host *host, u8 opcode, 707mmc_send_bus_test(struct mmc_card *card, struct mmc_host *host, u8 opcode,
666 u8 len) 708 u8 len)
diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h
index f1b8e81aaa28..abd525ed74be 100644
--- a/drivers/mmc/core/mmc_ops.h
+++ b/drivers/mmc/core/mmc_ops.h
@@ -27,10 +27,11 @@ int mmc_spi_set_crc(struct mmc_host *host, int use_crc);
27int mmc_bus_test(struct mmc_card *card, u8 bus_width); 27int mmc_bus_test(struct mmc_card *card, u8 bus_width);
28int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status); 28int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status);
29int mmc_can_ext_csd(struct mmc_card *card); 29int mmc_can_ext_csd(struct mmc_card *card);
30int mmc_switch_status_error(struct mmc_host *host, u32 status); 30int mmc_switch_status(struct mmc_card *card);
31int __mmc_switch_status(struct mmc_card *card, bool crc_err_fatal);
31int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, 32int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
32 unsigned int timeout_ms, bool use_busy_signal, bool send_status, 33 unsigned int timeout_ms, unsigned char timing,
33 bool ignore_crc); 34 bool use_busy_signal, bool send_status, bool retry_crc_err);
34 35
35#endif 36#endif
36 37
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 73c762a28dfe..deb90c2ff6b4 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -927,7 +927,6 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
927 u32 cid[4]; 927 u32 cid[4];
928 u32 rocr = 0; 928 u32 rocr = 0;
929 929
930 BUG_ON(!host);
931 WARN_ON(!host->claimed); 930 WARN_ON(!host->claimed);
932 931
933 err = mmc_sd_get_cid(host, ocr, cid, &rocr); 932 err = mmc_sd_get_cid(host, ocr, cid, &rocr);
@@ -1043,9 +1042,6 @@ free_card:
1043 */ 1042 */
1044static void mmc_sd_remove(struct mmc_host *host) 1043static void mmc_sd_remove(struct mmc_host *host)
1045{ 1044{
1046 BUG_ON(!host);
1047 BUG_ON(!host->card);
1048
1049 mmc_remove_card(host->card); 1045 mmc_remove_card(host->card);
1050 host->card = NULL; 1046 host->card = NULL;
1051} 1047}
@@ -1065,9 +1061,6 @@ static void mmc_sd_detect(struct mmc_host *host)
1065{ 1061{
1066 int err; 1062 int err;
1067 1063
1068 BUG_ON(!host);
1069 BUG_ON(!host->card);
1070
1071 mmc_get_card(host->card); 1064 mmc_get_card(host->card);
1072 1065
1073 /* 1066 /*
@@ -1091,9 +1084,6 @@ static int _mmc_sd_suspend(struct mmc_host *host)
1091{ 1084{
1092 int err = 0; 1085 int err = 0;
1093 1086
1094 BUG_ON(!host);
1095 BUG_ON(!host->card);
1096
1097 mmc_claim_host(host); 1087 mmc_claim_host(host);
1098 1088
1099 if (mmc_card_suspended(host->card)) 1089 if (mmc_card_suspended(host->card))
@@ -1136,9 +1126,6 @@ static int _mmc_sd_resume(struct mmc_host *host)
1136{ 1126{
1137 int err = 0; 1127 int err = 0;
1138 1128
1139 BUG_ON(!host);
1140 BUG_ON(!host->card);
1141
1142 mmc_claim_host(host); 1129 mmc_claim_host(host);
1143 1130
1144 if (!mmc_card_suspended(host->card)) 1131 if (!mmc_card_suspended(host->card))
@@ -1221,7 +1208,6 @@ int mmc_attach_sd(struct mmc_host *host)
1221 int err; 1208 int err;
1222 u32 ocr, rocr; 1209 u32 ocr, rocr;
1223 1210
1224 BUG_ON(!host);
1225 WARN_ON(!host->claimed); 1211 WARN_ON(!host->claimed);
1226 1212
1227 err = mmc_send_app_op_cond(host, 0, &ocr); 1213 err = mmc_send_app_op_cond(host, 0, &ocr);
diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
index 16b774c18e75..de125a41aa7a 100644
--- a/drivers/mmc/core/sd_ops.c
+++ b/drivers/mmc/core/sd_ops.c
@@ -27,8 +27,8 @@ int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
27 int err; 27 int err;
28 struct mmc_command cmd = {0}; 28 struct mmc_command cmd = {0};
29 29
30 BUG_ON(!host); 30 if (WARN_ON(card && card->host != host))
31 BUG_ON(card && (card->host != host)); 31 return -EINVAL;
32 32
33 cmd.opcode = MMC_APP_CMD; 33 cmd.opcode = MMC_APP_CMD;
34 34
@@ -72,8 +72,8 @@ int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
72 72
73 int i, err; 73 int i, err;
74 74
75 BUG_ON(!cmd); 75 if (retries < 0)
76 BUG_ON(retries < 0); 76 retries = MMC_CMD_RETRIES;
77 77
78 err = -EIO; 78 err = -EIO;
79 79
@@ -122,9 +122,6 @@ int mmc_app_set_bus_width(struct mmc_card *card, int width)
122{ 122{
123 struct mmc_command cmd = {0}; 123 struct mmc_command cmd = {0};
124 124
125 BUG_ON(!card);
126 BUG_ON(!card->host);
127
128 cmd.opcode = SD_APP_SET_BUS_WIDTH; 125 cmd.opcode = SD_APP_SET_BUS_WIDTH;
129 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 126 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
130 127
@@ -147,8 +144,6 @@ int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
147 struct mmc_command cmd = {0}; 144 struct mmc_command cmd = {0};
148 int i, err = 0; 145 int i, err = 0;
149 146
150 BUG_ON(!host);
151
152 cmd.opcode = SD_APP_OP_COND; 147 cmd.opcode = SD_APP_OP_COND;
153 if (mmc_host_is_spi(host)) 148 if (mmc_host_is_spi(host))
154 cmd.arg = ocr & (1 << 30); /* SPI only defines one bit */ 149 cmd.arg = ocr & (1 << 30); /* SPI only defines one bit */
@@ -224,9 +219,6 @@ int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca)
224 int err; 219 int err;
225 struct mmc_command cmd = {0}; 220 struct mmc_command cmd = {0};
226 221
227 BUG_ON(!host);
228 BUG_ON(!rca);
229
230 cmd.opcode = SD_SEND_RELATIVE_ADDR; 222 cmd.opcode = SD_SEND_RELATIVE_ADDR;
231 cmd.arg = 0; 223 cmd.arg = 0;
232 cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR; 224 cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR;
@@ -249,10 +241,6 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
249 struct scatterlist sg; 241 struct scatterlist sg;
250 void *data_buf; 242 void *data_buf;
251 243
252 BUG_ON(!card);
253 BUG_ON(!card->host);
254 BUG_ON(!scr);
255
256 /* NOTE: caller guarantees scr is heap-allocated */ 244 /* NOTE: caller guarantees scr is heap-allocated */
257 245
258 err = mmc_app_cmd(card->host, card); 246 err = mmc_app_cmd(card->host, card);
@@ -307,9 +295,6 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
307 struct mmc_data data = {0}; 295 struct mmc_data data = {0};
308 struct scatterlist sg; 296 struct scatterlist sg;
309 297
310 BUG_ON(!card);
311 BUG_ON(!card->host);
312
313 /* NOTE: caller guarantees resp is heap-allocated */ 298 /* NOTE: caller guarantees resp is heap-allocated */
314 299
315 mode = !!mode; 300 mode = !!mode;
@@ -352,10 +337,6 @@ int mmc_app_sd_status(struct mmc_card *card, void *ssr)
352 struct mmc_data data = {0}; 337 struct mmc_data data = {0};
353 struct scatterlist sg; 338 struct scatterlist sg;
354 339
355 BUG_ON(!card);
356 BUG_ON(!card->host);
357 BUG_ON(!ssr);
358
359 /* NOTE: caller guarantees ssr is heap-allocated */ 340 /* NOTE: caller guarantees ssr is heap-allocated */
360 341
361 err = mmc_app_cmd(card->host, card); 342 err = mmc_app_cmd(card->host, card);
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index bd44ba8116d1..ecbc52981ba5 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -63,7 +63,8 @@ static int sdio_init_func(struct mmc_card *card, unsigned int fn)
63 int ret; 63 int ret;
64 struct sdio_func *func; 64 struct sdio_func *func;
65 65
66 BUG_ON(fn > SDIO_MAX_FUNCS); 66 if (WARN_ON(fn > SDIO_MAX_FUNCS))
67 return -EINVAL;
67 68
68 func = sdio_alloc_func(card); 69 func = sdio_alloc_func(card);
69 if (IS_ERR(func)) 70 if (IS_ERR(func))
@@ -555,7 +556,6 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
555 u32 rocr = 0; 556 u32 rocr = 0;
556 u32 ocr_card = ocr; 557 u32 ocr_card = ocr;
557 558
558 BUG_ON(!host);
559 WARN_ON(!host->claimed); 559 WARN_ON(!host->claimed);
560 560
561 /* to query card if 1.8V signalling is supported */ 561 /* to query card if 1.8V signalling is supported */
@@ -791,9 +791,6 @@ static void mmc_sdio_remove(struct mmc_host *host)
791{ 791{
792 int i; 792 int i;
793 793
794 BUG_ON(!host);
795 BUG_ON(!host->card);
796
797 for (i = 0;i < host->card->sdio_funcs;i++) { 794 for (i = 0;i < host->card->sdio_funcs;i++) {
798 if (host->card->sdio_func[i]) { 795 if (host->card->sdio_func[i]) {
799 sdio_remove_func(host->card->sdio_func[i]); 796 sdio_remove_func(host->card->sdio_func[i]);
@@ -820,9 +817,6 @@ static void mmc_sdio_detect(struct mmc_host *host)
820{ 817{
821 int err; 818 int err;
822 819
823 BUG_ON(!host);
824 BUG_ON(!host->card);
825
826 /* Make sure card is powered before detecting it */ 820 /* Make sure card is powered before detecting it */
827 if (host->caps & MMC_CAP_POWER_OFF_CARD) { 821 if (host->caps & MMC_CAP_POWER_OFF_CARD) {
828 err = pm_runtime_get_sync(&host->card->dev); 822 err = pm_runtime_get_sync(&host->card->dev);
@@ -916,9 +910,6 @@ static int mmc_sdio_resume(struct mmc_host *host)
916{ 910{
917 int err = 0; 911 int err = 0;
918 912
919 BUG_ON(!host);
920 BUG_ON(!host->card);
921
922 /* Basic card reinitialization. */ 913 /* Basic card reinitialization. */
923 mmc_claim_host(host); 914 mmc_claim_host(host);
924 915
@@ -970,9 +961,6 @@ static int mmc_sdio_power_restore(struct mmc_host *host)
970{ 961{
971 int ret; 962 int ret;
972 963
973 BUG_ON(!host);
974 BUG_ON(!host->card);
975
976 mmc_claim_host(host); 964 mmc_claim_host(host);
977 965
978 /* 966 /*
@@ -1063,7 +1051,6 @@ int mmc_attach_sdio(struct mmc_host *host)
1063 u32 ocr, rocr; 1051 u32 ocr, rocr;
1064 struct mmc_card *card; 1052 struct mmc_card *card;
1065 1053
1066 BUG_ON(!host);
1067 WARN_ON(!host->claimed); 1054 WARN_ON(!host->claimed);
1068 1055
1069 err = mmc_send_io_op_cond(host, 0, &ocr); 1056 err = mmc_send_io_op_cond(host, 0, &ocr);
diff --git a/drivers/mmc/core/sdio_cis.c b/drivers/mmc/core/sdio_cis.c
index dcb3dee59fa5..f8c372839d24 100644
--- a/drivers/mmc/core/sdio_cis.c
+++ b/drivers/mmc/core/sdio_cis.c
@@ -262,7 +262,8 @@ static int sdio_read_cis(struct mmc_card *card, struct sdio_func *func)
262 else 262 else
263 prev = &card->tuples; 263 prev = &card->tuples;
264 264
265 BUG_ON(*prev); 265 if (*prev)
266 return -EINVAL;
266 267
267 do { 268 do {
268 unsigned char tpl_code, tpl_link; 269 unsigned char tpl_code, tpl_link;
diff --git a/drivers/mmc/core/sdio_irq.c b/drivers/mmc/core/sdio_irq.c
index 91bbbfb29f3f..f1faf9acc007 100644
--- a/drivers/mmc/core/sdio_irq.c
+++ b/drivers/mmc/core/sdio_irq.c
@@ -214,7 +214,9 @@ static int sdio_card_irq_put(struct mmc_card *card)
214 struct mmc_host *host = card->host; 214 struct mmc_host *host = card->host;
215 215
216 WARN_ON(!host->claimed); 216 WARN_ON(!host->claimed);
217 BUG_ON(host->sdio_irqs < 1); 217
218 if (host->sdio_irqs < 1)
219 return -EINVAL;
218 220
219 if (!--host->sdio_irqs) { 221 if (!--host->sdio_irqs) {
220 if (!(host->caps2 & MMC_CAP2_SDIO_IRQ_NOTHREAD)) { 222 if (!(host->caps2 & MMC_CAP2_SDIO_IRQ_NOTHREAD)) {
@@ -261,8 +263,8 @@ int sdio_claim_irq(struct sdio_func *func, sdio_irq_handler_t *handler)
261 int ret; 263 int ret;
262 unsigned char reg; 264 unsigned char reg;
263 265
264 BUG_ON(!func); 266 if (!func)
265 BUG_ON(!func->card); 267 return -EINVAL;
266 268
267 pr_debug("SDIO: Enabling IRQ for %s...\n", sdio_func_id(func)); 269 pr_debug("SDIO: Enabling IRQ for %s...\n", sdio_func_id(func));
268 270
@@ -304,8 +306,8 @@ int sdio_release_irq(struct sdio_func *func)
304 int ret; 306 int ret;
305 unsigned char reg; 307 unsigned char reg;
306 308
307 BUG_ON(!func); 309 if (!func)
308 BUG_ON(!func->card); 310 return -EINVAL;
309 311
310 pr_debug("SDIO: Disabling IRQ for %s...\n", sdio_func_id(func)); 312 pr_debug("SDIO: Disabling IRQ for %s...\n", sdio_func_id(func));
311 313
diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c
index 27117ba47073..babe591aea96 100644
--- a/drivers/mmc/core/slot-gpio.c
+++ b/drivers/mmc/core/slot-gpio.c
@@ -258,6 +258,14 @@ int mmc_gpiod_request_cd(struct mmc_host *host, const char *con_id,
258} 258}
259EXPORT_SYMBOL(mmc_gpiod_request_cd); 259EXPORT_SYMBOL(mmc_gpiod_request_cd);
260 260
261bool mmc_can_gpio_cd(struct mmc_host *host)
262{
263 struct mmc_gpio *ctx = host->slot.handler_priv;
264
265 return ctx->cd_gpio ? true : false;
266}
267EXPORT_SYMBOL(mmc_can_gpio_cd);
268
261/** 269/**
262 * mmc_gpiod_request_ro - request a gpio descriptor for write protection 270 * mmc_gpiod_request_ro - request a gpio descriptor for write protection
263 * @host: mmc host 271 * @host: mmc host
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 5274f503a39a..2eb97014dc3f 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -135,7 +135,6 @@ config MMC_SDHCI_OF_AT91
135 tristate "SDHCI OF support for the Atmel SDMMC controller" 135 tristate "SDHCI OF support for the Atmel SDMMC controller"
136 depends on MMC_SDHCI_PLTFM 136 depends on MMC_SDHCI_PLTFM
137 depends on OF 137 depends on OF
138 select MMC_SDHCI_IO_ACCESSORS
139 help 138 help
140 This selects the Atmel SDMMC driver 139 This selects the Atmel SDMMC driver
141 140
@@ -144,6 +143,7 @@ config MMC_SDHCI_OF_ESDHC
144 depends on MMC_SDHCI_PLTFM 143 depends on MMC_SDHCI_PLTFM
145 depends on PPC || ARCH_MXC || ARCH_LAYERSCAPE 144 depends on PPC || ARCH_MXC || ARCH_LAYERSCAPE
146 select MMC_SDHCI_IO_ACCESSORS 145 select MMC_SDHCI_IO_ACCESSORS
146 select FSL_GUTS
147 help 147 help
148 This selects the Freescale eSDHC controller support. 148 This selects the Freescale eSDHC controller support.
149 149
@@ -165,6 +165,17 @@ config MMC_SDHCI_OF_HLWD
165 165
166 If unsure, say N. 166 If unsure, say N.
167 167
168config MMC_SDHCI_CADENCE
169 tristate "SDHCI support for the Cadence SD/SDIO/eMMC controller"
170 depends on MMC_SDHCI_PLTFM
171 depends on OF
172 help
173 This selects the Cadence SD/SDIO/eMMC driver.
174
175 If you have a controller with this interface, say Y or M here.
176
177 If unsure, say N.
178
168config MMC_SDHCI_CNS3XXX 179config MMC_SDHCI_CNS3XXX
169 tristate "SDHCI support on the Cavium Networks CNS3xxx SoC" 180 tristate "SDHCI support on the Cavium Networks CNS3xxx SoC"
170 depends on ARCH_CNS3XXX 181 depends on ARCH_CNS3XXX
@@ -322,6 +333,16 @@ config MMC_SDHCI_IPROC
322 333
323 If unsure, say N. 334 If unsure, say N.
324 335
336config MMC_MESON_GX
337 tristate "Amlogic S905/GX* SD/MMC Host Controller support"
338 depends on ARCH_MESON && MMC
339 help
340 This selects support for the Amlogic SD/MMC Host Controller
341 found on the S905/GX* family of SoCs. This controller is
342 MMC 5.1 compliant and supports SD, eMMC and SDIO interfaces.
343
344 If you have a controller with this interface, say Y here.
345
325config MMC_MOXART 346config MMC_MOXART
326 tristate "MOXART SD/MMC Host Controller support" 347 tristate "MOXART SD/MMC Host Controller support"
327 depends on ARCH_MOXART && MMC 348 depends on ARCH_MOXART && MMC
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index e2bdaaf43184..ccc9c4cba154 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -53,6 +53,7 @@ obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o
53obj-$(CONFIG_MMC_VUB300) += vub300.o 53obj-$(CONFIG_MMC_VUB300) += vub300.o
54obj-$(CONFIG_MMC_USHC) += ushc.o 54obj-$(CONFIG_MMC_USHC) += ushc.o
55obj-$(CONFIG_MMC_WMT) += wmt-sdmmc.o 55obj-$(CONFIG_MMC_WMT) += wmt-sdmmc.o
56obj-$(CONFIG_MMC_MESON_GX) += meson-gx-mmc.o
56obj-$(CONFIG_MMC_MOXART) += moxart-mmc.o 57obj-$(CONFIG_MMC_MOXART) += moxart-mmc.o
57obj-$(CONFIG_MMC_SUNXI) += sunxi-mmc.o 58obj-$(CONFIG_MMC_SUNXI) += sunxi-mmc.o
58obj-$(CONFIG_MMC_USDHI6ROL0) += usdhi6rol0.o 59obj-$(CONFIG_MMC_USDHI6ROL0) += usdhi6rol0.o
@@ -62,6 +63,7 @@ obj-$(CONFIG_MMC_REALTEK_PCI) += rtsx_pci_sdmmc.o
62obj-$(CONFIG_MMC_REALTEK_USB) += rtsx_usb_sdmmc.o 63obj-$(CONFIG_MMC_REALTEK_USB) += rtsx_usb_sdmmc.o
63 64
64obj-$(CONFIG_MMC_SDHCI_PLTFM) += sdhci-pltfm.o 65obj-$(CONFIG_MMC_SDHCI_PLTFM) += sdhci-pltfm.o
66obj-$(CONFIG_MMC_SDHCI_CADENCE) += sdhci-cadence.o
65obj-$(CONFIG_MMC_SDHCI_CNS3XXX) += sdhci-cns3xxx.o 67obj-$(CONFIG_MMC_SDHCI_CNS3XXX) += sdhci-cns3xxx.o
66obj-$(CONFIG_MMC_SDHCI_ESDHC_IMX) += sdhci-esdhc-imx.o 68obj-$(CONFIG_MMC_SDHCI_ESDHC_IMX) += sdhci-esdhc-imx.o
67obj-$(CONFIG_MMC_SDHCI_DOVE) += sdhci-dove.o 69obj-$(CONFIG_MMC_SDHCI_DOVE) += sdhci-dove.o
diff --git a/drivers/mmc/host/davinci_mmc.c b/drivers/mmc/host/davinci_mmc.c
index 8fa478c3b0db..36b5af8eadb8 100644
--- a/drivers/mmc/host/davinci_mmc.c
+++ b/drivers/mmc/host/davinci_mmc.c
@@ -35,6 +35,7 @@
35#include <linux/mmc/mmc.h> 35#include <linux/mmc/mmc.h>
36#include <linux/of.h> 36#include <linux/of.h>
37#include <linux/of_device.h> 37#include <linux/of_device.h>
38#include <linux/mmc/slot-gpio.h>
38 39
39#include <linux/platform_data/mmc-davinci.h> 40#include <linux/platform_data/mmc-davinci.h>
40 41
@@ -1029,9 +1030,10 @@ static int mmc_davinci_get_cd(struct mmc_host *mmc)
1029 struct platform_device *pdev = to_platform_device(mmc->parent); 1030 struct platform_device *pdev = to_platform_device(mmc->parent);
1030 struct davinci_mmc_config *config = pdev->dev.platform_data; 1031 struct davinci_mmc_config *config = pdev->dev.platform_data;
1031 1032
1032 if (!config || !config->get_cd) 1033 if (config && config->get_cd)
1033 return -ENOSYS; 1034 return config->get_cd(pdev->id);
1034 return config->get_cd(pdev->id); 1035
1036 return mmc_gpio_get_cd(mmc);
1035} 1037}
1036 1038
1037static int mmc_davinci_get_ro(struct mmc_host *mmc) 1039static int mmc_davinci_get_ro(struct mmc_host *mmc)
@@ -1039,9 +1041,10 @@ static int mmc_davinci_get_ro(struct mmc_host *mmc)
1039 struct platform_device *pdev = to_platform_device(mmc->parent); 1041 struct platform_device *pdev = to_platform_device(mmc->parent);
1040 struct davinci_mmc_config *config = pdev->dev.platform_data; 1042 struct davinci_mmc_config *config = pdev->dev.platform_data;
1041 1043
1042 if (!config || !config->get_ro) 1044 if (config && config->get_ro)
1043 return -ENOSYS; 1045 return config->get_ro(pdev->id);
1044 return config->get_ro(pdev->id); 1046
1047 return mmc_gpio_get_ro(mmc);
1045} 1048}
1046 1049
1047static void mmc_davinci_enable_sdio_irq(struct mmc_host *mmc, int enable) 1050static void mmc_davinci_enable_sdio_irq(struct mmc_host *mmc, int enable)
@@ -1159,49 +1162,53 @@ static const struct of_device_id davinci_mmc_dt_ids[] = {
1159}; 1162};
1160MODULE_DEVICE_TABLE(of, davinci_mmc_dt_ids); 1163MODULE_DEVICE_TABLE(of, davinci_mmc_dt_ids);
1161 1164
1162static struct davinci_mmc_config 1165static int mmc_davinci_parse_pdata(struct mmc_host *mmc)
1163 *mmc_parse_pdata(struct platform_device *pdev)
1164{ 1166{
1165 struct device_node *np; 1167 struct platform_device *pdev = to_platform_device(mmc->parent);
1166 struct davinci_mmc_config *pdata = pdev->dev.platform_data; 1168 struct davinci_mmc_config *pdata = pdev->dev.platform_data;
1167 const struct of_device_id *match = 1169 struct mmc_davinci_host *host;
1168 of_match_device(davinci_mmc_dt_ids, &pdev->dev); 1170 int ret;
1169 u32 data;
1170
1171 np = pdev->dev.of_node;
1172 if (!np)
1173 return pdata;
1174
1175 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
1176 if (!pdata) {
1177 dev_err(&pdev->dev, "Failed to allocate memory for struct davinci_mmc_config\n");
1178 goto nodata;
1179 }
1180 1171
1181 if (match) 1172 if (!pdata)
1182 pdev->id_entry = match->data; 1173 return -EINVAL;
1183 1174
1184 if (of_property_read_u32(np, "max-frequency", &pdata->max_freq)) 1175 host = mmc_priv(mmc);
1185 dev_info(&pdev->dev, "'max-frequency' property not specified, defaulting to 25MHz\n"); 1176 if (!host)
1177 return -EINVAL;
1186 1178
1187 of_property_read_u32(np, "bus-width", &data); 1179 if (pdata && pdata->nr_sg)
1188 switch (data) { 1180 host->nr_sg = pdata->nr_sg - 1;
1189 case 1: 1181
1190 case 4: 1182 if (pdata && (pdata->wires == 4 || pdata->wires == 0))
1191 case 8: 1183 mmc->caps |= MMC_CAP_4_BIT_DATA;
1192 pdata->wires = data; 1184
1193 break; 1185 if (pdata && (pdata->wires == 8))
1194 default: 1186 mmc->caps |= (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA);
1195 pdata->wires = 1; 1187
1196 dev_info(&pdev->dev, "Unsupported buswidth, defaulting to 1 bit\n"); 1188 mmc->f_min = 312500;
1197 } 1189 mmc->f_max = 25000000;
1198nodata: 1190 if (pdata && pdata->max_freq)
1199 return pdata; 1191 mmc->f_max = pdata->max_freq;
1192 if (pdata && pdata->caps)
1193 mmc->caps |= pdata->caps;
1194
1195 /* Register a cd gpio, if there is not one, enable polling */
1196 ret = mmc_gpiod_request_cd(mmc, "cd", 0, false, 0, NULL);
1197 if (ret == -EPROBE_DEFER)
1198 return ret;
1199 else if (ret)
1200 mmc->caps |= MMC_CAP_NEEDS_POLL;
1201
1202 ret = mmc_gpiod_request_ro(mmc, "wp", 0, false, 0, NULL);
1203 if (ret == -EPROBE_DEFER)
1204 return ret;
1205
1206 return 0;
1200} 1207}
1201 1208
1202static int __init davinci_mmcsd_probe(struct platform_device *pdev) 1209static int __init davinci_mmcsd_probe(struct platform_device *pdev)
1203{ 1210{
1204 struct davinci_mmc_config *pdata = NULL; 1211 const struct of_device_id *match;
1205 struct mmc_davinci_host *host = NULL; 1212 struct mmc_davinci_host *host = NULL;
1206 struct mmc_host *mmc = NULL; 1213 struct mmc_host *mmc = NULL;
1207 struct resource *r, *mem = NULL; 1214 struct resource *r, *mem = NULL;
@@ -1209,12 +1216,6 @@ static int __init davinci_mmcsd_probe(struct platform_device *pdev)
1209 size_t mem_size; 1216 size_t mem_size;
1210 const struct platform_device_id *id_entry; 1217 const struct platform_device_id *id_entry;
1211 1218
1212 pdata = mmc_parse_pdata(pdev);
1213 if (pdata == NULL) {
1214 dev_err(&pdev->dev, "Couldn't get platform data\n");
1215 return -ENOENT;
1216 }
1217
1218 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1219 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1219 if (!r) 1220 if (!r)
1220 return -ENODEV; 1221 return -ENODEV;
@@ -1253,14 +1254,28 @@ static int __init davinci_mmcsd_probe(struct platform_device *pdev)
1253 1254
1254 host->mmc_input_clk = clk_get_rate(host->clk); 1255 host->mmc_input_clk = clk_get_rate(host->clk);
1255 1256
1256 init_mmcsd_host(host); 1257 match = of_match_device(davinci_mmc_dt_ids, &pdev->dev);
1257 1258 if (match) {
1258 if (pdata->nr_sg) 1259 pdev->id_entry = match->data;
1259 host->nr_sg = pdata->nr_sg - 1; 1260 ret = mmc_of_parse(mmc);
1261 if (ret) {
1262 dev_err(&pdev->dev,
1263 "could not parse of data: %d\n", ret);
1264 goto parse_fail;
1265 }
1266 } else {
1267 ret = mmc_davinci_parse_pdata(mmc);
1268 if (ret) {
1269 dev_err(&pdev->dev,
1270 "could not parse platform data: %d\n", ret);
1271 goto parse_fail;
1272 } }
1260 1273
1261 if (host->nr_sg > MAX_NR_SG || !host->nr_sg) 1274 if (host->nr_sg > MAX_NR_SG || !host->nr_sg)
1262 host->nr_sg = MAX_NR_SG; 1275 host->nr_sg = MAX_NR_SG;
1263 1276
1277 init_mmcsd_host(host);
1278
1264 host->use_dma = use_dma; 1279 host->use_dma = use_dma;
1265 host->mmc_irq = irq; 1280 host->mmc_irq = irq;
1266 host->sdio_irq = platform_get_irq(pdev, 1); 1281 host->sdio_irq = platform_get_irq(pdev, 1);
@@ -1273,27 +1288,13 @@ static int __init davinci_mmcsd_probe(struct platform_device *pdev)
1273 host->use_dma = 0; 1288 host->use_dma = 0;
1274 } 1289 }
1275 1290
1276 /* REVISIT: someday, support IRQ-driven card detection. */
1277 mmc->caps |= MMC_CAP_NEEDS_POLL;
1278 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY; 1291 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
1279 1292
1280 if (pdata && (pdata->wires == 4 || pdata->wires == 0))
1281 mmc->caps |= MMC_CAP_4_BIT_DATA;
1282
1283 if (pdata && (pdata->wires == 8))
1284 mmc->caps |= (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA);
1285
1286 id_entry = platform_get_device_id(pdev); 1293 id_entry = platform_get_device_id(pdev);
1287 if (id_entry) 1294 if (id_entry)
1288 host->version = id_entry->driver_data; 1295 host->version = id_entry->driver_data;
1289 1296
1290 mmc->ops = &mmc_davinci_ops; 1297 mmc->ops = &mmc_davinci_ops;
1291 mmc->f_min = 312500;
1292 mmc->f_max = 25000000;
1293 if (pdata && pdata->max_freq)
1294 mmc->f_max = pdata->max_freq;
1295 if (pdata && pdata->caps)
1296 mmc->caps |= pdata->caps;
1297 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; 1298 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
1298 1299
1299 /* With no iommu coalescing pages, each phys_seg is a hw_seg. 1300 /* With no iommu coalescing pages, each phys_seg is a hw_seg.
@@ -1354,6 +1355,7 @@ mmc_add_host_fail:
1354 mmc_davinci_cpufreq_deregister(host); 1355 mmc_davinci_cpufreq_deregister(host);
1355cpu_freq_fail: 1356cpu_freq_fail:
1356 davinci_release_dma_channels(host); 1357 davinci_release_dma_channels(host);
1358parse_fail:
1357dma_probe_defer: 1359dma_probe_defer:
1358 clk_disable_unprepare(host->clk); 1360 clk_disable_unprepare(host->clk);
1359clk_prepare_enable_fail: 1361clk_prepare_enable_fail:
diff --git a/drivers/mmc/host/dw_mmc-exynos.c b/drivers/mmc/host/dw_mmc-exynos.c
index 7ab3d749b5ae..e1335289316c 100644
--- a/drivers/mmc/host/dw_mmc-exynos.c
+++ b/drivers/mmc/host/dw_mmc-exynos.c
@@ -17,6 +17,7 @@
17#include <linux/mmc/mmc.h> 17#include <linux/mmc/mmc.h>
18#include <linux/of.h> 18#include <linux/of.h>
19#include <linux/of_gpio.h> 19#include <linux/of_gpio.h>
20#include <linux/pm_runtime.h>
20#include <linux/slab.h> 21#include <linux/slab.h>
21 22
22#include "dw_mmc.h" 23#include "dw_mmc.h"
@@ -161,20 +162,13 @@ static void dw_mci_exynos_set_clksel_timing(struct dw_mci *host, u32 timing)
161 set_bit(DW_MMC_CARD_NO_USE_HOLD, &host->cur_slot->flags); 162 set_bit(DW_MMC_CARD_NO_USE_HOLD, &host->cur_slot->flags);
162} 163}
163 164
164#ifdef CONFIG_PM_SLEEP 165#ifdef CONFIG_PM
165static int dw_mci_exynos_suspend(struct device *dev) 166static int dw_mci_exynos_runtime_resume(struct device *dev)
166{
167 struct dw_mci *host = dev_get_drvdata(dev);
168
169 return dw_mci_suspend(host);
170}
171
172static int dw_mci_exynos_resume(struct device *dev)
173{ 167{
174 struct dw_mci *host = dev_get_drvdata(dev); 168 struct dw_mci *host = dev_get_drvdata(dev);
175 169
176 dw_mci_exynos_config_smu(host); 170 dw_mci_exynos_config_smu(host);
177 return dw_mci_resume(host); 171 return dw_mci_runtime_resume(dev);
178} 172}
179 173
180/** 174/**
@@ -211,10 +205,8 @@ static int dw_mci_exynos_resume_noirq(struct device *dev)
211 return 0; 205 return 0;
212} 206}
213#else 207#else
214#define dw_mci_exynos_suspend NULL
215#define dw_mci_exynos_resume NULL
216#define dw_mci_exynos_resume_noirq NULL 208#define dw_mci_exynos_resume_noirq NULL
217#endif /* CONFIG_PM_SLEEP */ 209#endif /* CONFIG_PM */
218 210
219static void dw_mci_exynos_config_hs400(struct dw_mci *host, u32 timing) 211static void dw_mci_exynos_config_hs400(struct dw_mci *host, u32 timing)
220{ 212{
@@ -524,14 +516,42 @@ static int dw_mci_exynos_probe(struct platform_device *pdev)
524{ 516{
525 const struct dw_mci_drv_data *drv_data; 517 const struct dw_mci_drv_data *drv_data;
526 const struct of_device_id *match; 518 const struct of_device_id *match;
519 int ret;
527 520
528 match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node); 521 match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node);
529 drv_data = match->data; 522 drv_data = match->data;
530 return dw_mci_pltfm_register(pdev, drv_data); 523
524 pm_runtime_get_noresume(&pdev->dev);
525 pm_runtime_set_active(&pdev->dev);
526 pm_runtime_enable(&pdev->dev);
527
528 ret = dw_mci_pltfm_register(pdev, drv_data);
529 if (ret) {
530 pm_runtime_disable(&pdev->dev);
531 pm_runtime_set_suspended(&pdev->dev);
532 pm_runtime_put_noidle(&pdev->dev);
533
534 return ret;
535 }
536
537 return 0;
538}
539
540static int dw_mci_exynos_remove(struct platform_device *pdev)
541{
542 pm_runtime_disable(&pdev->dev);
543 pm_runtime_set_suspended(&pdev->dev);
544 pm_runtime_put_noidle(&pdev->dev);
545
546 return dw_mci_pltfm_remove(pdev);
531} 547}
532 548
533static const struct dev_pm_ops dw_mci_exynos_pmops = { 549static const struct dev_pm_ops dw_mci_exynos_pmops = {
534 SET_SYSTEM_SLEEP_PM_OPS(dw_mci_exynos_suspend, dw_mci_exynos_resume) 550 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
551 pm_runtime_force_resume)
552 SET_RUNTIME_PM_OPS(dw_mci_runtime_suspend,
553 dw_mci_exynos_runtime_resume,
554 NULL)
535 .resume_noirq = dw_mci_exynos_resume_noirq, 555 .resume_noirq = dw_mci_exynos_resume_noirq,
536 .thaw_noirq = dw_mci_exynos_resume_noirq, 556 .thaw_noirq = dw_mci_exynos_resume_noirq,
537 .restore_noirq = dw_mci_exynos_resume_noirq, 557 .restore_noirq = dw_mci_exynos_resume_noirq,
@@ -539,7 +559,7 @@ static const struct dev_pm_ops dw_mci_exynos_pmops = {
539 559
540static struct platform_driver dw_mci_exynos_pltfm_driver = { 560static struct platform_driver dw_mci_exynos_pltfm_driver = {
541 .probe = dw_mci_exynos_probe, 561 .probe = dw_mci_exynos_probe,
542 .remove = dw_mci_pltfm_remove, 562 .remove = dw_mci_exynos_remove,
543 .driver = { 563 .driver = {
544 .name = "dwmmc_exynos", 564 .name = "dwmmc_exynos",
545 .of_match_table = dw_mci_exynos_match, 565 .of_match_table = dw_mci_exynos_match,
diff --git a/drivers/mmc/host/dw_mmc-k3.c b/drivers/mmc/host/dw_mmc-k3.c
index 624789496dce..9821e6bd5d5e 100644
--- a/drivers/mmc/host/dw_mmc-k3.c
+++ b/drivers/mmc/host/dw_mmc-k3.c
@@ -15,6 +15,7 @@
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/of_address.h> 16#include <linux/of_address.h>
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/pm_runtime.h>
18#include <linux/regmap.h> 19#include <linux/regmap.h>
19#include <linux/regulator/consumer.h> 20#include <linux/regulator/consumer.h>
20 21
@@ -162,35 +163,13 @@ static int dw_mci_k3_probe(struct platform_device *pdev)
162 return dw_mci_pltfm_register(pdev, drv_data); 163 return dw_mci_pltfm_register(pdev, drv_data);
163} 164}
164 165
165#ifdef CONFIG_PM_SLEEP 166static const struct dev_pm_ops dw_mci_k3_dev_pm_ops = {
166static int dw_mci_k3_suspend(struct device *dev) 167 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
167{ 168 pm_runtime_force_resume)
168 struct dw_mci *host = dev_get_drvdata(dev); 169 SET_RUNTIME_PM_OPS(dw_mci_runtime_suspend,
169 int ret; 170 dw_mci_runtime_resume,
170 171 NULL)
171 ret = dw_mci_suspend(host); 172};
172 if (!ret)
173 clk_disable_unprepare(host->ciu_clk);
174
175 return ret;
176}
177
178static int dw_mci_k3_resume(struct device *dev)
179{
180 struct dw_mci *host = dev_get_drvdata(dev);
181 int ret;
182
183 ret = clk_prepare_enable(host->ciu_clk);
184 if (ret) {
185 dev_err(host->dev, "failed to enable ciu clock\n");
186 return ret;
187 }
188
189 return dw_mci_resume(host);
190}
191#endif /* CONFIG_PM_SLEEP */
192
193static SIMPLE_DEV_PM_OPS(dw_mci_k3_pmops, dw_mci_k3_suspend, dw_mci_k3_resume);
194 173
195static struct platform_driver dw_mci_k3_pltfm_driver = { 174static struct platform_driver dw_mci_k3_pltfm_driver = {
196 .probe = dw_mci_k3_probe, 175 .probe = dw_mci_k3_probe,
@@ -198,7 +177,7 @@ static struct platform_driver dw_mci_k3_pltfm_driver = {
198 .driver = { 177 .driver = {
199 .name = "dwmmc_k3", 178 .name = "dwmmc_k3",
200 .of_match_table = dw_mci_k3_match, 179 .of_match_table = dw_mci_k3_match,
201 .pm = &dw_mci_k3_pmops, 180 .pm = &dw_mci_k3_dev_pm_ops,
202 }, 181 },
203}; 182};
204 183
diff --git a/drivers/mmc/host/dw_mmc-pci.c b/drivers/mmc/host/dw_mmc-pci.c
index 4c69fbd29811..ab82796b01e2 100644
--- a/drivers/mmc/host/dw_mmc-pci.c
+++ b/drivers/mmc/host/dw_mmc-pci.c
@@ -14,6 +14,7 @@
14#include <linux/io.h> 14#include <linux/io.h>
15#include <linux/irq.h> 15#include <linux/irq.h>
16#include <linux/pci.h> 16#include <linux/pci.h>
17#include <linux/pm_runtime.h>
17#include <linux/slab.h> 18#include <linux/slab.h>
18#include <linux/mmc/host.h> 19#include <linux/mmc/host.h>
19#include <linux/mmc/mmc.h> 20#include <linux/mmc/mmc.h>
@@ -79,25 +80,13 @@ static void dw_mci_pci_remove(struct pci_dev *pdev)
79 dw_mci_remove(host); 80 dw_mci_remove(host);
80} 81}
81 82
82#ifdef CONFIG_PM_SLEEP 83static const struct dev_pm_ops dw_mci_pci_dev_pm_ops = {
83static int dw_mci_pci_suspend(struct device *dev) 84 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
84{ 85 pm_runtime_force_resume)
85 struct pci_dev *pdev = to_pci_dev(dev); 86 SET_RUNTIME_PM_OPS(dw_mci_runtime_suspend,
86 struct dw_mci *host = pci_get_drvdata(pdev); 87 dw_mci_runtime_resume,
87 88 NULL)
88 return dw_mci_suspend(host); 89};
89}
90
91static int dw_mci_pci_resume(struct device *dev)
92{
93 struct pci_dev *pdev = to_pci_dev(dev);
94 struct dw_mci *host = pci_get_drvdata(pdev);
95
96 return dw_mci_resume(host);
97}
98#endif /* CONFIG_PM_SLEEP */
99
100static SIMPLE_DEV_PM_OPS(dw_mci_pci_pmops, dw_mci_pci_suspend, dw_mci_pci_resume);
101 90
102static const struct pci_device_id dw_mci_pci_id[] = { 91static const struct pci_device_id dw_mci_pci_id[] = {
103 { PCI_DEVICE(SYNOPSYS_DW_MCI_VENDOR_ID, SYNOPSYS_DW_MCI_DEVICE_ID) }, 92 { PCI_DEVICE(SYNOPSYS_DW_MCI_VENDOR_ID, SYNOPSYS_DW_MCI_DEVICE_ID) },
@@ -111,7 +100,7 @@ static struct pci_driver dw_mci_pci_driver = {
111 .probe = dw_mci_pci_probe, 100 .probe = dw_mci_pci_probe,
112 .remove = dw_mci_pci_remove, 101 .remove = dw_mci_pci_remove,
113 .driver = { 102 .driver = {
114 .pm = &dw_mci_pci_pmops 103 .pm = &dw_mci_pci_dev_pm_ops,
115 }, 104 },
116}; 105};
117 106
diff --git a/drivers/mmc/host/dw_mmc-pltfm.c b/drivers/mmc/host/dw_mmc-pltfm.c
index dbbc4303bdd0..1236d49ba36e 100644
--- a/drivers/mmc/host/dw_mmc-pltfm.c
+++ b/drivers/mmc/host/dw_mmc-pltfm.c
@@ -16,6 +16,7 @@
16#include <linux/io.h> 16#include <linux/io.h>
17#include <linux/irq.h> 17#include <linux/irq.h>
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/pm_runtime.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
20#include <linux/mmc/host.h> 21#include <linux/mmc/host.h>
21#include <linux/mmc/mmc.h> 22#include <linux/mmc/mmc.h>
@@ -58,26 +59,13 @@ int dw_mci_pltfm_register(struct platform_device *pdev,
58} 59}
59EXPORT_SYMBOL_GPL(dw_mci_pltfm_register); 60EXPORT_SYMBOL_GPL(dw_mci_pltfm_register);
60 61
61#ifdef CONFIG_PM_SLEEP 62const struct dev_pm_ops dw_mci_pltfm_pmops = {
62/* 63 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
63 * TODO: we should probably disable the clock to the card in the suspend path. 64 pm_runtime_force_resume)
64 */ 65 SET_RUNTIME_PM_OPS(dw_mci_runtime_suspend,
65static int dw_mci_pltfm_suspend(struct device *dev) 66 dw_mci_runtime_resume,
66{ 67 NULL)
67 struct dw_mci *host = dev_get_drvdata(dev); 68};
68
69 return dw_mci_suspend(host);
70}
71
72static int dw_mci_pltfm_resume(struct device *dev)
73{
74 struct dw_mci *host = dev_get_drvdata(dev);
75
76 return dw_mci_resume(host);
77}
78#endif /* CONFIG_PM_SLEEP */
79
80SIMPLE_DEV_PM_OPS(dw_mci_pltfm_pmops, dw_mci_pltfm_suspend, dw_mci_pltfm_resume);
81EXPORT_SYMBOL_GPL(dw_mci_pltfm_pmops); 69EXPORT_SYMBOL_GPL(dw_mci_pltfm_pmops);
82 70
83static const struct of_device_id dw_mci_pltfm_match[] = { 71static const struct of_device_id dw_mci_pltfm_match[] = {
diff --git a/drivers/mmc/host/dw_mmc-rockchip.c b/drivers/mmc/host/dw_mmc-rockchip.c
index 25eae359a5ea..9a46e4694227 100644
--- a/drivers/mmc/host/dw_mmc-rockchip.c
+++ b/drivers/mmc/host/dw_mmc-rockchip.c
@@ -13,6 +13,8 @@
13#include <linux/mmc/host.h> 13#include <linux/mmc/host.h>
14#include <linux/mmc/dw_mmc.h> 14#include <linux/mmc/dw_mmc.h>
15#include <linux/of_address.h> 15#include <linux/of_address.h>
16#include <linux/mmc/slot-gpio.h>
17#include <linux/pm_runtime.h>
16#include <linux/slab.h> 18#include <linux/slab.h>
17 19
18#include "dw_mmc.h" 20#include "dw_mmc.h"
@@ -325,6 +327,7 @@ static int dw_mci_rockchip_probe(struct platform_device *pdev)
325{ 327{
326 const struct dw_mci_drv_data *drv_data; 328 const struct dw_mci_drv_data *drv_data;
327 const struct of_device_id *match; 329 const struct of_device_id *match;
330 int ret;
328 331
329 if (!pdev->dev.of_node) 332 if (!pdev->dev.of_node)
330 return -ENODEV; 333 return -ENODEV;
@@ -332,16 +335,49 @@ static int dw_mci_rockchip_probe(struct platform_device *pdev)
332 match = of_match_node(dw_mci_rockchip_match, pdev->dev.of_node); 335 match = of_match_node(dw_mci_rockchip_match, pdev->dev.of_node);
333 drv_data = match->data; 336 drv_data = match->data;
334 337
335 return dw_mci_pltfm_register(pdev, drv_data); 338 pm_runtime_get_noresume(&pdev->dev);
339 pm_runtime_set_active(&pdev->dev);
340 pm_runtime_enable(&pdev->dev);
341 pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
342 pm_runtime_use_autosuspend(&pdev->dev);
343
344 ret = dw_mci_pltfm_register(pdev, drv_data);
345 if (ret) {
346 pm_runtime_disable(&pdev->dev);
347 pm_runtime_set_suspended(&pdev->dev);
348 pm_runtime_put_noidle(&pdev->dev);
349 return ret;
350 }
351
352 pm_runtime_put_autosuspend(&pdev->dev);
353
354 return 0;
336} 355}
337 356
357static int dw_mci_rockchip_remove(struct platform_device *pdev)
358{
359 pm_runtime_get_sync(&pdev->dev);
360 pm_runtime_disable(&pdev->dev);
361 pm_runtime_put_noidle(&pdev->dev);
362
363 return dw_mci_pltfm_remove(pdev);
364}
365
366static const struct dev_pm_ops dw_mci_rockchip_dev_pm_ops = {
367 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
368 pm_runtime_force_resume)
369 SET_RUNTIME_PM_OPS(dw_mci_runtime_suspend,
370 dw_mci_runtime_resume,
371 NULL)
372};
373
338static struct platform_driver dw_mci_rockchip_pltfm_driver = { 374static struct platform_driver dw_mci_rockchip_pltfm_driver = {
339 .probe = dw_mci_rockchip_probe, 375 .probe = dw_mci_rockchip_probe,
340 .remove = dw_mci_pltfm_remove, 376 .remove = dw_mci_rockchip_remove,
341 .driver = { 377 .driver = {
342 .name = "dwmmc_rockchip", 378 .name = "dwmmc_rockchip",
343 .of_match_table = dw_mci_rockchip_match, 379 .of_match_table = dw_mci_rockchip_match,
344 .pm = &dw_mci_pltfm_pmops, 380 .pm = &dw_mci_rockchip_dev_pm_ops,
345 }, 381 },
346}; 382};
347 383
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index df478ae72e23..b44306b886cb 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -54,7 +54,7 @@
54#define DW_MCI_DMA_THRESHOLD 16 54#define DW_MCI_DMA_THRESHOLD 16
55 55
56#define DW_MCI_FREQ_MAX 200000000 /* unit: HZ */ 56#define DW_MCI_FREQ_MAX 200000000 /* unit: HZ */
57#define DW_MCI_FREQ_MIN 400000 /* unit: HZ */ 57#define DW_MCI_FREQ_MIN 100000 /* unit: HZ */
58 58
59#define IDMAC_INT_CLR (SDMMC_IDMAC_INT_AI | SDMMC_IDMAC_INT_NI | \ 59#define IDMAC_INT_CLR (SDMMC_IDMAC_INT_AI | SDMMC_IDMAC_INT_NI | \
60 SDMMC_IDMAC_INT_CES | SDMMC_IDMAC_INT_DU | \ 60 SDMMC_IDMAC_INT_CES | SDMMC_IDMAC_INT_DU | \
@@ -165,12 +165,14 @@ static const struct file_operations dw_mci_req_fops = {
165 165
166static int dw_mci_regs_show(struct seq_file *s, void *v) 166static int dw_mci_regs_show(struct seq_file *s, void *v)
167{ 167{
168 seq_printf(s, "STATUS:\t0x%08x\n", SDMMC_STATUS); 168 struct dw_mci *host = s->private;
169 seq_printf(s, "RINTSTS:\t0x%08x\n", SDMMC_RINTSTS); 169
170 seq_printf(s, "CMD:\t0x%08x\n", SDMMC_CMD); 170 seq_printf(s, "STATUS:\t0x%08x\n", mci_readl(host, STATUS));
171 seq_printf(s, "CTRL:\t0x%08x\n", SDMMC_CTRL); 171 seq_printf(s, "RINTSTS:\t0x%08x\n", mci_readl(host, RINTSTS));
172 seq_printf(s, "INTMASK:\t0x%08x\n", SDMMC_INTMASK); 172 seq_printf(s, "CMD:\t0x%08x\n", mci_readl(host, CMD));
173 seq_printf(s, "CLKENA:\t0x%08x\n", SDMMC_CLKENA); 173 seq_printf(s, "CTRL:\t0x%08x\n", mci_readl(host, CTRL));
174 seq_printf(s, "INTMASK:\t0x%08x\n", mci_readl(host, INTMASK));
175 seq_printf(s, "CLKENA:\t0x%08x\n", mci_readl(host, CLKENA));
174 176
175 return 0; 177 return 0;
176} 178}
@@ -234,7 +236,6 @@ static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg);
234 236
235static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd) 237static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
236{ 238{
237 struct mmc_data *data;
238 struct dw_mci_slot *slot = mmc_priv(mmc); 239 struct dw_mci_slot *slot = mmc_priv(mmc);
239 struct dw_mci *host = slot->host; 240 struct dw_mci *host = slot->host;
240 u32 cmdr; 241 u32 cmdr;
@@ -289,10 +290,9 @@ static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
289 if (cmd->flags & MMC_RSP_CRC) 290 if (cmd->flags & MMC_RSP_CRC)
290 cmdr |= SDMMC_CMD_RESP_CRC; 291 cmdr |= SDMMC_CMD_RESP_CRC;
291 292
292 data = cmd->data; 293 if (cmd->data) {
293 if (data) {
294 cmdr |= SDMMC_CMD_DAT_EXP; 294 cmdr |= SDMMC_CMD_DAT_EXP;
295 if (data->flags & MMC_DATA_WRITE) 295 if (cmd->data->flags & MMC_DATA_WRITE)
296 cmdr |= SDMMC_CMD_DAT_WR; 296 cmdr |= SDMMC_CMD_DAT_WR;
297 } 297 }
298 298
@@ -335,6 +335,9 @@ static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd)
335 cmdr = stop->opcode | SDMMC_CMD_STOP | 335 cmdr = stop->opcode | SDMMC_CMD_STOP |
336 SDMMC_CMD_RESP_CRC | SDMMC_CMD_RESP_EXP; 336 SDMMC_CMD_RESP_CRC | SDMMC_CMD_RESP_EXP;
337 337
338 if (!test_bit(DW_MMC_CARD_NO_USE_HOLD, &host->cur_slot->flags))
339 cmdr |= SDMMC_CMD_USE_HOLD_REG;
340
338 return cmdr; 341 return cmdr;
339} 342}
340 343
@@ -380,7 +383,7 @@ static void dw_mci_start_command(struct dw_mci *host,
380 383
381static inline void send_stop_abort(struct dw_mci *host, struct mmc_data *data) 384static inline void send_stop_abort(struct dw_mci *host, struct mmc_data *data)
382{ 385{
383 struct mmc_command *stop = data->stop ? data->stop : &host->stop_abort; 386 struct mmc_command *stop = &host->stop_abort;
384 387
385 dw_mci_start_command(host, stop, host->stop_cmdr); 388 dw_mci_start_command(host, stop, host->stop_cmdr);
386} 389}
@@ -409,12 +412,13 @@ static void dw_mci_dma_cleanup(struct dw_mci *host)
409{ 412{
410 struct mmc_data *data = host->data; 413 struct mmc_data *data = host->data;
411 414
412 if (data) 415 if (data && data->host_cookie == COOKIE_MAPPED) {
413 if (!data->host_cookie) 416 dma_unmap_sg(host->dev,
414 dma_unmap_sg(host->dev, 417 data->sg,
415 data->sg, 418 data->sg_len,
416 data->sg_len, 419 dw_mci_get_dma_dir(data));
417 dw_mci_get_dma_dir(data)); 420 data->host_cookie = COOKIE_UNMAPPED;
421 }
418} 422}
419 423
420static void dw_mci_idmac_reset(struct dw_mci *host) 424static void dw_mci_idmac_reset(struct dw_mci *host)
@@ -612,7 +616,7 @@ static inline int dw_mci_prepare_desc64(struct dw_mci *host,
612 return 0; 616 return 0;
613err_own_bit: 617err_own_bit:
614 /* restore the descriptor chain as it's polluted */ 618 /* restore the descriptor chain as it's polluted */
615 dev_dbg(host->dev, "desciptor is still owned by IDMAC.\n"); 619 dev_dbg(host->dev, "descriptor is still owned by IDMAC.\n");
616 memset(host->sg_cpu, 0, DESC_RING_BUF_SZ); 620 memset(host->sg_cpu, 0, DESC_RING_BUF_SZ);
617 dw_mci_idmac_init(host); 621 dw_mci_idmac_init(host);
618 return -EINVAL; 622 return -EINVAL;
@@ -688,7 +692,7 @@ static inline int dw_mci_prepare_desc32(struct dw_mci *host,
688 return 0; 692 return 0;
689err_own_bit: 693err_own_bit:
690 /* restore the descriptor chain as it's polluted */ 694 /* restore the descriptor chain as it's polluted */
691 dev_dbg(host->dev, "desciptor is still owned by IDMAC.\n"); 695 dev_dbg(host->dev, "descriptor is still owned by IDMAC.\n");
692 memset(host->sg_cpu, 0, DESC_RING_BUF_SZ); 696 memset(host->sg_cpu, 0, DESC_RING_BUF_SZ);
693 dw_mci_idmac_init(host); 697 dw_mci_idmac_init(host);
694 return -EINVAL; 698 return -EINVAL;
@@ -845,13 +849,13 @@ static const struct dw_mci_dma_ops dw_mci_edmac_ops = {
845 849
846static int dw_mci_pre_dma_transfer(struct dw_mci *host, 850static int dw_mci_pre_dma_transfer(struct dw_mci *host,
847 struct mmc_data *data, 851 struct mmc_data *data,
848 bool next) 852 int cookie)
849{ 853{
850 struct scatterlist *sg; 854 struct scatterlist *sg;
851 unsigned int i, sg_len; 855 unsigned int i, sg_len;
852 856
853 if (!next && data->host_cookie) 857 if (data->host_cookie == COOKIE_PRE_MAPPED)
854 return data->host_cookie; 858 return data->sg_len;
855 859
856 /* 860 /*
857 * We don't do DMA on "complex" transfers, i.e. with 861 * We don't do DMA on "complex" transfers, i.e. with
@@ -876,15 +880,13 @@ static int dw_mci_pre_dma_transfer(struct dw_mci *host,
876 if (sg_len == 0) 880 if (sg_len == 0)
877 return -EINVAL; 881 return -EINVAL;
878 882
879 if (next) 883 data->host_cookie = cookie;
880 data->host_cookie = sg_len;
881 884
882 return sg_len; 885 return sg_len;
883} 886}
884 887
885static void dw_mci_pre_req(struct mmc_host *mmc, 888static void dw_mci_pre_req(struct mmc_host *mmc,
886 struct mmc_request *mrq, 889 struct mmc_request *mrq)
887 bool is_first_req)
888{ 890{
889 struct dw_mci_slot *slot = mmc_priv(mmc); 891 struct dw_mci_slot *slot = mmc_priv(mmc);
890 struct mmc_data *data = mrq->data; 892 struct mmc_data *data = mrq->data;
@@ -892,13 +894,12 @@ static void dw_mci_pre_req(struct mmc_host *mmc,
892 if (!slot->host->use_dma || !data) 894 if (!slot->host->use_dma || !data)
893 return; 895 return;
894 896
895 if (data->host_cookie) { 897 /* This data might be unmapped at this time */
896 data->host_cookie = 0; 898 data->host_cookie = COOKIE_UNMAPPED;
897 return;
898 }
899 899
900 if (dw_mci_pre_dma_transfer(slot->host, mrq->data, 1) < 0) 900 if (dw_mci_pre_dma_transfer(slot->host, mrq->data,
901 data->host_cookie = 0; 901 COOKIE_PRE_MAPPED) < 0)
902 data->host_cookie = COOKIE_UNMAPPED;
902} 903}
903 904
904static void dw_mci_post_req(struct mmc_host *mmc, 905static void dw_mci_post_req(struct mmc_host *mmc,
@@ -911,12 +912,12 @@ static void dw_mci_post_req(struct mmc_host *mmc,
911 if (!slot->host->use_dma || !data) 912 if (!slot->host->use_dma || !data)
912 return; 913 return;
913 914
914 if (data->host_cookie) 915 if (data->host_cookie != COOKIE_UNMAPPED)
915 dma_unmap_sg(slot->host->dev, 916 dma_unmap_sg(slot->host->dev,
916 data->sg, 917 data->sg,
917 data->sg_len, 918 data->sg_len,
918 dw_mci_get_dma_dir(data)); 919 dw_mci_get_dma_dir(data));
919 data->host_cookie = 0; 920 data->host_cookie = COOKIE_UNMAPPED;
920} 921}
921 922
922static void dw_mci_adjust_fifoth(struct dw_mci *host, struct mmc_data *data) 923static void dw_mci_adjust_fifoth(struct dw_mci *host, struct mmc_data *data)
@@ -1022,7 +1023,7 @@ static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
1022 if (!host->use_dma) 1023 if (!host->use_dma)
1023 return -ENODEV; 1024 return -ENODEV;
1024 1025
1025 sg_len = dw_mci_pre_dma_transfer(host, data, 0); 1026 sg_len = dw_mci_pre_dma_transfer(host, data, COOKIE_MAPPED);
1026 if (sg_len < 0) { 1027 if (sg_len < 0) {
1027 host->dma_ops->stop(host); 1028 host->dma_ops->stop(host);
1028 return sg_len; 1029 return sg_len;
@@ -1175,13 +1176,24 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
1175 1176
1176 div = (host->bus_hz != clock) ? DIV_ROUND_UP(div, 2) : 0; 1177 div = (host->bus_hz != clock) ? DIV_ROUND_UP(div, 2) : 0;
1177 1178
1178 if (clock != slot->__clk_old || force_clkinit) 1179 if ((clock != slot->__clk_old &&
1180 !test_bit(DW_MMC_CARD_NEEDS_POLL, &slot->flags)) ||
1181 force_clkinit) {
1179 dev_info(&slot->mmc->class_dev, 1182 dev_info(&slot->mmc->class_dev,
1180 "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ div = %d)\n", 1183 "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ div = %d)\n",
1181 slot->id, host->bus_hz, clock, 1184 slot->id, host->bus_hz, clock,
1182 div ? ((host->bus_hz / div) >> 1) : 1185 div ? ((host->bus_hz / div) >> 1) :
1183 host->bus_hz, div); 1186 host->bus_hz, div);
1184 1187
1188 /*
1189 * If card is polling, display the message only
1190 * one time at boot time.
1191 */
1192 if (slot->mmc->caps & MMC_CAP_NEEDS_POLL &&
1193 slot->mmc->f_min == clock)
1194 set_bit(DW_MMC_CARD_NEEDS_POLL, &slot->flags);
1195 }
1196
1185 /* disable clock */ 1197 /* disable clock */
1186 mci_writel(host, CLKENA, 0); 1198 mci_writel(host, CLKENA, 0);
1187 mci_writel(host, CLKSRC, 0); 1199 mci_writel(host, CLKSRC, 0);
@@ -1273,10 +1285,7 @@ static void __dw_mci_start_request(struct dw_mci *host,
1273 spin_unlock_irqrestore(&host->irq_lock, irqflags); 1285 spin_unlock_irqrestore(&host->irq_lock, irqflags);
1274 } 1286 }
1275 1287
1276 if (mrq->stop) 1288 host->stop_cmdr = dw_mci_prep_stop_abort(host, cmd);
1277 host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop);
1278 else
1279 host->stop_cmdr = dw_mci_prep_stop_abort(host, cmd);
1280} 1289}
1281 1290
1282static void dw_mci_start_request(struct dw_mci *host, 1291static void dw_mci_start_request(struct dw_mci *host,
@@ -1527,22 +1536,34 @@ static int dw_mci_get_cd(struct mmc_host *mmc)
1527 int gpio_cd = mmc_gpio_get_cd(mmc); 1536 int gpio_cd = mmc_gpio_get_cd(mmc);
1528 1537
1529 /* Use platform get_cd function, else try onboard card detect */ 1538 /* Use platform get_cd function, else try onboard card detect */
1530 if ((mmc->caps & MMC_CAP_NEEDS_POLL) || !mmc_card_is_removable(mmc)) 1539 if (((mmc->caps & MMC_CAP_NEEDS_POLL)
1540 || !mmc_card_is_removable(mmc))) {
1531 present = 1; 1541 present = 1;
1532 else if (gpio_cd >= 0) 1542
1543 if (!test_bit(DW_MMC_CARD_PRESENT, &slot->flags)) {
1544 if (mmc->caps & MMC_CAP_NEEDS_POLL) {
1545 dev_info(&mmc->class_dev,
1546 "card is polling.\n");
1547 } else {
1548 dev_info(&mmc->class_dev,
1549 "card is non-removable.\n");
1550 }
1551 set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
1552 }
1553
1554 return present;
1555 } else if (gpio_cd >= 0)
1533 present = gpio_cd; 1556 present = gpio_cd;
1534 else 1557 else
1535 present = (mci_readl(slot->host, CDETECT) & (1 << slot->id)) 1558 present = (mci_readl(slot->host, CDETECT) & (1 << slot->id))
1536 == 0 ? 1 : 0; 1559 == 0 ? 1 : 0;
1537 1560
1538 spin_lock_bh(&host->lock); 1561 spin_lock_bh(&host->lock);
1539 if (present) { 1562 if (present && !test_and_set_bit(DW_MMC_CARD_PRESENT, &slot->flags))
1540 set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
1541 dev_dbg(&mmc->class_dev, "card is present\n"); 1563 dev_dbg(&mmc->class_dev, "card is present\n");
1542 } else { 1564 else if (!present &&
1543 clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); 1565 !test_and_clear_bit(DW_MMC_CARD_PRESENT, &slot->flags))
1544 dev_dbg(&mmc->class_dev, "card is not present\n"); 1566 dev_dbg(&mmc->class_dev, "card is not present\n");
1545 }
1546 spin_unlock_bh(&host->lock); 1567 spin_unlock_bh(&host->lock);
1547 1568
1548 return present; 1569 return present;
@@ -1889,8 +1910,7 @@ static void dw_mci_tasklet_func(unsigned long priv)
1889 if (test_and_clear_bit(EVENT_DATA_ERROR, 1910 if (test_and_clear_bit(EVENT_DATA_ERROR,
1890 &host->pending_events)) { 1911 &host->pending_events)) {
1891 dw_mci_stop_dma(host); 1912 dw_mci_stop_dma(host);
1892 if (data->stop || 1913 if (!(host->data_status & (SDMMC_INT_DRTO |
1893 !(host->data_status & (SDMMC_INT_DRTO |
1894 SDMMC_INT_EBE))) 1914 SDMMC_INT_EBE)))
1895 send_stop_abort(host, data); 1915 send_stop_abort(host, data);
1896 state = STATE_DATA_ERROR; 1916 state = STATE_DATA_ERROR;
@@ -1926,8 +1946,7 @@ static void dw_mci_tasklet_func(unsigned long priv)
1926 if (test_and_clear_bit(EVENT_DATA_ERROR, 1946 if (test_and_clear_bit(EVENT_DATA_ERROR,
1927 &host->pending_events)) { 1947 &host->pending_events)) {
1928 dw_mci_stop_dma(host); 1948 dw_mci_stop_dma(host);
1929 if (data->stop || 1949 if (!(host->data_status & (SDMMC_INT_DRTO |
1930 !(host->data_status & (SDMMC_INT_DRTO |
1931 SDMMC_INT_EBE))) 1950 SDMMC_INT_EBE)))
1932 send_stop_abort(host, data); 1951 send_stop_abort(host, data);
1933 state = STATE_DATA_ERROR; 1952 state = STATE_DATA_ERROR;
@@ -2003,7 +2022,7 @@ static void dw_mci_tasklet_func(unsigned long priv)
2003 host->cmd = NULL; 2022 host->cmd = NULL;
2004 host->data = NULL; 2023 host->data = NULL;
2005 2024
2006 if (mrq->stop) 2025 if (!mrq->sbc && mrq->stop)
2007 dw_mci_command_complete(host, mrq->stop); 2026 dw_mci_command_complete(host, mrq->stop);
2008 else 2027 else
2009 host->cmd_status = 0; 2028 host->cmd_status = 0;
@@ -2615,6 +2634,8 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
2615 mmc->f_min = DW_MCI_FREQ_MIN; 2634 mmc->f_min = DW_MCI_FREQ_MIN;
2616 mmc->f_max = DW_MCI_FREQ_MAX; 2635 mmc->f_max = DW_MCI_FREQ_MAX;
2617 } else { 2636 } else {
2637 dev_info(host->dev,
2638 "'clock-freq-min-max' property was deprecated.\n");
2618 mmc->f_min = freq[0]; 2639 mmc->f_min = freq[0];
2619 mmc->f_max = freq[1]; 2640 mmc->f_max = freq[1];
2620 } 2641 }
@@ -3267,26 +3288,46 @@ EXPORT_SYMBOL(dw_mci_remove);
3267 3288
3268 3289
3269 3290
3270#ifdef CONFIG_PM_SLEEP 3291#ifdef CONFIG_PM
3271/* 3292int dw_mci_runtime_suspend(struct device *dev)
3272 * TODO: we should probably disable the clock to the card in the suspend path.
3273 */
3274int dw_mci_suspend(struct dw_mci *host)
3275{ 3293{
3294 struct dw_mci *host = dev_get_drvdata(dev);
3295
3276 if (host->use_dma && host->dma_ops->exit) 3296 if (host->use_dma && host->dma_ops->exit)
3277 host->dma_ops->exit(host); 3297 host->dma_ops->exit(host);
3278 3298
3299 clk_disable_unprepare(host->ciu_clk);
3300
3301 if (host->cur_slot &&
3302 (mmc_can_gpio_cd(host->cur_slot->mmc) ||
3303 !mmc_card_is_removable(host->cur_slot->mmc)))
3304 clk_disable_unprepare(host->biu_clk);
3305
3279 return 0; 3306 return 0;
3280} 3307}
3281EXPORT_SYMBOL(dw_mci_suspend); 3308EXPORT_SYMBOL(dw_mci_runtime_suspend);
3282 3309
3283int dw_mci_resume(struct dw_mci *host) 3310int dw_mci_runtime_resume(struct device *dev)
3284{ 3311{
3285 int i, ret; 3312 int i, ret = 0;
3313 struct dw_mci *host = dev_get_drvdata(dev);
3314
3315 if (host->cur_slot &&
3316 (mmc_can_gpio_cd(host->cur_slot->mmc) ||
3317 !mmc_card_is_removable(host->cur_slot->mmc))) {
3318 ret = clk_prepare_enable(host->biu_clk);
3319 if (ret)
3320 return ret;
3321 }
3322
3323 ret = clk_prepare_enable(host->ciu_clk);
3324 if (ret)
3325 goto err;
3286 3326
3287 if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_ALL_RESET_FLAGS)) { 3327 if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_ALL_RESET_FLAGS)) {
3328 clk_disable_unprepare(host->ciu_clk);
3288 ret = -ENODEV; 3329 ret = -ENODEV;
3289 return ret; 3330 goto err;
3290 } 3331 }
3291 3332
3292 if (host->use_dma && host->dma_ops->init) 3333 if (host->use_dma && host->dma_ops->init)
@@ -3296,8 +3337,8 @@ int dw_mci_resume(struct dw_mci *host)
3296 * Restore the initial value at FIFOTH register 3337 * Restore the initial value at FIFOTH register
3297 * And Invalidate the prev_blksz with zero 3338 * And Invalidate the prev_blksz with zero
3298 */ 3339 */
3299 mci_writel(host, FIFOTH, host->fifoth_val); 3340 mci_writel(host, FIFOTH, host->fifoth_val);
3300 host->prev_blksz = 0; 3341 host->prev_blksz = 0;
3301 3342
3302 /* Put in max timeout */ 3343 /* Put in max timeout */
3303 mci_writel(host, TMOUT, 0xFFFFFFFF); 3344 mci_writel(host, TMOUT, 0xFFFFFFFF);
@@ -3323,9 +3364,17 @@ int dw_mci_resume(struct dw_mci *host)
3323 dw_mci_enable_cd(host); 3364 dw_mci_enable_cd(host);
3324 3365
3325 return 0; 3366 return 0;
3367
3368err:
3369 if (host->cur_slot &&
3370 (mmc_can_gpio_cd(host->cur_slot->mmc) ||
3371 !mmc_card_is_removable(host->cur_slot->mmc)))
3372 clk_disable_unprepare(host->biu_clk);
3373
3374 return ret;
3326} 3375}
3327EXPORT_SYMBOL(dw_mci_resume); 3376EXPORT_SYMBOL(dw_mci_runtime_resume);
3328#endif /* CONFIG_PM_SLEEP */ 3377#endif /* CONFIG_PM */
3329 3378
3330static int __init dw_mci_init(void) 3379static int __init dw_mci_init(void)
3331{ 3380{
diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
index e8cd2dec3263..c59465829387 100644
--- a/drivers/mmc/host/dw_mmc.h
+++ b/drivers/mmc/host/dw_mmc.h
@@ -234,9 +234,9 @@
234 234
235extern int dw_mci_probe(struct dw_mci *host); 235extern int dw_mci_probe(struct dw_mci *host);
236extern void dw_mci_remove(struct dw_mci *host); 236extern void dw_mci_remove(struct dw_mci *host);
237#ifdef CONFIG_PM_SLEEP 237#ifdef CONFIG_PM
238extern int dw_mci_suspend(struct dw_mci *host); 238extern int dw_mci_runtime_suspend(struct device *device);
239extern int dw_mci_resume(struct dw_mci *host); 239extern int dw_mci_runtime_resume(struct device *device);
240#endif 240#endif
241 241
242/** 242/**
@@ -272,6 +272,7 @@ struct dw_mci_slot {
272#define DW_MMC_CARD_NEED_INIT 1 272#define DW_MMC_CARD_NEED_INIT 1
273#define DW_MMC_CARD_NO_LOW_PWR 2 273#define DW_MMC_CARD_NO_LOW_PWR 2
274#define DW_MMC_CARD_NO_USE_HOLD 3 274#define DW_MMC_CARD_NO_USE_HOLD 3
275#define DW_MMC_CARD_NEEDS_POLL 4
275 int id; 276 int id;
276 int sdio_id; 277 int sdio_id;
277}; 278};
diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
index 684087db170b..819ad32964fc 100644
--- a/drivers/mmc/host/jz4740_mmc.c
+++ b/drivers/mmc/host/jz4740_mmc.c
@@ -320,8 +320,7 @@ dma_unmap:
320} 320}
321 321
322static void jz4740_mmc_pre_request(struct mmc_host *mmc, 322static void jz4740_mmc_pre_request(struct mmc_host *mmc,
323 struct mmc_request *mrq, 323 struct mmc_request *mrq)
324 bool is_first_req)
325{ 324{
326 struct jz4740_mmc_host *host = mmc_priv(mmc); 325 struct jz4740_mmc_host *host = mmc_priv(mmc);
327 struct mmc_data *data = mrq->data; 326 struct mmc_data *data = mrq->data;
diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c
new file mode 100644
index 000000000000..b352760c041e
--- /dev/null
+++ b/drivers/mmc/host/meson-gx-mmc.c
@@ -0,0 +1,851 @@
1/*
2 * Amlogic SD/eMMC driver for the GX/S905 family SoCs
3 *
4 * Copyright (c) 2016 BayLibre, SAS.
5 * Author: Kevin Hilman <khilman@baylibre.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution
19 * in the file called COPYING.
20 */
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/device.h>
25#include <linux/of_device.h>
26#include <linux/platform_device.h>
27#include <linux/ioport.h>
28#include <linux/spinlock.h>
29#include <linux/dma-mapping.h>
30#include <linux/mmc/host.h>
31#include <linux/mmc/mmc.h>
32#include <linux/mmc/sdio.h>
33#include <linux/mmc/slot-gpio.h>
34#include <linux/io.h>
35#include <linux/clk.h>
36#include <linux/clk-provider.h>
37#include <linux/regulator/consumer.h>
38
39#define DRIVER_NAME "meson-gx-mmc"
40
41#define SD_EMMC_CLOCK 0x0
42#define CLK_DIV_SHIFT 0
43#define CLK_DIV_WIDTH 6
44#define CLK_DIV_MASK 0x3f
45#define CLK_DIV_MAX 63
46#define CLK_SRC_SHIFT 6
47#define CLK_SRC_WIDTH 2
48#define CLK_SRC_MASK 0x3
49#define CLK_SRC_XTAL 0 /* external crystal */
50#define CLK_SRC_XTAL_RATE 24000000
51#define CLK_SRC_PLL 1 /* FCLK_DIV2 */
52#define CLK_SRC_PLL_RATE 1000000000
53#define CLK_PHASE_SHIFT 8
54#define CLK_PHASE_MASK 0x3
55#define CLK_PHASE_0 0
56#define CLK_PHASE_90 1
57#define CLK_PHASE_180 2
58#define CLK_PHASE_270 3
59#define CLK_ALWAYS_ON BIT(24)
60
61#define SD_EMMC_DElAY 0x4
62#define SD_EMMC_ADJUST 0x8
63#define SD_EMMC_CALOUT 0x10
64#define SD_EMMC_START 0x40
65#define START_DESC_INIT BIT(0)
66#define START_DESC_BUSY BIT(1)
67#define START_DESC_ADDR_SHIFT 2
68#define START_DESC_ADDR_MASK (~0x3)
69
70#define SD_EMMC_CFG 0x44
71#define CFG_BUS_WIDTH_SHIFT 0
72#define CFG_BUS_WIDTH_MASK 0x3
73#define CFG_BUS_WIDTH_1 0x0
74#define CFG_BUS_WIDTH_4 0x1
75#define CFG_BUS_WIDTH_8 0x2
76#define CFG_DDR BIT(2)
77#define CFG_BLK_LEN_SHIFT 4
78#define CFG_BLK_LEN_MASK 0xf
79#define CFG_RESP_TIMEOUT_SHIFT 8
80#define CFG_RESP_TIMEOUT_MASK 0xf
81#define CFG_RC_CC_SHIFT 12
82#define CFG_RC_CC_MASK 0xf
83#define CFG_STOP_CLOCK BIT(22)
84#define CFG_CLK_ALWAYS_ON BIT(18)
85#define CFG_AUTO_CLK BIT(23)
86
87#define SD_EMMC_STATUS 0x48
88#define STATUS_BUSY BIT(31)
89
90#define SD_EMMC_IRQ_EN 0x4c
91#define IRQ_EN_MASK 0x3fff
92#define IRQ_RXD_ERR_SHIFT 0
93#define IRQ_RXD_ERR_MASK 0xff
94#define IRQ_TXD_ERR BIT(8)
95#define IRQ_DESC_ERR BIT(9)
96#define IRQ_RESP_ERR BIT(10)
97#define IRQ_RESP_TIMEOUT BIT(11)
98#define IRQ_DESC_TIMEOUT BIT(12)
99#define IRQ_END_OF_CHAIN BIT(13)
100#define IRQ_RESP_STATUS BIT(14)
101#define IRQ_SDIO BIT(15)
102
103#define SD_EMMC_CMD_CFG 0x50
104#define SD_EMMC_CMD_ARG 0x54
105#define SD_EMMC_CMD_DAT 0x58
106#define SD_EMMC_CMD_RSP 0x5c
107#define SD_EMMC_CMD_RSP1 0x60
108#define SD_EMMC_CMD_RSP2 0x64
109#define SD_EMMC_CMD_RSP3 0x68
110
111#define SD_EMMC_RXD 0x94
112#define SD_EMMC_TXD 0x94
113#define SD_EMMC_LAST_REG SD_EMMC_TXD
114
115#define SD_EMMC_CFG_BLK_SIZE 512 /* internal buffer max: 512 bytes */
116#define SD_EMMC_CFG_RESP_TIMEOUT 256 /* in clock cycles */
117#define SD_EMMC_CFG_CMD_GAP 16 /* in clock cycles */
118#define MUX_CLK_NUM_PARENTS 2
119
120struct meson_host {
121 struct device *dev;
122 struct mmc_host *mmc;
123 struct mmc_request *mrq;
124 struct mmc_command *cmd;
125
126 spinlock_t lock;
127 void __iomem *regs;
128 int irq;
129 u32 ocr_mask;
130 struct clk *core_clk;
131 struct clk_mux mux;
132 struct clk *mux_clk;
133 struct clk *mux_parent[MUX_CLK_NUM_PARENTS];
134 unsigned long mux_parent_rate[MUX_CLK_NUM_PARENTS];
135
136 struct clk_divider cfg_div;
137 struct clk *cfg_div_clk;
138
139 unsigned int bounce_buf_size;
140 void *bounce_buf;
141 dma_addr_t bounce_dma_addr;
142
143 bool vqmmc_enabled;
144};
145
146struct sd_emmc_desc {
147 u32 cmd_cfg;
148 u32 cmd_arg;
149 u32 cmd_data;
150 u32 cmd_resp;
151};
152#define CMD_CFG_LENGTH_SHIFT 0
153#define CMD_CFG_LENGTH_MASK 0x1ff
154#define CMD_CFG_BLOCK_MODE BIT(9)
155#define CMD_CFG_R1B BIT(10)
156#define CMD_CFG_END_OF_CHAIN BIT(11)
157#define CMD_CFG_TIMEOUT_SHIFT 12
158#define CMD_CFG_TIMEOUT_MASK 0xf
159#define CMD_CFG_NO_RESP BIT(16)
160#define CMD_CFG_NO_CMD BIT(17)
161#define CMD_CFG_DATA_IO BIT(18)
162#define CMD_CFG_DATA_WR BIT(19)
163#define CMD_CFG_RESP_NOCRC BIT(20)
164#define CMD_CFG_RESP_128 BIT(21)
165#define CMD_CFG_RESP_NUM BIT(22)
166#define CMD_CFG_DATA_NUM BIT(23)
167#define CMD_CFG_CMD_INDEX_SHIFT 24
168#define CMD_CFG_CMD_INDEX_MASK 0x3f
169#define CMD_CFG_ERROR BIT(30)
170#define CMD_CFG_OWNER BIT(31)
171
172#define CMD_DATA_MASK (~0x3)
173#define CMD_DATA_BIG_ENDIAN BIT(1)
174#define CMD_DATA_SRAM BIT(0)
175#define CMD_RESP_MASK (~0x1)
176#define CMD_RESP_SRAM BIT(0)
177
178static int meson_mmc_clk_set(struct meson_host *host, unsigned long clk_rate)
179{
180 struct mmc_host *mmc = host->mmc;
181 int ret = 0;
182 u32 cfg;
183
184 if (clk_rate) {
185 if (WARN_ON(clk_rate > mmc->f_max))
186 clk_rate = mmc->f_max;
187 else if (WARN_ON(clk_rate < mmc->f_min))
188 clk_rate = mmc->f_min;
189 }
190
191 if (clk_rate == mmc->actual_clock)
192 return 0;
193
194 /* stop clock */
195 cfg = readl(host->regs + SD_EMMC_CFG);
196 if (!(cfg & CFG_STOP_CLOCK)) {
197 cfg |= CFG_STOP_CLOCK;
198 writel(cfg, host->regs + SD_EMMC_CFG);
199 }
200
201 dev_dbg(host->dev, "change clock rate %u -> %lu\n",
202 mmc->actual_clock, clk_rate);
203
204 if (clk_rate == 0) {
205 mmc->actual_clock = 0;
206 return 0;
207 }
208
209 ret = clk_set_rate(host->cfg_div_clk, clk_rate);
210 if (ret)
211 dev_warn(host->dev, "Unable to set cfg_div_clk to %lu. ret=%d\n",
212 clk_rate, ret);
213 else if (clk_rate && clk_rate != clk_get_rate(host->cfg_div_clk))
214 dev_warn(host->dev, "divider requested rate %lu != actual rate %lu: ret=%d\n",
215 clk_rate, clk_get_rate(host->cfg_div_clk), ret);
216 else
217 mmc->actual_clock = clk_rate;
218
219 /* (re)start clock, if non-zero */
220 if (!ret && clk_rate) {
221 cfg = readl(host->regs + SD_EMMC_CFG);
222 cfg &= ~CFG_STOP_CLOCK;
223 writel(cfg, host->regs + SD_EMMC_CFG);
224 }
225
226 return ret;
227}
228
229/*
230 * The SD/eMMC IP block has an internal mux and divider used for
231 * generating the MMC clock. Use the clock framework to create and
232 * manage these clocks.
233 */
234static int meson_mmc_clk_init(struct meson_host *host)
235{
236 struct clk_init_data init;
237 char clk_name[32];
238 int i, ret = 0;
239 const char *mux_parent_names[MUX_CLK_NUM_PARENTS];
240 unsigned int mux_parent_count = 0;
241 const char *clk_div_parents[1];
242 unsigned int f_min = UINT_MAX;
243 u32 clk_reg, cfg;
244
245 /* get the mux parents */
246 for (i = 0; i < MUX_CLK_NUM_PARENTS; i++) {
247 char name[16];
248
249 snprintf(name, sizeof(name), "clkin%d", i);
250 host->mux_parent[i] = devm_clk_get(host->dev, name);
251 if (IS_ERR(host->mux_parent[i])) {
252 ret = PTR_ERR(host->mux_parent[i]);
253 if (PTR_ERR(host->mux_parent[i]) != -EPROBE_DEFER)
254 dev_err(host->dev, "Missing clock %s\n", name);
255 host->mux_parent[i] = NULL;
256 return ret;
257 }
258
259 host->mux_parent_rate[i] = clk_get_rate(host->mux_parent[i]);
260 mux_parent_names[i] = __clk_get_name(host->mux_parent[i]);
261 mux_parent_count++;
262 if (host->mux_parent_rate[i] < f_min)
263 f_min = host->mux_parent_rate[i];
264 }
265
266 /* cacluate f_min based on input clocks, and max divider value */
267 if (f_min != UINT_MAX)
268 f_min = DIV_ROUND_UP(CLK_SRC_XTAL_RATE, CLK_DIV_MAX);
269 else
270 f_min = 4000000; /* default min: 400 MHz */
271 host->mmc->f_min = f_min;
272
273 /* create the mux */
274 snprintf(clk_name, sizeof(clk_name), "%s#mux", dev_name(host->dev));
275 init.name = clk_name;
276 init.ops = &clk_mux_ops;
277 init.flags = 0;
278 init.parent_names = mux_parent_names;
279 init.num_parents = mux_parent_count;
280
281 host->mux.reg = host->regs + SD_EMMC_CLOCK;
282 host->mux.shift = CLK_SRC_SHIFT;
283 host->mux.mask = CLK_SRC_MASK;
284 host->mux.flags = 0;
285 host->mux.table = NULL;
286 host->mux.hw.init = &init;
287
288 host->mux_clk = devm_clk_register(host->dev, &host->mux.hw);
289 if (WARN_ON(IS_ERR(host->mux_clk)))
290 return PTR_ERR(host->mux_clk);
291
292 /* create the divider */
293 snprintf(clk_name, sizeof(clk_name), "%s#div", dev_name(host->dev));
294 init.name = devm_kstrdup(host->dev, clk_name, GFP_KERNEL);
295 init.ops = &clk_divider_ops;
296 init.flags = CLK_SET_RATE_PARENT;
297 clk_div_parents[0] = __clk_get_name(host->mux_clk);
298 init.parent_names = clk_div_parents;
299 init.num_parents = ARRAY_SIZE(clk_div_parents);
300
301 host->cfg_div.reg = host->regs + SD_EMMC_CLOCK;
302 host->cfg_div.shift = CLK_DIV_SHIFT;
303 host->cfg_div.width = CLK_DIV_WIDTH;
304 host->cfg_div.hw.init = &init;
305 host->cfg_div.flags = CLK_DIVIDER_ONE_BASED |
306 CLK_DIVIDER_ROUND_CLOSEST | CLK_DIVIDER_ALLOW_ZERO;
307
308 host->cfg_div_clk = devm_clk_register(host->dev, &host->cfg_div.hw);
309 if (WARN_ON(PTR_ERR_OR_ZERO(host->cfg_div_clk)))
310 return PTR_ERR(host->cfg_div_clk);
311
312 /* init SD_EMMC_CLOCK to sane defaults w/min clock rate */
313 clk_reg = 0;
314 clk_reg |= CLK_PHASE_180 << CLK_PHASE_SHIFT;
315 clk_reg |= CLK_SRC_XTAL << CLK_SRC_SHIFT;
316 clk_reg |= CLK_DIV_MAX << CLK_DIV_SHIFT;
317 clk_reg &= ~CLK_ALWAYS_ON;
318 writel(clk_reg, host->regs + SD_EMMC_CLOCK);
319
320 /* Ensure clock starts in "auto" mode, not "always on" */
321 cfg = readl(host->regs + SD_EMMC_CFG);
322 cfg &= ~CFG_CLK_ALWAYS_ON;
323 cfg |= CFG_AUTO_CLK;
324 writel(cfg, host->regs + SD_EMMC_CFG);
325
326 ret = clk_prepare_enable(host->cfg_div_clk);
327 if (!ret)
328 ret = meson_mmc_clk_set(host, f_min);
329
330 if (!ret)
331 clk_disable_unprepare(host->cfg_div_clk);
332
333 return ret;
334}
335
336static void meson_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
337{
338 struct meson_host *host = mmc_priv(mmc);
339 u32 bus_width;
340 u32 val, orig;
341
342 /*
343 * GPIO regulator, only controls switching between 1v8 and
344 * 3v3, doesn't support MMC_POWER_OFF, MMC_POWER_ON.
345 */
346 switch (ios->power_mode) {
347 case MMC_POWER_OFF:
348 if (!IS_ERR(mmc->supply.vmmc))
349 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
350
351 if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled) {
352 regulator_disable(mmc->supply.vqmmc);
353 host->vqmmc_enabled = false;
354 }
355
356 break;
357
358 case MMC_POWER_UP:
359 if (!IS_ERR(mmc->supply.vmmc))
360 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd);
361 break;
362
363 case MMC_POWER_ON:
364 if (!IS_ERR(mmc->supply.vqmmc) && !host->vqmmc_enabled) {
365 int ret = regulator_enable(mmc->supply.vqmmc);
366
367 if (ret < 0)
368 dev_err(mmc_dev(mmc),
369 "failed to enable vqmmc regulator\n");
370 else
371 host->vqmmc_enabled = true;
372 }
373
374 break;
375 }
376
377
378 meson_mmc_clk_set(host, ios->clock);
379
380 /* Bus width */
381 val = readl(host->regs + SD_EMMC_CFG);
382 switch (ios->bus_width) {
383 case MMC_BUS_WIDTH_1:
384 bus_width = CFG_BUS_WIDTH_1;
385 break;
386 case MMC_BUS_WIDTH_4:
387 bus_width = CFG_BUS_WIDTH_4;
388 break;
389 case MMC_BUS_WIDTH_8:
390 bus_width = CFG_BUS_WIDTH_8;
391 break;
392 default:
393 dev_err(host->dev, "Invalid ios->bus_width: %u. Setting to 4.\n",
394 ios->bus_width);
395 bus_width = CFG_BUS_WIDTH_4;
396 return;
397 }
398
399 val = readl(host->regs + SD_EMMC_CFG);
400 orig = val;
401
402 val &= ~(CFG_BUS_WIDTH_MASK << CFG_BUS_WIDTH_SHIFT);
403 val |= bus_width << CFG_BUS_WIDTH_SHIFT;
404
405 val &= ~(CFG_BLK_LEN_MASK << CFG_BLK_LEN_SHIFT);
406 val |= ilog2(SD_EMMC_CFG_BLK_SIZE) << CFG_BLK_LEN_SHIFT;
407
408 val &= ~(CFG_RESP_TIMEOUT_MASK << CFG_RESP_TIMEOUT_SHIFT);
409 val |= ilog2(SD_EMMC_CFG_RESP_TIMEOUT) << CFG_RESP_TIMEOUT_SHIFT;
410
411 val &= ~(CFG_RC_CC_MASK << CFG_RC_CC_SHIFT);
412 val |= ilog2(SD_EMMC_CFG_CMD_GAP) << CFG_RC_CC_SHIFT;
413
414 writel(val, host->regs + SD_EMMC_CFG);
415
416 if (val != orig)
417 dev_dbg(host->dev, "%s: SD_EMMC_CFG: 0x%08x -> 0x%08x\n",
418 __func__, orig, val);
419}
420
421static int meson_mmc_request_done(struct mmc_host *mmc, struct mmc_request *mrq)
422{
423 struct meson_host *host = mmc_priv(mmc);
424
425 WARN_ON(host->mrq != mrq);
426
427 host->mrq = NULL;
428 host->cmd = NULL;
429 mmc_request_done(host->mmc, mrq);
430
431 return 0;
432}
433
434static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd)
435{
436 struct meson_host *host = mmc_priv(mmc);
437 struct sd_emmc_desc *desc, desc_tmp;
438 u32 cfg;
439 u8 blk_len, cmd_cfg_timeout;
440 unsigned int xfer_bytes = 0;
441
442 /* Setup descriptors */
443 dma_rmb();
444 desc = &desc_tmp;
445 memset(desc, 0, sizeof(struct sd_emmc_desc));
446
447 desc->cmd_cfg |= (cmd->opcode & CMD_CFG_CMD_INDEX_MASK) <<
448 CMD_CFG_CMD_INDEX_SHIFT;
449 desc->cmd_cfg |= CMD_CFG_OWNER; /* owned by CPU */
450 desc->cmd_arg = cmd->arg;
451
452 /* Response */
453 if (cmd->flags & MMC_RSP_PRESENT) {
454 desc->cmd_cfg &= ~CMD_CFG_NO_RESP;
455 if (cmd->flags & MMC_RSP_136)
456 desc->cmd_cfg |= CMD_CFG_RESP_128;
457 desc->cmd_cfg |= CMD_CFG_RESP_NUM;
458 desc->cmd_resp = 0;
459
460 if (!(cmd->flags & MMC_RSP_CRC))
461 desc->cmd_cfg |= CMD_CFG_RESP_NOCRC;
462
463 if (cmd->flags & MMC_RSP_BUSY)
464 desc->cmd_cfg |= CMD_CFG_R1B;
465 } else {
466 desc->cmd_cfg |= CMD_CFG_NO_RESP;
467 }
468
469 /* data? */
470 if (cmd->data) {
471 desc->cmd_cfg |= CMD_CFG_DATA_IO;
472 if (cmd->data->blocks > 1) {
473 desc->cmd_cfg |= CMD_CFG_BLOCK_MODE;
474 desc->cmd_cfg |=
475 (cmd->data->blocks & CMD_CFG_LENGTH_MASK) <<
476 CMD_CFG_LENGTH_SHIFT;
477
478 /* check if block-size matches, if not update */
479 cfg = readl(host->regs + SD_EMMC_CFG);
480 blk_len = cfg & (CFG_BLK_LEN_MASK << CFG_BLK_LEN_SHIFT);
481 blk_len >>= CFG_BLK_LEN_SHIFT;
482 if (blk_len != ilog2(cmd->data->blksz)) {
483 dev_warn(host->dev, "%s: update blk_len %d -> %d\n",
484 __func__, blk_len,
485 ilog2(cmd->data->blksz));
486 blk_len = ilog2(cmd->data->blksz);
487 cfg &= ~(CFG_BLK_LEN_MASK << CFG_BLK_LEN_SHIFT);
488 cfg |= blk_len << CFG_BLK_LEN_SHIFT;
489 writel(cfg, host->regs + SD_EMMC_CFG);
490 }
491 } else {
492 desc->cmd_cfg &= ~CMD_CFG_BLOCK_MODE;
493 desc->cmd_cfg |=
494 (cmd->data->blksz & CMD_CFG_LENGTH_MASK) <<
495 CMD_CFG_LENGTH_SHIFT;
496 }
497
498 cmd->data->bytes_xfered = 0;
499 xfer_bytes = cmd->data->blksz * cmd->data->blocks;
500 if (cmd->data->flags & MMC_DATA_WRITE) {
501 desc->cmd_cfg |= CMD_CFG_DATA_WR;
502 WARN_ON(xfer_bytes > host->bounce_buf_size);
503 sg_copy_to_buffer(cmd->data->sg, cmd->data->sg_len,
504 host->bounce_buf, xfer_bytes);
505 cmd->data->bytes_xfered = xfer_bytes;
506 dma_wmb();
507 } else {
508 desc->cmd_cfg &= ~CMD_CFG_DATA_WR;
509 }
510
511 if (xfer_bytes > 0) {
512 desc->cmd_cfg &= ~CMD_CFG_DATA_NUM;
513 desc->cmd_data = host->bounce_dma_addr & CMD_DATA_MASK;
514 } else {
515 /* write data to data_addr */
516 desc->cmd_cfg |= CMD_CFG_DATA_NUM;
517 desc->cmd_data = 0;
518 }
519
520 cmd_cfg_timeout = 12;
521 } else {
522 desc->cmd_cfg &= ~CMD_CFG_DATA_IO;
523 cmd_cfg_timeout = 10;
524 }
525 desc->cmd_cfg |= (cmd_cfg_timeout & CMD_CFG_TIMEOUT_MASK) <<
526 CMD_CFG_TIMEOUT_SHIFT;
527
528 host->cmd = cmd;
529
530 /* Last descriptor */
531 desc->cmd_cfg |= CMD_CFG_END_OF_CHAIN;
532 writel(desc->cmd_cfg, host->regs + SD_EMMC_CMD_CFG);
533 writel(desc->cmd_data, host->regs + SD_EMMC_CMD_DAT);
534 writel(desc->cmd_resp, host->regs + SD_EMMC_CMD_RSP);
535 wmb(); /* ensure descriptor is written before kicked */
536 writel(desc->cmd_arg, host->regs + SD_EMMC_CMD_ARG);
537}
538
539static void meson_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
540{
541 struct meson_host *host = mmc_priv(mmc);
542
543 WARN_ON(host->mrq != NULL);
544
545 /* Stop execution */
546 writel(0, host->regs + SD_EMMC_START);
547
548 /* clear, ack, enable all interrupts */
549 writel(0, host->regs + SD_EMMC_IRQ_EN);
550 writel(IRQ_EN_MASK, host->regs + SD_EMMC_STATUS);
551 writel(IRQ_EN_MASK, host->regs + SD_EMMC_IRQ_EN);
552
553 host->mrq = mrq;
554
555 if (mrq->sbc)
556 meson_mmc_start_cmd(mmc, mrq->sbc);
557 else
558 meson_mmc_start_cmd(mmc, mrq->cmd);
559}
560
561static int meson_mmc_read_resp(struct mmc_host *mmc, struct mmc_command *cmd)
562{
563 struct meson_host *host = mmc_priv(mmc);
564
565 if (cmd->flags & MMC_RSP_136) {
566 cmd->resp[0] = readl(host->regs + SD_EMMC_CMD_RSP3);
567 cmd->resp[1] = readl(host->regs + SD_EMMC_CMD_RSP2);
568 cmd->resp[2] = readl(host->regs + SD_EMMC_CMD_RSP1);
569 cmd->resp[3] = readl(host->regs + SD_EMMC_CMD_RSP);
570 } else if (cmd->flags & MMC_RSP_PRESENT) {
571 cmd->resp[0] = readl(host->regs + SD_EMMC_CMD_RSP);
572 }
573
574 return 0;
575}
576
577static irqreturn_t meson_mmc_irq(int irq, void *dev_id)
578{
579 struct meson_host *host = dev_id;
580 struct mmc_request *mrq;
581 struct mmc_command *cmd = host->cmd;
582 u32 irq_en, status, raw_status;
583 irqreturn_t ret = IRQ_HANDLED;
584
585 if (WARN_ON(!host))
586 return IRQ_NONE;
587
588 mrq = host->mrq;
589
590 if (WARN_ON(!mrq))
591 return IRQ_NONE;
592
593 if (WARN_ON(!cmd))
594 return IRQ_NONE;
595
596 spin_lock(&host->lock);
597 irq_en = readl(host->regs + SD_EMMC_IRQ_EN);
598 raw_status = readl(host->regs + SD_EMMC_STATUS);
599 status = raw_status & irq_en;
600
601 if (!status) {
602 dev_warn(host->dev, "Spurious IRQ! status=0x%08x, irq_en=0x%08x\n",
603 raw_status, irq_en);
604 ret = IRQ_NONE;
605 goto out;
606 }
607
608 cmd->error = 0;
609 if (status & IRQ_RXD_ERR_MASK) {
610 dev_dbg(host->dev, "Unhandled IRQ: RXD error\n");
611 cmd->error = -EILSEQ;
612 }
613 if (status & IRQ_TXD_ERR) {
614 dev_dbg(host->dev, "Unhandled IRQ: TXD error\n");
615 cmd->error = -EILSEQ;
616 }
617 if (status & IRQ_DESC_ERR)
618 dev_dbg(host->dev, "Unhandled IRQ: Descriptor error\n");
619 if (status & IRQ_RESP_ERR) {
620 dev_dbg(host->dev, "Unhandled IRQ: Response error\n");
621 cmd->error = -EILSEQ;
622 }
623 if (status & IRQ_RESP_TIMEOUT) {
624 dev_dbg(host->dev, "Unhandled IRQ: Response timeout\n");
625 cmd->error = -ETIMEDOUT;
626 }
627 if (status & IRQ_DESC_TIMEOUT) {
628 dev_dbg(host->dev, "Unhandled IRQ: Descriptor timeout\n");
629 cmd->error = -ETIMEDOUT;
630 }
631 if (status & IRQ_SDIO)
632 dev_dbg(host->dev, "Unhandled IRQ: SDIO.\n");
633
634 if (status & (IRQ_END_OF_CHAIN | IRQ_RESP_STATUS))
635 ret = IRQ_WAKE_THREAD;
636 else {
637 dev_warn(host->dev, "Unknown IRQ! status=0x%04x: MMC CMD%u arg=0x%08x flags=0x%08x stop=%d\n",
638 status, cmd->opcode, cmd->arg,
639 cmd->flags, mrq->stop ? 1 : 0);
640 if (cmd->data) {
641 struct mmc_data *data = cmd->data;
642
643 dev_warn(host->dev, "\tblksz %u blocks %u flags 0x%08x (%s%s)",
644 data->blksz, data->blocks, data->flags,
645 data->flags & MMC_DATA_WRITE ? "write" : "",
646 data->flags & MMC_DATA_READ ? "read" : "");
647 }
648 }
649
650out:
651 /* ack all (enabled) interrupts */
652 writel(status, host->regs + SD_EMMC_STATUS);
653
654 if (ret == IRQ_HANDLED) {
655 meson_mmc_read_resp(host->mmc, cmd);
656 meson_mmc_request_done(host->mmc, cmd->mrq);
657 }
658
659 spin_unlock(&host->lock);
660 return ret;
661}
662
663static irqreturn_t meson_mmc_irq_thread(int irq, void *dev_id)
664{
665 struct meson_host *host = dev_id;
666 struct mmc_request *mrq = host->mrq;
667 struct mmc_command *cmd = host->cmd;
668 struct mmc_data *data;
669 unsigned int xfer_bytes;
670 int ret = IRQ_HANDLED;
671
672 if (WARN_ON(!mrq))
673 ret = IRQ_NONE;
674
675 if (WARN_ON(!cmd))
676 ret = IRQ_NONE;
677
678 data = cmd->data;
679 if (data) {
680 xfer_bytes = data->blksz * data->blocks;
681 if (data->flags & MMC_DATA_READ) {
682 WARN_ON(xfer_bytes > host->bounce_buf_size);
683 sg_copy_from_buffer(data->sg, data->sg_len,
684 host->bounce_buf, xfer_bytes);
685 data->bytes_xfered = xfer_bytes;
686 }
687 }
688
689 meson_mmc_read_resp(host->mmc, cmd);
690 if (!data || !data->stop || mrq->sbc)
691 meson_mmc_request_done(host->mmc, mrq);
692 else
693 meson_mmc_start_cmd(host->mmc, data->stop);
694
695 return ret;
696}
697
698/*
699 * NOTE: we only need this until the GPIO/pinctrl driver can handle
700 * interrupts. For now, the MMC core will use this for polling.
701 */
702static int meson_mmc_get_cd(struct mmc_host *mmc)
703{
704 int status = mmc_gpio_get_cd(mmc);
705
706 if (status == -ENOSYS)
707 return 1; /* assume present */
708
709 return status;
710}
711
712static const struct mmc_host_ops meson_mmc_ops = {
713 .request = meson_mmc_request,
714 .set_ios = meson_mmc_set_ios,
715 .get_cd = meson_mmc_get_cd,
716};
717
718static int meson_mmc_probe(struct platform_device *pdev)
719{
720 struct resource *res;
721 struct meson_host *host;
722 struct mmc_host *mmc;
723 int ret;
724
725 mmc = mmc_alloc_host(sizeof(struct meson_host), &pdev->dev);
726 if (!mmc)
727 return -ENOMEM;
728 host = mmc_priv(mmc);
729 host->mmc = mmc;
730 host->dev = &pdev->dev;
731 dev_set_drvdata(&pdev->dev, host);
732
733 spin_lock_init(&host->lock);
734
735 /* Get regulators and the supported OCR mask */
736 host->vqmmc_enabled = false;
737 ret = mmc_regulator_get_supply(mmc);
738 if (ret == -EPROBE_DEFER)
739 goto free_host;
740
741 ret = mmc_of_parse(mmc);
742 if (ret) {
743 dev_warn(&pdev->dev, "error parsing DT: %d\n", ret);
744 goto free_host;
745 }
746
747 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
748 host->regs = devm_ioremap_resource(&pdev->dev, res);
749 if (IS_ERR(host->regs)) {
750 ret = PTR_ERR(host->regs);
751 goto free_host;
752 }
753
754 host->irq = platform_get_irq(pdev, 0);
755 if (host->irq == 0) {
756 dev_err(&pdev->dev, "failed to get interrupt resource.\n");
757 ret = -EINVAL;
758 goto free_host;
759 }
760
761 host->core_clk = devm_clk_get(&pdev->dev, "core");
762 if (IS_ERR(host->core_clk)) {
763 ret = PTR_ERR(host->core_clk);
764 goto free_host;
765 }
766
767 ret = clk_prepare_enable(host->core_clk);
768 if (ret)
769 goto free_host;
770
771 ret = meson_mmc_clk_init(host);
772 if (ret)
773 goto free_host;
774
775 /* Stop execution */
776 writel(0, host->regs + SD_EMMC_START);
777
778 /* clear, ack, enable all interrupts */
779 writel(0, host->regs + SD_EMMC_IRQ_EN);
780 writel(IRQ_EN_MASK, host->regs + SD_EMMC_STATUS);
781
782 ret = devm_request_threaded_irq(&pdev->dev, host->irq,
783 meson_mmc_irq, meson_mmc_irq_thread,
784 IRQF_SHARED, DRIVER_NAME, host);
785 if (ret)
786 goto free_host;
787
788 /* data bounce buffer */
789 host->bounce_buf_size = SZ_512K;
790 host->bounce_buf =
791 dma_alloc_coherent(host->dev, host->bounce_buf_size,
792 &host->bounce_dma_addr, GFP_KERNEL);
793 if (host->bounce_buf == NULL) {
794 dev_err(host->dev, "Unable to map allocate DMA bounce buffer.\n");
795 ret = -ENOMEM;
796 goto free_host;
797 }
798
799 mmc->ops = &meson_mmc_ops;
800 mmc_add_host(mmc);
801
802 return 0;
803
804free_host:
805 clk_disable_unprepare(host->cfg_div_clk);
806 clk_disable_unprepare(host->core_clk);
807 mmc_free_host(mmc);
808 return ret;
809}
810
811static int meson_mmc_remove(struct platform_device *pdev)
812{
813 struct meson_host *host = dev_get_drvdata(&pdev->dev);
814
815 if (WARN_ON(!host))
816 return 0;
817
818 if (host->bounce_buf)
819 dma_free_coherent(host->dev, host->bounce_buf_size,
820 host->bounce_buf, host->bounce_dma_addr);
821
822 clk_disable_unprepare(host->cfg_div_clk);
823 clk_disable_unprepare(host->core_clk);
824
825 mmc_free_host(host->mmc);
826 return 0;
827}
828
829static const struct of_device_id meson_mmc_of_match[] = {
830 { .compatible = "amlogic,meson-gx-mmc", },
831 { .compatible = "amlogic,meson-gxbb-mmc", },
832 { .compatible = "amlogic,meson-gxl-mmc", },
833 { .compatible = "amlogic,meson-gxm-mmc", },
834 {}
835};
836MODULE_DEVICE_TABLE(of, meson_mmc_of_match);
837
838static struct platform_driver meson_mmc_driver = {
839 .probe = meson_mmc_probe,
840 .remove = meson_mmc_remove,
841 .driver = {
842 .name = DRIVER_NAME,
843 .of_match_table = of_match_ptr(meson_mmc_of_match),
844 },
845};
846
847module_platform_driver(meson_mmc_driver);
848
849MODULE_DESCRIPTION("Amlogic S905*/GX* SD/eMMC driver");
850MODULE_AUTHOR("Kevin Hilman <khilman@baylibre.com>");
851MODULE_LICENSE("GPL v2");
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index df990bb8c873..01a804792f30 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -71,7 +71,12 @@ static unsigned int fmax = 515633;
71 * @f_max: maximum clk frequency supported by the controller. 71 * @f_max: maximum clk frequency supported by the controller.
72 * @signal_direction: input/out direction of bus signals can be indicated 72 * @signal_direction: input/out direction of bus signals can be indicated
73 * @pwrreg_clkgate: MMCIPOWER register must be used to gate the clock 73 * @pwrreg_clkgate: MMCIPOWER register must be used to gate the clock
74 * @busy_detect: true if busy detection on dat0 is supported 74 * @busy_detect: true if the variant supports busy detection on DAT0.
75 * @busy_dpsm_flag: bitmask enabling busy detection in the DPSM
76 * @busy_detect_flag: bitmask identifying the bit in the MMCISTATUS register
77 * indicating that the card is busy
78 * @busy_detect_mask: bitmask identifying the bit in the MMCIMASK0 to mask for
79 * getting busy end detection interrupts
75 * @pwrreg_nopower: bits in MMCIPOWER don't controls ext. power supply 80 * @pwrreg_nopower: bits in MMCIPOWER don't controls ext. power supply
76 * @explicit_mclk_control: enable explicit mclk control in driver. 81 * @explicit_mclk_control: enable explicit mclk control in driver.
77 * @qcom_fifo: enables qcom specific fifo pio read logic. 82 * @qcom_fifo: enables qcom specific fifo pio read logic.
@@ -98,6 +103,9 @@ struct variant_data {
98 bool signal_direction; 103 bool signal_direction;
99 bool pwrreg_clkgate; 104 bool pwrreg_clkgate;
100 bool busy_detect; 105 bool busy_detect;
106 u32 busy_dpsm_flag;
107 u32 busy_detect_flag;
108 u32 busy_detect_mask;
101 bool pwrreg_nopower; 109 bool pwrreg_nopower;
102 bool explicit_mclk_control; 110 bool explicit_mclk_control;
103 bool qcom_fifo; 111 bool qcom_fifo;
@@ -137,7 +145,7 @@ static struct variant_data variant_u300 = {
137 .clkreg_enable = MCI_ST_U300_HWFCEN, 145 .clkreg_enable = MCI_ST_U300_HWFCEN,
138 .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS, 146 .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
139 .datalength_bits = 16, 147 .datalength_bits = 16,
140 .datactrl_mask_sdio = MCI_ST_DPSM_SDIOEN, 148 .datactrl_mask_sdio = MCI_DPSM_ST_SDIOEN,
141 .st_sdio = true, 149 .st_sdio = true,
142 .pwrreg_powerup = MCI_PWR_ON, 150 .pwrreg_powerup = MCI_PWR_ON,
143 .f_max = 100000000, 151 .f_max = 100000000,
@@ -152,7 +160,7 @@ static struct variant_data variant_nomadik = {
152 .clkreg = MCI_CLK_ENABLE, 160 .clkreg = MCI_CLK_ENABLE,
153 .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS, 161 .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
154 .datalength_bits = 24, 162 .datalength_bits = 24,
155 .datactrl_mask_sdio = MCI_ST_DPSM_SDIOEN, 163 .datactrl_mask_sdio = MCI_DPSM_ST_SDIOEN,
156 .st_sdio = true, 164 .st_sdio = true,
157 .st_clkdiv = true, 165 .st_clkdiv = true,
158 .pwrreg_powerup = MCI_PWR_ON, 166 .pwrreg_powerup = MCI_PWR_ON,
@@ -170,7 +178,7 @@ static struct variant_data variant_ux500 = {
170 .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS, 178 .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
171 .clkreg_neg_edge_enable = MCI_ST_UX500_NEG_EDGE, 179 .clkreg_neg_edge_enable = MCI_ST_UX500_NEG_EDGE,
172 .datalength_bits = 24, 180 .datalength_bits = 24,
173 .datactrl_mask_sdio = MCI_ST_DPSM_SDIOEN, 181 .datactrl_mask_sdio = MCI_DPSM_ST_SDIOEN,
174 .st_sdio = true, 182 .st_sdio = true,
175 .st_clkdiv = true, 183 .st_clkdiv = true,
176 .pwrreg_powerup = MCI_PWR_ON, 184 .pwrreg_powerup = MCI_PWR_ON,
@@ -178,6 +186,9 @@ static struct variant_data variant_ux500 = {
178 .signal_direction = true, 186 .signal_direction = true,
179 .pwrreg_clkgate = true, 187 .pwrreg_clkgate = true,
180 .busy_detect = true, 188 .busy_detect = true,
189 .busy_dpsm_flag = MCI_DPSM_ST_BUSYMODE,
190 .busy_detect_flag = MCI_ST_CARDBUSY,
191 .busy_detect_mask = MCI_ST_BUSYENDMASK,
181 .pwrreg_nopower = true, 192 .pwrreg_nopower = true,
182}; 193};
183 194
@@ -188,9 +199,9 @@ static struct variant_data variant_ux500v2 = {
188 .clkreg_enable = MCI_ST_UX500_HWFCEN, 199 .clkreg_enable = MCI_ST_UX500_HWFCEN,
189 .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS, 200 .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
190 .clkreg_neg_edge_enable = MCI_ST_UX500_NEG_EDGE, 201 .clkreg_neg_edge_enable = MCI_ST_UX500_NEG_EDGE,
191 .datactrl_mask_ddrmode = MCI_ST_DPSM_DDRMODE, 202 .datactrl_mask_ddrmode = MCI_DPSM_ST_DDRMODE,
192 .datalength_bits = 24, 203 .datalength_bits = 24,
193 .datactrl_mask_sdio = MCI_ST_DPSM_SDIOEN, 204 .datactrl_mask_sdio = MCI_DPSM_ST_SDIOEN,
194 .st_sdio = true, 205 .st_sdio = true,
195 .st_clkdiv = true, 206 .st_clkdiv = true,
196 .blksz_datactrl16 = true, 207 .blksz_datactrl16 = true,
@@ -199,6 +210,9 @@ static struct variant_data variant_ux500v2 = {
199 .signal_direction = true, 210 .signal_direction = true,
200 .pwrreg_clkgate = true, 211 .pwrreg_clkgate = true,
201 .busy_detect = true, 212 .busy_detect = true,
213 .busy_dpsm_flag = MCI_DPSM_ST_BUSYMODE,
214 .busy_detect_flag = MCI_ST_CARDBUSY,
215 .busy_detect_mask = MCI_ST_BUSYENDMASK,
202 .pwrreg_nopower = true, 216 .pwrreg_nopower = true,
203}; 217};
204 218
@@ -210,7 +224,7 @@ static struct variant_data variant_qcom = {
210 MCI_QCOM_CLK_SELECT_IN_FBCLK, 224 MCI_QCOM_CLK_SELECT_IN_FBCLK,
211 .clkreg_8bit_bus_enable = MCI_QCOM_CLK_WIDEBUS_8, 225 .clkreg_8bit_bus_enable = MCI_QCOM_CLK_WIDEBUS_8,
212 .datactrl_mask_ddrmode = MCI_QCOM_CLK_SELECT_IN_DDR_MODE, 226 .datactrl_mask_ddrmode = MCI_QCOM_CLK_SELECT_IN_DDR_MODE,
213 .data_cmd_enable = MCI_QCOM_CSPM_DATCMD, 227 .data_cmd_enable = MCI_CPSM_QCOM_DATCMD,
214 .blksz_datactrl4 = true, 228 .blksz_datactrl4 = true,
215 .datalength_bits = 24, 229 .datalength_bits = 24,
216 .pwrreg_powerup = MCI_PWR_UP, 230 .pwrreg_powerup = MCI_PWR_UP,
@@ -220,6 +234,7 @@ static struct variant_data variant_qcom = {
220 .qcom_dml = true, 234 .qcom_dml = true,
221}; 235};
222 236
237/* Busy detection for the ST Micro variant */
223static int mmci_card_busy(struct mmc_host *mmc) 238static int mmci_card_busy(struct mmc_host *mmc)
224{ 239{
225 struct mmci_host *host = mmc_priv(mmc); 240 struct mmci_host *host = mmc_priv(mmc);
@@ -227,7 +242,7 @@ static int mmci_card_busy(struct mmc_host *mmc)
227 int busy = 0; 242 int busy = 0;
228 243
229 spin_lock_irqsave(&host->lock, flags); 244 spin_lock_irqsave(&host->lock, flags);
230 if (readl(host->base + MMCISTATUS) & MCI_ST_CARDBUSY) 245 if (readl(host->base + MMCISTATUS) & host->variant->busy_detect_flag)
231 busy = 1; 246 busy = 1;
232 spin_unlock_irqrestore(&host->lock, flags); 247 spin_unlock_irqrestore(&host->lock, flags);
233 248
@@ -294,8 +309,8 @@ static void mmci_write_pwrreg(struct mmci_host *host, u32 pwr)
294 */ 309 */
295static void mmci_write_datactrlreg(struct mmci_host *host, u32 datactrl) 310static void mmci_write_datactrlreg(struct mmci_host *host, u32 datactrl)
296{ 311{
297 /* Keep ST Micro busy mode if enabled */ 312 /* Keep busy mode in DPSM if enabled */
298 datactrl |= host->datactrl_reg & MCI_ST_DPSM_BUSYMODE; 313 datactrl |= host->datactrl_reg & host->variant->busy_dpsm_flag;
299 314
300 if (host->datactrl_reg != datactrl) { 315 if (host->datactrl_reg != datactrl) {
301 host->datactrl_reg = datactrl; 316 host->datactrl_reg = datactrl;
@@ -684,8 +699,7 @@ static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data)
684 next->dma_chan = NULL; 699 next->dma_chan = NULL;
685} 700}
686 701
687static void mmci_pre_request(struct mmc_host *mmc, struct mmc_request *mrq, 702static void mmci_pre_request(struct mmc_host *mmc, struct mmc_request *mrq)
688 bool is_first_req)
689{ 703{
690 struct mmci_host *host = mmc_priv(mmc); 704 struct mmci_host *host = mmc_priv(mmc);
691 struct mmc_data *data = mrq->data; 705 struct mmc_data *data = mrq->data;
@@ -973,37 +987,66 @@ mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd,
973 unsigned int status) 987 unsigned int status)
974{ 988{
975 void __iomem *base = host->base; 989 void __iomem *base = host->base;
976 bool sbc, busy_resp; 990 bool sbc;
977 991
978 if (!cmd) 992 if (!cmd)
979 return; 993 return;
980 994
981 sbc = (cmd == host->mrq->sbc); 995 sbc = (cmd == host->mrq->sbc);
982 busy_resp = host->variant->busy_detect && (cmd->flags & MMC_RSP_BUSY);
983 996
984 if (!((status|host->busy_status) & (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT| 997 /*
985 MCI_CMDSENT|MCI_CMDRESPEND))) 998 * We need to be one of these interrupts to be considered worth
999 * handling. Note that we tag on any latent IRQs postponed
1000 * due to waiting for busy status.
1001 */
1002 if (!((status|host->busy_status) &
1003 (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT|MCI_CMDSENT|MCI_CMDRESPEND)))
986 return; 1004 return;
987 1005
988 /* Check if we need to wait for busy completion. */ 1006 /*
989 if (host->busy_status && (status & MCI_ST_CARDBUSY)) 1007 * ST Micro variant: handle busy detection.
990 return; 1008 */
1009 if (host->variant->busy_detect) {
1010 bool busy_resp = !!(cmd->flags & MMC_RSP_BUSY);
991 1011
992 /* Enable busy completion if needed and supported. */ 1012 /* We are busy with a command, return */
993 if (!host->busy_status && busy_resp && 1013 if (host->busy_status &&
994 !(status & (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT)) && 1014 (status & host->variant->busy_detect_flag))
995 (readl(base + MMCISTATUS) & MCI_ST_CARDBUSY)) { 1015 return;
996 writel(readl(base + MMCIMASK0) | MCI_ST_BUSYEND, 1016
997 base + MMCIMASK0); 1017 /*
998 host->busy_status = status & (MCI_CMDSENT|MCI_CMDRESPEND); 1018 * We were not busy, but we now got a busy response on
999 return; 1019 * something that was not an error, and we double-check
1000 } 1020 * that the special busy status bit is still set before
1021 * proceeding.
1022 */
1023 if (!host->busy_status && busy_resp &&
1024 !(status & (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT)) &&
1025 (readl(base + MMCISTATUS) & host->variant->busy_detect_flag)) {
1026 /* Unmask the busy IRQ */
1027 writel(readl(base + MMCIMASK0) |
1028 host->variant->busy_detect_mask,
1029 base + MMCIMASK0);
1030 /*
1031 * Now cache the last response status code (until
1032 * the busy bit goes low), and return.
1033 */
1034 host->busy_status =
1035 status & (MCI_CMDSENT|MCI_CMDRESPEND);
1036 return;
1037 }
1001 1038
1002 /* At busy completion, mask the IRQ and complete the request. */ 1039 /*
1003 if (host->busy_status) { 1040 * At this point we are not busy with a command, we have
1004 writel(readl(base + MMCIMASK0) & ~MCI_ST_BUSYEND, 1041 * not received a new busy request, mask the busy IRQ and
1005 base + MMCIMASK0); 1042 * fall through to process the IRQ.
1006 host->busy_status = 0; 1043 */
1044 if (host->busy_status) {
1045 writel(readl(base + MMCIMASK0) &
1046 ~host->variant->busy_detect_mask,
1047 base + MMCIMASK0);
1048 host->busy_status = 0;
1049 }
1007 } 1050 }
1008 1051
1009 host->cmd = NULL; 1052 host->cmd = NULL;
@@ -1257,9 +1300,11 @@ static irqreturn_t mmci_irq(int irq, void *dev_id)
1257 mmci_data_irq(host, host->data, status); 1300 mmci_data_irq(host, host->data, status);
1258 } 1301 }
1259 1302
1260 /* Don't poll for busy completion in irq context. */ 1303 /*
1261 if (host->busy_status) 1304 * Don't poll for busy completion in irq context.
1262 status &= ~MCI_ST_CARDBUSY; 1305 */
1306 if (host->variant->busy_detect && host->busy_status)
1307 status &= ~host->variant->busy_detect_flag;
1263 1308
1264 ret = 1; 1309 ret = 1;
1265 } while (status); 1310 } while (status);
@@ -1612,9 +1657,18 @@ static int mmci_probe(struct amba_device *dev,
1612 /* We support these capabilities. */ 1657 /* We support these capabilities. */
1613 mmc->caps |= MMC_CAP_CMD23; 1658 mmc->caps |= MMC_CAP_CMD23;
1614 1659
1660 /*
1661 * Enable busy detection.
1662 */
1615 if (variant->busy_detect) { 1663 if (variant->busy_detect) {
1616 mmci_ops.card_busy = mmci_card_busy; 1664 mmci_ops.card_busy = mmci_card_busy;
1617 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE); 1665 /*
1666 * Not all variants have a flag to enable busy detection
1667 * in the DPSM, but if they do, set it here.
1668 */
1669 if (variant->busy_dpsm_flag)
1670 mmci_write_datactrlreg(host,
1671 host->variant->busy_dpsm_flag);
1618 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY; 1672 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
1619 mmc->max_busy_timeout = 0; 1673 mmc->max_busy_timeout = 0;
1620 } 1674 }
diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h
index a1f5e4f49e2a..56322c6afba4 100644
--- a/drivers/mmc/host/mmci.h
+++ b/drivers/mmc/host/mmci.h
@@ -51,25 +51,27 @@
51#define MCI_QCOM_CLK_SELECT_IN_DDR_MODE (BIT(14) | BIT(15)) 51#define MCI_QCOM_CLK_SELECT_IN_DDR_MODE (BIT(14) | BIT(15))
52 52
53#define MMCIARGUMENT 0x008 53#define MMCIARGUMENT 0x008
54#define MMCICOMMAND 0x00c
55#define MCI_CPSM_RESPONSE (1 << 6)
56#define MCI_CPSM_LONGRSP (1 << 7)
57#define MCI_CPSM_INTERRUPT (1 << 8)
58#define MCI_CPSM_PENDING (1 << 9)
59#define MCI_CPSM_ENABLE (1 << 10)
60/* Argument flag extenstions in the ST Micro versions */
61#define MCI_ST_SDIO_SUSP (1 << 11)
62#define MCI_ST_ENCMD_COMPL (1 << 12)
63#define MCI_ST_NIEN (1 << 13)
64#define MCI_ST_CE_ATACMD (1 << 14)
65 54
66/* Modified on Qualcomm Integrations */ 55/* The command register controls the Command Path State Machine (CPSM) */
67#define MCI_QCOM_CSPM_DATCMD BIT(12) 56#define MMCICOMMAND 0x00c
68#define MCI_QCOM_CSPM_MCIABORT BIT(13) 57#define MCI_CPSM_RESPONSE BIT(6)
69#define MCI_QCOM_CSPM_CCSENABLE BIT(14) 58#define MCI_CPSM_LONGRSP BIT(7)
70#define MCI_QCOM_CSPM_CCSDISABLE BIT(15) 59#define MCI_CPSM_INTERRUPT BIT(8)
71#define MCI_QCOM_CSPM_AUTO_CMD19 BIT(16) 60#define MCI_CPSM_PENDING BIT(9)
72#define MCI_QCOM_CSPM_AUTO_CMD21 BIT(21) 61#define MCI_CPSM_ENABLE BIT(10)
62/* Command register flag extenstions in the ST Micro versions */
63#define MCI_CPSM_ST_SDIO_SUSP BIT(11)
64#define MCI_CPSM_ST_ENCMD_COMPL BIT(12)
65#define MCI_CPSM_ST_NIEN BIT(13)
66#define MCI_CPSM_ST_CE_ATACMD BIT(14)
67/* Command register flag extensions in the Qualcomm versions */
68#define MCI_CPSM_QCOM_PROGENA BIT(11)
69#define MCI_CPSM_QCOM_DATCMD BIT(12)
70#define MCI_CPSM_QCOM_MCIABORT BIT(13)
71#define MCI_CPSM_QCOM_CCSENABLE BIT(14)
72#define MCI_CPSM_QCOM_CCSDISABLE BIT(15)
73#define MCI_CPSM_QCOM_AUTO_CMD19 BIT(16)
74#define MCI_CPSM_QCOM_AUTO_CMD21 BIT(21)
73 75
74#define MMCIRESPCMD 0x010 76#define MMCIRESPCMD 0x010
75#define MMCIRESPONSE0 0x014 77#define MMCIRESPONSE0 0x014
@@ -78,22 +80,27 @@
78#define MMCIRESPONSE3 0x020 80#define MMCIRESPONSE3 0x020
79#define MMCIDATATIMER 0x024 81#define MMCIDATATIMER 0x024
80#define MMCIDATALENGTH 0x028 82#define MMCIDATALENGTH 0x028
83
84/* The data control register controls the Data Path State Machine (DPSM) */
81#define MMCIDATACTRL 0x02c 85#define MMCIDATACTRL 0x02c
82#define MCI_DPSM_ENABLE (1 << 0) 86#define MCI_DPSM_ENABLE BIT(0)
83#define MCI_DPSM_DIRECTION (1 << 1) 87#define MCI_DPSM_DIRECTION BIT(1)
84#define MCI_DPSM_MODE (1 << 2) 88#define MCI_DPSM_MODE BIT(2)
85#define MCI_DPSM_DMAENABLE (1 << 3) 89#define MCI_DPSM_DMAENABLE BIT(3)
86#define MCI_DPSM_BLOCKSIZE (1 << 4) 90#define MCI_DPSM_BLOCKSIZE BIT(4)
87/* Control register extensions in the ST Micro U300 and Ux500 versions */ 91/* Control register extensions in the ST Micro U300 and Ux500 versions */
88#define MCI_ST_DPSM_RWSTART (1 << 8) 92#define MCI_DPSM_ST_RWSTART BIT(8)
89#define MCI_ST_DPSM_RWSTOP (1 << 9) 93#define MCI_DPSM_ST_RWSTOP BIT(9)
90#define MCI_ST_DPSM_RWMOD (1 << 10) 94#define MCI_DPSM_ST_RWMOD BIT(10)
91#define MCI_ST_DPSM_SDIOEN (1 << 11) 95#define MCI_DPSM_ST_SDIOEN BIT(11)
92/* Control register extensions in the ST Micro Ux500 versions */ 96/* Control register extensions in the ST Micro Ux500 versions */
93#define MCI_ST_DPSM_DMAREQCTL (1 << 12) 97#define MCI_DPSM_ST_DMAREQCTL BIT(12)
94#define MCI_ST_DPSM_DBOOTMODEEN (1 << 13) 98#define MCI_DPSM_ST_DBOOTMODEEN BIT(13)
95#define MCI_ST_DPSM_BUSYMODE (1 << 14) 99#define MCI_DPSM_ST_BUSYMODE BIT(14)
96#define MCI_ST_DPSM_DDRMODE (1 << 15) 100#define MCI_DPSM_ST_DDRMODE BIT(15)
101/* Control register extensions in the Qualcomm versions */
102#define MCI_DPSM_QCOM_DATA_PEND BIT(17)
103#define MCI_DPSM_QCOM_RX_DATA_PEND BIT(20)
97 104
98#define MMCIDATACNT 0x030 105#define MMCIDATACNT 0x030
99#define MMCISTATUS 0x034 106#define MMCISTATUS 0x034
@@ -167,7 +174,7 @@
167/* Extended status bits for the ST Micro variants */ 174/* Extended status bits for the ST Micro variants */
168#define MCI_ST_SDIOITMASK (1 << 22) 175#define MCI_ST_SDIOITMASK (1 << 22)
169#define MCI_ST_CEATAENDMASK (1 << 23) 176#define MCI_ST_CEATAENDMASK (1 << 23)
170#define MCI_ST_BUSYEND (1 << 24) 177#define MCI_ST_BUSYENDMASK (1 << 24)
171 178
172#define MMCIMASK1 0x040 179#define MMCIMASK1 0x040
173#define MMCIFIFOCNT 0x048 180#define MMCIFIFOCNT 0x048
diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
index 84e9afcb5c09..10ef2ae1d2f6 100644
--- a/drivers/mmc/host/mtk-sd.c
+++ b/drivers/mmc/host/mtk-sd.c
@@ -927,8 +927,7 @@ static void msdc_ops_request(struct mmc_host *mmc, struct mmc_request *mrq)
927 msdc_start_command(host, mrq, mrq->cmd); 927 msdc_start_command(host, mrq, mrq->cmd);
928} 928}
929 929
930static void msdc_pre_req(struct mmc_host *mmc, struct mmc_request *mrq, 930static void msdc_pre_req(struct mmc_host *mmc, struct mmc_request *mrq)
931 bool is_first_req)
932{ 931{
933 struct msdc_host *host = mmc_priv(mmc); 932 struct msdc_host *host = mmc_priv(mmc);
934 struct mmc_data *data = mrq->data; 933 struct mmc_data *data = mrq->data;
@@ -1713,6 +1712,7 @@ static const struct of_device_id msdc_of_ids[] = {
1713 { .compatible = "mediatek,mt8135-mmc", }, 1712 { .compatible = "mediatek,mt8135-mmc", },
1714 {} 1713 {}
1715}; 1714};
1715MODULE_DEVICE_TABLE(of, msdc_of_ids);
1716 1716
1717static struct platform_driver mt_msdc_driver = { 1717static struct platform_driver mt_msdc_driver = {
1718 .probe = msdc_drv_probe, 1718 .probe = msdc_drv_probe,
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 5f2f24a7360d..ad11c4cc12ed 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -1565,8 +1565,7 @@ static void omap_hsmmc_post_req(struct mmc_host *mmc, struct mmc_request *mrq,
1565 } 1565 }
1566} 1566}
1567 1567
1568static void omap_hsmmc_pre_req(struct mmc_host *mmc, struct mmc_request *mrq, 1568static void omap_hsmmc_pre_req(struct mmc_host *mmc, struct mmc_request *mrq)
1569 bool is_first_req)
1570{ 1569{
1571 struct omap_hsmmc_host *host = mmc_priv(mmc); 1570 struct omap_hsmmc_host *host = mmc_priv(mmc);
1572 1571
diff --git a/drivers/mmc/host/rtsx_pci_sdmmc.c b/drivers/mmc/host/rtsx_pci_sdmmc.c
index 3ccaa1415f33..ecb99a8d2fa2 100644
--- a/drivers/mmc/host/rtsx_pci_sdmmc.c
+++ b/drivers/mmc/host/rtsx_pci_sdmmc.c
@@ -190,8 +190,7 @@ static int sd_pre_dma_transfer(struct realtek_pci_sdmmc *host,
190 return using_cookie; 190 return using_cookie;
191} 191}
192 192
193static void sdmmc_pre_req(struct mmc_host *mmc, struct mmc_request *mrq, 193static void sdmmc_pre_req(struct mmc_host *mmc, struct mmc_request *mrq)
194 bool is_first_req)
195{ 194{
196 struct realtek_pci_sdmmc *host = mmc_priv(mmc); 195 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
197 struct mmc_data *data = mrq->data; 196 struct mmc_data *data = mrq->data;
diff --git a/drivers/mmc/host/rtsx_usb_sdmmc.c b/drivers/mmc/host/rtsx_usb_sdmmc.c
index 6e9c0f8fddb1..dc1abd14acbc 100644
--- a/drivers/mmc/host/rtsx_usb_sdmmc.c
+++ b/drivers/mmc/host/rtsx_usb_sdmmc.c
@@ -1374,6 +1374,8 @@ static int rtsx_usb_sdmmc_drv_probe(struct platform_device *pdev)
1374 1374
1375 mutex_init(&host->host_mutex); 1375 mutex_init(&host->host_mutex);
1376 rtsx_usb_init_host(host); 1376 rtsx_usb_init_host(host);
1377 pm_runtime_use_autosuspend(&pdev->dev);
1378 pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
1377 pm_runtime_enable(&pdev->dev); 1379 pm_runtime_enable(&pdev->dev);
1378 1380
1379#ifdef RTSX_USB_USE_LEDS_CLASS 1381#ifdef RTSX_USB_USE_LEDS_CLASS
@@ -1428,6 +1430,7 @@ static int rtsx_usb_sdmmc_drv_remove(struct platform_device *pdev)
1428 1430
1429 mmc_free_host(mmc); 1431 mmc_free_host(mmc);
1430 pm_runtime_disable(&pdev->dev); 1432 pm_runtime_disable(&pdev->dev);
1433 pm_runtime_dont_use_autosuspend(&pdev->dev);
1431 platform_set_drvdata(pdev, NULL); 1434 platform_set_drvdata(pdev, NULL);
1432 1435
1433 dev_dbg(&(pdev->dev), 1436 dev_dbg(&(pdev->dev),
diff --git a/drivers/mmc/host/s3cmci.c b/drivers/mmc/host/s3cmci.c
index c531deef3258..932a4b1fed33 100644
--- a/drivers/mmc/host/s3cmci.c
+++ b/drivers/mmc/host/s3cmci.c
@@ -28,7 +28,6 @@
28#include <mach/dma.h> 28#include <mach/dma.h>
29#include <mach/gpio-samsung.h> 29#include <mach/gpio-samsung.h>
30 30
31#include <linux/platform_data/dma-s3c24xx.h>
32#include <linux/platform_data/mmc-s3cmci.h> 31#include <linux/platform_data/mmc-s3cmci.h>
33 32
34#include "s3cmci.h" 33#include "s3cmci.h"
@@ -1682,19 +1681,13 @@ static int s3cmci_probe(struct platform_device *pdev)
1682 gpio_direction_input(host->pdata->gpio_wprotect); 1681 gpio_direction_input(host->pdata->gpio_wprotect);
1683 } 1682 }
1684 1683
1685 /* depending on the dma state, get a dma channel to use. */ 1684 /* Depending on the dma state, get a DMA channel to use. */
1686 1685
1687 if (s3cmci_host_usedma(host)) { 1686 if (s3cmci_host_usedma(host)) {
1688 dma_cap_mask_t mask; 1687 host->dma = dma_request_chan(&pdev->dev, "rx-tx");
1689 1688 ret = PTR_ERR_OR_ZERO(host->dma);
1690 dma_cap_zero(mask); 1689 if (ret) {
1691 dma_cap_set(DMA_SLAVE, mask);
1692
1693 host->dma = dma_request_slave_channel_compat(mask,
1694 s3c24xx_dma_filter, (void *)DMACH_SDI, &pdev->dev, "rx-tx");
1695 if (!host->dma) {
1696 dev_err(&pdev->dev, "cannot get DMA channel.\n"); 1690 dev_err(&pdev->dev, "cannot get DMA channel.\n");
1697 ret = -EBUSY;
1698 goto probe_free_gpio_wp; 1691 goto probe_free_gpio_wp;
1699 } 1692 }
1700 } 1693 }
diff --git a/drivers/mmc/host/sdhci-acpi.c b/drivers/mmc/host/sdhci-acpi.c
index 81d4dc034793..160f695cc09c 100644
--- a/drivers/mmc/host/sdhci-acpi.c
+++ b/drivers/mmc/host/sdhci-acpi.c
@@ -328,6 +328,7 @@ static const struct sdhci_acpi_uid_slot sdhci_acpi_uids[] = {
328 { "80865ACC", NULL, &sdhci_acpi_slot_int_emmc }, 328 { "80865ACC", NULL, &sdhci_acpi_slot_int_emmc },
329 { "80865AD0", NULL, &sdhci_acpi_slot_int_sdio }, 329 { "80865AD0", NULL, &sdhci_acpi_slot_int_sdio },
330 { "80860F14" , "1" , &sdhci_acpi_slot_int_emmc }, 330 { "80860F14" , "1" , &sdhci_acpi_slot_int_emmc },
331 { "80860F14" , "2" , &sdhci_acpi_slot_int_sdio },
331 { "80860F14" , "3" , &sdhci_acpi_slot_int_sd }, 332 { "80860F14" , "3" , &sdhci_acpi_slot_int_sd },
332 { "80860F16" , NULL, &sdhci_acpi_slot_int_sd }, 333 { "80860F16" , NULL, &sdhci_acpi_slot_int_sd },
333 { "INT33BB" , "2" , &sdhci_acpi_slot_int_sdio }, 334 { "INT33BB" , "2" , &sdhci_acpi_slot_int_sdio },
diff --git a/drivers/mmc/host/sdhci-cadence.c b/drivers/mmc/host/sdhci-cadence.c
new file mode 100644
index 000000000000..1501cfdac473
--- /dev/null
+++ b/drivers/mmc/host/sdhci-cadence.c
@@ -0,0 +1,283 @@
1/*
2 * Copyright (C) 2016 Socionext Inc.
3 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <linux/bitops.h>
17#include <linux/iopoll.h>
18#include <linux/module.h>
19#include <linux/mmc/host.h>
20
21#include "sdhci-pltfm.h"
22
23/* HRS - Host Register Set (specific to Cadence) */
24#define SDHCI_CDNS_HRS04 0x10 /* PHY access port */
25#define SDHCI_CDNS_HRS04_ACK BIT(26)
26#define SDHCI_CDNS_HRS04_RD BIT(25)
27#define SDHCI_CDNS_HRS04_WR BIT(24)
28#define SDHCI_CDNS_HRS04_RDATA_SHIFT 12
29#define SDHCI_CDNS_HRS04_WDATA_SHIFT 8
30#define SDHCI_CDNS_HRS04_ADDR_SHIFT 0
31
32#define SDHCI_CDNS_HRS06 0x18 /* eMMC control */
33#define SDHCI_CDNS_HRS06_TUNE_UP BIT(15)
34#define SDHCI_CDNS_HRS06_TUNE_SHIFT 8
35#define SDHCI_CDNS_HRS06_TUNE_MASK 0x3f
36#define SDHCI_CDNS_HRS06_MODE_MASK 0x7
37#define SDHCI_CDNS_HRS06_MODE_SD 0x0
38#define SDHCI_CDNS_HRS06_MODE_MMC_SDR 0x2
39#define SDHCI_CDNS_HRS06_MODE_MMC_DDR 0x3
40#define SDHCI_CDNS_HRS06_MODE_MMC_HS200 0x4
41#define SDHCI_CDNS_HRS06_MODE_MMC_HS400 0x5
42
43/* SRS - Slot Register Set (SDHCI-compatible) */
44#define SDHCI_CDNS_SRS_BASE 0x200
45
46/* PHY */
47#define SDHCI_CDNS_PHY_DLY_SD_HS 0x00
48#define SDHCI_CDNS_PHY_DLY_SD_DEFAULT 0x01
49#define SDHCI_CDNS_PHY_DLY_UHS_SDR12 0x02
50#define SDHCI_CDNS_PHY_DLY_UHS_SDR25 0x03
51#define SDHCI_CDNS_PHY_DLY_UHS_SDR50 0x04
52#define SDHCI_CDNS_PHY_DLY_UHS_DDR50 0x05
53#define SDHCI_CDNS_PHY_DLY_EMMC_LEGACY 0x06
54#define SDHCI_CDNS_PHY_DLY_EMMC_SDR 0x07
55#define SDHCI_CDNS_PHY_DLY_EMMC_DDR 0x08
56
57/*
58 * The tuned val register is 6 bit-wide, but not the whole of the range is
59 * available. The range 0-42 seems to be available (then 43 wraps around to 0)
60 * but I am not quite sure if it is official. Use only 0 to 39 for safety.
61 */
62#define SDHCI_CDNS_MAX_TUNING_LOOP 40
63
64struct sdhci_cdns_priv {
65 void __iomem *hrs_addr;
66};
67
68static void sdhci_cdns_write_phy_reg(struct sdhci_cdns_priv *priv,
69 u8 addr, u8 data)
70{
71 void __iomem *reg = priv->hrs_addr + SDHCI_CDNS_HRS04;
72 u32 tmp;
73
74 tmp = (data << SDHCI_CDNS_HRS04_WDATA_SHIFT) |
75 (addr << SDHCI_CDNS_HRS04_ADDR_SHIFT);
76 writel(tmp, reg);
77
78 tmp |= SDHCI_CDNS_HRS04_WR;
79 writel(tmp, reg);
80
81 tmp &= ~SDHCI_CDNS_HRS04_WR;
82 writel(tmp, reg);
83}
84
85static void sdhci_cdns_phy_init(struct sdhci_cdns_priv *priv)
86{
87 sdhci_cdns_write_phy_reg(priv, SDHCI_CDNS_PHY_DLY_SD_HS, 4);
88 sdhci_cdns_write_phy_reg(priv, SDHCI_CDNS_PHY_DLY_SD_DEFAULT, 4);
89 sdhci_cdns_write_phy_reg(priv, SDHCI_CDNS_PHY_DLY_EMMC_LEGACY, 9);
90 sdhci_cdns_write_phy_reg(priv, SDHCI_CDNS_PHY_DLY_EMMC_SDR, 2);
91 sdhci_cdns_write_phy_reg(priv, SDHCI_CDNS_PHY_DLY_EMMC_DDR, 3);
92}
93
94static inline void *sdhci_cdns_priv(struct sdhci_host *host)
95{
96 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
97
98 return sdhci_pltfm_priv(pltfm_host);
99}
100
101static unsigned int sdhci_cdns_get_timeout_clock(struct sdhci_host *host)
102{
103 /*
104 * Cadence's spec says the Timeout Clock Frequency is the same as the
105 * Base Clock Frequency. Divide it by 1000 to return a value in kHz.
106 */
107 return host->max_clk / 1000;
108}
109
110static void sdhci_cdns_set_uhs_signaling(struct sdhci_host *host,
111 unsigned int timing)
112{
113 struct sdhci_cdns_priv *priv = sdhci_cdns_priv(host);
114 u32 mode, tmp;
115
116 switch (timing) {
117 case MMC_TIMING_MMC_HS:
118 mode = SDHCI_CDNS_HRS06_MODE_MMC_SDR;
119 break;
120 case MMC_TIMING_MMC_DDR52:
121 mode = SDHCI_CDNS_HRS06_MODE_MMC_DDR;
122 break;
123 case MMC_TIMING_MMC_HS200:
124 mode = SDHCI_CDNS_HRS06_MODE_MMC_HS200;
125 break;
126 case MMC_TIMING_MMC_HS400:
127 mode = SDHCI_CDNS_HRS06_MODE_MMC_HS400;
128 break;
129 default:
130 mode = SDHCI_CDNS_HRS06_MODE_SD;
131 break;
132 }
133
134 /* The speed mode for eMMC is selected by HRS06 register */
135 tmp = readl(priv->hrs_addr + SDHCI_CDNS_HRS06);
136 tmp &= ~SDHCI_CDNS_HRS06_MODE_MASK;
137 tmp |= mode;
138 writel(tmp, priv->hrs_addr + SDHCI_CDNS_HRS06);
139
140 /* For SD, fall back to the default handler */
141 if (mode == SDHCI_CDNS_HRS06_MODE_SD)
142 sdhci_set_uhs_signaling(host, timing);
143}
144
145static const struct sdhci_ops sdhci_cdns_ops = {
146 .set_clock = sdhci_set_clock,
147 .get_timeout_clock = sdhci_cdns_get_timeout_clock,
148 .set_bus_width = sdhci_set_bus_width,
149 .reset = sdhci_reset,
150 .set_uhs_signaling = sdhci_cdns_set_uhs_signaling,
151};
152
153static const struct sdhci_pltfm_data sdhci_cdns_pltfm_data = {
154 .ops = &sdhci_cdns_ops,
155};
156
157static int sdhci_cdns_set_tune_val(struct sdhci_host *host, unsigned int val)
158{
159 struct sdhci_cdns_priv *priv = sdhci_cdns_priv(host);
160 void __iomem *reg = priv->hrs_addr + SDHCI_CDNS_HRS06;
161 u32 tmp;
162
163 if (WARN_ON(val > SDHCI_CDNS_HRS06_TUNE_MASK))
164 return -EINVAL;
165
166 tmp = readl(reg);
167 tmp &= ~(SDHCI_CDNS_HRS06_TUNE_MASK << SDHCI_CDNS_HRS06_TUNE_SHIFT);
168 tmp |= val << SDHCI_CDNS_HRS06_TUNE_SHIFT;
169 tmp |= SDHCI_CDNS_HRS06_TUNE_UP;
170 writel(tmp, reg);
171
172 return readl_poll_timeout(reg, tmp, !(tmp & SDHCI_CDNS_HRS06_TUNE_UP),
173 0, 1);
174}
175
176static int sdhci_cdns_execute_tuning(struct mmc_host *mmc, u32 opcode)
177{
178 struct sdhci_host *host = mmc_priv(mmc);
179 int cur_streak = 0;
180 int max_streak = 0;
181 int end_of_streak = 0;
182 int i;
183
184 /*
185 * This handler only implements the eMMC tuning that is specific to
186 * this controller. Fall back to the standard method for SD timing.
187 */
188 if (host->timing != MMC_TIMING_MMC_HS200)
189 return sdhci_execute_tuning(mmc, opcode);
190
191 if (WARN_ON(opcode != MMC_SEND_TUNING_BLOCK_HS200))
192 return -EINVAL;
193
194 for (i = 0; i < SDHCI_CDNS_MAX_TUNING_LOOP; i++) {
195 if (sdhci_cdns_set_tune_val(host, i) ||
196 mmc_send_tuning(host->mmc, opcode, NULL)) { /* bad */
197 cur_streak = 0;
198 } else { /* good */
199 cur_streak++;
200 if (cur_streak > max_streak) {
201 max_streak = cur_streak;
202 end_of_streak = i;
203 }
204 }
205 }
206
207 if (!max_streak) {
208 dev_err(mmc_dev(host->mmc), "no tuning point found\n");
209 return -EIO;
210 }
211
212 return sdhci_cdns_set_tune_val(host, end_of_streak - max_streak / 2);
213}
214
215static int sdhci_cdns_probe(struct platform_device *pdev)
216{
217 struct sdhci_host *host;
218 struct sdhci_pltfm_host *pltfm_host;
219 struct sdhci_cdns_priv *priv;
220 struct clk *clk;
221 int ret;
222
223 clk = devm_clk_get(&pdev->dev, NULL);
224 if (IS_ERR(clk))
225 return PTR_ERR(clk);
226
227 ret = clk_prepare_enable(clk);
228 if (ret)
229 return ret;
230
231 host = sdhci_pltfm_init(pdev, &sdhci_cdns_pltfm_data, sizeof(*priv));
232 if (IS_ERR(host)) {
233 ret = PTR_ERR(host);
234 goto disable_clk;
235 }
236
237 pltfm_host = sdhci_priv(host);
238 pltfm_host->clk = clk;
239
240 priv = sdhci_cdns_priv(host);
241 priv->hrs_addr = host->ioaddr;
242 host->ioaddr += SDHCI_CDNS_SRS_BASE;
243 host->mmc_host_ops.execute_tuning = sdhci_cdns_execute_tuning;
244
245 ret = mmc_of_parse(host->mmc);
246 if (ret)
247 goto free;
248
249 sdhci_cdns_phy_init(priv);
250
251 ret = sdhci_add_host(host);
252 if (ret)
253 goto free;
254
255 return 0;
256free:
257 sdhci_pltfm_free(pdev);
258disable_clk:
259 clk_disable_unprepare(clk);
260
261 return ret;
262}
263
264static const struct of_device_id sdhci_cdns_match[] = {
265 { .compatible = "cdns,sd4hc" },
266 { /* sentinel */ }
267};
268MODULE_DEVICE_TABLE(of, sdhci_cdns_match);
269
270static struct platform_driver sdhci_cdns_driver = {
271 .driver = {
272 .name = "sdhci-cdns",
273 .pm = &sdhci_pltfm_pmops,
274 .of_match_table = sdhci_cdns_match,
275 },
276 .probe = sdhci_cdns_probe,
277 .remove = sdhci_pltfm_unregister,
278};
279module_platform_driver(sdhci_cdns_driver);
280
281MODULE_AUTHOR("Masahiro Yamada <yamada.masahiro@socionext.com>");
282MODULE_DESCRIPTION("Cadence SD/SDIO/eMMC Host Controller Driver");
283MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/host/sdhci-iproc.c b/drivers/mmc/host/sdhci-iproc.c
index 726246665850..d7046d67415a 100644
--- a/drivers/mmc/host/sdhci-iproc.c
+++ b/drivers/mmc/host/sdhci-iproc.c
@@ -143,6 +143,14 @@ static void sdhci_iproc_writeb(struct sdhci_host *host, u8 val, int reg)
143} 143}
144 144
145static const struct sdhci_ops sdhci_iproc_ops = { 145static const struct sdhci_ops sdhci_iproc_ops = {
146 .set_clock = sdhci_set_clock,
147 .get_max_clock = sdhci_pltfm_clk_get_max_clock,
148 .set_bus_width = sdhci_set_bus_width,
149 .reset = sdhci_reset,
150 .set_uhs_signaling = sdhci_set_uhs_signaling,
151};
152
153static const struct sdhci_ops sdhci_iproc_32only_ops = {
146 .read_l = sdhci_iproc_readl, 154 .read_l = sdhci_iproc_readl,
147 .read_w = sdhci_iproc_readw, 155 .read_w = sdhci_iproc_readw,
148 .read_b = sdhci_iproc_readb, 156 .read_b = sdhci_iproc_readb,
@@ -156,6 +164,28 @@ static const struct sdhci_ops sdhci_iproc_ops = {
156 .set_uhs_signaling = sdhci_set_uhs_signaling, 164 .set_uhs_signaling = sdhci_set_uhs_signaling,
157}; 165};
158 166
167static const struct sdhci_pltfm_data sdhci_iproc_cygnus_pltfm_data = {
168 .quirks = SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK,
169 .quirks2 = SDHCI_QUIRK2_ACMD23_BROKEN,
170 .ops = &sdhci_iproc_32only_ops,
171};
172
173static const struct sdhci_iproc_data iproc_cygnus_data = {
174 .pdata = &sdhci_iproc_cygnus_pltfm_data,
175 .caps = ((0x1 << SDHCI_MAX_BLOCK_SHIFT)
176 & SDHCI_MAX_BLOCK_MASK) |
177 SDHCI_CAN_VDD_330 |
178 SDHCI_CAN_VDD_180 |
179 SDHCI_CAN_DO_SUSPEND |
180 SDHCI_CAN_DO_HISPD |
181 SDHCI_CAN_DO_ADMA2 |
182 SDHCI_CAN_DO_SDMA,
183 .caps1 = SDHCI_DRIVER_TYPE_C |
184 SDHCI_DRIVER_TYPE_D |
185 SDHCI_SUPPORT_DDR50,
186 .mmc_caps = MMC_CAP_1_8V_DDR,
187};
188
159static const struct sdhci_pltfm_data sdhci_iproc_pltfm_data = { 189static const struct sdhci_pltfm_data sdhci_iproc_pltfm_data = {
160 .quirks = SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK, 190 .quirks = SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK,
161 .quirks2 = SDHCI_QUIRK2_ACMD23_BROKEN, 191 .quirks2 = SDHCI_QUIRK2_ACMD23_BROKEN,
@@ -182,7 +212,7 @@ static const struct sdhci_pltfm_data sdhci_bcm2835_pltfm_data = {
182 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION | 212 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
183 SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK | 213 SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
184 SDHCI_QUIRK_MISSING_CAPS, 214 SDHCI_QUIRK_MISSING_CAPS,
185 .ops = &sdhci_iproc_ops, 215 .ops = &sdhci_iproc_32only_ops,
186}; 216};
187 217
188static const struct sdhci_iproc_data bcm2835_data = { 218static const struct sdhci_iproc_data bcm2835_data = {
@@ -194,7 +224,8 @@ static const struct sdhci_iproc_data bcm2835_data = {
194 224
195static const struct of_device_id sdhci_iproc_of_match[] = { 225static const struct of_device_id sdhci_iproc_of_match[] = {
196 { .compatible = "brcm,bcm2835-sdhci", .data = &bcm2835_data }, 226 { .compatible = "brcm,bcm2835-sdhci", .data = &bcm2835_data },
197 { .compatible = "brcm,sdhci-iproc-cygnus", .data = &iproc_data }, 227 { .compatible = "brcm,sdhci-iproc-cygnus", .data = &iproc_cygnus_data},
228 { .compatible = "brcm,sdhci-iproc", .data = &iproc_data },
198 { } 229 { }
199}; 230};
200MODULE_DEVICE_TABLE(of, sdhci_iproc_of_match); 231MODULE_DEVICE_TABLE(of, sdhci_iproc_of_match);
diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
index 90ed2e12d345..32879b845b75 100644
--- a/drivers/mmc/host/sdhci-msm.c
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -18,7 +18,9 @@
18#include <linux/of_device.h> 18#include <linux/of_device.h>
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/mmc/mmc.h> 20#include <linux/mmc/mmc.h>
21#include <linux/pm_runtime.h>
21#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/iopoll.h>
22 24
23#include "sdhci-pltfm.h" 25#include "sdhci-pltfm.h"
24 26
@@ -31,6 +33,7 @@
31#define HC_MODE_EN 0x1 33#define HC_MODE_EN 0x1
32#define CORE_POWER 0x0 34#define CORE_POWER 0x0
33#define CORE_SW_RST BIT(7) 35#define CORE_SW_RST BIT(7)
36#define FF_CLK_SW_RST_DIS BIT(13)
34 37
35#define CORE_PWRCTL_STATUS 0xdc 38#define CORE_PWRCTL_STATUS 0xdc
36#define CORE_PWRCTL_MASK 0xe0 39#define CORE_PWRCTL_MASK 0xe0
@@ -49,6 +52,7 @@
49#define INT_MASK 0xf 52#define INT_MASK 0xf
50#define MAX_PHASES 16 53#define MAX_PHASES 16
51#define CORE_DLL_LOCK BIT(7) 54#define CORE_DLL_LOCK BIT(7)
55#define CORE_DDR_DLL_LOCK BIT(11)
52#define CORE_DLL_EN BIT(16) 56#define CORE_DLL_EN BIT(16)
53#define CORE_CDR_EN BIT(17) 57#define CORE_CDR_EN BIT(17)
54#define CORE_CK_OUT_EN BIT(18) 58#define CORE_CK_OUT_EN BIT(18)
@@ -56,18 +60,67 @@
56#define CORE_DLL_PDN BIT(29) 60#define CORE_DLL_PDN BIT(29)
57#define CORE_DLL_RST BIT(30) 61#define CORE_DLL_RST BIT(30)
58#define CORE_DLL_CONFIG 0x100 62#define CORE_DLL_CONFIG 0x100
63#define CORE_CMD_DAT_TRACK_SEL BIT(0)
59#define CORE_DLL_STATUS 0x108 64#define CORE_DLL_STATUS 0x108
60 65
66#define CORE_DLL_CONFIG_2 0x1b4
67#define CORE_DDR_CAL_EN BIT(0)
68#define CORE_FLL_CYCLE_CNT BIT(18)
69#define CORE_DLL_CLOCK_DISABLE BIT(21)
70
61#define CORE_VENDOR_SPEC 0x10c 71#define CORE_VENDOR_SPEC 0x10c
62#define CORE_CLK_PWRSAVE BIT(1) 72#define CORE_CLK_PWRSAVE BIT(1)
73#define CORE_HC_MCLK_SEL_DFLT (2 << 8)
74#define CORE_HC_MCLK_SEL_HS400 (3 << 8)
75#define CORE_HC_MCLK_SEL_MASK (3 << 8)
76#define CORE_HC_SELECT_IN_EN BIT(18)
77#define CORE_HC_SELECT_IN_HS400 (6 << 19)
78#define CORE_HC_SELECT_IN_MASK (7 << 19)
79
80#define CORE_CSR_CDC_CTLR_CFG0 0x130
81#define CORE_SW_TRIG_FULL_CALIB BIT(16)
82#define CORE_HW_AUTOCAL_ENA BIT(17)
83
84#define CORE_CSR_CDC_CTLR_CFG1 0x134
85#define CORE_CSR_CDC_CAL_TIMER_CFG0 0x138
86#define CORE_TIMER_ENA BIT(16)
87
88#define CORE_CSR_CDC_CAL_TIMER_CFG1 0x13C
89#define CORE_CSR_CDC_REFCOUNT_CFG 0x140
90#define CORE_CSR_CDC_COARSE_CAL_CFG 0x144
91#define CORE_CDC_OFFSET_CFG 0x14C
92#define CORE_CSR_CDC_DELAY_CFG 0x150
93#define CORE_CDC_SLAVE_DDA_CFG 0x160
94#define CORE_CSR_CDC_STATUS0 0x164
95#define CORE_CALIBRATION_DONE BIT(0)
96
97#define CORE_CDC_ERROR_CODE_MASK 0x7000000
98
99#define CORE_CSR_CDC_GEN_CFG 0x178
100#define CORE_CDC_SWITCH_BYPASS_OFF BIT(0)
101#define CORE_CDC_SWITCH_RC_EN BIT(1)
102
103#define CORE_DDR_200_CFG 0x184
104#define CORE_CDC_T4_DLY_SEL BIT(0)
105#define CORE_START_CDC_TRAFFIC BIT(6)
106#define CORE_VENDOR_SPEC3 0x1b0
107#define CORE_PWRSAVE_DLL BIT(3)
108
109#define CORE_DDR_CONFIG 0x1b8
110#define DDR_CONFIG_POR_VAL 0x80040853
63 111
64#define CORE_VENDOR_SPEC_CAPABILITIES0 0x11c 112#define CORE_VENDOR_SPEC_CAPABILITIES0 0x11c
65 113
114#define INVALID_TUNING_PHASE -1
115#define SDHCI_MSM_MIN_CLOCK 400000
116#define CORE_FREQ_100MHZ (100 * 1000 * 1000)
117
66#define CDR_SELEXT_SHIFT 20 118#define CDR_SELEXT_SHIFT 20
67#define CDR_SELEXT_MASK (0xf << CDR_SELEXT_SHIFT) 119#define CDR_SELEXT_MASK (0xf << CDR_SELEXT_SHIFT)
68#define CMUX_SHIFT_PHASE_SHIFT 24 120#define CMUX_SHIFT_PHASE_SHIFT 24
69#define CMUX_SHIFT_PHASE_MASK (7 << CMUX_SHIFT_PHASE_SHIFT) 121#define CMUX_SHIFT_PHASE_MASK (7 << CMUX_SHIFT_PHASE_SHIFT)
70 122
123#define MSM_MMC_AUTOSUSPEND_DELAY_MS 50
71struct sdhci_msm_host { 124struct sdhci_msm_host {
72 struct platform_device *pdev; 125 struct platform_device *pdev;
73 void __iomem *core_mem; /* MSM SDCC mapped address */ 126 void __iomem *core_mem; /* MSM SDCC mapped address */
@@ -75,7 +128,14 @@ struct sdhci_msm_host {
75 struct clk *clk; /* main SD/MMC bus clock */ 128 struct clk *clk; /* main SD/MMC bus clock */
76 struct clk *pclk; /* SDHC peripheral bus clock */ 129 struct clk *pclk; /* SDHC peripheral bus clock */
77 struct clk *bus_clk; /* SDHC bus voter clock */ 130 struct clk *bus_clk; /* SDHC bus voter clock */
131 struct clk *xo_clk; /* TCXO clk needed for FLL feature of cm_dll*/
132 unsigned long clk_rate;
78 struct mmc_host *mmc; 133 struct mmc_host *mmc;
134 bool use_14lpp_dll_reset;
135 bool tuning_done;
136 bool calibration_done;
137 u8 saved_tuning_phase;
138 bool use_cdclp533;
79}; 139};
80 140
81/* Platform specific tuning */ 141/* Platform specific tuning */
@@ -115,6 +175,9 @@ static int msm_config_cm_dll_phase(struct sdhci_host *host, u8 phase)
115 u32 config; 175 u32 config;
116 struct mmc_host *mmc = host->mmc; 176 struct mmc_host *mmc = host->mmc;
117 177
178 if (phase > 0xf)
179 return -EINVAL;
180
118 spin_lock_irqsave(&host->lock, flags); 181 spin_lock_irqsave(&host->lock, flags);
119 182
120 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG); 183 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
@@ -136,9 +199,9 @@ static int msm_config_cm_dll_phase(struct sdhci_host *host, u8 phase)
136 config |= grey_coded_phase_table[phase] << CDR_SELEXT_SHIFT; 199 config |= grey_coded_phase_table[phase] << CDR_SELEXT_SHIFT;
137 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG); 200 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
138 201
139 /* Set CK_OUT_EN bit of DLL_CONFIG register to 1. */ 202 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
140 writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) 203 config |= CORE_CK_OUT_EN;
141 | CORE_CK_OUT_EN), host->ioaddr + CORE_DLL_CONFIG); 204 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
142 205
143 /* Wait until CK_OUT_EN bit of DLL_CONFIG register becomes '1' */ 206 /* Wait until CK_OUT_EN bit of DLL_CONFIG register becomes '1' */
144 rc = msm_dll_poll_ck_out_en(host, 1); 207 rc = msm_dll_poll_ck_out_en(host, 1);
@@ -163,8 +226,8 @@ out:
163 * Find out the greatest range of consecuitive selected 226 * Find out the greatest range of consecuitive selected
164 * DLL clock output phases that can be used as sampling 227 * DLL clock output phases that can be used as sampling
165 * setting for SD3.0 UHS-I card read operation (in SDR104 228 * setting for SD3.0 UHS-I card read operation (in SDR104
166 * timing mode) or for eMMC4.5 card read operation (in HS200 229 * timing mode) or for eMMC4.5 card read operation (in
167 * timing mode). 230 * HS400/HS200 timing mode).
168 * Select the 3/4 of the range and configure the DLL with the 231 * Select the 3/4 of the range and configure the DLL with the
169 * selected DLL clock output phase. 232 * selected DLL clock output phase.
170 */ 233 */
@@ -303,8 +366,11 @@ static inline void msm_cm_dll_set_freq(struct sdhci_host *host)
303static int msm_init_cm_dll(struct sdhci_host *host) 366static int msm_init_cm_dll(struct sdhci_host *host)
304{ 367{
305 struct mmc_host *mmc = host->mmc; 368 struct mmc_host *mmc = host->mmc;
369 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
370 struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
306 int wait_cnt = 50; 371 int wait_cnt = 50;
307 unsigned long flags; 372 unsigned long flags;
373 u32 config;
308 374
309 spin_lock_irqsave(&host->lock, flags); 375 spin_lock_irqsave(&host->lock, flags);
310 376
@@ -313,33 +379,73 @@ static int msm_init_cm_dll(struct sdhci_host *host)
313 * tuning is in progress. Keeping PWRSAVE ON may 379 * tuning is in progress. Keeping PWRSAVE ON may
314 * turn off the clock. 380 * turn off the clock.
315 */ 381 */
316 writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) 382 config = readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC);
317 & ~CORE_CLK_PWRSAVE), host->ioaddr + CORE_VENDOR_SPEC); 383 config &= ~CORE_CLK_PWRSAVE;
384 writel_relaxed(config, host->ioaddr + CORE_VENDOR_SPEC);
385
386 if (msm_host->use_14lpp_dll_reset) {
387 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
388 config &= ~CORE_CK_OUT_EN;
389 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
390
391 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG_2);
392 config |= CORE_DLL_CLOCK_DISABLE;
393 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG_2);
394 }
318 395
319 /* Write 1 to DLL_RST bit of DLL_CONFIG register */ 396 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
320 writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) 397 config |= CORE_DLL_RST;
321 | CORE_DLL_RST), host->ioaddr + CORE_DLL_CONFIG); 398 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
322 399
323 /* Write 1 to DLL_PDN bit of DLL_CONFIG register */ 400 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
324 writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) 401 config |= CORE_DLL_PDN;
325 | CORE_DLL_PDN), host->ioaddr + CORE_DLL_CONFIG); 402 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
326 msm_cm_dll_set_freq(host); 403 msm_cm_dll_set_freq(host);
327 404
328 /* Write 0 to DLL_RST bit of DLL_CONFIG register */ 405 if (msm_host->use_14lpp_dll_reset &&
329 writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) 406 !IS_ERR_OR_NULL(msm_host->xo_clk)) {
330 & ~CORE_DLL_RST), host->ioaddr + CORE_DLL_CONFIG); 407 u32 mclk_freq = 0;
408
409 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG_2);
410 config &= CORE_FLL_CYCLE_CNT;
411 if (config)
412 mclk_freq = DIV_ROUND_CLOSEST_ULL((host->clock * 8),
413 clk_get_rate(msm_host->xo_clk));
414 else
415 mclk_freq = DIV_ROUND_CLOSEST_ULL((host->clock * 4),
416 clk_get_rate(msm_host->xo_clk));
417
418 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG_2);
419 config &= ~(0xFF << 10);
420 config |= mclk_freq << 10;
331 421
332 /* Write 0 to DLL_PDN bit of DLL_CONFIG register */ 422 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG_2);
333 writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) 423 /* wait for 5us before enabling DLL clock */
334 & ~CORE_DLL_PDN), host->ioaddr + CORE_DLL_CONFIG); 424 udelay(5);
425 }
426
427 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
428 config &= ~CORE_DLL_RST;
429 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
430
431 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
432 config &= ~CORE_DLL_PDN;
433 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
434
435 if (msm_host->use_14lpp_dll_reset) {
436 msm_cm_dll_set_freq(host);
437 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG_2);
438 config &= ~CORE_DLL_CLOCK_DISABLE;
439 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG_2);
440 }
335 441
336 /* Set DLL_EN bit to 1. */ 442 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
337 writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) 443 config |= CORE_DLL_EN;
338 | CORE_DLL_EN), host->ioaddr + CORE_DLL_CONFIG); 444 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
339 445
340 /* Set CK_OUT_EN bit to 1. */ 446 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
341 writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) 447 config |= CORE_CK_OUT_EN;
342 | CORE_CK_OUT_EN), host->ioaddr + CORE_DLL_CONFIG); 448 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
343 449
344 /* Wait until DLL_LOCK bit of DLL_STATUS register becomes '1' */ 450 /* Wait until DLL_LOCK bit of DLL_STATUS register becomes '1' */
345 while (!(readl_relaxed(host->ioaddr + CORE_DLL_STATUS) & 451 while (!(readl_relaxed(host->ioaddr + CORE_DLL_STATUS) &
@@ -358,6 +464,200 @@ static int msm_init_cm_dll(struct sdhci_host *host)
358 return 0; 464 return 0;
359} 465}
360 466
467static int sdhci_msm_cdclp533_calibration(struct sdhci_host *host)
468{
469 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
470 struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
471 u32 config, calib_done;
472 int ret;
473
474 pr_debug("%s: %s: Enter\n", mmc_hostname(host->mmc), __func__);
475
476 /*
477 * Retuning in HS400 (DDR mode) will fail, just reset the
478 * tuning block and restore the saved tuning phase.
479 */
480 ret = msm_init_cm_dll(host);
481 if (ret)
482 goto out;
483
484 /* Set the selected phase in delay line hw block */
485 ret = msm_config_cm_dll_phase(host, msm_host->saved_tuning_phase);
486 if (ret)
487 goto out;
488
489 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
490 config |= CORE_CMD_DAT_TRACK_SEL;
491 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
492
493 config = readl_relaxed(host->ioaddr + CORE_DDR_200_CFG);
494 config &= ~CORE_CDC_T4_DLY_SEL;
495 writel_relaxed(config, host->ioaddr + CORE_DDR_200_CFG);
496
497 config = readl_relaxed(host->ioaddr + CORE_CSR_CDC_GEN_CFG);
498 config &= ~CORE_CDC_SWITCH_BYPASS_OFF;
499 writel_relaxed(config, host->ioaddr + CORE_CSR_CDC_GEN_CFG);
500
501 config = readl_relaxed(host->ioaddr + CORE_CSR_CDC_GEN_CFG);
502 config |= CORE_CDC_SWITCH_RC_EN;
503 writel_relaxed(config, host->ioaddr + CORE_CSR_CDC_GEN_CFG);
504
505 config = readl_relaxed(host->ioaddr + CORE_DDR_200_CFG);
506 config &= ~CORE_START_CDC_TRAFFIC;
507 writel_relaxed(config, host->ioaddr + CORE_DDR_200_CFG);
508
509 /*
510 * Perform CDC Register Initialization Sequence
511 *
512 * CORE_CSR_CDC_CTLR_CFG0 0x11800EC
513 * CORE_CSR_CDC_CTLR_CFG1 0x3011111
514 * CORE_CSR_CDC_CAL_TIMER_CFG0 0x1201000
515 * CORE_CSR_CDC_CAL_TIMER_CFG1 0x4
516 * CORE_CSR_CDC_REFCOUNT_CFG 0xCB732020
517 * CORE_CSR_CDC_COARSE_CAL_CFG 0xB19
518 * CORE_CSR_CDC_DELAY_CFG 0x3AC
519 * CORE_CDC_OFFSET_CFG 0x0
520 * CORE_CDC_SLAVE_DDA_CFG 0x16334
521 */
522
523 writel_relaxed(0x11800EC, host->ioaddr + CORE_CSR_CDC_CTLR_CFG0);
524 writel_relaxed(0x3011111, host->ioaddr + CORE_CSR_CDC_CTLR_CFG1);
525 writel_relaxed(0x1201000, host->ioaddr + CORE_CSR_CDC_CAL_TIMER_CFG0);
526 writel_relaxed(0x4, host->ioaddr + CORE_CSR_CDC_CAL_TIMER_CFG1);
527 writel_relaxed(0xCB732020, host->ioaddr + CORE_CSR_CDC_REFCOUNT_CFG);
528 writel_relaxed(0xB19, host->ioaddr + CORE_CSR_CDC_COARSE_CAL_CFG);
529 writel_relaxed(0x3AC, host->ioaddr + CORE_CSR_CDC_DELAY_CFG);
530 writel_relaxed(0x0, host->ioaddr + CORE_CDC_OFFSET_CFG);
531 writel_relaxed(0x16334, host->ioaddr + CORE_CDC_SLAVE_DDA_CFG);
532
533 /* CDC HW Calibration */
534
535 config = readl_relaxed(host->ioaddr + CORE_CSR_CDC_CTLR_CFG0);
536 config |= CORE_SW_TRIG_FULL_CALIB;
537 writel_relaxed(config, host->ioaddr + CORE_CSR_CDC_CTLR_CFG0);
538
539 config = readl_relaxed(host->ioaddr + CORE_CSR_CDC_CTLR_CFG0);
540 config &= ~CORE_SW_TRIG_FULL_CALIB;
541 writel_relaxed(config, host->ioaddr + CORE_CSR_CDC_CTLR_CFG0);
542
543 config = readl_relaxed(host->ioaddr + CORE_CSR_CDC_CTLR_CFG0);
544 config |= CORE_HW_AUTOCAL_ENA;
545 writel_relaxed(config, host->ioaddr + CORE_CSR_CDC_CTLR_CFG0);
546
547 config = readl_relaxed(host->ioaddr + CORE_CSR_CDC_CAL_TIMER_CFG0);
548 config |= CORE_TIMER_ENA;
549 writel_relaxed(config, host->ioaddr + CORE_CSR_CDC_CAL_TIMER_CFG0);
550
551 ret = readl_relaxed_poll_timeout(host->ioaddr + CORE_CSR_CDC_STATUS0,
552 calib_done,
553 (calib_done & CORE_CALIBRATION_DONE),
554 1, 50);
555
556 if (ret == -ETIMEDOUT) {
557 pr_err("%s: %s: CDC calibration was not completed\n",
558 mmc_hostname(host->mmc), __func__);
559 goto out;
560 }
561
562 ret = readl_relaxed(host->ioaddr + CORE_CSR_CDC_STATUS0)
563 & CORE_CDC_ERROR_CODE_MASK;
564 if (ret) {
565 pr_err("%s: %s: CDC error code %d\n",
566 mmc_hostname(host->mmc), __func__, ret);
567 ret = -EINVAL;
568 goto out;
569 }
570
571 config = readl_relaxed(host->ioaddr + CORE_DDR_200_CFG);
572 config |= CORE_START_CDC_TRAFFIC;
573 writel_relaxed(config, host->ioaddr + CORE_DDR_200_CFG);
574out:
575 pr_debug("%s: %s: Exit, ret %d\n", mmc_hostname(host->mmc),
576 __func__, ret);
577 return ret;
578}
579
580static int sdhci_msm_cm_dll_sdc4_calibration(struct sdhci_host *host)
581{
582 u32 dll_status, config;
583 int ret;
584
585 pr_debug("%s: %s: Enter\n", mmc_hostname(host->mmc), __func__);
586
587 /*
588 * Currently the CORE_DDR_CONFIG register defaults to desired
589 * configuration on reset. Currently reprogramming the power on
590 * reset (POR) value in case it might have been modified by
591 * bootloaders. In the future, if this changes, then the desired
592 * values will need to be programmed appropriately.
593 */
594 writel_relaxed(DDR_CONFIG_POR_VAL, host->ioaddr + CORE_DDR_CONFIG);
595
596 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG_2);
597 config |= CORE_DDR_CAL_EN;
598 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG_2);
599
600 ret = readl_relaxed_poll_timeout(host->ioaddr + CORE_DLL_STATUS,
601 dll_status,
602 (dll_status & CORE_DDR_DLL_LOCK),
603 10, 1000);
604
605 if (ret == -ETIMEDOUT) {
606 pr_err("%s: %s: CM_DLL_SDC4 calibration was not completed\n",
607 mmc_hostname(host->mmc), __func__);
608 goto out;
609 }
610
611 config = readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC3);
612 config |= CORE_PWRSAVE_DLL;
613 writel_relaxed(config, host->ioaddr + CORE_VENDOR_SPEC3);
614
615 /*
616 * Drain writebuffer to ensure above DLL calibration
617 * and PWRSAVE DLL is enabled.
618 */
619 wmb();
620out:
621 pr_debug("%s: %s: Exit, ret %d\n", mmc_hostname(host->mmc),
622 __func__, ret);
623 return ret;
624}
625
626static int sdhci_msm_hs400_dll_calibration(struct sdhci_host *host)
627{
628 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
629 struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
630 int ret;
631 u32 config;
632
633 pr_debug("%s: %s: Enter\n", mmc_hostname(host->mmc), __func__);
634
635 /*
636 * Retuning in HS400 (DDR mode) will fail, just reset the
637 * tuning block and restore the saved tuning phase.
638 */
639 ret = msm_init_cm_dll(host);
640 if (ret)
641 goto out;
642
643 /* Set the selected phase in delay line hw block */
644 ret = msm_config_cm_dll_phase(host, msm_host->saved_tuning_phase);
645 if (ret)
646 goto out;
647
648 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
649 config |= CORE_CMD_DAT_TRACK_SEL;
650 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
651 if (msm_host->use_cdclp533)
652 ret = sdhci_msm_cdclp533_calibration(host);
653 else
654 ret = sdhci_msm_cm_dll_sdc4_calibration(host);
655out:
656 pr_debug("%s: %s: Exit, ret %d\n", mmc_hostname(host->mmc),
657 __func__, ret);
658 return ret;
659}
660
361static int sdhci_msm_execute_tuning(struct sdhci_host *host, u32 opcode) 661static int sdhci_msm_execute_tuning(struct sdhci_host *host, u32 opcode)
362{ 662{
363 int tuning_seq_cnt = 3; 663 int tuning_seq_cnt = 3;
@@ -365,14 +665,17 @@ static int sdhci_msm_execute_tuning(struct sdhci_host *host, u32 opcode)
365 int rc; 665 int rc;
366 struct mmc_host *mmc = host->mmc; 666 struct mmc_host *mmc = host->mmc;
367 struct mmc_ios ios = host->mmc->ios; 667 struct mmc_ios ios = host->mmc->ios;
668 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
669 struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
368 670
369 /* 671 /*
370 * Tuning is required for SDR104, HS200 and HS400 cards and 672 * Tuning is required for SDR104, HS200 and HS400 cards and
371 * if clock frequency is greater than 100MHz in these modes. 673 * if clock frequency is greater than 100MHz in these modes.
372 */ 674 */
373 if (host->clock <= 100 * 1000 * 1000 || 675 if (host->clock <= CORE_FREQ_100MHZ ||
374 !((ios.timing == MMC_TIMING_MMC_HS200) || 676 !(ios.timing == MMC_TIMING_MMC_HS400 ||
375 (ios.timing == MMC_TIMING_UHS_SDR104))) 677 ios.timing == MMC_TIMING_MMC_HS200 ||
678 ios.timing == MMC_TIMING_UHS_SDR104))
376 return 0; 679 return 0;
377 680
378retry: 681retry:
@@ -388,6 +691,7 @@ retry:
388 if (rc) 691 if (rc)
389 return rc; 692 return rc;
390 693
694 msm_host->saved_tuning_phase = phase;
391 rc = mmc_send_tuning(mmc, opcode, NULL); 695 rc = mmc_send_tuning(mmc, opcode, NULL);
392 if (!rc) { 696 if (!rc) {
393 /* Tuning is successful at this tuning point */ 697 /* Tuning is successful at this tuning point */
@@ -423,6 +727,8 @@ retry:
423 rc = -EIO; 727 rc = -EIO;
424 } 728 }
425 729
730 if (!rc)
731 msm_host->tuning_done = true;
426 return rc; 732 return rc;
427} 733}
428 734
@@ -430,7 +736,10 @@ static void sdhci_msm_set_uhs_signaling(struct sdhci_host *host,
430 unsigned int uhs) 736 unsigned int uhs)
431{ 737{
432 struct mmc_host *mmc = host->mmc; 738 struct mmc_host *mmc = host->mmc;
739 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
740 struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
433 u16 ctrl_2; 741 u16 ctrl_2;
742 u32 config;
434 743
435 ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); 744 ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2);
436 /* Select Bus Speed Mode for host */ 745 /* Select Bus Speed Mode for host */
@@ -445,6 +754,7 @@ static void sdhci_msm_set_uhs_signaling(struct sdhci_host *host,
445 case MMC_TIMING_UHS_SDR50: 754 case MMC_TIMING_UHS_SDR50:
446 ctrl_2 |= SDHCI_CTRL_UHS_SDR50; 755 ctrl_2 |= SDHCI_CTRL_UHS_SDR50;
447 break; 756 break;
757 case MMC_TIMING_MMC_HS400:
448 case MMC_TIMING_MMC_HS200: 758 case MMC_TIMING_MMC_HS200:
449 case MMC_TIMING_UHS_SDR104: 759 case MMC_TIMING_UHS_SDR104:
450 ctrl_2 |= SDHCI_CTRL_UHS_SDR104; 760 ctrl_2 |= SDHCI_CTRL_UHS_SDR104;
@@ -461,15 +771,42 @@ static void sdhci_msm_set_uhs_signaling(struct sdhci_host *host,
461 * provide feedback clock, the mode selection can be any value less 771 * provide feedback clock, the mode selection can be any value less
462 * than 3'b011 in bits [2:0] of HOST CONTROL2 register. 772 * than 3'b011 in bits [2:0] of HOST CONTROL2 register.
463 */ 773 */
464 if (host->clock <= 100000000 && 774 if (host->clock <= CORE_FREQ_100MHZ) {
465 (uhs == MMC_TIMING_MMC_HS400 || 775 if (uhs == MMC_TIMING_MMC_HS400 ||
466 uhs == MMC_TIMING_MMC_HS200 || 776 uhs == MMC_TIMING_MMC_HS200 ||
467 uhs == MMC_TIMING_UHS_SDR104)) 777 uhs == MMC_TIMING_UHS_SDR104)
468 ctrl_2 &= ~SDHCI_CTRL_UHS_MASK; 778 ctrl_2 &= ~SDHCI_CTRL_UHS_MASK;
779 /*
780 * DLL is not required for clock <= 100MHz
781 * Thus, make sure DLL it is disabled when not required
782 */
783 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
784 config |= CORE_DLL_RST;
785 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
786
787 config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
788 config |= CORE_DLL_PDN;
789 writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
790
791 /*
792 * The DLL needs to be restored and CDCLP533 recalibrated
793 * when the clock frequency is set back to 400MHz.
794 */
795 msm_host->calibration_done = false;
796 }
469 797
470 dev_dbg(mmc_dev(mmc), "%s: clock=%u uhs=%u ctrl_2=0x%x\n", 798 dev_dbg(mmc_dev(mmc), "%s: clock=%u uhs=%u ctrl_2=0x%x\n",
471 mmc_hostname(host->mmc), host->clock, uhs, ctrl_2); 799 mmc_hostname(host->mmc), host->clock, uhs, ctrl_2);
472 sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); 800 sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2);
801
802 spin_unlock_irq(&host->lock);
803 /* CDCLP533 HW calibration is only required for HS400 mode*/
804 if (host->clock > CORE_FREQ_100MHZ &&
805 msm_host->tuning_done && !msm_host->calibration_done &&
806 mmc->ios.timing == MMC_TIMING_MMC_HS400)
807 if (!sdhci_msm_hs400_dll_calibration(host))
808 msm_host->calibration_done = true;
809 spin_lock_irq(&host->lock);
473} 810}
474 811
475static void sdhci_msm_voltage_switch(struct sdhci_host *host) 812static void sdhci_msm_voltage_switch(struct sdhci_host *host)
@@ -505,6 +842,183 @@ static irqreturn_t sdhci_msm_pwr_irq(int irq, void *data)
505 return IRQ_HANDLED; 842 return IRQ_HANDLED;
506} 843}
507 844
845static unsigned int sdhci_msm_get_max_clock(struct sdhci_host *host)
846{
847 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
848 struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
849
850 return clk_round_rate(msm_host->clk, ULONG_MAX);
851}
852
853static unsigned int sdhci_msm_get_min_clock(struct sdhci_host *host)
854{
855 return SDHCI_MSM_MIN_CLOCK;
856}
857
858/**
859 * __sdhci_msm_set_clock - sdhci_msm clock control.
860 *
861 * Description:
862 * MSM controller does not use internal divider and
863 * instead directly control the GCC clock as per
864 * HW recommendation.
865 **/
866void __sdhci_msm_set_clock(struct sdhci_host *host, unsigned int clock)
867{
868 u16 clk;
869 /*
870 * Keep actual_clock as zero -
871 * - since there is no divider used so no need of having actual_clock.
872 * - MSM controller uses SDCLK for data timeout calculation. If
873 * actual_clock is zero, host->clock is taken for calculation.
874 */
875 host->mmc->actual_clock = 0;
876
877 sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
878
879 if (clock == 0)
880 return;
881
882 /*
883 * MSM controller do not use clock divider.
884 * Thus read SDHCI_CLOCK_CONTROL and only enable
885 * clock with no divider value programmed.
886 */
887 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
888 sdhci_enable_clk(host, clk);
889}
890
891/* sdhci_msm_set_clock - Called with (host->lock) spinlock held. */
892static void sdhci_msm_set_clock(struct sdhci_host *host, unsigned int clock)
893{
894 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
895 struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
896 struct mmc_ios curr_ios = host->mmc->ios;
897 u32 config, dll_lock;
898 int rc;
899
900 if (!clock) {
901 msm_host->clk_rate = clock;
902 goto out;
903 }
904
905 spin_unlock_irq(&host->lock);
906 /*
907 * The SDHC requires internal clock frequency to be double the
908 * actual clock that will be set for DDR mode. The controller
909 * uses the faster clock(100/400MHz) for some of its parts and
910 * send the actual required clock (50/200MHz) to the card.
911 */
912 if (curr_ios.timing == MMC_TIMING_UHS_DDR50 ||
913 curr_ios.timing == MMC_TIMING_MMC_DDR52 ||
914 curr_ios.timing == MMC_TIMING_MMC_HS400)
915 clock *= 2;
916 /*
917 * In general all timing modes are controlled via UHS mode select in
918 * Host Control2 register. eMMC specific HS200/HS400 doesn't have
919 * their respective modes defined here, hence we use these values.
920 *
921 * HS200 - SDR104 (Since they both are equivalent in functionality)
922 * HS400 - This involves multiple configurations
923 * Initially SDR104 - when tuning is required as HS200
924 * Then when switching to DDR @ 400MHz (HS400) we use
925 * the vendor specific HC_SELECT_IN to control the mode.
926 *
927 * In addition to controlling the modes we also need to select the
928 * correct input clock for DLL depending on the mode.
929 *
930 * HS400 - divided clock (free running MCLK/2)
931 * All other modes - default (free running MCLK)
932 */
933 if (curr_ios.timing == MMC_TIMING_MMC_HS400) {
934 /* Select the divided clock (free running MCLK/2) */
935 config = readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC);
936 config &= ~CORE_HC_MCLK_SEL_MASK;
937 config |= CORE_HC_MCLK_SEL_HS400;
938
939 writel_relaxed(config, host->ioaddr + CORE_VENDOR_SPEC);
940 /*
941 * Select HS400 mode using the HC_SELECT_IN from VENDOR SPEC
942 * register
943 */
944 if (msm_host->tuning_done && !msm_host->calibration_done) {
945 /*
946 * Write 0x6 to HC_SELECT_IN and 1 to HC_SELECT_IN_EN
947 * field in VENDOR_SPEC_FUNC
948 */
949 config = readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC);
950 config |= CORE_HC_SELECT_IN_HS400;
951 config |= CORE_HC_SELECT_IN_EN;
952 writel_relaxed(config, host->ioaddr + CORE_VENDOR_SPEC);
953 }
954 if (!msm_host->clk_rate && !msm_host->use_cdclp533) {
955 /*
956 * Poll on DLL_LOCK or DDR_DLL_LOCK bits in
957 * CORE_DLL_STATUS to be set. This should get set
958 * within 15 us at 200 MHz.
959 */
960 rc = readl_relaxed_poll_timeout(host->ioaddr +
961 CORE_DLL_STATUS,
962 dll_lock,
963 (dll_lock &
964 (CORE_DLL_LOCK |
965 CORE_DDR_DLL_LOCK)), 10,
966 1000);
967 if (rc == -ETIMEDOUT)
968 pr_err("%s: Unable to get DLL_LOCK/DDR_DLL_LOCK, dll_status: 0x%08x\n",
969 mmc_hostname(host->mmc), dll_lock);
970 }
971 } else {
972 if (!msm_host->use_cdclp533) {
973 config = readl_relaxed(host->ioaddr +
974 CORE_VENDOR_SPEC3);
975 config &= ~CORE_PWRSAVE_DLL;
976 writel_relaxed(config, host->ioaddr +
977 CORE_VENDOR_SPEC3);
978 }
979
980 config = readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC);
981 config &= ~CORE_HC_MCLK_SEL_MASK;
982 config |= CORE_HC_MCLK_SEL_DFLT;
983 writel_relaxed(config, host->ioaddr + CORE_VENDOR_SPEC);
984
985 /*
986 * Disable HC_SELECT_IN to be able to use the UHS mode select
987 * configuration from Host Control2 register for all other
988 * modes.
989 * Write 0 to HC_SELECT_IN and HC_SELECT_IN_EN field
990 * in VENDOR_SPEC_FUNC
991 */
992 config = readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC);
993 config &= ~CORE_HC_SELECT_IN_EN;
994 config &= ~CORE_HC_SELECT_IN_MASK;
995 writel_relaxed(config, host->ioaddr + CORE_VENDOR_SPEC);
996 }
997
998 /*
999 * Make sure above writes impacting free running MCLK are completed
1000 * before changing the clk_rate at GCC.
1001 */
1002 wmb();
1003
1004 rc = clk_set_rate(msm_host->clk, clock);
1005 if (rc) {
1006 pr_err("%s: Failed to set clock at rate %u at timing %d\n",
1007 mmc_hostname(host->mmc), clock,
1008 curr_ios.timing);
1009 goto out_lock;
1010 }
1011 msm_host->clk_rate = clock;
1012 pr_debug("%s: Setting clock at rate %lu at timing %d\n",
1013 mmc_hostname(host->mmc), clk_get_rate(msm_host->clk),
1014 curr_ios.timing);
1015
1016out_lock:
1017 spin_lock_irq(&host->lock);
1018out:
1019 __sdhci_msm_set_clock(host, clock);
1020}
1021
508static const struct of_device_id sdhci_msm_dt_match[] = { 1022static const struct of_device_id sdhci_msm_dt_match[] = {
509 { .compatible = "qcom,sdhci-msm-v4" }, 1023 { .compatible = "qcom,sdhci-msm-v4" },
510 {}, 1024 {},
@@ -515,7 +1029,9 @@ MODULE_DEVICE_TABLE(of, sdhci_msm_dt_match);
515static const struct sdhci_ops sdhci_msm_ops = { 1029static const struct sdhci_ops sdhci_msm_ops = {
516 .platform_execute_tuning = sdhci_msm_execute_tuning, 1030 .platform_execute_tuning = sdhci_msm_execute_tuning,
517 .reset = sdhci_reset, 1031 .reset = sdhci_reset,
518 .set_clock = sdhci_set_clock, 1032 .set_clock = sdhci_msm_set_clock,
1033 .get_min_clock = sdhci_msm_get_min_clock,
1034 .get_max_clock = sdhci_msm_get_max_clock,
519 .set_bus_width = sdhci_set_bus_width, 1035 .set_bus_width = sdhci_set_bus_width,
520 .set_uhs_signaling = sdhci_msm_set_uhs_signaling, 1036 .set_uhs_signaling = sdhci_msm_set_uhs_signaling,
521 .voltage_switch = sdhci_msm_voltage_switch, 1037 .voltage_switch = sdhci_msm_voltage_switch,
@@ -524,7 +1040,9 @@ static const struct sdhci_ops sdhci_msm_ops = {
524static const struct sdhci_pltfm_data sdhci_msm_pdata = { 1040static const struct sdhci_pltfm_data sdhci_msm_pdata = {
525 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION | 1041 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
526 SDHCI_QUIRK_NO_CARD_NO_RESET | 1042 SDHCI_QUIRK_NO_CARD_NO_RESET |
527 SDHCI_QUIRK_SINGLE_POWER_WRITE, 1043 SDHCI_QUIRK_SINGLE_POWER_WRITE |
1044 SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
1045 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
528 .ops = &sdhci_msm_ops, 1046 .ops = &sdhci_msm_ops,
529}; 1047};
530 1048
@@ -536,7 +1054,7 @@ static int sdhci_msm_probe(struct platform_device *pdev)
536 struct resource *core_memres; 1054 struct resource *core_memres;
537 int ret; 1055 int ret;
538 u16 host_version, core_minor; 1056 u16 host_version, core_minor;
539 u32 core_version, caps; 1057 u32 core_version, config;
540 u8 core_major; 1058 u8 core_major;
541 1059
542 host = sdhci_pltfm_init(pdev, &sdhci_msm_pdata, sizeof(*msm_host)); 1060 host = sdhci_pltfm_init(pdev, &sdhci_msm_pdata, sizeof(*msm_host));
@@ -554,6 +1072,8 @@ static int sdhci_msm_probe(struct platform_device *pdev)
554 1072
555 sdhci_get_of_property(pdev); 1073 sdhci_get_of_property(pdev);
556 1074
1075 msm_host->saved_tuning_phase = INVALID_TUNING_PHASE;
1076
557 /* Setup SDCC bus voter clock. */ 1077 /* Setup SDCC bus voter clock. */
558 msm_host->bus_clk = devm_clk_get(&pdev->dev, "bus"); 1078 msm_host->bus_clk = devm_clk_get(&pdev->dev, "bus");
559 if (!IS_ERR(msm_host->bus_clk)) { 1079 if (!IS_ERR(msm_host->bus_clk)) {
@@ -586,6 +1106,16 @@ static int sdhci_msm_probe(struct platform_device *pdev)
586 goto pclk_disable; 1106 goto pclk_disable;
587 } 1107 }
588 1108
1109 /*
1110 * xo clock is needed for FLL feature of cm_dll.
1111 * In case if xo clock is not mentioned in DT, warn and proceed.
1112 */
1113 msm_host->xo_clk = devm_clk_get(&pdev->dev, "xo");
1114 if (IS_ERR(msm_host->xo_clk)) {
1115 ret = PTR_ERR(msm_host->xo_clk);
1116 dev_warn(&pdev->dev, "TCXO clk not present (%d)\n", ret);
1117 }
1118
589 /* Vote for maximum clock rate for maximum performance */ 1119 /* Vote for maximum clock rate for maximum performance */
590 ret = clk_set_rate(msm_host->clk, INT_MAX); 1120 ret = clk_set_rate(msm_host->clk, INT_MAX);
591 if (ret) 1121 if (ret)
@@ -604,9 +1134,9 @@ static int sdhci_msm_probe(struct platform_device *pdev)
604 goto clk_disable; 1134 goto clk_disable;
605 } 1135 }
606 1136
607 /* Reset the core and Enable SDHC mode */ 1137 config = readl_relaxed(msm_host->core_mem + CORE_POWER);
608 writel_relaxed(readl_relaxed(msm_host->core_mem + CORE_POWER) | 1138 config |= CORE_SW_RST;
609 CORE_SW_RST, msm_host->core_mem + CORE_POWER); 1139 writel_relaxed(config, msm_host->core_mem + CORE_POWER);
610 1140
611 /* SW reset can take upto 10HCLK + 15MCLK cycles. (min 40us) */ 1141 /* SW reset can take upto 10HCLK + 15MCLK cycles. (min 40us) */
612 usleep_range(1000, 5000); 1142 usleep_range(1000, 5000);
@@ -619,6 +1149,10 @@ static int sdhci_msm_probe(struct platform_device *pdev)
619 /* Set HC_MODE_EN bit in HC_MODE register */ 1149 /* Set HC_MODE_EN bit in HC_MODE register */
620 writel_relaxed(HC_MODE_EN, (msm_host->core_mem + CORE_HC_MODE)); 1150 writel_relaxed(HC_MODE_EN, (msm_host->core_mem + CORE_HC_MODE));
621 1151
1152 config = readl_relaxed(msm_host->core_mem + CORE_HC_MODE);
1153 config |= FF_CLK_SW_RST_DIS;
1154 writel_relaxed(config, msm_host->core_mem + CORE_HC_MODE);
1155
622 host_version = readw_relaxed((host->ioaddr + SDHCI_HOST_VERSION)); 1156 host_version = readw_relaxed((host->ioaddr + SDHCI_HOST_VERSION));
623 dev_dbg(&pdev->dev, "Host Version: 0x%x Vendor Version 0x%x\n", 1157 dev_dbg(&pdev->dev, "Host Version: 0x%x Vendor Version 0x%x\n",
624 host_version, ((host_version & SDHCI_VENDOR_VER_MASK) >> 1158 host_version, ((host_version & SDHCI_VENDOR_VER_MASK) >>
@@ -631,14 +1165,24 @@ static int sdhci_msm_probe(struct platform_device *pdev)
631 dev_dbg(&pdev->dev, "MCI Version: 0x%08x, major: 0x%04x, minor: 0x%02x\n", 1165 dev_dbg(&pdev->dev, "MCI Version: 0x%08x, major: 0x%04x, minor: 0x%02x\n",
632 core_version, core_major, core_minor); 1166 core_version, core_major, core_minor);
633 1167
1168 if (core_major == 1 && core_minor >= 0x42)
1169 msm_host->use_14lpp_dll_reset = true;
1170
1171 /*
1172 * SDCC 5 controller with major version 1, minor version 0x34 and later
1173 * with HS 400 mode support will use CM DLL instead of CDC LP 533 DLL.
1174 */
1175 if (core_major == 1 && core_minor < 0x34)
1176 msm_host->use_cdclp533 = true;
1177
634 /* 1178 /*
635 * Support for some capabilities is not advertised by newer 1179 * Support for some capabilities is not advertised by newer
636 * controller versions and must be explicitly enabled. 1180 * controller versions and must be explicitly enabled.
637 */ 1181 */
638 if (core_major >= 1 && core_minor != 0x11 && core_minor != 0x12) { 1182 if (core_major >= 1 && core_minor != 0x11 && core_minor != 0x12) {
639 caps = readl_relaxed(host->ioaddr + SDHCI_CAPABILITIES); 1183 config = readl_relaxed(host->ioaddr + SDHCI_CAPABILITIES);
640 caps |= SDHCI_CAN_VDD_300 | SDHCI_CAN_DO_8BIT; 1184 config |= SDHCI_CAN_VDD_300 | SDHCI_CAN_DO_8BIT;
641 writel_relaxed(caps, host->ioaddr + 1185 writel_relaxed(config, host->ioaddr +
642 CORE_VENDOR_SPEC_CAPABILITIES0); 1186 CORE_VENDOR_SPEC_CAPABILITIES0);
643 } 1187 }
644 1188
@@ -659,12 +1203,26 @@ static int sdhci_msm_probe(struct platform_device *pdev)
659 goto clk_disable; 1203 goto clk_disable;
660 } 1204 }
661 1205
1206 pm_runtime_get_noresume(&pdev->dev);
1207 pm_runtime_set_active(&pdev->dev);
1208 pm_runtime_enable(&pdev->dev);
1209 pm_runtime_set_autosuspend_delay(&pdev->dev,
1210 MSM_MMC_AUTOSUSPEND_DELAY_MS);
1211 pm_runtime_use_autosuspend(&pdev->dev);
1212
662 ret = sdhci_add_host(host); 1213 ret = sdhci_add_host(host);
663 if (ret) 1214 if (ret)
664 goto clk_disable; 1215 goto pm_runtime_disable;
1216
1217 pm_runtime_mark_last_busy(&pdev->dev);
1218 pm_runtime_put_autosuspend(&pdev->dev);
665 1219
666 return 0; 1220 return 0;
667 1221
1222pm_runtime_disable:
1223 pm_runtime_disable(&pdev->dev);
1224 pm_runtime_set_suspended(&pdev->dev);
1225 pm_runtime_put_noidle(&pdev->dev);
668clk_disable: 1226clk_disable:
669 clk_disable_unprepare(msm_host->clk); 1227 clk_disable_unprepare(msm_host->clk);
670pclk_disable: 1228pclk_disable:
@@ -686,6 +1244,11 @@ static int sdhci_msm_remove(struct platform_device *pdev)
686 0xffffffff); 1244 0xffffffff);
687 1245
688 sdhci_remove_host(host, dead); 1246 sdhci_remove_host(host, dead);
1247
1248 pm_runtime_get_sync(&pdev->dev);
1249 pm_runtime_disable(&pdev->dev);
1250 pm_runtime_put_noidle(&pdev->dev);
1251
689 clk_disable_unprepare(msm_host->clk); 1252 clk_disable_unprepare(msm_host->clk);
690 clk_disable_unprepare(msm_host->pclk); 1253 clk_disable_unprepare(msm_host->pclk);
691 if (!IS_ERR(msm_host->bus_clk)) 1254 if (!IS_ERR(msm_host->bus_clk))
@@ -694,12 +1257,57 @@ static int sdhci_msm_remove(struct platform_device *pdev)
694 return 0; 1257 return 0;
695} 1258}
696 1259
1260#ifdef CONFIG_PM
1261static int sdhci_msm_runtime_suspend(struct device *dev)
1262{
1263 struct sdhci_host *host = dev_get_drvdata(dev);
1264 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
1265 struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
1266
1267 clk_disable_unprepare(msm_host->clk);
1268 clk_disable_unprepare(msm_host->pclk);
1269
1270 return 0;
1271}
1272
1273static int sdhci_msm_runtime_resume(struct device *dev)
1274{
1275 struct sdhci_host *host = dev_get_drvdata(dev);
1276 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
1277 struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
1278 int ret;
1279
1280 ret = clk_prepare_enable(msm_host->clk);
1281 if (ret) {
1282 dev_err(dev, "clk_enable failed for core_clk: %d\n", ret);
1283 return ret;
1284 }
1285 ret = clk_prepare_enable(msm_host->pclk);
1286 if (ret) {
1287 dev_err(dev, "clk_enable failed for iface_clk: %d\n", ret);
1288 clk_disable_unprepare(msm_host->clk);
1289 return ret;
1290 }
1291
1292 return 0;
1293}
1294#endif
1295
1296static const struct dev_pm_ops sdhci_msm_pm_ops = {
1297 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
1298 pm_runtime_force_resume)
1299 SET_RUNTIME_PM_OPS(sdhci_msm_runtime_suspend,
1300 sdhci_msm_runtime_resume,
1301 NULL)
1302};
1303
697static struct platform_driver sdhci_msm_driver = { 1304static struct platform_driver sdhci_msm_driver = {
698 .probe = sdhci_msm_probe, 1305 .probe = sdhci_msm_probe,
699 .remove = sdhci_msm_remove, 1306 .remove = sdhci_msm_remove,
700 .driver = { 1307 .driver = {
701 .name = "sdhci_msm", 1308 .name = "sdhci_msm",
702 .of_match_table = sdhci_msm_dt_match, 1309 .of_match_table = sdhci_msm_dt_match,
1310 .pm = &sdhci_msm_pm_ops,
703 }, 1311 },
704}; 1312};
705 1313
diff --git a/drivers/mmc/host/sdhci-of-at91.c b/drivers/mmc/host/sdhci-of-at91.c
index a9b7fc06c434..2f9ad213377a 100644
--- a/drivers/mmc/host/sdhci-of-at91.c
+++ b/drivers/mmc/host/sdhci-of-at91.c
@@ -100,6 +100,7 @@ static const struct of_device_id sdhci_at91_dt_match[] = {
100 { .compatible = "atmel,sama5d2-sdhci", .data = &soc_data_sama5d2 }, 100 { .compatible = "atmel,sama5d2-sdhci", .data = &soc_data_sama5d2 },
101 {} 101 {}
102}; 102};
103MODULE_DEVICE_TABLE(of, sdhci_at91_dt_match);
103 104
104#ifdef CONFIG_PM 105#ifdef CONFIG_PM
105static int sdhci_at91_runtime_suspend(struct device *dev) 106static int sdhci_at91_runtime_suspend(struct device *dev)
diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c
index 1bb11e4a9fe5..9a6eb4492172 100644
--- a/drivers/mmc/host/sdhci-of-esdhc.c
+++ b/drivers/mmc/host/sdhci-of-esdhc.c
@@ -18,6 +18,7 @@
18#include <linux/of.h> 18#include <linux/of.h>
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/sys_soc.h>
21#include <linux/mmc/host.h> 22#include <linux/mmc/host.h>
22#include "sdhci-pltfm.h" 23#include "sdhci-pltfm.h"
23#include "sdhci-esdhc.h" 24#include "sdhci-esdhc.h"
@@ -28,6 +29,7 @@
28struct sdhci_esdhc { 29struct sdhci_esdhc {
29 u8 vendor_ver; 30 u8 vendor_ver;
30 u8 spec_ver; 31 u8 spec_ver;
32 bool quirk_incorrect_hostver;
31}; 33};
32 34
33/** 35/**
@@ -87,6 +89,8 @@ static u32 esdhc_readl_fixup(struct sdhci_host *host,
87static u16 esdhc_readw_fixup(struct sdhci_host *host, 89static u16 esdhc_readw_fixup(struct sdhci_host *host,
88 int spec_reg, u32 value) 90 int spec_reg, u32 value)
89{ 91{
92 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
93 struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
90 u16 ret; 94 u16 ret;
91 int shift = (spec_reg & 0x2) * 8; 95 int shift = (spec_reg & 0x2) * 8;
92 96
@@ -94,6 +98,12 @@ static u16 esdhc_readw_fixup(struct sdhci_host *host,
94 ret = value & 0xffff; 98 ret = value & 0xffff;
95 else 99 else
96 ret = (value >> shift) & 0xffff; 100 ret = (value >> shift) & 0xffff;
101 /* Workaround for T4240-R1.0-R2.0 eSDHC which has incorrect
102 * vendor version and spec version information.
103 */
104 if ((spec_reg == SDHCI_HOST_VERSION) &&
105 (esdhc->quirk_incorrect_hostver))
106 ret = (VENDOR_V_23 << SDHCI_VENDOR_VER_SHIFT) | SDHCI_SPEC_200;
97 return ret; 107 return ret;
98} 108}
99 109
@@ -572,6 +582,12 @@ static const struct sdhci_pltfm_data sdhci_esdhc_le_pdata = {
572 .ops = &sdhci_esdhc_le_ops, 582 .ops = &sdhci_esdhc_le_ops,
573}; 583};
574 584
585static struct soc_device_attribute soc_incorrect_hostver[] = {
586 { .family = "QorIQ T4240", .revision = "1.0", },
587 { .family = "QorIQ T4240", .revision = "2.0", },
588 { },
589};
590
575static void esdhc_init(struct platform_device *pdev, struct sdhci_host *host) 591static void esdhc_init(struct platform_device *pdev, struct sdhci_host *host)
576{ 592{
577 struct sdhci_pltfm_host *pltfm_host; 593 struct sdhci_pltfm_host *pltfm_host;
@@ -585,6 +601,10 @@ static void esdhc_init(struct platform_device *pdev, struct sdhci_host *host)
585 esdhc->vendor_ver = (host_ver & SDHCI_VENDOR_VER_MASK) >> 601 esdhc->vendor_ver = (host_ver & SDHCI_VENDOR_VER_MASK) >>
586 SDHCI_VENDOR_VER_SHIFT; 602 SDHCI_VENDOR_VER_SHIFT;
587 esdhc->spec_ver = host_ver & SDHCI_SPEC_VER_MASK; 603 esdhc->spec_ver = host_ver & SDHCI_SPEC_VER_MASK;
604 if (soc_device_match(soc_incorrect_hostver))
605 esdhc->quirk_incorrect_hostver = true;
606 else
607 esdhc->quirk_incorrect_hostver = false;
588} 608}
589 609
590static int sdhci_esdhc_probe(struct platform_device *pdev) 610static int sdhci_esdhc_probe(struct platform_device *pdev)
diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c
index 1d9e00a00e9f..1a72d32af07f 100644
--- a/drivers/mmc/host/sdhci-pci-core.c
+++ b/drivers/mmc/host/sdhci-pci-core.c
@@ -27,6 +27,7 @@
27#include <linux/pm_runtime.h> 27#include <linux/pm_runtime.h>
28#include <linux/mmc/slot-gpio.h> 28#include <linux/mmc/slot-gpio.h>
29#include <linux/mmc/sdhci-pci-data.h> 29#include <linux/mmc/sdhci-pci-data.h>
30#include <linux/acpi.h>
30 31
31#include "sdhci.h" 32#include "sdhci.h"
32#include "sdhci-pci.h" 33#include "sdhci-pci.h"
@@ -375,6 +376,44 @@ static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot)
375 return 0; 376 return 0;
376} 377}
377 378
379#ifdef CONFIG_ACPI
380static int ni_set_max_freq(struct sdhci_pci_slot *slot)
381{
382 acpi_status status;
383 unsigned long long max_freq;
384
385 status = acpi_evaluate_integer(ACPI_HANDLE(&slot->chip->pdev->dev),
386 "MXFQ", NULL, &max_freq);
387 if (ACPI_FAILURE(status)) {
388 dev_err(&slot->chip->pdev->dev,
389 "MXFQ not found in acpi table\n");
390 return -EINVAL;
391 }
392
393 slot->host->mmc->f_max = max_freq * 1000000;
394
395 return 0;
396}
397#else
398static inline int ni_set_max_freq(struct sdhci_pci_slot *slot)
399{
400 return 0;
401}
402#endif
403
404static int ni_byt_sdio_probe_slot(struct sdhci_pci_slot *slot)
405{
406 int err;
407
408 err = ni_set_max_freq(slot);
409 if (err)
410 return err;
411
412 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE |
413 MMC_CAP_WAIT_WHILE_BUSY;
414 return 0;
415}
416
378static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot) 417static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot)
379{ 418{
380 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE | 419 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE |
@@ -390,7 +429,8 @@ static int byt_sd_probe_slot(struct sdhci_pci_slot *slot)
390 slot->cd_override_level = true; 429 slot->cd_override_level = true;
391 if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXT_SD || 430 if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXT_SD ||
392 slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXTM_SD || 431 slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXTM_SD ||
393 slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_APL_SD) { 432 slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_APL_SD ||
433 slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_GLK_SD) {
394 slot->host->mmc_host_ops.get_cd = bxt_get_cd; 434 slot->host->mmc_host_ops.get_cd = bxt_get_cd;
395 slot->host->mmc->caps |= MMC_CAP_AGGRESSIVE_PM; 435 slot->host->mmc->caps |= MMC_CAP_AGGRESSIVE_PM;
396 } 436 }
@@ -447,6 +487,15 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = {
447 .ops = &sdhci_intel_byt_ops, 487 .ops = &sdhci_intel_byt_ops,
448}; 488};
449 489
490static const struct sdhci_pci_fixes sdhci_ni_byt_sdio = {
491 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
492 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON |
493 SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
494 .allow_runtime_pm = true,
495 .probe_slot = ni_byt_sdio_probe_slot,
496 .ops = &sdhci_intel_byt_ops,
497};
498
450static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = { 499static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
451 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 500 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
452 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON | 501 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON |
@@ -1079,6 +1128,14 @@ static const struct pci_device_id pci_ids[] = {
1079 { 1128 {
1080 .vendor = PCI_VENDOR_ID_INTEL, 1129 .vendor = PCI_VENDOR_ID_INTEL,
1081 .device = PCI_DEVICE_ID_INTEL_BYT_SDIO, 1130 .device = PCI_DEVICE_ID_INTEL_BYT_SDIO,
1131 .subvendor = PCI_VENDOR_ID_NI,
1132 .subdevice = 0x7884,
1133 .driver_data = (kernel_ulong_t)&sdhci_ni_byt_sdio,
1134 },
1135
1136 {
1137 .vendor = PCI_VENDOR_ID_INTEL,
1138 .device = PCI_DEVICE_ID_INTEL_BYT_SDIO,
1082 .subvendor = PCI_ANY_ID, 1139 .subvendor = PCI_ANY_ID,
1083 .subdevice = PCI_ANY_ID, 1140 .subdevice = PCI_ANY_ID,
1084 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio, 1141 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
@@ -1277,6 +1334,30 @@ static const struct pci_device_id pci_ids[] = {
1277 }, 1334 },
1278 1335
1279 { 1336 {
1337 .vendor = PCI_VENDOR_ID_INTEL,
1338 .device = PCI_DEVICE_ID_INTEL_GLK_EMMC,
1339 .subvendor = PCI_ANY_ID,
1340 .subdevice = PCI_ANY_ID,
1341 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
1342 },
1343
1344 {
1345 .vendor = PCI_VENDOR_ID_INTEL,
1346 .device = PCI_DEVICE_ID_INTEL_GLK_SDIO,
1347 .subvendor = PCI_ANY_ID,
1348 .subdevice = PCI_ANY_ID,
1349 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
1350 },
1351
1352 {
1353 .vendor = PCI_VENDOR_ID_INTEL,
1354 .device = PCI_DEVICE_ID_INTEL_GLK_SD,
1355 .subvendor = PCI_ANY_ID,
1356 .subdevice = PCI_ANY_ID,
1357 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
1358 },
1359
1360 {
1280 .vendor = PCI_VENDOR_ID_O2, 1361 .vendor = PCI_VENDOR_ID_O2,
1281 .device = PCI_DEVICE_ID_O2_8120, 1362 .device = PCI_DEVICE_ID_O2_8120,
1282 .subvendor = PCI_ANY_ID, 1363 .subvendor = PCI_ANY_ID,
@@ -1735,11 +1816,16 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
1735 host->mmc->slotno = slotno; 1816 host->mmc->slotno = slotno;
1736 host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP; 1817 host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
1737 1818
1738 if (slot->cd_idx >= 0 && 1819 if (slot->cd_idx >= 0) {
1739 mmc_gpiod_request_cd(host->mmc, slot->cd_con_id, slot->cd_idx, 1820 ret = mmc_gpiod_request_cd(host->mmc, slot->cd_con_id, slot->cd_idx,
1740 slot->cd_override_level, 0, NULL)) { 1821 slot->cd_override_level, 0, NULL);
1741 dev_warn(&pdev->dev, "failed to setup card detect gpio\n"); 1822 if (ret == -EPROBE_DEFER)
1742 slot->cd_idx = -1; 1823 goto remove;
1824
1825 if (ret) {
1826 dev_warn(&pdev->dev, "failed to setup card detect gpio\n");
1827 slot->cd_idx = -1;
1828 }
1743 } 1829 }
1744 1830
1745 ret = sdhci_add_host(host); 1831 ret = sdhci_add_host(host);
diff --git a/drivers/mmc/host/sdhci-pci.h b/drivers/mmc/host/sdhci-pci.h
index 6bccf56bc5ff..4abdaed72bd4 100644
--- a/drivers/mmc/host/sdhci-pci.h
+++ b/drivers/mmc/host/sdhci-pci.h
@@ -34,6 +34,9 @@
34#define PCI_DEVICE_ID_INTEL_APL_SD 0x5aca 34#define PCI_DEVICE_ID_INTEL_APL_SD 0x5aca
35#define PCI_DEVICE_ID_INTEL_APL_EMMC 0x5acc 35#define PCI_DEVICE_ID_INTEL_APL_EMMC 0x5acc
36#define PCI_DEVICE_ID_INTEL_APL_SDIO 0x5ad0 36#define PCI_DEVICE_ID_INTEL_APL_SDIO 0x5ad0
37#define PCI_DEVICE_ID_INTEL_GLK_SD 0x31ca
38#define PCI_DEVICE_ID_INTEL_GLK_EMMC 0x31cc
39#define PCI_DEVICE_ID_INTEL_GLK_SDIO 0x31d0
37 40
38/* 41/*
39 * PCI registers 42 * PCI registers
diff --git a/drivers/mmc/host/sdhci-pltfm.h b/drivers/mmc/host/sdhci-pltfm.h
index 3280f2077959..957839d0fe37 100644
--- a/drivers/mmc/host/sdhci-pltfm.h
+++ b/drivers/mmc/host/sdhci-pltfm.h
@@ -106,7 +106,7 @@ extern unsigned int sdhci_pltfm_clk_get_max_clock(struct sdhci_host *host);
106 106
107static inline void *sdhci_pltfm_priv(struct sdhci_pltfm_host *host) 107static inline void *sdhci_pltfm_priv(struct sdhci_pltfm_host *host)
108{ 108{
109 return (void *)host->private; 109 return host->private;
110} 110}
111 111
112extern const struct dev_pm_ops sdhci_pltfm_pmops; 112extern const struct dev_pm_ops sdhci_pltfm_pmops;
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index 784c5a848fb4..de219ca7ea7c 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -121,7 +121,9 @@ static unsigned int sdhci_s3c_consider_clock(struct sdhci_s3c *ourhost,
121 * speed possible with selected clock source and skip the division. 121 * speed possible with selected clock source and skip the division.
122 */ 122 */
123 if (ourhost->no_divider) { 123 if (ourhost->no_divider) {
124 spin_unlock_irq(&ourhost->host->lock);
124 rate = clk_round_rate(clksrc, wanted); 125 rate = clk_round_rate(clksrc, wanted);
126 spin_lock_irq(&ourhost->host->lock);
125 return wanted - rate; 127 return wanted - rate;
126 } 128 }
127 129
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 42ef3ebb1d8c..111991e5b9a0 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -22,6 +22,7 @@
22#include <linux/scatterlist.h> 22#include <linux/scatterlist.h>
23#include <linux/regulator/consumer.h> 23#include <linux/regulator/consumer.h>
24#include <linux/pm_runtime.h> 24#include <linux/pm_runtime.h>
25#include <linux/of.h>
25 26
26#include <linux/leds.h> 27#include <linux/leds.h>
27 28
@@ -1343,20 +1344,10 @@ clock_set:
1343} 1344}
1344EXPORT_SYMBOL_GPL(sdhci_calc_clk); 1345EXPORT_SYMBOL_GPL(sdhci_calc_clk);
1345 1346
1346void sdhci_set_clock(struct sdhci_host *host, unsigned int clock) 1347void sdhci_enable_clk(struct sdhci_host *host, u16 clk)
1347{ 1348{
1348 u16 clk;
1349 unsigned long timeout; 1349 unsigned long timeout;
1350 1350
1351 host->mmc->actual_clock = 0;
1352
1353 sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
1354
1355 if (clock == 0)
1356 return;
1357
1358 clk = sdhci_calc_clk(host, clock, &host->mmc->actual_clock);
1359
1360 clk |= SDHCI_CLOCK_INT_EN; 1351 clk |= SDHCI_CLOCK_INT_EN;
1361 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); 1352 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
1362 1353
@@ -1377,6 +1368,22 @@ void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
1377 clk |= SDHCI_CLOCK_CARD_EN; 1368 clk |= SDHCI_CLOCK_CARD_EN;
1378 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); 1369 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
1379} 1370}
1371EXPORT_SYMBOL_GPL(sdhci_enable_clk);
1372
1373void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
1374{
1375 u16 clk;
1376
1377 host->mmc->actual_clock = 0;
1378
1379 sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
1380
1381 if (clock == 0)
1382 return;
1383
1384 clk = sdhci_calc_clk(host, clock, &host->mmc->actual_clock);
1385 sdhci_enable_clk(host, clk);
1386}
1380EXPORT_SYMBOL_GPL(sdhci_set_clock); 1387EXPORT_SYMBOL_GPL(sdhci_set_clock);
1381 1388
1382static void sdhci_set_power_reg(struct sdhci_host *host, unsigned char mode, 1389static void sdhci_set_power_reg(struct sdhci_host *host, unsigned char mode,
@@ -1623,7 +1630,14 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1623 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); 1630 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
1624 1631
1625 if ((ios->timing == MMC_TIMING_SD_HS || 1632 if ((ios->timing == MMC_TIMING_SD_HS ||
1626 ios->timing == MMC_TIMING_MMC_HS) 1633 ios->timing == MMC_TIMING_MMC_HS ||
1634 ios->timing == MMC_TIMING_MMC_HS400 ||
1635 ios->timing == MMC_TIMING_MMC_HS200 ||
1636 ios->timing == MMC_TIMING_MMC_DDR52 ||
1637 ios->timing == MMC_TIMING_UHS_SDR50 ||
1638 ios->timing == MMC_TIMING_UHS_SDR104 ||
1639 ios->timing == MMC_TIMING_UHS_DDR50 ||
1640 ios->timing == MMC_TIMING_UHS_SDR25)
1627 && !(host->quirks & SDHCI_QUIRK_NO_HISPD_BIT)) 1641 && !(host->quirks & SDHCI_QUIRK_NO_HISPD_BIT))
1628 ctrl |= SDHCI_CTRL_HISPD; 1642 ctrl |= SDHCI_CTRL_HISPD;
1629 else 1643 else
@@ -1632,16 +1646,6 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1632 if (host->version >= SDHCI_SPEC_300) { 1646 if (host->version >= SDHCI_SPEC_300) {
1633 u16 clk, ctrl_2; 1647 u16 clk, ctrl_2;
1634 1648
1635 /* In case of UHS-I modes, set High Speed Enable */
1636 if ((ios->timing == MMC_TIMING_MMC_HS400) ||
1637 (ios->timing == MMC_TIMING_MMC_HS200) ||
1638 (ios->timing == MMC_TIMING_MMC_DDR52) ||
1639 (ios->timing == MMC_TIMING_UHS_SDR50) ||
1640 (ios->timing == MMC_TIMING_UHS_SDR104) ||
1641 (ios->timing == MMC_TIMING_UHS_DDR50) ||
1642 (ios->timing == MMC_TIMING_UHS_SDR25))
1643 ctrl |= SDHCI_CTRL_HISPD;
1644
1645 if (!host->preset_enabled) { 1649 if (!host->preset_enabled) {
1646 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); 1650 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
1647 /* 1651 /*
@@ -1948,11 +1952,157 @@ static int sdhci_prepare_hs400_tuning(struct mmc_host *mmc, struct mmc_ios *ios)
1948 return 0; 1952 return 0;
1949} 1953}
1950 1954
1951static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) 1955static void sdhci_start_tuning(struct sdhci_host *host)
1952{ 1956{
1953 struct sdhci_host *host = mmc_priv(mmc);
1954 u16 ctrl; 1957 u16 ctrl;
1955 int tuning_loop_counter = MAX_TUNING_LOOP; 1958
1959 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
1960 ctrl |= SDHCI_CTRL_EXEC_TUNING;
1961 if (host->quirks2 & SDHCI_QUIRK2_TUNING_WORK_AROUND)
1962 ctrl |= SDHCI_CTRL_TUNED_CLK;
1963 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
1964
1965 /*
1966 * As per the Host Controller spec v3.00, tuning command
1967 * generates Buffer Read Ready interrupt, so enable that.
1968 *
1969 * Note: The spec clearly says that when tuning sequence
1970 * is being performed, the controller does not generate
1971 * interrupts other than Buffer Read Ready interrupt. But
1972 * to make sure we don't hit a controller bug, we _only_
1973 * enable Buffer Read Ready interrupt here.
1974 */
1975 sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_INT_ENABLE);
1976 sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_SIGNAL_ENABLE);
1977}
1978
1979static void sdhci_end_tuning(struct sdhci_host *host)
1980{
1981 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
1982 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
1983}
1984
1985static void sdhci_reset_tuning(struct sdhci_host *host)
1986{
1987 u16 ctrl;
1988
1989 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
1990 ctrl &= ~SDHCI_CTRL_TUNED_CLK;
1991 ctrl &= ~SDHCI_CTRL_EXEC_TUNING;
1992 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
1993}
1994
1995static void sdhci_abort_tuning(struct sdhci_host *host, u32 opcode,
1996 unsigned long flags)
1997{
1998 sdhci_reset_tuning(host);
1999
2000 sdhci_do_reset(host, SDHCI_RESET_CMD);
2001 sdhci_do_reset(host, SDHCI_RESET_DATA);
2002
2003 sdhci_end_tuning(host);
2004
2005 spin_unlock_irqrestore(&host->lock, flags);
2006 mmc_abort_tuning(host->mmc, opcode);
2007 spin_lock_irqsave(&host->lock, flags);
2008}
2009
2010/*
2011 * We use sdhci_send_tuning() because mmc_send_tuning() is not a good fit. SDHCI
2012 * tuning command does not have a data payload (or rather the hardware does it
2013 * automatically) so mmc_send_tuning() will return -EIO. Also the tuning command
2014 * interrupt setup is different to other commands and there is no timeout
2015 * interrupt so special handling is needed.
2016 */
2017static void sdhci_send_tuning(struct sdhci_host *host, u32 opcode,
2018 unsigned long flags)
2019{
2020 struct mmc_host *mmc = host->mmc;
2021 struct mmc_command cmd = {0};
2022 struct mmc_request mrq = {NULL};
2023
2024 cmd.opcode = opcode;
2025 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
2026 cmd.mrq = &mrq;
2027
2028 mrq.cmd = &cmd;
2029 /*
2030 * In response to CMD19, the card sends 64 bytes of tuning
2031 * block to the Host Controller. So we set the block size
2032 * to 64 here.
2033 */
2034 if (cmd.opcode == MMC_SEND_TUNING_BLOCK_HS200 &&
2035 mmc->ios.bus_width == MMC_BUS_WIDTH_8)
2036 sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 128), SDHCI_BLOCK_SIZE);
2037 else
2038 sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 64), SDHCI_BLOCK_SIZE);
2039
2040 /*
2041 * The tuning block is sent by the card to the host controller.
2042 * So we set the TRNS_READ bit in the Transfer Mode register.
2043 * This also takes care of setting DMA Enable and Multi Block
2044 * Select in the same register to 0.
2045 */
2046 sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE);
2047
2048 sdhci_send_command(host, &cmd);
2049
2050 host->cmd = NULL;
2051
2052 sdhci_del_timer(host, &mrq);
2053
2054 host->tuning_done = 0;
2055
2056 spin_unlock_irqrestore(&host->lock, flags);
2057
2058 /* Wait for Buffer Read Ready interrupt */
2059 wait_event_timeout(host->buf_ready_int, (host->tuning_done == 1),
2060 msecs_to_jiffies(50));
2061
2062 spin_lock_irqsave(&host->lock, flags);
2063}
2064
2065static void __sdhci_execute_tuning(struct sdhci_host *host, u32 opcode,
2066 unsigned long flags)
2067{
2068 int i;
2069
2070 /*
2071 * Issue opcode repeatedly till Execute Tuning is set to 0 or the number
2072 * of loops reaches 40 times.
2073 */
2074 for (i = 0; i < MAX_TUNING_LOOP; i++) {
2075 u16 ctrl;
2076
2077 sdhci_send_tuning(host, opcode, flags);
2078
2079 if (!host->tuning_done) {
2080 pr_info("%s: Tuning timeout, falling back to fixed sampling clock\n",
2081 mmc_hostname(host->mmc));
2082 sdhci_abort_tuning(host, opcode, flags);
2083 return;
2084 }
2085
2086 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
2087 if (!(ctrl & SDHCI_CTRL_EXEC_TUNING)) {
2088 if (ctrl & SDHCI_CTRL_TUNED_CLK)
2089 return; /* Success! */
2090 break;
2091 }
2092
2093 /* eMMC spec does not require a delay between tuning cycles */
2094 if (opcode == MMC_SEND_TUNING_BLOCK)
2095 mdelay(1);
2096 }
2097
2098 pr_info("%s: Tuning failed, falling back to fixed sampling clock\n",
2099 mmc_hostname(host->mmc));
2100 sdhci_reset_tuning(host);
2101}
2102
2103int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
2104{
2105 struct sdhci_host *host = mmc_priv(mmc);
1956 int err = 0; 2106 int err = 0;
1957 unsigned long flags; 2107 unsigned long flags;
1958 unsigned int tuning_count = 0; 2108 unsigned int tuning_count = 0;
@@ -2003,144 +2153,22 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
2003 2153
2004 if (host->ops->platform_execute_tuning) { 2154 if (host->ops->platform_execute_tuning) {
2005 spin_unlock_irqrestore(&host->lock, flags); 2155 spin_unlock_irqrestore(&host->lock, flags);
2006 err = host->ops->platform_execute_tuning(host, opcode); 2156 return host->ops->platform_execute_tuning(host, opcode);
2007 return err;
2008 } 2157 }
2009 2158
2010 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); 2159 host->mmc->retune_period = tuning_count;
2011 ctrl |= SDHCI_CTRL_EXEC_TUNING;
2012 if (host->quirks2 & SDHCI_QUIRK2_TUNING_WORK_AROUND)
2013 ctrl |= SDHCI_CTRL_TUNED_CLK;
2014 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
2015
2016 /*
2017 * As per the Host Controller spec v3.00, tuning command
2018 * generates Buffer Read Ready interrupt, so enable that.
2019 *
2020 * Note: The spec clearly says that when tuning sequence
2021 * is being performed, the controller does not generate
2022 * interrupts other than Buffer Read Ready interrupt. But
2023 * to make sure we don't hit a controller bug, we _only_
2024 * enable Buffer Read Ready interrupt here.
2025 */
2026 sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_INT_ENABLE);
2027 sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_SIGNAL_ENABLE);
2028
2029 /*
2030 * Issue CMD19 repeatedly till Execute Tuning is set to 0 or the number
2031 * of loops reaches 40 times.
2032 */
2033 do {
2034 struct mmc_command cmd = {0};
2035 struct mmc_request mrq = {NULL};
2036
2037 cmd.opcode = opcode;
2038 cmd.arg = 0;
2039 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
2040 cmd.retries = 0;
2041 cmd.data = NULL;
2042 cmd.mrq = &mrq;
2043 cmd.error = 0;
2044
2045 if (tuning_loop_counter-- == 0)
2046 break;
2047
2048 mrq.cmd = &cmd;
2049
2050 /*
2051 * In response to CMD19, the card sends 64 bytes of tuning
2052 * block to the Host Controller. So we set the block size
2053 * to 64 here.
2054 */
2055 if (cmd.opcode == MMC_SEND_TUNING_BLOCK_HS200) {
2056 if (mmc->ios.bus_width == MMC_BUS_WIDTH_8)
2057 sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 128),
2058 SDHCI_BLOCK_SIZE);
2059 else if (mmc->ios.bus_width == MMC_BUS_WIDTH_4)
2060 sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 64),
2061 SDHCI_BLOCK_SIZE);
2062 } else {
2063 sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 64),
2064 SDHCI_BLOCK_SIZE);
2065 }
2066
2067 /*
2068 * The tuning block is sent by the card to the host controller.
2069 * So we set the TRNS_READ bit in the Transfer Mode register.
2070 * This also takes care of setting DMA Enable and Multi Block
2071 * Select in the same register to 0.
2072 */
2073 sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE);
2074
2075 sdhci_send_command(host, &cmd);
2076
2077 host->cmd = NULL;
2078 sdhci_del_timer(host, &mrq);
2079
2080 spin_unlock_irqrestore(&host->lock, flags);
2081 /* Wait for Buffer Read Ready interrupt */
2082 wait_event_timeout(host->buf_ready_int,
2083 (host->tuning_done == 1),
2084 msecs_to_jiffies(50));
2085 spin_lock_irqsave(&host->lock, flags);
2086
2087 if (!host->tuning_done) {
2088 pr_info(DRIVER_NAME ": Timeout waiting for Buffer Read Ready interrupt during tuning procedure, falling back to fixed sampling clock\n");
2089
2090 sdhci_do_reset(host, SDHCI_RESET_CMD);
2091 sdhci_do_reset(host, SDHCI_RESET_DATA);
2092
2093 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
2094 ctrl &= ~SDHCI_CTRL_TUNED_CLK;
2095 ctrl &= ~SDHCI_CTRL_EXEC_TUNING;
2096 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
2097
2098 err = -EIO;
2099 goto out;
2100 }
2101 2160
2102 host->tuning_done = 0; 2161 sdhci_start_tuning(host);
2103 2162
2104 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); 2163 __sdhci_execute_tuning(host, opcode, flags);
2105 2164
2106 /* eMMC spec does not require a delay between tuning cycles */ 2165 sdhci_end_tuning(host);
2107 if (opcode == MMC_SEND_TUNING_BLOCK)
2108 mdelay(1);
2109 } while (ctrl & SDHCI_CTRL_EXEC_TUNING);
2110
2111 /*
2112 * The Host Driver has exhausted the maximum number of loops allowed,
2113 * so use fixed sampling frequency.
2114 */
2115 if (tuning_loop_counter < 0) {
2116 ctrl &= ~SDHCI_CTRL_TUNED_CLK;
2117 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
2118 }
2119 if (!(ctrl & SDHCI_CTRL_TUNED_CLK)) {
2120 pr_info(DRIVER_NAME ": Tuning procedure failed, falling back to fixed sampling clock\n");
2121 err = -EIO;
2122 }
2123
2124out:
2125 if (tuning_count) {
2126 /*
2127 * In case tuning fails, host controllers which support
2128 * re-tuning can try tuning again at a later time, when the
2129 * re-tuning timer expires. So for these controllers, we
2130 * return 0. Since there might be other controllers who do not
2131 * have this capability, we return error for them.
2132 */
2133 err = 0;
2134 }
2135
2136 host->mmc->retune_period = err ? 0 : tuning_count;
2137
2138 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
2139 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
2140out_unlock: 2166out_unlock:
2141 spin_unlock_irqrestore(&host->lock, flags); 2167 spin_unlock_irqrestore(&host->lock, flags);
2168
2142 return err; 2169 return err;
2143} 2170}
2171EXPORT_SYMBOL_GPL(sdhci_execute_tuning);
2144 2172
2145static int sdhci_select_drive_strength(struct mmc_card *card, 2173static int sdhci_select_drive_strength(struct mmc_card *card,
2146 unsigned int max_dtr, int host_drv, 2174 unsigned int max_dtr, int host_drv,
@@ -2198,8 +2226,7 @@ static void sdhci_post_req(struct mmc_host *mmc, struct mmc_request *mrq,
2198 data->host_cookie = COOKIE_UNMAPPED; 2226 data->host_cookie = COOKIE_UNMAPPED;
2199} 2227}
2200 2228
2201static void sdhci_pre_req(struct mmc_host *mmc, struct mmc_request *mrq, 2229static void sdhci_pre_req(struct mmc_host *mmc, struct mmc_request *mrq)
2202 bool is_first_req)
2203{ 2230{
2204 struct sdhci_host *host = mmc_priv(mmc); 2231 struct sdhci_host *host = mmc_priv(mmc);
2205 2232
@@ -3010,6 +3037,8 @@ static int sdhci_set_dma_mask(struct sdhci_host *host)
3010void __sdhci_read_caps(struct sdhci_host *host, u16 *ver, u32 *caps, u32 *caps1) 3037void __sdhci_read_caps(struct sdhci_host *host, u16 *ver, u32 *caps, u32 *caps1)
3011{ 3038{
3012 u16 v; 3039 u16 v;
3040 u64 dt_caps_mask = 0;
3041 u64 dt_caps = 0;
3013 3042
3014 if (host->read_caps) 3043 if (host->read_caps)
3015 return; 3044 return;
@@ -3024,18 +3053,35 @@ void __sdhci_read_caps(struct sdhci_host *host, u16 *ver, u32 *caps, u32 *caps1)
3024 3053
3025 sdhci_do_reset(host, SDHCI_RESET_ALL); 3054 sdhci_do_reset(host, SDHCI_RESET_ALL);
3026 3055
3056 of_property_read_u64(mmc_dev(host->mmc)->of_node,
3057 "sdhci-caps-mask", &dt_caps_mask);
3058 of_property_read_u64(mmc_dev(host->mmc)->of_node,
3059 "sdhci-caps", &dt_caps);
3060
3027 v = ver ? *ver : sdhci_readw(host, SDHCI_HOST_VERSION); 3061 v = ver ? *ver : sdhci_readw(host, SDHCI_HOST_VERSION);
3028 host->version = (v & SDHCI_SPEC_VER_MASK) >> SDHCI_SPEC_VER_SHIFT; 3062 host->version = (v & SDHCI_SPEC_VER_MASK) >> SDHCI_SPEC_VER_SHIFT;
3029 3063
3030 if (host->quirks & SDHCI_QUIRK_MISSING_CAPS) 3064 if (host->quirks & SDHCI_QUIRK_MISSING_CAPS)
3031 return; 3065 return;
3032 3066
3033 host->caps = caps ? *caps : sdhci_readl(host, SDHCI_CAPABILITIES); 3067 if (caps) {
3068 host->caps = *caps;
3069 } else {
3070 host->caps = sdhci_readl(host, SDHCI_CAPABILITIES);
3071 host->caps &= ~lower_32_bits(dt_caps_mask);
3072 host->caps |= lower_32_bits(dt_caps);
3073 }
3034 3074
3035 if (host->version < SDHCI_SPEC_300) 3075 if (host->version < SDHCI_SPEC_300)
3036 return; 3076 return;
3037 3077
3038 host->caps1 = caps1 ? *caps1 : sdhci_readl(host, SDHCI_CAPABILITIES_1); 3078 if (caps1) {
3079 host->caps1 = *caps1;
3080 } else {
3081 host->caps1 = sdhci_readl(host, SDHCI_CAPABILITIES_1);
3082 host->caps1 &= ~upper_32_bits(dt_caps_mask);
3083 host->caps1 |= upper_32_bits(dt_caps);
3084 }
3039} 3085}
3040EXPORT_SYMBOL_GPL(__sdhci_read_caps); 3086EXPORT_SYMBOL_GPL(__sdhci_read_caps);
3041 3087
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index 2570455b219a..0b66f210ae82 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -656,7 +656,7 @@ extern void sdhci_free_host(struct sdhci_host *host);
656 656
657static inline void *sdhci_priv(struct sdhci_host *host) 657static inline void *sdhci_priv(struct sdhci_host *host)
658{ 658{
659 return (void *)host->private; 659 return host->private;
660} 660}
661 661
662extern void sdhci_card_detect(struct sdhci_host *host); 662extern void sdhci_card_detect(struct sdhci_host *host);
@@ -682,6 +682,7 @@ static inline bool sdhci_sdio_irq_enabled(struct sdhci_host *host)
682u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock, 682u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock,
683 unsigned int *actual_clock); 683 unsigned int *actual_clock);
684void sdhci_set_clock(struct sdhci_host *host, unsigned int clock); 684void sdhci_set_clock(struct sdhci_host *host, unsigned int clock);
685void sdhci_enable_clk(struct sdhci_host *host, u16 clk);
685void sdhci_set_power(struct sdhci_host *host, unsigned char mode, 686void sdhci_set_power(struct sdhci_host *host, unsigned char mode,
686 unsigned short vdd); 687 unsigned short vdd);
687void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode, 688void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode,
@@ -689,6 +690,7 @@ void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode,
689void sdhci_set_bus_width(struct sdhci_host *host, int width); 690void sdhci_set_bus_width(struct sdhci_host *host, int width);
690void sdhci_reset(struct sdhci_host *host, u8 mask); 691void sdhci_reset(struct sdhci_host *host, u8 mask);
691void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing); 692void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing);
693int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode);
692 694
693#ifdef CONFIG_PM 695#ifdef CONFIG_PM
694extern int sdhci_suspend_host(struct sdhci_host *host); 696extern int sdhci_suspend_host(struct sdhci_host *host);
diff --git a/drivers/mmc/host/sh_mobile_sdhi.c b/drivers/mmc/host/sh_mobile_sdhi.c
index 49edff7fee49..d46c2d00c182 100644
--- a/drivers/mmc/host/sh_mobile_sdhi.c
+++ b/drivers/mmc/host/sh_mobile_sdhi.c
@@ -47,31 +47,69 @@
47 47
48#define host_to_priv(host) container_of((host)->pdata, struct sh_mobile_sdhi, mmc_data) 48#define host_to_priv(host) container_of((host)->pdata, struct sh_mobile_sdhi, mmc_data)
49 49
50struct sh_mobile_sdhi_scc {
51 unsigned long clk_rate; /* clock rate for SDR104 */
52 u32 tap; /* sampling clock position for SDR104 */
53};
54
50struct sh_mobile_sdhi_of_data { 55struct sh_mobile_sdhi_of_data {
51 unsigned long tmio_flags; 56 unsigned long tmio_flags;
57 u32 tmio_ocr_mask;
52 unsigned long capabilities; 58 unsigned long capabilities;
53 unsigned long capabilities2; 59 unsigned long capabilities2;
54 enum dma_slave_buswidth dma_buswidth; 60 enum dma_slave_buswidth dma_buswidth;
55 dma_addr_t dma_rx_offset; 61 dma_addr_t dma_rx_offset;
56 unsigned bus_shift; 62 unsigned bus_shift;
63 int scc_offset;
64 struct sh_mobile_sdhi_scc *taps;
65 int taps_num;
57}; 66};
58 67
59static const struct sh_mobile_sdhi_of_data of_default_cfg = { 68static const struct sh_mobile_sdhi_of_data of_default_cfg = {
60 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT, 69 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
61}; 70};
62 71
72static const struct sh_mobile_sdhi_of_data of_rz_compatible = {
73 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_32BIT_DATA_PORT,
74 .tmio_ocr_mask = MMC_VDD_32_33,
75 .capabilities = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
76};
77
63static const struct sh_mobile_sdhi_of_data of_rcar_gen1_compatible = { 78static const struct sh_mobile_sdhi_of_data of_rcar_gen1_compatible = {
64 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_WRPROTECT_DISABLE | 79 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_WRPROTECT_DISABLE |
65 TMIO_MMC_CLK_ACTUAL, 80 TMIO_MMC_CLK_ACTUAL,
66 .capabilities = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ, 81 .capabilities = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
67}; 82};
68 83
84/* Definitions for sampling clocks */
85static struct sh_mobile_sdhi_scc rcar_gen2_scc_taps[] = {
86 {
87 .clk_rate = 156000000,
88 .tap = 0x00000703,
89 },
90 {
91 .clk_rate = 0,
92 .tap = 0x00000300,
93 },
94};
95
69static const struct sh_mobile_sdhi_of_data of_rcar_gen2_compatible = { 96static const struct sh_mobile_sdhi_of_data of_rcar_gen2_compatible = {
70 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_WRPROTECT_DISABLE | 97 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_WRPROTECT_DISABLE |
71 TMIO_MMC_CLK_ACTUAL | TMIO_MMC_MIN_RCAR2, 98 TMIO_MMC_CLK_ACTUAL | TMIO_MMC_MIN_RCAR2,
72 .capabilities = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ, 99 .capabilities = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
73 .dma_buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES, 100 .dma_buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES,
74 .dma_rx_offset = 0x2000, 101 .dma_rx_offset = 0x2000,
102 .scc_offset = 0x0300,
103 .taps = rcar_gen2_scc_taps,
104 .taps_num = ARRAY_SIZE(rcar_gen2_scc_taps),
105};
106
107/* Definitions for sampling clocks */
108static struct sh_mobile_sdhi_scc rcar_gen3_scc_taps[] = {
109 {
110 .clk_rate = 0,
111 .tap = 0x00000300,
112 },
75}; 113};
76 114
77static const struct sh_mobile_sdhi_of_data of_rcar_gen3_compatible = { 115static const struct sh_mobile_sdhi_of_data of_rcar_gen3_compatible = {
@@ -79,6 +117,9 @@ static const struct sh_mobile_sdhi_of_data of_rcar_gen3_compatible = {
79 TMIO_MMC_CLK_ACTUAL | TMIO_MMC_MIN_RCAR2, 117 TMIO_MMC_CLK_ACTUAL | TMIO_MMC_MIN_RCAR2,
80 .capabilities = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ, 118 .capabilities = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
81 .bus_shift = 2, 119 .bus_shift = 2,
120 .scc_offset = 0x1000,
121 .taps = rcar_gen3_scc_taps,
122 .taps_num = ARRAY_SIZE(rcar_gen3_scc_taps),
82}; 123};
83 124
84static const struct of_device_id sh_mobile_sdhi_of_match[] = { 125static const struct of_device_id sh_mobile_sdhi_of_match[] = {
@@ -86,6 +127,7 @@ static const struct of_device_id sh_mobile_sdhi_of_match[] = {
86 { .compatible = "renesas,sdhi-sh73a0", .data = &of_default_cfg, }, 127 { .compatible = "renesas,sdhi-sh73a0", .data = &of_default_cfg, },
87 { .compatible = "renesas,sdhi-r8a73a4", .data = &of_default_cfg, }, 128 { .compatible = "renesas,sdhi-r8a73a4", .data = &of_default_cfg, },
88 { .compatible = "renesas,sdhi-r8a7740", .data = &of_default_cfg, }, 129 { .compatible = "renesas,sdhi-r8a7740", .data = &of_default_cfg, },
130 { .compatible = "renesas,sdhi-r7s72100", .data = &of_rz_compatible, },
89 { .compatible = "renesas,sdhi-r8a7778", .data = &of_rcar_gen1_compatible, }, 131 { .compatible = "renesas,sdhi-r8a7778", .data = &of_rcar_gen1_compatible, },
90 { .compatible = "renesas,sdhi-r8a7779", .data = &of_rcar_gen1_compatible, }, 132 { .compatible = "renesas,sdhi-r8a7779", .data = &of_rcar_gen1_compatible, },
91 { .compatible = "renesas,sdhi-r8a7790", .data = &of_rcar_gen2_compatible, }, 133 { .compatible = "renesas,sdhi-r8a7790", .data = &of_rcar_gen2_compatible, },
@@ -105,6 +147,7 @@ struct sh_mobile_sdhi {
105 struct tmio_mmc_dma dma_priv; 147 struct tmio_mmc_dma dma_priv;
106 struct pinctrl *pinctrl; 148 struct pinctrl *pinctrl;
107 struct pinctrl_state *pins_default, *pins_uhs; 149 struct pinctrl_state *pins_default, *pins_uhs;
150 void __iomem *scc_ctl;
108}; 151};
109 152
110static void sh_mobile_sdhi_sdbuf_width(struct tmio_mmc_host *host, int width) 153static void sh_mobile_sdhi_sdbuf_width(struct tmio_mmc_host *host, int width)
@@ -255,6 +298,201 @@ static int sh_mobile_sdhi_start_signal_voltage_switch(struct mmc_host *mmc,
255 return pinctrl_select_state(priv->pinctrl, pin_state); 298 return pinctrl_select_state(priv->pinctrl, pin_state);
256} 299}
257 300
301/* SCC registers */
302#define SH_MOBILE_SDHI_SCC_DTCNTL 0x000
303#define SH_MOBILE_SDHI_SCC_TAPSET 0x002
304#define SH_MOBILE_SDHI_SCC_DT2FF 0x004
305#define SH_MOBILE_SDHI_SCC_CKSEL 0x006
306#define SH_MOBILE_SDHI_SCC_RVSCNTL 0x008
307#define SH_MOBILE_SDHI_SCC_RVSREQ 0x00A
308
309/* Definitions for values the SH_MOBILE_SDHI_SCC_DTCNTL register */
310#define SH_MOBILE_SDHI_SCC_DTCNTL_TAPEN BIT(0)
311#define SH_MOBILE_SDHI_SCC_DTCNTL_TAPNUM_SHIFT 16
312#define SH_MOBILE_SDHI_SCC_DTCNTL_TAPNUM_MASK 0xff
313
314/* Definitions for values the SH_MOBILE_SDHI_SCC_CKSEL register */
315#define SH_MOBILE_SDHI_SCC_CKSEL_DTSEL BIT(0)
316/* Definitions for values the SH_MOBILE_SDHI_SCC_RVSCNTL register */
317#define SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN BIT(0)
318/* Definitions for values the SH_MOBILE_SDHI_SCC_RVSREQ register */
319#define SH_MOBILE_SDHI_SCC_RVSREQ_RVSERR BIT(2)
320
321static inline u32 sd_scc_read32(struct tmio_mmc_host *host,
322 struct sh_mobile_sdhi *priv, int addr)
323{
324 return readl(priv->scc_ctl + (addr << host->bus_shift));
325}
326
327static inline void sd_scc_write32(struct tmio_mmc_host *host,
328 struct sh_mobile_sdhi *priv,
329 int addr, u32 val)
330{
331 writel(val, priv->scc_ctl + (addr << host->bus_shift));
332}
333
334static unsigned int sh_mobile_sdhi_init_tuning(struct tmio_mmc_host *host)
335{
336 struct sh_mobile_sdhi *priv;
337
338 if (!(host->mmc->caps & MMC_CAP_UHS_SDR104))
339 return 0;
340
341 priv = host_to_priv(host);
342
343 /* set sampling clock selection range */
344 sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_DTCNTL,
345 0x8 << SH_MOBILE_SDHI_SCC_DTCNTL_TAPNUM_SHIFT);
346
347 /* Initialize SCC */
348 sd_ctrl_write32_as_16_and_16(host, CTL_STATUS, 0x0);
349
350 sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_DTCNTL,
351 SH_MOBILE_SDHI_SCC_DTCNTL_TAPEN |
352 sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_DTCNTL));
353
354 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN &
355 sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
356
357 sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_CKSEL,
358 SH_MOBILE_SDHI_SCC_CKSEL_DTSEL |
359 sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_CKSEL));
360
361 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN |
362 sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
363
364 sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL,
365 ~SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN &
366 sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL));
367
368 sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_DT2FF, host->scc_tappos);
369
370 /* Read TAPNUM */
371 return (sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_DTCNTL) >>
372 SH_MOBILE_SDHI_SCC_DTCNTL_TAPNUM_SHIFT) &
373 SH_MOBILE_SDHI_SCC_DTCNTL_TAPNUM_MASK;
374}
375
376static void sh_mobile_sdhi_prepare_tuning(struct tmio_mmc_host *host,
377 unsigned long tap)
378{
379 struct sh_mobile_sdhi *priv = host_to_priv(host);
380
381 /* Set sampling clock position */
382 sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TAPSET, tap);
383}
384
385#define SH_MOBILE_SDHI_MAX_TAP 3
386
387static int sh_mobile_sdhi_select_tuning(struct tmio_mmc_host *host)
388{
389 struct sh_mobile_sdhi *priv = host_to_priv(host);
390 unsigned long tap_cnt; /* counter of tuning success */
391 unsigned long tap_set; /* tap position */
392 unsigned long tap_start;/* start position of tuning success */
393 unsigned long tap_end; /* end position of tuning success */
394 unsigned long ntap; /* temporary counter of tuning success */
395 unsigned long i;
396
397 /* Clear SCC_RVSREQ */
398 sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSREQ, 0);
399
400 /*
401 * Find the longest consecutive run of successful probes. If that
402 * is more than SH_MOBILE_SDHI_MAX_TAP probes long then use the
403 * center index as the tap.
404 */
405 tap_cnt = 0;
406 ntap = 0;
407 tap_start = 0;
408 tap_end = 0;
409 for (i = 0; i < host->tap_num * 2; i++) {
410 if (test_bit(i, host->taps))
411 ntap++;
412 else {
413 if (ntap > tap_cnt) {
414 tap_start = i - ntap;
415 tap_end = i - 1;
416 tap_cnt = ntap;
417 }
418 ntap = 0;
419 }
420 }
421
422 if (ntap > tap_cnt) {
423 tap_start = i - ntap;
424 tap_end = i - 1;
425 tap_cnt = ntap;
426 }
427
428 if (tap_cnt >= SH_MOBILE_SDHI_MAX_TAP)
429 tap_set = (tap_start + tap_end) / 2 % host->tap_num;
430 else
431 return -EIO;
432
433 /* Set SCC */
434 sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TAPSET, tap_set);
435
436 /* Enable auto re-tuning */
437 sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL,
438 SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN |
439 sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL));
440
441 return 0;
442}
443
444
445static bool sh_mobile_sdhi_check_scc_error(struct tmio_mmc_host *host)
446{
447 struct sh_mobile_sdhi *priv;
448
449 if (!(host->mmc->caps & MMC_CAP_UHS_SDR104))
450 return 0;
451
452 priv = host_to_priv(host);
453
454 /* Check SCC error */
455 if (sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL) &
456 SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN &&
457 sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSREQ) &
458 SH_MOBILE_SDHI_SCC_RVSREQ_RVSERR) {
459 /* Clear SCC error */
460 sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSREQ, 0);
461 return true;
462 }
463
464 return false;
465}
466
467static void sh_mobile_sdhi_hw_reset(struct tmio_mmc_host *host)
468{
469 struct sh_mobile_sdhi *priv;
470
471 if (!(host->mmc->caps & MMC_CAP_UHS_SDR104))
472 return;
473
474 priv = host_to_priv(host);
475
476 /* Reset SCC */
477 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN &
478 sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
479
480 sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_CKSEL,
481 ~SH_MOBILE_SDHI_SCC_CKSEL_DTSEL &
482 sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_CKSEL));
483
484 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN |
485 sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
486
487 sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL,
488 ~SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN &
489 sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL));
490
491 sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL,
492 ~SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN &
493 sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL));
494}
495
258static int sh_mobile_sdhi_wait_idle(struct tmio_mmc_host *host) 496static int sh_mobile_sdhi_wait_idle(struct tmio_mmc_host *host)
259{ 497{
260 int timeout = 1000; 498 int timeout = 1000;
@@ -325,7 +563,7 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev)
325 struct tmio_mmc_data *mmd = pdev->dev.platform_data; 563 struct tmio_mmc_data *mmd = pdev->dev.platform_data;
326 struct tmio_mmc_host *host; 564 struct tmio_mmc_host *host;
327 struct resource *res; 565 struct resource *res;
328 int irq, ret, i = 0; 566 int irq, ret, i;
329 struct tmio_mmc_dma *dma_priv; 567 struct tmio_mmc_dma *dma_priv;
330 568
331 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 569 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -364,6 +602,7 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev)
364 const struct sh_mobile_sdhi_of_data *of_data = of_id->data; 602 const struct sh_mobile_sdhi_of_data *of_data = of_id->data;
365 603
366 mmc_data->flags |= of_data->tmio_flags; 604 mmc_data->flags |= of_data->tmio_flags;
605 mmc_data->ocr_mask = of_data->tmio_ocr_mask;
367 mmc_data->capabilities |= of_data->capabilities; 606 mmc_data->capabilities |= of_data->capabilities;
368 mmc_data->capabilities2 |= of_data->capabilities2; 607 mmc_data->capabilities2 |= of_data->capabilities2;
369 mmc_data->dma_rx_offset = of_data->dma_rx_offset; 608 mmc_data->dma_rx_offset = of_data->dma_rx_offset;
@@ -384,6 +623,11 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev)
384 host->card_busy = sh_mobile_sdhi_card_busy; 623 host->card_busy = sh_mobile_sdhi_card_busy;
385 host->start_signal_voltage_switch = 624 host->start_signal_voltage_switch =
386 sh_mobile_sdhi_start_signal_voltage_switch; 625 sh_mobile_sdhi_start_signal_voltage_switch;
626 host->init_tuning = sh_mobile_sdhi_init_tuning;
627 host->prepare_tuning = sh_mobile_sdhi_prepare_tuning;
628 host->select_tuning = sh_mobile_sdhi_select_tuning;
629 host->check_scc_error = sh_mobile_sdhi_check_scc_error;
630 host->hw_reset = sh_mobile_sdhi_hw_reset;
387 } 631 }
388 632
389 /* Orginally registers were 16 bit apart, could be 32 or 64 nowadays */ 633 /* Orginally registers were 16 bit apart, could be 32 or 64 nowadays */
@@ -424,6 +668,34 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev)
424 if (ret < 0) 668 if (ret < 0)
425 goto efree; 669 goto efree;
426 670
671 if (host->mmc->caps & MMC_CAP_UHS_SDR104) {
672 host->mmc->caps |= MMC_CAP_HW_RESET;
673
674 if (of_id && of_id->data) {
675 const struct sh_mobile_sdhi_of_data *of_data;
676 const struct sh_mobile_sdhi_scc *taps;
677 bool hit = false;
678
679 of_data = of_id->data;
680 taps = of_data->taps;
681
682 for (i = 0; i < of_data->taps_num; i++) {
683 if (taps[i].clk_rate == 0 ||
684 taps[i].clk_rate == host->mmc->f_max) {
685 host->scc_tappos = taps->tap;
686 hit = true;
687 break;
688 }
689 }
690
691 if (!hit)
692 dev_warn(&host->pdev->dev, "Unknown clock rate for SDR104\n");
693
694 priv->scc_ctl = host->ctl + of_data->scc_offset;
695 }
696 }
697
698 i = 0;
427 while (1) { 699 while (1) {
428 irq = platform_get_irq(pdev, i); 700 irq = platform_get_irq(pdev, i);
429 if (irq < 0) 701 if (irq < 0)
diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index c0a5c676d0e8..b1d1303389a7 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -822,10 +822,13 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
822 break; 822 break;
823 823
824 case MMC_POWER_UP: 824 case MMC_POWER_UP:
825 host->ferror = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 825 if (!IS_ERR(mmc->supply.vmmc)) {
826 ios->vdd); 826 host->ferror = mmc_regulator_set_ocr(mmc,
827 if (host->ferror) 827 mmc->supply.vmmc,
828 return; 828 ios->vdd);
829 if (host->ferror)
830 return;
831 }
829 832
830 if (!IS_ERR(mmc->supply.vqmmc)) { 833 if (!IS_ERR(mmc->supply.vqmmc)) {
831 host->ferror = regulator_enable(mmc->supply.vqmmc); 834 host->ferror = regulator_enable(mmc->supply.vqmmc);
@@ -847,7 +850,9 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
847 case MMC_POWER_OFF: 850 case MMC_POWER_OFF:
848 dev_dbg(mmc_dev(mmc), "power off!\n"); 851 dev_dbg(mmc_dev(mmc), "power off!\n");
849 sunxi_mmc_reset_host(host); 852 sunxi_mmc_reset_host(host);
850 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); 853 if (!IS_ERR(mmc->supply.vmmc))
854 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
855
851 if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled) 856 if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled)
852 regulator_disable(mmc->supply.vqmmc); 857 regulator_disable(mmc->supply.vqmmc);
853 host->vqmmc_enabled = false; 858 host->vqmmc_enabled = false;
diff --git a/drivers/mmc/host/tmio_mmc.h b/drivers/mmc/host/tmio_mmc.h
index 8e126afd988c..9e20bcf3aa8d 100644
--- a/drivers/mmc/host/tmio_mmc.h
+++ b/drivers/mmc/host/tmio_mmc.h
@@ -153,9 +153,12 @@ struct tmio_mmc_host {
153 struct mutex ios_lock; /* protect set_ios() context */ 153 struct mutex ios_lock; /* protect set_ios() context */
154 bool native_hotplug; 154 bool native_hotplug;
155 bool sdio_irq_enabled; 155 bool sdio_irq_enabled;
156 u32 scc_tappos;
156 157
157 int (*write16_hook)(struct tmio_mmc_host *host, int addr); 158 /* Mandatory callback */
158 int (*clk_enable)(struct tmio_mmc_host *host); 159 int (*clk_enable)(struct tmio_mmc_host *host);
160
161 /* Optional callbacks */
159 unsigned int (*clk_update)(struct tmio_mmc_host *host, 162 unsigned int (*clk_update)(struct tmio_mmc_host *host,
160 unsigned int new_clock); 163 unsigned int new_clock);
161 void (*clk_disable)(struct tmio_mmc_host *host); 164 void (*clk_disable)(struct tmio_mmc_host *host);
@@ -164,6 +167,21 @@ struct tmio_mmc_host {
164 int (*card_busy)(struct mmc_host *mmc); 167 int (*card_busy)(struct mmc_host *mmc);
165 int (*start_signal_voltage_switch)(struct mmc_host *mmc, 168 int (*start_signal_voltage_switch)(struct mmc_host *mmc,
166 struct mmc_ios *ios); 169 struct mmc_ios *ios);
170 int (*write16_hook)(struct tmio_mmc_host *host, int addr);
171 void (*hw_reset)(struct tmio_mmc_host *host);
172 void (*prepare_tuning)(struct tmio_mmc_host *host, unsigned long tap);
173 bool (*check_scc_error)(struct tmio_mmc_host *host);
174
175 /*
176 * Mandatory callback for tuning to occur which is optional for SDR50
177 * and mandatory for SDR104.
178 */
179 unsigned int (*init_tuning)(struct tmio_mmc_host *host);
180 int (*select_tuning)(struct tmio_mmc_host *host);
181
182 /* Tuning values: 1 for success, 0 for failure */
183 DECLARE_BITMAP(taps, BITS_PER_BYTE * sizeof(long));
184 unsigned int tap_num;
167}; 185};
168 186
169struct tmio_mmc_host *tmio_mmc_host_alloc(struct platform_device *pdev); 187struct tmio_mmc_host *tmio_mmc_host_alloc(struct platform_device *pdev);
@@ -245,6 +263,12 @@ static inline u32 sd_ctrl_read16_and_16_as_32(struct tmio_mmc_host *host, int ad
245 readw(host->ctl + ((addr + 2) << host->bus_shift)) << 16; 263 readw(host->ctl + ((addr + 2) << host->bus_shift)) << 16;
246} 264}
247 265
266static inline void sd_ctrl_read32_rep(struct tmio_mmc_host *host, int addr,
267 u32 *buf, int count)
268{
269 readsl(host->ctl + (addr << host->bus_shift), buf, count);
270}
271
248static inline void sd_ctrl_write16(struct tmio_mmc_host *host, int addr, u16 val) 272static inline void sd_ctrl_write16(struct tmio_mmc_host *host, int addr, u16 val)
249{ 273{
250 /* If there is a hook and it returns non-zero then there 274 /* If there is a hook and it returns non-zero then there
@@ -267,4 +291,10 @@ static inline void sd_ctrl_write32_as_16_and_16(struct tmio_mmc_host *host, int
267 writew(val >> 16, host->ctl + ((addr + 2) << host->bus_shift)); 291 writew(val >> 16, host->ctl + ((addr + 2) << host->bus_shift));
268} 292}
269 293
294static inline void sd_ctrl_write32_rep(struct tmio_mmc_host *host, int addr,
295 const u32 *buf, int count)
296{
297 writesl(host->ctl + (addr << host->bus_shift), buf, count);
298}
299
270#endif 300#endif
diff --git a/drivers/mmc/host/tmio_mmc_pio.c b/drivers/mmc/host/tmio_mmc_pio.c
index 700567603107..2064fa1a5bf1 100644
--- a/drivers/mmc/host/tmio_mmc_pio.c
+++ b/drivers/mmc/host/tmio_mmc_pio.c
@@ -22,7 +22,6 @@
22 * TODO: 22 * TODO:
23 * Investigate using a workqueue for PIO transfers 23 * Investigate using a workqueue for PIO transfers
24 * Eliminate FIXMEs 24 * Eliminate FIXMEs
25 * SDIO support
26 * Better Power management 25 * Better Power management
27 * Handle MMC errors better 26 * Handle MMC errors better
28 * double buffer support 27 * double buffer support
@@ -36,6 +35,7 @@
36#include <linux/io.h> 35#include <linux/io.h>
37#include <linux/irq.h> 36#include <linux/irq.h>
38#include <linux/mfd/tmio.h> 37#include <linux/mfd/tmio.h>
38#include <linux/mmc/card.h>
39#include <linux/mmc/host.h> 39#include <linux/mmc/host.h>
40#include <linux/mmc/mmc.h> 40#include <linux/mmc/mmc.h>
41#include <linux/mmc/slot-gpio.h> 41#include <linux/mmc/slot-gpio.h>
@@ -298,6 +298,9 @@ static void tmio_mmc_finish_request(struct tmio_mmc_host *host)
298 if (mrq->cmd->error || (mrq->data && mrq->data->error)) 298 if (mrq->cmd->error || (mrq->data && mrq->data->error))
299 tmio_mmc_abort_dma(host); 299 tmio_mmc_abort_dma(host);
300 300
301 if (host->check_scc_error)
302 host->check_scc_error(host);
303
301 mmc_request_done(host->mmc, mrq); 304 mmc_request_done(host->mmc, mrq);
302} 305}
303 306
@@ -393,6 +396,36 @@ static void tmio_mmc_transfer_data(struct tmio_mmc_host *host,
393 /* 396 /*
394 * Transfer the data 397 * Transfer the data
395 */ 398 */
399 if (host->pdata->flags & TMIO_MMC_32BIT_DATA_PORT) {
400 u8 data[4] = { };
401
402 if (is_read)
403 sd_ctrl_read32_rep(host, CTL_SD_DATA_PORT, (u32 *)buf,
404 count >> 2);
405 else
406 sd_ctrl_write32_rep(host, CTL_SD_DATA_PORT, (u32 *)buf,
407 count >> 2);
408
409 /* if count was multiple of 4 */
410 if (!(count & 0x3))
411 return;
412
413 buf8 = (u8 *)(buf + (count >> 2));
414 count %= 4;
415
416 if (is_read) {
417 sd_ctrl_read32_rep(host, CTL_SD_DATA_PORT,
418 (u32 *)data, 1);
419 memcpy(buf8, data, count);
420 } else {
421 memcpy(data, buf8, count);
422 sd_ctrl_write32_rep(host, CTL_SD_DATA_PORT,
423 (u32 *)data, 1);
424 }
425
426 return;
427 }
428
396 if (is_read) 429 if (is_read)
397 sd_ctrl_read16_rep(host, CTL_SD_DATA_PORT, buf, count >> 1); 430 sd_ctrl_read16_rep(host, CTL_SD_DATA_PORT, buf, count >> 1);
398 else 431 else
@@ -522,7 +555,7 @@ void tmio_mmc_do_data_irq(struct tmio_mmc_host *host)
522 schedule_work(&host->done); 555 schedule_work(&host->done);
523} 556}
524 557
525static void tmio_mmc_data_irq(struct tmio_mmc_host *host) 558static void tmio_mmc_data_irq(struct tmio_mmc_host *host, unsigned int stat)
526{ 559{
527 struct mmc_data *data; 560 struct mmc_data *data;
528 spin_lock(&host->lock); 561 spin_lock(&host->lock);
@@ -531,6 +564,9 @@ static void tmio_mmc_data_irq(struct tmio_mmc_host *host)
531 if (!data) 564 if (!data)
532 goto out; 565 goto out;
533 566
567 if (stat & TMIO_STAT_CRCFAIL || stat & TMIO_STAT_STOPBIT_ERR ||
568 stat & TMIO_STAT_TXUNDERRUN)
569 data->error = -EILSEQ;
534 if (host->chan_tx && (data->flags & MMC_DATA_WRITE) && !host->force_pio) { 570 if (host->chan_tx && (data->flags & MMC_DATA_WRITE) && !host->force_pio) {
535 u32 status = sd_ctrl_read16_and_16_as_32(host, CTL_STATUS); 571 u32 status = sd_ctrl_read16_and_16_as_32(host, CTL_STATUS);
536 bool done = false; 572 bool done = false;
@@ -579,8 +615,6 @@ static void tmio_mmc_cmd_irq(struct tmio_mmc_host *host,
579 goto out; 615 goto out;
580 } 616 }
581 617
582 host->cmd = NULL;
583
584 /* This controller is sicker than the PXA one. Not only do we need to 618 /* This controller is sicker than the PXA one. Not only do we need to
585 * drop the top 8 bits of the first response word, we also need to 619 * drop the top 8 bits of the first response word, we also need to
586 * modify the order of the response for short response command types. 620 * modify the order of the response for short response command types.
@@ -600,14 +634,16 @@ static void tmio_mmc_cmd_irq(struct tmio_mmc_host *host,
600 634
601 if (stat & TMIO_STAT_CMDTIMEOUT) 635 if (stat & TMIO_STAT_CMDTIMEOUT)
602 cmd->error = -ETIMEDOUT; 636 cmd->error = -ETIMEDOUT;
603 else if (stat & TMIO_STAT_CRCFAIL && cmd->flags & MMC_RSP_CRC) 637 else if ((stat & TMIO_STAT_CRCFAIL && cmd->flags & MMC_RSP_CRC) ||
638 stat & TMIO_STAT_STOPBIT_ERR ||
639 stat & TMIO_STAT_CMD_IDX_ERR)
604 cmd->error = -EILSEQ; 640 cmd->error = -EILSEQ;
605 641
606 /* If there is data to handle we enable data IRQs here, and 642 /* If there is data to handle we enable data IRQs here, and
607 * we will ultimatley finish the request in the data_end handler. 643 * we will ultimatley finish the request in the data_end handler.
608 * If theres no data or we encountered an error, finish now. 644 * If theres no data or we encountered an error, finish now.
609 */ 645 */
610 if (host->data && !cmd->error) { 646 if (host->data && (!cmd->error || cmd->error == -EILSEQ)) {
611 if (host->data->flags & MMC_DATA_READ) { 647 if (host->data->flags & MMC_DATA_READ) {
612 if (host->force_pio || !host->chan_rx) 648 if (host->force_pio || !host->chan_rx)
613 tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_READOP); 649 tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_READOP);
@@ -668,7 +704,7 @@ static bool __tmio_mmc_sdcard_irq(struct tmio_mmc_host *host,
668 /* Data transfer completion */ 704 /* Data transfer completion */
669 if (ireg & TMIO_STAT_DATAEND) { 705 if (ireg & TMIO_STAT_DATAEND) {
670 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_DATAEND); 706 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_DATAEND);
671 tmio_mmc_data_irq(host); 707 tmio_mmc_data_irq(host, status);
672 return true; 708 return true;
673 } 709 }
674 710
@@ -687,7 +723,7 @@ static void tmio_mmc_sdio_irq(int irq, void *devid)
687 return; 723 return;
688 724
689 status = sd_ctrl_read16(host, CTL_SDIO_STATUS); 725 status = sd_ctrl_read16(host, CTL_SDIO_STATUS);
690 ireg = status & TMIO_SDIO_MASK_ALL & ~host->sdcard_irq_mask; 726 ireg = status & TMIO_SDIO_MASK_ALL & ~host->sdio_irq_mask;
691 727
692 sdio_status = status & ~TMIO_SDIO_MASK_ALL; 728 sdio_status = status & ~TMIO_SDIO_MASK_ALL;
693 if (pdata->flags & TMIO_MMC_SDIO_STATUS_QUIRK) 729 if (pdata->flags & TMIO_MMC_SDIO_STATUS_QUIRK)
@@ -756,6 +792,63 @@ static int tmio_mmc_start_data(struct tmio_mmc_host *host,
756 return 0; 792 return 0;
757} 793}
758 794
795static void tmio_mmc_hw_reset(struct mmc_host *mmc)
796{
797 struct tmio_mmc_host *host = mmc_priv(mmc);
798
799 if (host->hw_reset)
800 host->hw_reset(host);
801}
802
803static int tmio_mmc_execute_tuning(struct mmc_host *mmc, u32 opcode)
804{
805 struct tmio_mmc_host *host = mmc_priv(mmc);
806 int i, ret = 0;
807
808 if (!host->tap_num) {
809 if (!host->init_tuning || !host->select_tuning)
810 /* Tuning is not supported */
811 goto out;
812
813 host->tap_num = host->init_tuning(host);
814 if (!host->tap_num)
815 /* Tuning is not supported */
816 goto out;
817 }
818
819 if (host->tap_num * 2 >= sizeof(host->taps) * BITS_PER_BYTE) {
820 dev_warn_once(&host->pdev->dev,
821 "Too many taps, skipping tuning. Please consider updating size of taps field of tmio_mmc_host\n");
822 goto out;
823 }
824
825 bitmap_zero(host->taps, host->tap_num * 2);
826
827 /* Issue CMD19 twice for each tap */
828 for (i = 0; i < 2 * host->tap_num; i++) {
829 if (host->prepare_tuning)
830 host->prepare_tuning(host, i % host->tap_num);
831
832 ret = mmc_send_tuning(mmc, opcode, NULL);
833 if (ret && ret != -EILSEQ)
834 goto out;
835 if (ret == 0)
836 set_bit(i, host->taps);
837
838 mdelay(1);
839 }
840
841 ret = host->select_tuning(host);
842
843out:
844 if (ret < 0) {
845 dev_warn(&host->pdev->dev, "Tuning procedure failed\n");
846 tmio_mmc_hw_reset(mmc);
847 }
848
849 return ret;
850}
851
759/* Process requests from the MMC layer */ 852/* Process requests from the MMC layer */
760static void tmio_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq) 853static void tmio_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
761{ 854{
@@ -972,6 +1065,8 @@ static struct mmc_host_ops tmio_mmc_ops = {
972 .get_cd = mmc_gpio_get_cd, 1065 .get_cd = mmc_gpio_get_cd,
973 .enable_sdio_irq = tmio_mmc_enable_sdio_irq, 1066 .enable_sdio_irq = tmio_mmc_enable_sdio_irq,
974 .multi_io_quirk = tmio_multi_io_quirk, 1067 .multi_io_quirk = tmio_multi_io_quirk,
1068 .hw_reset = tmio_mmc_hw_reset,
1069 .execute_tuning = tmio_mmc_execute_tuning,
975}; 1070};
976 1071
977static int tmio_mmc_init_ocr(struct tmio_mmc_host *host) 1072static int tmio_mmc_init_ocr(struct tmio_mmc_host *host)
@@ -1218,6 +1313,11 @@ int tmio_mmc_host_runtime_suspend(struct device *dev)
1218} 1313}
1219EXPORT_SYMBOL(tmio_mmc_host_runtime_suspend); 1314EXPORT_SYMBOL(tmio_mmc_host_runtime_suspend);
1220 1315
1316static bool tmio_mmc_can_retune(struct tmio_mmc_host *host)
1317{
1318 return host->tap_num && mmc_can_retune(host->mmc);
1319}
1320
1221int tmio_mmc_host_runtime_resume(struct device *dev) 1321int tmio_mmc_host_runtime_resume(struct device *dev)
1222{ 1322{
1223 struct mmc_host *mmc = dev_get_drvdata(dev); 1323 struct mmc_host *mmc = dev_get_drvdata(dev);
@@ -1231,6 +1331,9 @@ int tmio_mmc_host_runtime_resume(struct device *dev)
1231 1331
1232 tmio_mmc_enable_dma(host, true); 1332 tmio_mmc_enable_dma(host, true);
1233 1333
1334 if (tmio_mmc_can_retune(host) && host->select_tuning(host))
1335 dev_warn(&host->pdev->dev, "Tuning selection failed\n");
1336
1234 return 0; 1337 return 0;
1235} 1338}
1236EXPORT_SYMBOL(tmio_mmc_host_runtime_resume); 1339EXPORT_SYMBOL(tmio_mmc_host_runtime_resume);
diff --git a/drivers/mmc/host/wbsd.c b/drivers/mmc/host/wbsd.c
index c3fd16d997ca..80a3b11f3217 100644
--- a/drivers/mmc/host/wbsd.c
+++ b/drivers/mmc/host/wbsd.c
@@ -1395,23 +1395,25 @@ static void wbsd_request_dma(struct wbsd_host *host, int dma)
1395 */ 1395 */
1396 host->dma_addr = dma_map_single(mmc_dev(host->mmc), host->dma_buffer, 1396 host->dma_addr = dma_map_single(mmc_dev(host->mmc), host->dma_buffer,
1397 WBSD_DMA_SIZE, DMA_BIDIRECTIONAL); 1397 WBSD_DMA_SIZE, DMA_BIDIRECTIONAL);
1398 if (dma_mapping_error(mmc_dev(host->mmc), host->dma_addr))
1399 goto kfree;
1398 1400
1399 /* 1401 /*
1400 * ISA DMA must be aligned on a 64k basis. 1402 * ISA DMA must be aligned on a 64k basis.
1401 */ 1403 */
1402 if ((host->dma_addr & 0xffff) != 0) 1404 if ((host->dma_addr & 0xffff) != 0)
1403 goto kfree; 1405 goto unmap;
1404 /* 1406 /*
1405 * ISA cannot access memory above 16 MB. 1407 * ISA cannot access memory above 16 MB.
1406 */ 1408 */
1407 else if (host->dma_addr >= 0x1000000) 1409 else if (host->dma_addr >= 0x1000000)
1408 goto kfree; 1410 goto unmap;
1409 1411
1410 host->dma = dma; 1412 host->dma = dma;
1411 1413
1412 return; 1414 return;
1413 1415
1414kfree: 1416unmap:
1415 /* 1417 /*
1416 * If we've gotten here then there is some kind of alignment bug 1418 * If we've gotten here then there is some kind of alignment bug
1417 */ 1419 */
@@ -1421,6 +1423,7 @@ kfree:
1421 WBSD_DMA_SIZE, DMA_BIDIRECTIONAL); 1423 WBSD_DMA_SIZE, DMA_BIDIRECTIONAL);
1422 host->dma_addr = 0; 1424 host->dma_addr = 0;
1423 1425
1426kfree:
1424 kfree(host->dma_buffer); 1427 kfree(host->dma_buffer);
1425 host->dma_buffer = NULL; 1428 host->dma_buffer = NULL;
1426 1429
@@ -1434,7 +1437,7 @@ err:
1434 1437
1435static void wbsd_release_dma(struct wbsd_host *host) 1438static void wbsd_release_dma(struct wbsd_host *host)
1436{ 1439{
1437 if (host->dma_addr) { 1440 if (!dma_mapping_error(mmc_dev(host->mmc), host->dma_addr)) {
1438 dma_unmap_single(mmc_dev(host->mmc), host->dma_addr, 1441 dma_unmap_single(mmc_dev(host->mmc), host->dma_addr,
1439 WBSD_DMA_SIZE, DMA_BIDIRECTIONAL); 1442 WBSD_DMA_SIZE, DMA_BIDIRECTIONAL);
1440 } 1443 }
diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index e6e90e80519a..f31bceb69c0d 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -1,8 +1,7 @@
1menu "SOC (System On Chip) specific Drivers" 1menu "SOC (System On Chip) specific Drivers"
2 2
3source "drivers/soc/bcm/Kconfig" 3source "drivers/soc/bcm/Kconfig"
4source "drivers/soc/fsl/qbman/Kconfig" 4source "drivers/soc/fsl/Kconfig"
5source "drivers/soc/fsl/qe/Kconfig"
6source "drivers/soc/mediatek/Kconfig" 5source "drivers/soc/mediatek/Kconfig"
7source "drivers/soc/qcom/Kconfig" 6source "drivers/soc/qcom/Kconfig"
8source "drivers/soc/rockchip/Kconfig" 7source "drivers/soc/rockchip/Kconfig"
diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig
new file mode 100644
index 000000000000..7a9fb9baa66d
--- /dev/null
+++ b/drivers/soc/fsl/Kconfig
@@ -0,0 +1,18 @@
1#
2# Freescale SOC drivers
3#
4
5source "drivers/soc/fsl/qbman/Kconfig"
6source "drivers/soc/fsl/qe/Kconfig"
7
8config FSL_GUTS
9 bool
10 select SOC_BUS
11 help
12 The global utilities block controls power management, I/O device
13 enabling, power-onreset(POR) configuration monitoring, alternate
14 function selection for multiplexed signals,and clock control.
15 This driver is to manage and access global utilities block.
16 Initially only reading SVR and registering soc device are supported.
17 Other guts accesses, such as reading RCW, should eventually be moved
18 into this driver as well.
diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile
index 75e1f5334821..44b3bebef24a 100644
--- a/drivers/soc/fsl/Makefile
+++ b/drivers/soc/fsl/Makefile
@@ -5,3 +5,4 @@
5obj-$(CONFIG_FSL_DPAA) += qbman/ 5obj-$(CONFIG_FSL_DPAA) += qbman/
6obj-$(CONFIG_QUICC_ENGINE) += qe/ 6obj-$(CONFIG_QUICC_ENGINE) += qe/
7obj-$(CONFIG_CPM) += qe/ 7obj-$(CONFIG_CPM) += qe/
8obj-$(CONFIG_FSL_GUTS) += guts.o
diff --git a/drivers/soc/fsl/guts.c b/drivers/soc/fsl/guts.c
new file mode 100644
index 000000000000..6af7a11f09a5
--- /dev/null
+++ b/drivers/soc/fsl/guts.c
@@ -0,0 +1,239 @@
1/*
2 * Freescale QorIQ Platforms GUTS Driver
3 *
4 * Copyright (C) 2016 Freescale Semiconductor, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/io.h>
13#include <linux/slab.h>
14#include <linux/module.h>
15#include <linux/of_fdt.h>
16#include <linux/sys_soc.h>
17#include <linux/of_address.h>
18#include <linux/platform_device.h>
19#include <linux/fsl/guts.h>
20
21struct guts {
22 struct ccsr_guts __iomem *regs;
23 bool little_endian;
24};
25
26struct fsl_soc_die_attr {
27 char *die;
28 u32 svr;
29 u32 mask;
30};
31
32static struct guts *guts;
33static struct soc_device_attribute soc_dev_attr;
34static struct soc_device *soc_dev;
35
36
37/* SoC die attribute definition for QorIQ platform */
38static const struct fsl_soc_die_attr fsl_soc_die[] = {
39 /*
40 * Power Architecture-based SoCs T Series
41 */
42
43 /* Die: T4240, SoC: T4240/T4160/T4080 */
44 { .die = "T4240",
45 .svr = 0x82400000,
46 .mask = 0xfff00000,
47 },
48 /* Die: T1040, SoC: T1040/T1020/T1042/T1022 */
49 { .die = "T1040",
50 .svr = 0x85200000,
51 .mask = 0xfff00000,
52 },
53 /* Die: T2080, SoC: T2080/T2081 */
54 { .die = "T2080",
55 .svr = 0x85300000,
56 .mask = 0xfff00000,
57 },
58 /* Die: T1024, SoC: T1024/T1014/T1023/T1013 */
59 { .die = "T1024",
60 .svr = 0x85400000,
61 .mask = 0xfff00000,
62 },
63
64 /*
65 * ARM-based SoCs LS Series
66 */
67
68 /* Die: LS1043A, SoC: LS1043A/LS1023A */
69 { .die = "LS1043A",
70 .svr = 0x87920000,
71 .mask = 0xffff0000,
72 },
73 /* Die: LS2080A, SoC: LS2080A/LS2040A/LS2085A */
74 { .die = "LS2080A",
75 .svr = 0x87010000,
76 .mask = 0xff3f0000,
77 },
78 /* Die: LS1088A, SoC: LS1088A/LS1048A/LS1084A/LS1044A */
79 { .die = "LS1088A",
80 .svr = 0x87030000,
81 .mask = 0xff3f0000,
82 },
83 /* Die: LS1012A, SoC: LS1012A */
84 { .die = "LS1012A",
85 .svr = 0x87040000,
86 .mask = 0xffff0000,
87 },
88 /* Die: LS1046A, SoC: LS1046A/LS1026A */
89 { .die = "LS1046A",
90 .svr = 0x87070000,
91 .mask = 0xffff0000,
92 },
93 /* Die: LS2088A, SoC: LS2088A/LS2048A/LS2084A/LS2044A */
94 { .die = "LS2088A",
95 .svr = 0x87090000,
96 .mask = 0xff3f0000,
97 },
98 /* Die: LS1021A, SoC: LS1021A/LS1020A/LS1022A */
99 { .die = "LS1021A",
100 .svr = 0x87000000,
101 .mask = 0xfff70000,
102 },
103 { },
104};
105
106static const struct fsl_soc_die_attr *fsl_soc_die_match(
107 u32 svr, const struct fsl_soc_die_attr *matches)
108{
109 while (matches->svr) {
110 if (matches->svr == (svr & matches->mask))
111 return matches;
112 matches++;
113 };
114 return NULL;
115}
116
117u32 fsl_guts_get_svr(void)
118{
119 u32 svr = 0;
120
121 if (!guts || !guts->regs)
122 return svr;
123
124 if (guts->little_endian)
125 svr = ioread32(&guts->regs->svr);
126 else
127 svr = ioread32be(&guts->regs->svr);
128
129 return svr;
130}
131EXPORT_SYMBOL(fsl_guts_get_svr);
132
133static int fsl_guts_probe(struct platform_device *pdev)
134{
135 struct device_node *root, *np = pdev->dev.of_node;
136 struct device *dev = &pdev->dev;
137 struct resource *res;
138 const struct fsl_soc_die_attr *soc_die;
139 const char *machine;
140 u32 svr;
141
142 /* Initialize guts */
143 guts = devm_kzalloc(dev, sizeof(*guts), GFP_KERNEL);
144 if (!guts)
145 return -ENOMEM;
146
147 guts->little_endian = of_property_read_bool(np, "little-endian");
148
149 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
150 guts->regs = devm_ioremap_resource(dev, res);
151 if (IS_ERR(guts->regs))
152 return PTR_ERR(guts->regs);
153
154 /* Register soc device */
155 root = of_find_node_by_path("/");
156 if (of_property_read_string(root, "model", &machine))
157 of_property_read_string_index(root, "compatible", 0, &machine);
158 of_node_put(root);
159 if (machine)
160 soc_dev_attr.machine = devm_kstrdup(dev, machine, GFP_KERNEL);
161
162 svr = fsl_guts_get_svr();
163 soc_die = fsl_soc_die_match(svr, fsl_soc_die);
164 if (soc_die) {
165 soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL,
166 "QorIQ %s", soc_die->die);
167 } else {
168 soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL, "QorIQ");
169 }
170 soc_dev_attr.soc_id = devm_kasprintf(dev, GFP_KERNEL,
171 "svr:0x%08x", svr);
172 soc_dev_attr.revision = devm_kasprintf(dev, GFP_KERNEL, "%d.%d",
173 (svr >> 4) & 0xf, svr & 0xf);
174
175 soc_dev = soc_device_register(&soc_dev_attr);
176 if (IS_ERR(soc_dev))
177 return PTR_ERR(soc_dev);
178
179 pr_info("Machine: %s\n", soc_dev_attr.machine);
180 pr_info("SoC family: %s\n", soc_dev_attr.family);
181 pr_info("SoC ID: %s, Revision: %s\n",
182 soc_dev_attr.soc_id, soc_dev_attr.revision);
183 return 0;
184}
185
186static int fsl_guts_remove(struct platform_device *dev)
187{
188 soc_device_unregister(soc_dev);
189 return 0;
190}
191
192/*
193 * Table for matching compatible strings, for device tree
194 * guts node, for Freescale QorIQ SOCs.
195 */
196static const struct of_device_id fsl_guts_of_match[] = {
197 { .compatible = "fsl,qoriq-device-config-1.0", },
198 { .compatible = "fsl,qoriq-device-config-2.0", },
199 { .compatible = "fsl,p1010-guts", },
200 { .compatible = "fsl,p1020-guts", },
201 { .compatible = "fsl,p1021-guts", },
202 { .compatible = "fsl,p1022-guts", },
203 { .compatible = "fsl,p1023-guts", },
204 { .compatible = "fsl,p2020-guts", },
205 { .compatible = "fsl,bsc9131-guts", },
206 { .compatible = "fsl,bsc9132-guts", },
207 { .compatible = "fsl,mpc8536-guts", },
208 { .compatible = "fsl,mpc8544-guts", },
209 { .compatible = "fsl,mpc8548-guts", },
210 { .compatible = "fsl,mpc8568-guts", },
211 { .compatible = "fsl,mpc8569-guts", },
212 { .compatible = "fsl,mpc8572-guts", },
213 { .compatible = "fsl,ls1021a-dcfg", },
214 { .compatible = "fsl,ls1043a-dcfg", },
215 { .compatible = "fsl,ls2080a-dcfg", },
216 {}
217};
218MODULE_DEVICE_TABLE(of, fsl_guts_of_match);
219
220static struct platform_driver fsl_guts_driver = {
221 .driver = {
222 .name = "fsl-guts",
223 .of_match_table = fsl_guts_of_match,
224 },
225 .probe = fsl_guts_probe,
226 .remove = fsl_guts_remove,
227};
228
229static int __init fsl_guts_init(void)
230{
231 return platform_driver_register(&fsl_guts_driver);
232}
233core_initcall(fsl_guts_init);
234
235static void __exit fsl_guts_exit(void)
236{
237 platform_driver_unregister(&fsl_guts_driver);
238}
239module_exit(fsl_guts_exit);
diff --git a/include/linux/fsl/guts.h b/include/linux/fsl/guts.h
index 649e9171a9b3..3efa3b861d44 100644
--- a/include/linux/fsl/guts.h
+++ b/include/linux/fsl/guts.h
@@ -29,83 +29,112 @@
29 * #ifdefs. 29 * #ifdefs.
30 */ 30 */
31struct ccsr_guts { 31struct ccsr_guts {
32 __be32 porpllsr; /* 0x.0000 - POR PLL Ratio Status Register */ 32 u32 porpllsr; /* 0x.0000 - POR PLL Ratio Status Register */
33 __be32 porbmsr; /* 0x.0004 - POR Boot Mode Status Register */ 33 u32 porbmsr; /* 0x.0004 - POR Boot Mode Status Register */
34 __be32 porimpscr; /* 0x.0008 - POR I/O Impedance Status and Control Register */ 34 u32 porimpscr; /* 0x.0008 - POR I/O Impedance Status and
35 __be32 pordevsr; /* 0x.000c - POR I/O Device Status Register */ 35 * Control Register
36 __be32 pordbgmsr; /* 0x.0010 - POR Debug Mode Status Register */ 36 */
37 __be32 pordevsr2; /* 0x.0014 - POR device status register 2 */ 37 u32 pordevsr; /* 0x.000c - POR I/O Device Status Register */
38 u32 pordbgmsr; /* 0x.0010 - POR Debug Mode Status Register */
39 u32 pordevsr2; /* 0x.0014 - POR device status register 2 */
38 u8 res018[0x20 - 0x18]; 40 u8 res018[0x20 - 0x18];
39 __be32 porcir; /* 0x.0020 - POR Configuration Information Register */ 41 u32 porcir; /* 0x.0020 - POR Configuration Information
42 * Register
43 */
40 u8 res024[0x30 - 0x24]; 44 u8 res024[0x30 - 0x24];
41 __be32 gpiocr; /* 0x.0030 - GPIO Control Register */ 45 u32 gpiocr; /* 0x.0030 - GPIO Control Register */
42 u8 res034[0x40 - 0x34]; 46 u8 res034[0x40 - 0x34];
43 __be32 gpoutdr; /* 0x.0040 - General-Purpose Output Data Register */ 47 u32 gpoutdr; /* 0x.0040 - General-Purpose Output Data
48 * Register
49 */
44 u8 res044[0x50 - 0x44]; 50 u8 res044[0x50 - 0x44];
45 __be32 gpindr; /* 0x.0050 - General-Purpose Input Data Register */ 51 u32 gpindr; /* 0x.0050 - General-Purpose Input Data
52 * Register
53 */
46 u8 res054[0x60 - 0x54]; 54 u8 res054[0x60 - 0x54];
47 __be32 pmuxcr; /* 0x.0060 - Alternate Function Signal Multiplex Control */ 55 u32 pmuxcr; /* 0x.0060 - Alternate Function Signal
48 __be32 pmuxcr2; /* 0x.0064 - Alternate function signal multiplex control 2 */ 56 * Multiplex Control
49 __be32 dmuxcr; /* 0x.0068 - DMA Mux Control Register */ 57 */
58 u32 pmuxcr2; /* 0x.0064 - Alternate function signal
59 * multiplex control 2
60 */
61 u32 dmuxcr; /* 0x.0068 - DMA Mux Control Register */
50 u8 res06c[0x70 - 0x6c]; 62 u8 res06c[0x70 - 0x6c];
51 __be32 devdisr; /* 0x.0070 - Device Disable Control */ 63 u32 devdisr; /* 0x.0070 - Device Disable Control */
52#define CCSR_GUTS_DEVDISR_TB1 0x00001000 64#define CCSR_GUTS_DEVDISR_TB1 0x00001000
53#define CCSR_GUTS_DEVDISR_TB0 0x00004000 65#define CCSR_GUTS_DEVDISR_TB0 0x00004000
54 __be32 devdisr2; /* 0x.0074 - Device Disable Control 2 */ 66 u32 devdisr2; /* 0x.0074 - Device Disable Control 2 */
55 u8 res078[0x7c - 0x78]; 67 u8 res078[0x7c - 0x78];
56 __be32 pmjcr; /* 0x.007c - 4 Power Management Jog Control Register */ 68 u32 pmjcr; /* 0x.007c - 4 Power Management Jog Control
57 __be32 powmgtcsr; /* 0x.0080 - Power Management Status and Control Register */ 69 * Register
58 __be32 pmrccr; /* 0x.0084 - Power Management Reset Counter Configuration Register */ 70 */
59 __be32 pmpdccr; /* 0x.0088 - Power Management Power Down Counter Configuration Register */ 71 u32 powmgtcsr; /* 0x.0080 - Power Management Status and
60 __be32 pmcdr; /* 0x.008c - 4Power management clock disable register */ 72 * Control Register
61 __be32 mcpsumr; /* 0x.0090 - Machine Check Summary Register */ 73 */
62 __be32 rstrscr; /* 0x.0094 - Reset Request Status and Control Register */ 74 u32 pmrccr; /* 0x.0084 - Power Management Reset Counter
63 __be32 ectrstcr; /* 0x.0098 - Exception reset control register */ 75 * Configuration Register
64 __be32 autorstsr; /* 0x.009c - Automatic reset status register */ 76 */
65 __be32 pvr; /* 0x.00a0 - Processor Version Register */ 77 u32 pmpdccr; /* 0x.0088 - Power Management Power Down Counter
66 __be32 svr; /* 0x.00a4 - System Version Register */ 78 * Configuration Register
79 */
80 u32 pmcdr; /* 0x.008c - 4Power management clock disable
81 * register
82 */
83 u32 mcpsumr; /* 0x.0090 - Machine Check Summary Register */
84 u32 rstrscr; /* 0x.0094 - Reset Request Status and
85 * Control Register
86 */
87 u32 ectrstcr; /* 0x.0098 - Exception reset control register */
88 u32 autorstsr; /* 0x.009c - Automatic reset status register */
89 u32 pvr; /* 0x.00a0 - Processor Version Register */
90 u32 svr; /* 0x.00a4 - System Version Register */
67 u8 res0a8[0xb0 - 0xa8]; 91 u8 res0a8[0xb0 - 0xa8];
68 __be32 rstcr; /* 0x.00b0 - Reset Control Register */ 92 u32 rstcr; /* 0x.00b0 - Reset Control Register */
69 u8 res0b4[0xc0 - 0xb4]; 93 u8 res0b4[0xc0 - 0xb4];
70 __be32 iovselsr; /* 0x.00c0 - I/O voltage select status register 94 u32 iovselsr; /* 0x.00c0 - I/O voltage select status register
71 Called 'elbcvselcr' on 86xx SOCs */ 95 Called 'elbcvselcr' on 86xx SOCs */
72 u8 res0c4[0x100 - 0xc4]; 96 u8 res0c4[0x100 - 0xc4];
73 __be32 rcwsr[16]; /* 0x.0100 - Reset Control Word Status registers 97 u32 rcwsr[16]; /* 0x.0100 - Reset Control Word Status registers
74 There are 16 registers */ 98 There are 16 registers */
75 u8 res140[0x224 - 0x140]; 99 u8 res140[0x224 - 0x140];
76 __be32 iodelay1; /* 0x.0224 - IO delay control register 1 */ 100 u32 iodelay1; /* 0x.0224 - IO delay control register 1 */
77 __be32 iodelay2; /* 0x.0228 - IO delay control register 2 */ 101 u32 iodelay2; /* 0x.0228 - IO delay control register 2 */
78 u8 res22c[0x604 - 0x22c]; 102 u8 res22c[0x604 - 0x22c];
79 __be32 pamubypenr; /* 0x.604 - PAMU bypass enable register */ 103 u32 pamubypenr; /* 0x.604 - PAMU bypass enable register */
80 u8 res608[0x800 - 0x608]; 104 u8 res608[0x800 - 0x608];
81 __be32 clkdvdr; /* 0x.0800 - Clock Divide Register */ 105 u32 clkdvdr; /* 0x.0800 - Clock Divide Register */
82 u8 res804[0x900 - 0x804]; 106 u8 res804[0x900 - 0x804];
83 __be32 ircr; /* 0x.0900 - Infrared Control Register */ 107 u32 ircr; /* 0x.0900 - Infrared Control Register */
84 u8 res904[0x908 - 0x904]; 108 u8 res904[0x908 - 0x904];
85 __be32 dmacr; /* 0x.0908 - DMA Control Register */ 109 u32 dmacr; /* 0x.0908 - DMA Control Register */
86 u8 res90c[0x914 - 0x90c]; 110 u8 res90c[0x914 - 0x90c];
87 __be32 elbccr; /* 0x.0914 - eLBC Control Register */ 111 u32 elbccr; /* 0x.0914 - eLBC Control Register */
88 u8 res918[0xb20 - 0x918]; 112 u8 res918[0xb20 - 0x918];
89 __be32 ddr1clkdr; /* 0x.0b20 - DDR1 Clock Disable Register */ 113 u32 ddr1clkdr; /* 0x.0b20 - DDR1 Clock Disable Register */
90 __be32 ddr2clkdr; /* 0x.0b24 - DDR2 Clock Disable Register */ 114 u32 ddr2clkdr; /* 0x.0b24 - DDR2 Clock Disable Register */
91 __be32 ddrclkdr; /* 0x.0b28 - DDR Clock Disable Register */ 115 u32 ddrclkdr; /* 0x.0b28 - DDR Clock Disable Register */
92 u8 resb2c[0xe00 - 0xb2c]; 116 u8 resb2c[0xe00 - 0xb2c];
93 __be32 clkocr; /* 0x.0e00 - Clock Out Select Register */ 117 u32 clkocr; /* 0x.0e00 - Clock Out Select Register */
94 u8 rese04[0xe10 - 0xe04]; 118 u8 rese04[0xe10 - 0xe04];
95 __be32 ddrdllcr; /* 0x.0e10 - DDR DLL Control Register */ 119 u32 ddrdllcr; /* 0x.0e10 - DDR DLL Control Register */
96 u8 rese14[0xe20 - 0xe14]; 120 u8 rese14[0xe20 - 0xe14];
97 __be32 lbcdllcr; /* 0x.0e20 - LBC DLL Control Register */ 121 u32 lbcdllcr; /* 0x.0e20 - LBC DLL Control Register */
98 __be32 cpfor; /* 0x.0e24 - L2 charge pump fuse override register */ 122 u32 cpfor; /* 0x.0e24 - L2 charge pump fuse override
123 * register
124 */
99 u8 rese28[0xf04 - 0xe28]; 125 u8 rese28[0xf04 - 0xe28];
100 __be32 srds1cr0; /* 0x.0f04 - SerDes1 Control Register 0 */ 126 u32 srds1cr0; /* 0x.0f04 - SerDes1 Control Register 0 */
101 __be32 srds1cr1; /* 0x.0f08 - SerDes1 Control Register 0 */ 127 u32 srds1cr1; /* 0x.0f08 - SerDes1 Control Register 0 */
102 u8 resf0c[0xf2c - 0xf0c]; 128 u8 resf0c[0xf2c - 0xf0c];
103 __be32 itcr; /* 0x.0f2c - Internal transaction control register */ 129 u32 itcr; /* 0x.0f2c - Internal transaction control
130 * register
131 */
104 u8 resf30[0xf40 - 0xf30]; 132 u8 resf30[0xf40 - 0xf30];
105 __be32 srds2cr0; /* 0x.0f40 - SerDes2 Control Register 0 */ 133 u32 srds2cr0; /* 0x.0f40 - SerDes2 Control Register 0 */
106 __be32 srds2cr1; /* 0x.0f44 - SerDes2 Control Register 0 */ 134 u32 srds2cr1; /* 0x.0f44 - SerDes2 Control Register 0 */
107} __attribute__ ((packed)); 135} __attribute__ ((packed));
108 136
137u32 fsl_guts_get_svr(void);
109 138
110/* Alternate function signal multiplex control */ 139/* Alternate function signal multiplex control */
111#define MPC85xx_PMUXCR_QE(x) (0x8000 >> (x)) 140#define MPC85xx_PMUXCR_QE(x) (0x8000 >> (x))
diff --git a/include/linux/mfd/tmio.h b/include/linux/mfd/tmio.h
index 7a26286db895..fba44abd05ba 100644
--- a/include/linux/mfd/tmio.h
+++ b/include/linux/mfd/tmio.h
@@ -100,6 +100,11 @@
100#define TMIO_MMC_SDIO_STATUS_QUIRK (1 << 8) 100#define TMIO_MMC_SDIO_STATUS_QUIRK (1 << 8)
101 101
102/* 102/*
103 * Some controllers have a 32-bit wide data port register
104 */
105#define TMIO_MMC_32BIT_DATA_PORT (1 << 9)
106
107/*
103 * Some controllers allows to set SDx actual clock 108 * Some controllers allows to set SDx actual clock
104 */ 109 */
105#define TMIO_MMC_CLK_ACTUAL (1 << 10) 110#define TMIO_MMC_CLK_ACTUAL (1 << 10)
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 73fad83acbcb..95d69d498296 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -89,6 +89,8 @@ struct mmc_ext_csd {
89 unsigned int boot_ro_lock; /* ro lock support */ 89 unsigned int boot_ro_lock; /* ro lock support */
90 bool boot_ro_lockable; 90 bool boot_ro_lockable;
91 bool ffu_capable; /* Firmware upgrade support */ 91 bool ffu_capable; /* Firmware upgrade support */
92 bool cmdq_support; /* Command Queue supported */
93 unsigned int cmdq_depth; /* Command Queue depth */
92#define MMC_FIRMWARE_LEN 8 94#define MMC_FIRMWARE_LEN 8
93 u8 fwrev[MMC_FIRMWARE_LEN]; /* FW version */ 95 u8 fwrev[MMC_FIRMWARE_LEN]; /* FW version */
94 u8 raw_exception_status; /* 54 */ 96 u8 raw_exception_status; /* 54 */
@@ -207,18 +209,6 @@ struct sdio_func_tuple;
207 209
208#define SDIO_MAX_FUNCS 7 210#define SDIO_MAX_FUNCS 7
209 211
210enum mmc_blk_status {
211 MMC_BLK_SUCCESS = 0,
212 MMC_BLK_PARTIAL,
213 MMC_BLK_CMD_ERR,
214 MMC_BLK_RETRY,
215 MMC_BLK_ABORT,
216 MMC_BLK_DATA_ERR,
217 MMC_BLK_ECC_ERR,
218 MMC_BLK_NOMEDIUM,
219 MMC_BLK_NEW_REQUEST,
220};
221
222/* The number of MMC physical partitions. These consist of: 212/* The number of MMC physical partitions. These consist of:
223 * boot partitions (2), general purpose partitions (4) and 213 * boot partitions (2), general purpose partitions (4) and
224 * RPMB partition (1) in MMC v4.4. 214 * RPMB partition (1) in MMC v4.4.
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index 2b953eb8ceae..e33cc748dcfe 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -15,6 +15,18 @@ struct request;
15struct mmc_data; 15struct mmc_data;
16struct mmc_request; 16struct mmc_request;
17 17
18enum mmc_blk_status {
19 MMC_BLK_SUCCESS = 0,
20 MMC_BLK_PARTIAL,
21 MMC_BLK_CMD_ERR,
22 MMC_BLK_RETRY,
23 MMC_BLK_ABORT,
24 MMC_BLK_DATA_ERR,
25 MMC_BLK_ECC_ERR,
26 MMC_BLK_NOMEDIUM,
27 MMC_BLK_NEW_REQUEST,
28};
29
18struct mmc_command { 30struct mmc_command {
19 u32 opcode; 31 u32 opcode;
20 u32 arg; 32 u32 arg;
@@ -150,7 +162,8 @@ struct mmc_async_req;
150extern int mmc_stop_bkops(struct mmc_card *); 162extern int mmc_stop_bkops(struct mmc_card *);
151extern int mmc_read_bkops_status(struct mmc_card *); 163extern int mmc_read_bkops_status(struct mmc_card *);
152extern struct mmc_async_req *mmc_start_req(struct mmc_host *, 164extern struct mmc_async_req *mmc_start_req(struct mmc_host *,
153 struct mmc_async_req *, int *); 165 struct mmc_async_req *,
166 enum mmc_blk_status *);
154extern int mmc_interrupt_hpi(struct mmc_card *); 167extern int mmc_interrupt_hpi(struct mmc_card *);
155extern void mmc_wait_for_req(struct mmc_host *, struct mmc_request *); 168extern void mmc_wait_for_req(struct mmc_host *, struct mmc_request *);
156extern void mmc_wait_for_req_done(struct mmc_host *host, 169extern void mmc_wait_for_req_done(struct mmc_host *host,
@@ -163,6 +176,7 @@ extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
163extern void mmc_start_bkops(struct mmc_card *card, bool from_exception); 176extern void mmc_start_bkops(struct mmc_card *card, bool from_exception);
164extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int); 177extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int);
165extern int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error); 178extern int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error);
179extern int mmc_abort_tuning(struct mmc_host *host, u32 opcode);
166extern int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd); 180extern int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd);
167 181
168#define MMC_ERASE_ARG 0x00000000 182#define MMC_ERASE_ARG 0x00000000
diff --git a/include/linux/mmc/dw_mmc.h b/include/linux/mmc/dw_mmc.h
index f5af2bd35e7f..15db6f83f53f 100644
--- a/include/linux/mmc/dw_mmc.h
+++ b/include/linux/mmc/dw_mmc.h
@@ -39,6 +39,12 @@ enum {
39 EVENT_DATA_ERROR, 39 EVENT_DATA_ERROR,
40}; 40};
41 41
42enum dw_mci_cookie {
43 COOKIE_UNMAPPED,
44 COOKIE_PRE_MAPPED, /* mapped by pre_req() of dwmmc */
45 COOKIE_MAPPED, /* mapped by prepare_data() of dwmmc */
46};
47
42struct mmc_data; 48struct mmc_data;
43 49
44enum { 50enum {
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 0b2439441cc8..8bc884121465 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -93,8 +93,7 @@ struct mmc_host_ops {
93 */ 93 */
94 void (*post_req)(struct mmc_host *host, struct mmc_request *req, 94 void (*post_req)(struct mmc_host *host, struct mmc_request *req,
95 int err); 95 int err);
96 void (*pre_req)(struct mmc_host *host, struct mmc_request *req, 96 void (*pre_req)(struct mmc_host *host, struct mmc_request *req);
97 bool is_first_req);
98 void (*request)(struct mmc_host *host, struct mmc_request *req); 97 void (*request)(struct mmc_host *host, struct mmc_request *req);
99 98
100 /* 99 /*
@@ -173,7 +172,7 @@ struct mmc_async_req {
173 * Check error status of completed mmc request. 172 * Check error status of completed mmc request.
174 * Returns 0 if success otherwise non zero. 173 * Returns 0 if success otherwise non zero.
175 */ 174 */
176 int (*err_check) (struct mmc_card *, struct mmc_async_req *); 175 enum mmc_blk_status (*err_check)(struct mmc_card *, struct mmc_async_req *);
177}; 176};
178 177
179/** 178/**
@@ -198,14 +197,12 @@ struct mmc_slot {
198 * @is_new_req wake up reason was new request 197 * @is_new_req wake up reason was new request
199 * @is_waiting_last_req mmc context waiting for single running request 198 * @is_waiting_last_req mmc context waiting for single running request
200 * @wait wait queue 199 * @wait wait queue
201 * @lock lock to protect data fields
202 */ 200 */
203struct mmc_context_info { 201struct mmc_context_info {
204 bool is_done_rcv; 202 bool is_done_rcv;
205 bool is_new_req; 203 bool is_new_req;
206 bool is_waiting_last_req; 204 bool is_waiting_last_req;
207 wait_queue_head_t wait; 205 wait_queue_head_t wait;
208 spinlock_t lock;
209}; 206};
210 207
211struct regulator; 208struct regulator;
@@ -495,11 +492,6 @@ static inline int mmc_host_uhs(struct mmc_host *host)
495 MMC_CAP_UHS_DDR50); 492 MMC_CAP_UHS_DDR50);
496} 493}
497 494
498static inline int mmc_host_packed_wr(struct mmc_host *host)
499{
500 return host->caps2 & MMC_CAP2_PACKED_WR;
501}
502
503static inline int mmc_card_hs(struct mmc_card *card) 495static inline int mmc_card_hs(struct mmc_card *card)
504{ 496{
505 return card->host->ios.timing == MMC_TIMING_SD_HS || 497 return card->host->ios.timing == MMC_TIMING_SD_HS ||
@@ -546,6 +538,11 @@ static inline void mmc_retune_recheck(struct mmc_host *host)
546 host->retune_now = 1; 538 host->retune_now = 1;
547} 539}
548 540
541static inline bool mmc_can_retune(struct mmc_host *host)
542{
543 return host->can_retune == 1;
544}
545
549void mmc_retune_pause(struct mmc_host *host); 546void mmc_retune_pause(struct mmc_host *host);
550void mmc_retune_unpause(struct mmc_host *host); 547void mmc_retune_unpause(struct mmc_host *host);
551 548
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index c376209c70ef..672730acc705 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -84,6 +84,13 @@
84#define MMC_APP_CMD 55 /* ac [31:16] RCA R1 */ 84#define MMC_APP_CMD 55 /* ac [31:16] RCA R1 */
85#define MMC_GEN_CMD 56 /* adtc [0] RD/WR R1 */ 85#define MMC_GEN_CMD 56 /* adtc [0] RD/WR R1 */
86 86
87 /* class 11 */
88#define MMC_QUE_TASK_PARAMS 44 /* ac [20:16] task id R1 */
89#define MMC_QUE_TASK_ADDR 45 /* ac [31:0] data addr R1 */
90#define MMC_EXECUTE_READ_TASK 46 /* adtc [20:16] task id R1 */
91#define MMC_EXECUTE_WRITE_TASK 47 /* adtc [20:16] task id R1 */
92#define MMC_CMDQ_TASK_MGMT 48 /* ac [20:16] task id R1b */
93
87static inline bool mmc_op_multi(u32 opcode) 94static inline bool mmc_op_multi(u32 opcode)
88{ 95{
89 return opcode == MMC_WRITE_MULTIPLE_BLOCK || 96 return opcode == MMC_WRITE_MULTIPLE_BLOCK ||
@@ -272,6 +279,7 @@ struct _mmc_csd {
272 * EXT_CSD fields 279 * EXT_CSD fields
273 */ 280 */
274 281
282#define EXT_CSD_CMDQ_MODE_EN 15 /* R/W */
275#define EXT_CSD_FLUSH_CACHE 32 /* W */ 283#define EXT_CSD_FLUSH_CACHE 32 /* W */
276#define EXT_CSD_CACHE_CTRL 33 /* R/W */ 284#define EXT_CSD_CACHE_CTRL 33 /* R/W */
277#define EXT_CSD_POWER_OFF_NOTIFICATION 34 /* R/W */ 285#define EXT_CSD_POWER_OFF_NOTIFICATION 34 /* R/W */
@@ -331,6 +339,8 @@ struct _mmc_csd {
331#define EXT_CSD_CACHE_SIZE 249 /* RO, 4 bytes */ 339#define EXT_CSD_CACHE_SIZE 249 /* RO, 4 bytes */
332#define EXT_CSD_PWR_CL_DDR_200_360 253 /* RO */ 340#define EXT_CSD_PWR_CL_DDR_200_360 253 /* RO */
333#define EXT_CSD_FIRMWARE_VERSION 254 /* RO, 8 bytes */ 341#define EXT_CSD_FIRMWARE_VERSION 254 /* RO, 8 bytes */
342#define EXT_CSD_CMDQ_DEPTH 307 /* RO */
343#define EXT_CSD_CMDQ_SUPPORT 308 /* RO */
334#define EXT_CSD_SUPPORTED_MODE 493 /* RO */ 344#define EXT_CSD_SUPPORTED_MODE 493 /* RO */
335#define EXT_CSD_TAG_UNIT_SIZE 498 /* RO */ 345#define EXT_CSD_TAG_UNIT_SIZE 498 /* RO */
336#define EXT_CSD_DATA_TAG_SUPPORT 499 /* RO */ 346#define EXT_CSD_DATA_TAG_SUPPORT 499 /* RO */
@@ -438,6 +448,13 @@ struct _mmc_csd {
438#define EXT_CSD_MANUAL_BKOPS_MASK 0x01 448#define EXT_CSD_MANUAL_BKOPS_MASK 0x01
439 449
440/* 450/*
451 * Command Queue
452 */
453#define EXT_CSD_CMDQ_MODE_ENABLED BIT(0)
454#define EXT_CSD_CMDQ_DEPTH_MASK GENMASK(4, 0)
455#define EXT_CSD_CMDQ_SUPPORTED BIT(0)
456
457/*
441 * MMC_SWITCH access modes 458 * MMC_SWITCH access modes
442 */ 459 */
443 460
diff --git a/include/linux/mmc/slot-gpio.h b/include/linux/mmc/slot-gpio.h
index 3945a8c9d3cb..a7972cd3bc14 100644
--- a/include/linux/mmc/slot-gpio.h
+++ b/include/linux/mmc/slot-gpio.h
@@ -29,5 +29,6 @@ int mmc_gpiod_request_ro(struct mmc_host *host, const char *con_id,
29void mmc_gpio_set_cd_isr(struct mmc_host *host, 29void mmc_gpio_set_cd_isr(struct mmc_host *host,
30 irqreturn_t (*isr)(int irq, void *dev_id)); 30 irqreturn_t (*isr)(int irq, void *dev_id));
31void mmc_gpiod_request_cd_irq(struct mmc_host *host); 31void mmc_gpiod_request_cd_irq(struct mmc_host *host);
32bool mmc_can_gpio_cd(struct mmc_host *host);
32 33
33#endif 34#endif
diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h
index 2739ccb69571..bed223b70217 100644
--- a/include/linux/sys_soc.h
+++ b/include/linux/sys_soc.h
@@ -13,6 +13,7 @@ struct soc_device_attribute {
13 const char *family; 13 const char *family;
14 const char *revision; 14 const char *revision;
15 const char *soc_id; 15 const char *soc_id;
16 const void *data;
16}; 17};
17 18
18/** 19/**
@@ -34,4 +35,12 @@ void soc_device_unregister(struct soc_device *soc_dev);
34 */ 35 */
35struct device *soc_device_to_device(struct soc_device *soc); 36struct device *soc_device_to_device(struct soc_device *soc);
36 37
38#ifdef CONFIG_SOC_BUS
39const struct soc_device_attribute *soc_device_match(
40 const struct soc_device_attribute *matches);
41#else
42static inline const struct soc_device_attribute *soc_device_match(
43 const struct soc_device_attribute *matches) { return NULL; }
44#endif
45
37#endif /* __SOC_BUS_H */ 46#endif /* __SOC_BUS_H */
diff --git a/include/uapi/linux/mmc/ioctl.h b/include/uapi/linux/mmc/ioctl.h
index 7e385b83b9d8..700a55156eee 100644
--- a/include/uapi/linux/mmc/ioctl.h
+++ b/include/uapi/linux/mmc/ioctl.h
@@ -69,6 +69,6 @@ struct mmc_ioc_multi_cmd {
69 * is enforced per ioctl call. For larger data transfers, use the normal 69 * is enforced per ioctl call. For larger data transfers, use the normal
70 * block device operations. 70 * block device operations.
71 */ 71 */
72#define MMC_IOC_MAX_BYTES (512L * 256) 72#define MMC_IOC_MAX_BYTES (512L * 1024)
73#define MMC_IOC_MAX_CMDS 255 73#define MMC_IOC_MAX_CMDS 255
74#endif /* LINUX_MMC_IOCTL_H */ 74#endif /* LINUX_MMC_IOCTL_H */