aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-04-13 17:53:03 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-13 17:53:03 -0400
commit8d9095c667a185c8e2449632343a2b6c65ae58f1 (patch)
tree738cdc0e1e5c96738c31ea327ac0d741349d3757
parent1a370f4cd95e056d55ef5bf1a183880e70195e59 (diff)
parent69f0fb2a592fc9ebc5e3e55178055d1cff31d479 (diff)
Merge tag 'mmc-v4.1' of git://git.linaro.org/people/ulf.hansson/mmc
Pull MMC updates from Ulf Hansson: "MMC core: - Add support for marking HPI as broken through devicetree - Enable runtime PM management of host devices - Remove the ->enable|disable() callbacks - Restructure code and cleanups - Refreshed some of the MMC sections in MAINTAINERS MMC host: - dw_mmc: HS400 mode support - dw_mmc: Add the cmd11 timer to detect a timeout - dw_mmc: Endian agnostic IO accessors - dw_mmc: Bugfixes - sh_mmcif: Add exclusion between cmd and interrupt - omap_hsmmc: Hibernation support - omap_hsmmc: Rework and simplify cover/card detect - omap_hsmmc: Stop using ->enable|disable() callbacks - atmel-mci: Endian agnostic IO - sunxi: Enable MMC_CAP_SDIO_IRQ - sdhci-st: Add support for the stih407 family silicon - sdhci-st: UHS card support in SDR104 mode - sdhci-st: HS200 mode support - sdhci-esdhc-imx: Use common mmc DT parser - sdhci-of-arasan: Use common mmc DT parser - sdhci-iproc: Add new driver for Broadcom IPROC SDHCI controller - sdhci-tegra: Convert to GPIO descriptors - sdhci-tegra: Optmize write_w path for tegra114 and later - sdhci-sirf: Update tuning procedure - sdhci: Fix card presence logic - sdhci: Cleanups and consolidation" * tag 'mmc-v4.1' of git://git.linaro.org/people/ulf.hansson/mmc: (79 commits) mmc: sdhci-st: Update ST SDHCI binding documentation. mmc: sdhci-st: Update the quirks for this controller. mmc: sdhci-st: Add sdhci_st_set_uhs_signaling function. mmc: sdhci-st: Add st_mmcss_cconfig function to configure mmcss glue registers. mmc: sdhci-st: Add delay management functions for top registers (eMMC). mmc: sdhci-st: Add support for de-asserting reset signal and top regs resource mmc: sdhci-st: Add macros for register offsets and bitfields for mmcss glue regs mmc: sdhci-esdhc-imx: Call mmc_of_parse() mmc: dw_mmc: Add locking around cmd11 timer mmc: dw_mmc: Add a return in an unexpected cmd11 timeout mmc: dw_mmc: Increase cmd11 timeout to 500ms mmc: dw_mmc: fix fifo ordering in big endian mmc: dw_mmc: change idmac descriptor files to __le32 mmc: dw_mmc: make IO accessors endian agnostic mmc: core: Convert the error field in struct mmc_command|data into an int mmc: sdhci-of-arasan: Call OF parsing for MMC mmc: sdhci-pci: fix 64 BIT DMA quirks for rtsx mmc: Add support for marking hpi as broken through devicetree mmc: sdhci-tegra: convert to use GPIO descriptors mmc: omap_hsmmc: use generic slot-gpio isr to manage card detect pin ...
-rw-r--r--CREDITS4
-rw-r--r--Documentation/devicetree/bindings/mmc/brcm,sdhci-iproc.txt23
-rw-r--r--Documentation/devicetree/bindings/mmc/exynos-dw-mshc.txt7
-rw-r--r--Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt4
-rw-r--r--Documentation/devicetree/bindings/mmc/mmc-card.txt31
-rw-r--r--Documentation/devicetree/bindings/mmc/sdhci-st.txt100
-rw-r--r--MAINTAINERS16
-rw-r--r--arch/arm/mach-omap2/hsmmc.c33
-rw-r--r--drivers/mmc/core/core.c15
-rw-r--r--drivers/mmc/core/mmc.c10
-rw-r--r--drivers/mmc/core/pwrseq.c16
-rw-r--r--drivers/mmc/core/pwrseq.h6
-rw-r--r--drivers/mmc/core/pwrseq_emmc.c11
-rw-r--r--drivers/mmc/core/pwrseq_simple.c11
-rw-r--r--drivers/mmc/core/sdio.c32
-rw-r--r--drivers/mmc/host/Kconfig21
-rw-r--r--drivers/mmc/host/Makefile1
-rw-r--r--drivers/mmc/host/atmel-mci-regs.h11
-rw-r--r--drivers/mmc/host/dw_mmc-exynos.c185
-rw-r--r--drivers/mmc/host/dw_mmc-exynos.h19
-rw-r--r--drivers/mmc/host/dw_mmc-rockchip.c8
-rw-r--r--drivers/mmc/host/dw_mmc.c281
-rw-r--r--drivers/mmc/host/dw_mmc.h28
-rw-r--r--drivers/mmc/host/mmc_spi.c2
-rw-r--r--drivers/mmc/host/mmci.c5
-rw-r--r--drivers/mmc/host/omap_hsmmc.c119
-rw-r--r--drivers/mmc/host/sdhci-acpi.c1
-rw-r--r--drivers/mmc/host/sdhci-bcm-kona.c61
-rw-r--r--drivers/mmc/host/sdhci-bcm2835.c7
-rw-r--r--drivers/mmc/host/sdhci-cns3xxx.c7
-rw-r--r--drivers/mmc/host/sdhci-dove.c39
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c46
-rw-r--r--drivers/mmc/host/sdhci-iproc.c241
-rw-r--r--drivers/mmc/host/sdhci-msm.c29
-rw-r--r--drivers/mmc/host/sdhci-of-arasan.c7
-rw-r--r--drivers/mmc/host/sdhci-of-esdhc.c7
-rw-r--r--drivers/mmc/host/sdhci-of-hlwd.c7
-rw-r--r--drivers/mmc/host/sdhci-pci.c1
-rw-r--r--drivers/mmc/host/sdhci-pltfm.c56
-rw-r--r--drivers/mmc/host/sdhci-sirf.c42
-rw-r--r--drivers/mmc/host/sdhci-spear.c47
-rw-r--r--drivers/mmc/host/sdhci-st.c346
-rw-r--r--drivers/mmc/host/sdhci-tegra.c105
-rw-r--r--drivers/mmc/host/sdhci.c27
-rw-r--r--drivers/mmc/host/sdhci.h203
-rw-r--r--drivers/mmc/host/sh_mmcif.c17
-rw-r--r--drivers/mmc/host/sunxi-mmc.c11
-rw-r--r--drivers/mmc/host/tmio_mmc_pio.c2
-rw-r--r--drivers/mmc/host/wmt-sdmmc.c2
-rw-r--r--include/linux/mmc/core.h4
-rw-r--r--include/linux/mmc/dw_mmc.h6
-rw-r--r--include/linux/mmc/host.h6
-rw-r--r--include/linux/mmc/sdhci-spear.h34
-rw-r--r--include/linux/mmc/sdhci.h218
-rw-r--r--include/linux/platform_data/hsmmc-omap.h6
55 files changed, 1692 insertions, 892 deletions
diff --git a/CREDITS b/CREDITS
index 96935df0b6fe..843e17647f3b 100644
--- a/CREDITS
+++ b/CREDITS
@@ -187,6 +187,10 @@ N: Krishna Balasubramanian
187E: balasub@cis.ohio-state.edu 187E: balasub@cis.ohio-state.edu
188D: Wrote SYS V IPC (part of standard kernel since 0.99.10) 188D: Wrote SYS V IPC (part of standard kernel since 0.99.10)
189 189
190N: Chris Ball
191E: chris@printf.net
192D: Former maintainer of the MMC/SD/SDIO subsystem.
193
190N: Dario Ballabio 194N: Dario Ballabio
191E: ballabio_dario@emc.com 195E: ballabio_dario@emc.com
192E: dario.ballabio@tiscalinet.it 196E: dario.ballabio@tiscalinet.it
diff --git a/Documentation/devicetree/bindings/mmc/brcm,sdhci-iproc.txt b/Documentation/devicetree/bindings/mmc/brcm,sdhci-iproc.txt
new file mode 100644
index 000000000000..72cc9cc95880
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/brcm,sdhci-iproc.txt
@@ -0,0 +1,23 @@
1Broadcom IPROC SDHCI controller
2
3This file documents differences between the core properties described
4by mmc.txt and the properties that represent the IPROC SDHCI controller.
5
6Required properties:
7- compatible : Should be "brcm,sdhci-iproc-cygnus".
8- clocks : The clock feeding the SDHCI controller.
9
10Optional properties:
11 - sdhci,auto-cmd12: specifies that controller should use auto CMD12.
12
13Example:
14
15sdhci0: sdhci@0x18041000 {
16 compatible = "brcm,sdhci-iproc-cygnus";
17 reg = <0x18041000 0x100>;
18 interrupts = <GIC_SPI 108 IRQ_TYPE_LEVEL_HIGH>;
19 clocks = <&lcpll0_clks BCM_CYGNUS_LCPLL0_SDIO_CLK>;
20 bus-width = <4>;
21 sdhci,auto-cmd12;
22 no-1-8-v;
23};
diff --git a/Documentation/devicetree/bindings/mmc/exynos-dw-mshc.txt b/Documentation/devicetree/bindings/mmc/exynos-dw-mshc.txt
index ee4fc0576c7d..aad98442788b 100644
--- a/Documentation/devicetree/bindings/mmc/exynos-dw-mshc.txt
+++ b/Documentation/devicetree/bindings/mmc/exynos-dw-mshc.txt
@@ -36,6 +36,8 @@ Required Properties:
36 in transmit mode and CIU clock phase shift value in receive mode for double 36 in transmit mode and CIU clock phase shift value in receive mode for double
37 data rate mode operation. Refer notes below for the order of the cells and the 37 data rate mode operation. Refer notes below for the order of the cells and the
38 valid values. 38 valid values.
39* samsung,dw-mshc-hs400-timing: Specifies the value of CIU TX and RX clock phase
40 shift value for hs400 mode operation.
39 41
40 Notes for the sdr-timing and ddr-timing values: 42 Notes for the sdr-timing and ddr-timing values:
41 43
@@ -50,6 +52,9 @@ Required Properties:
50 - if CIU clock divider value is 0 (that is divide by 1), both tx and rx 52 - if CIU clock divider value is 0 (that is divide by 1), both tx and rx
51 phase shift clocks should be 0. 53 phase shift clocks should be 0.
52 54
55* samsung,read-strobe-delay: RCLK (Data strobe) delay to control HS400 mode
56 (Latency value for delay line in Read path)
57
53Required properties for a slot (Deprecated - Recommend to use one slot per host): 58Required properties for a slot (Deprecated - Recommend to use one slot per host):
54 59
55* gpios: specifies a list of gpios used for command, clock and data bus. The 60* gpios: specifies a list of gpios used for command, clock and data bus. The
@@ -82,5 +87,7 @@ Example:
82 samsung,dw-mshc-ciu-div = <3>; 87 samsung,dw-mshc-ciu-div = <3>;
83 samsung,dw-mshc-sdr-timing = <2 3>; 88 samsung,dw-mshc-sdr-timing = <2 3>;
84 samsung,dw-mshc-ddr-timing = <1 2>; 89 samsung,dw-mshc-ddr-timing = <1 2>;
90 samsung,dw-mshc-hs400-timing = <0 2>;
91 samsung,read-strobe-delay = <90>;
85 bus-width = <8>; 92 bus-width = <8>;
86 }; 93 };
diff --git a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
index 9046ba06c47a..415c5575cbf7 100644
--- a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
+++ b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
@@ -17,6 +17,10 @@ Optional properties:
17 to select a proper data sampling window in case the clock quality is not good 17 to select a proper data sampling window in case the clock quality is not good
18 due to signal path is too long on the board. Please refer to eSDHC/uSDHC 18 due to signal path is too long on the board. Please refer to eSDHC/uSDHC
19 chapter, DLL (Delay Line) section in RM for details. 19 chapter, DLL (Delay Line) section in RM for details.
20- voltage-ranges : Specify the voltage range in case there are software
21 transparent level shifters on the outputs of the controller. Two cells are
22 required, first cell specifies minimum slot voltage (mV), second cell
23 specifies maximum slot voltage (mV). Several ranges could be specified.
20 24
21Examples: 25Examples:
22 26
diff --git a/Documentation/devicetree/bindings/mmc/mmc-card.txt b/Documentation/devicetree/bindings/mmc/mmc-card.txt
new file mode 100644
index 000000000000..a70fcd65b9ea
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/mmc-card.txt
@@ -0,0 +1,31 @@
1mmc-card / eMMC bindings
2------------------------
3
4This documents describes the devicetree bindings for a mmc-host controller
5child node describing a mmc-card / an eMMC, see "Use of Function subnodes"
6in mmc.txt
7
8Required properties:
9-compatible : Must be "mmc-card"
10-reg : Must be <0>
11
12Optional properties:
13-broken-hpi : Use this to indicate that the mmc-card has a broken hpi
14 implementation, and that hpi should not be used
15
16Example:
17
18&mmc2 {
19 pinctrl-names = "default";
20 pinctrl-0 = <&mmc2_pins_a>;
21 vmmc-supply = <&reg_vcc3v3>;
22 bus-width = <8>;
23 non-removable;
24 status = "okay";
25
26 mmccard: mmccard@0 {
27 reg = <0>;
28 compatible = "mmc-card";
29 broken-hpi;
30 };
31};
diff --git a/Documentation/devicetree/bindings/mmc/sdhci-st.txt b/Documentation/devicetree/bindings/mmc/sdhci-st.txt
index 7527db447a35..18d950df2749 100644
--- a/Documentation/devicetree/bindings/mmc/sdhci-st.txt
+++ b/Documentation/devicetree/bindings/mmc/sdhci-st.txt
@@ -5,20 +5,62 @@ Documentation/devicetree/bindings/mmc/mmc.txt and the properties
5used by the sdhci-st driver. 5used by the sdhci-st driver.
6 6
7Required properties: 7Required properties:
8- compatible : Must be "st,sdhci" 8- compatible: Must be "st,sdhci" and it can be compatible to "st,sdhci-stih407"
9- clock-names : Should be "mmc" 9 to set the internal glue logic used for configuring the MMC
10 See: Documentation/devicetree/bindings/resource-names.txt 10 subsystem (mmcss) inside the FlashSS (available in STiH407 SoC
11- clocks : Phandle of the clock used by the sdhci controler 11 family).
12 See: Documentation/devicetree/bindings/clock/clock-bindings.txt 12
13- clock-names: Should be "mmc".
14 See: Documentation/devicetree/bindings/resource-names.txt
15- clocks: Phandle to the clock.
16 See: Documentation/devicetree/bindings/clock/clock-bindings.txt
17
18- interrupts: One mmc interrupt should be described here.
19- interrupt-names: Should be "mmcirq".
20
21- pinctrl-names: A pinctrl state names "default" must be defined.
22- pinctrl-0: Phandle referencing pin configuration of the sd/emmc controller.
23 See: Documentation/devicetree/bindings/pinctrl/pinctrl-binding.txt
24
25- reg: This must provide the host controller base address and it can also
26 contain the FlashSS Top register for TX/RX delay used by the driver
27 to configure DLL inside the flashSS, if so reg-names must also be
28 specified.
13 29
14Optional properties: 30Optional properties:
15- non-removable: non-removable slot 31- reg-names: Should be "mmc" and "top-mmc-delay". "top-mmc-delay" is optional
16 See: Documentation/devicetree/bindings/mmc/mmc.txt 32 for eMMC on stih407 family silicon to configure DLL inside FlashSS.
17- bus-width: Number of data lines 33
18 See: Documentation/devicetree/bindings/mmc/mmc.txt 34- non-removable: Non-removable slot. Also used for configuring mmcss in STiH407 SoC
35 family.
36 See: Documentation/devicetree/bindings/mmc/mmc.txt.
37
38- bus-width: Number of data lines.
39 See: Documentation/devicetree/bindings/mmc/mmc.txt.
40
41- max-frequency: Can be 200MHz, 100Mz or 50MHz (default) and used for
42 configuring the CCONFIG3 in the mmcss.
43 See: Documentation/devicetree/bindings/mmc/mmc.txt.
44
45- resets: Phandle and reset specifier pair to softreset line of HC IP.
46 See: Documentation/devicetree/bindings/reset/reset.txt
47
48- vqmmc-supply: Phandle to the regulator dt node, mentioned as the vcc/vdd
49 supply in eMMC/SD specs.
50
51- sd-uhs--sdr50: To enable the SDR50 in the mmcss.
52 See: Documentation/devicetree/bindings/mmc/mmc.txt.
53
54- sd-uhs-sdr104: To enable the SDR104 in the mmcss.
55 See: Documentation/devicetree/bindings/mmc/mmc.txt.
56
57- sd-uhs-ddr50: To enable the DDR50 in the mmcss.
58 See: Documentation/devicetree/bindings/mmc/mmc.txt.
19 59
20Example: 60Example:
21 61
62/* Example stih416e eMMC configuration */
63
22mmc0: sdhci@fe81e000 { 64mmc0: sdhci@fe81e000 {
23 compatible = "st,sdhci"; 65 compatible = "st,sdhci";
24 status = "disabled"; 66 status = "disabled";
@@ -29,5 +71,43 @@ mmc0: sdhci@fe81e000 {
29 pinctrl-0 = <&pinctrl_mmc0>; 71 pinctrl-0 = <&pinctrl_mmc0>;
30 clock-names = "mmc"; 72 clock-names = "mmc";
31 clocks = <&clk_s_a1_ls 1>; 73 clocks = <&clk_s_a1_ls 1>;
32 bus-width = <8> 74 bus-width = <8>
75
76/* Example SD stih407 family configuration */
77
78mmc1: sdhci@09080000 {
79 compatible = "st,sdhci-stih407", "st,sdhci";
80 status = "disabled";
81 reg = <0x09080000 0x7ff>;
82 reg-names = "mmc";
83 interrupts = <GIC_SPI 90 IRQ_TYPE_NONE>;
84 interrupt-names = "mmcirq";
85 pinctrl-names = "default";
86 pinctrl-0 = <&pinctrl_sd1>;
87 clock-names = "mmc";
88 clocks = <&clk_s_c0_flexgen CLK_MMC_1>;
89 resets = <&softreset STIH407_MMC1_SOFTRESET>;
90 bus-width = <4>;
91};
92
93/* Example eMMC stih407 family configuration */
94
95mmc0: sdhci@09060000 {
96 compatible = "st,sdhci-stih407", "st,sdhci";
97 status = "disabled";
98 reg = <0x09060000 0x7ff>, <0x9061008 0x20>;
99 reg-names = "mmc", "top-mmc-delay";
100 interrupts = <GIC_SPI 92 IRQ_TYPE_NONE>;
101 interrupt-names = "mmcirq";
102 pinctrl-names = "default";
103 pinctrl-0 = <&pinctrl_mmc0>;
104 clock-names = "mmc";
105 clocks = <&clk_s_c0_flexgen CLK_MMC_0>;
106 vqmmc-supply = <&vmmc_reg>;
107 max-frequency = <200000000>;
108 bus-width = <8>;
109 non-removable;
110 sd-uhs-sdr50;
111 sd-uhs-sdr104;
112 sd-uhs-ddr50;
33}; 113};
diff --git a/MAINTAINERS b/MAINTAINERS
index b84686826b23..8d2ee8e010a1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6566,10 +6566,8 @@ F: drivers/mfd/
6566F: include/linux/mfd/ 6566F: include/linux/mfd/
6567 6567
6568MULTIMEDIA CARD (MMC), SECURE DIGITAL (SD) AND SDIO SUBSYSTEM 6568MULTIMEDIA CARD (MMC), SECURE DIGITAL (SD) AND SDIO SUBSYSTEM
6569M: Chris Ball <chris@printf.net>
6570M: Ulf Hansson <ulf.hansson@linaro.org> 6569M: Ulf Hansson <ulf.hansson@linaro.org>
6571L: linux-mmc@vger.kernel.org 6570L: linux-mmc@vger.kernel.org
6572T: git git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc.git
6573T: git git://git.linaro.org/people/ulf.hansson/mmc.git 6571T: git git://git.linaro.org/people/ulf.hansson/mmc.git
6574S: Maintained 6572S: Maintained
6575F: drivers/mmc/ 6573F: drivers/mmc/
@@ -8670,10 +8668,8 @@ S: Maintained
8670F: drivers/mmc/host/sdricoh_cs.c 8668F: drivers/mmc/host/sdricoh_cs.c
8671 8669
8672SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) DRIVER 8670SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) DRIVER
8673M: Chris Ball <chris@printf.net>
8674L: linux-mmc@vger.kernel.org 8671L: linux-mmc@vger.kernel.org
8675T: git git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc.git 8672S: Orphan
8676S: Maintained
8677F: drivers/mmc/host/sdhci.* 8673F: drivers/mmc/host/sdhci.*
8678F: drivers/mmc/host/sdhci-pltfm.[ch] 8674F: drivers/mmc/host/sdhci-pltfm.[ch]
8679 8675
@@ -8689,18 +8685,12 @@ F: include/linux/seccomp.h
8689K: \bsecure_computing 8685K: \bsecure_computing
8690K: \bTIF_SECCOMP\b 8686K: \bTIF_SECCOMP\b
8691 8687
8692SECURE DIGITAL HOST CONTROLLER INTERFACE, OPEN FIRMWARE BINDINGS (SDHCI-OF)
8693M: Anton Vorontsov <anton@enomsg.org>
8694L: linuxppc-dev@lists.ozlabs.org
8695L: linux-mmc@vger.kernel.org
8696S: Maintained
8697F: drivers/mmc/host/sdhci-pltfm.[ch]
8698
8699SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) SAMSUNG DRIVER 8688SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) SAMSUNG DRIVER
8700M: Ben Dooks <ben-linux@fluff.org> 8689M: Ben Dooks <ben-linux@fluff.org>
8690M: Jaehoon Chung <jh80.chung@samsung.com>
8701L: linux-mmc@vger.kernel.org 8691L: linux-mmc@vger.kernel.org
8702S: Maintained 8692S: Maintained
8703F: drivers/mmc/host/sdhci-s3c.c 8693F: drivers/mmc/host/sdhci-s3c*
8704 8694
8705SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) ST SPEAR DRIVER 8695SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) ST SPEAR DRIVER
8706M: Viresh Kumar <viresh.linux@gmail.com> 8696M: Viresh Kumar <viresh.linux@gmail.com>
diff --git a/arch/arm/mach-omap2/hsmmc.c b/arch/arm/mach-omap2/hsmmc.c
index dc6e79c4484a..9a8611ab5dfa 100644
--- a/arch/arm/mach-omap2/hsmmc.c
+++ b/arch/arm/mach-omap2/hsmmc.c
@@ -150,9 +150,13 @@ static int nop_mmc_set_power(struct device *dev, int power_on, int vdd)
150static inline void omap_hsmmc_mux(struct omap_hsmmc_platform_data 150static inline void omap_hsmmc_mux(struct omap_hsmmc_platform_data
151 *mmc_controller, int controller_nr) 151 *mmc_controller, int controller_nr)
152{ 152{
153 if (gpio_is_valid(mmc_controller->switch_pin) && 153 if (gpio_is_valid(mmc_controller->gpio_cd) &&
154 (mmc_controller->switch_pin < OMAP_MAX_GPIO_LINES)) 154 (mmc_controller->gpio_cd < OMAP_MAX_GPIO_LINES))
155 omap_mux_init_gpio(mmc_controller->switch_pin, 155 omap_mux_init_gpio(mmc_controller->gpio_cd,
156 OMAP_PIN_INPUT_PULLUP);
157 if (gpio_is_valid(mmc_controller->gpio_cod) &&
158 (mmc_controller->gpio_cod < OMAP_MAX_GPIO_LINES))
159 omap_mux_init_gpio(mmc_controller->gpio_cod,
156 OMAP_PIN_INPUT_PULLUP); 160 OMAP_PIN_INPUT_PULLUP);
157 if (gpio_is_valid(mmc_controller->gpio_wp) && 161 if (gpio_is_valid(mmc_controller->gpio_wp) &&
158 (mmc_controller->gpio_wp < OMAP_MAX_GPIO_LINES)) 162 (mmc_controller->gpio_wp < OMAP_MAX_GPIO_LINES))
@@ -250,15 +254,20 @@ static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
250 mmc->internal_clock = !c->ext_clock; 254 mmc->internal_clock = !c->ext_clock;
251 mmc->reg_offset = 0; 255 mmc->reg_offset = 0;
252 256
253 mmc->switch_pin = c->gpio_cd; 257 if (c->cover_only) {
258 /* detect if mobile phone cover removed */
259 mmc->gpio_cd = -EINVAL;
260 mmc->gpio_cod = c->gpio_cd;
261 } else {
262 /* card detect pin on the mmc socket itself */
263 mmc->gpio_cd = c->gpio_cd;
264 mmc->gpio_cod = -EINVAL;
265 }
254 mmc->gpio_wp = c->gpio_wp; 266 mmc->gpio_wp = c->gpio_wp;
255 267
256 mmc->remux = c->remux; 268 mmc->remux = c->remux;
257 mmc->init_card = c->init_card; 269 mmc->init_card = c->init_card;
258 270
259 if (c->cover_only)
260 mmc->cover = 1;
261
262 if (c->nonremovable) 271 if (c->nonremovable)
263 mmc->nonremovable = 1; 272 mmc->nonremovable = 1;
264 273
@@ -358,7 +367,15 @@ void omap_hsmmc_late_init(struct omap2_hsmmc_info *c)
358 if (!mmc_pdata) 367 if (!mmc_pdata)
359 continue; 368 continue;
360 369
361 mmc_pdata->switch_pin = c->gpio_cd; 370 if (c->cover_only) {
371 /* detect if mobile phone cover removed */
372 mmc_pdata->gpio_cd = -EINVAL;
373 mmc_pdata->gpio_cod = c->gpio_cd;
374 } else {
375 /* card detect pin on the mmc socket itself */
376 mmc_pdata->gpio_cd = c->gpio_cd;
377 mmc_pdata->gpio_cod = -EINVAL;
378 }
362 mmc_pdata->gpio_wp = c->gpio_wp; 379 mmc_pdata->gpio_wp = c->gpio_wp;
363 380
364 res = omap_device_register(pdev); 381 res = omap_device_register(pdev);
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 23f10f72e5f3..c296bc098fe2 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -897,6 +897,7 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
897 DECLARE_WAITQUEUE(wait, current); 897 DECLARE_WAITQUEUE(wait, current);
898 unsigned long flags; 898 unsigned long flags;
899 int stop; 899 int stop;
900 bool pm = false;
900 901
901 might_sleep(); 902 might_sleep();
902 903
@@ -916,15 +917,18 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
916 host->claimed = 1; 917 host->claimed = 1;
917 host->claimer = current; 918 host->claimer = current;
918 host->claim_cnt += 1; 919 host->claim_cnt += 1;
920 if (host->claim_cnt == 1)
921 pm = true;
919 } else 922 } else
920 wake_up(&host->wq); 923 wake_up(&host->wq);
921 spin_unlock_irqrestore(&host->lock, flags); 924 spin_unlock_irqrestore(&host->lock, flags);
922 remove_wait_queue(&host->wq, &wait); 925 remove_wait_queue(&host->wq, &wait);
923 if (host->ops->enable && !stop && host->claim_cnt == 1) 926
924 host->ops->enable(host); 927 if (pm)
928 pm_runtime_get_sync(mmc_dev(host));
929
925 return stop; 930 return stop;
926} 931}
927
928EXPORT_SYMBOL(__mmc_claim_host); 932EXPORT_SYMBOL(__mmc_claim_host);
929 933
930/** 934/**
@@ -940,9 +944,6 @@ void mmc_release_host(struct mmc_host *host)
940 944
941 WARN_ON(!host->claimed); 945 WARN_ON(!host->claimed);
942 946
943 if (host->ops->disable && host->claim_cnt == 1)
944 host->ops->disable(host);
945
946 spin_lock_irqsave(&host->lock, flags); 947 spin_lock_irqsave(&host->lock, flags);
947 if (--host->claim_cnt) { 948 if (--host->claim_cnt) {
948 /* Release for nested claim */ 949 /* Release for nested claim */
@@ -952,6 +953,8 @@ void mmc_release_host(struct mmc_host *host)
952 host->claimer = NULL; 953 host->claimer = NULL;
953 spin_unlock_irqrestore(&host->lock, flags); 954 spin_unlock_irqrestore(&host->lock, flags);
954 wake_up(&host->wq); 955 wake_up(&host->wq);
956 pm_runtime_mark_last_busy(mmc_dev(host));
957 pm_runtime_put_autosuspend(mmc_dev(host));
955 } 958 }
956} 959}
957EXPORT_SYMBOL(mmc_release_host); 960EXPORT_SYMBOL(mmc_release_host);
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 1d41e8541f38..c84131e28625 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <linux/err.h> 13#include <linux/err.h>
14#include <linux/of.h>
14#include <linux/slab.h> 15#include <linux/slab.h>
15#include <linux/stat.h> 16#include <linux/stat.h>
16#include <linux/pm_runtime.h> 17#include <linux/pm_runtime.h>
@@ -336,6 +337,8 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd)
336{ 337{
337 int err = 0, idx; 338 int err = 0, idx;
338 unsigned int part_size; 339 unsigned int part_size;
340 struct device_node *np;
341 bool broken_hpi = false;
339 342
340 /* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */ 343 /* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */
341 card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE]; 344 card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE];
@@ -349,6 +352,11 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd)
349 } 352 }
350 } 353 }
351 354
355 np = mmc_of_find_child_device(card->host, 0);
356 if (np && of_device_is_compatible(np, "mmc-card"))
357 broken_hpi = of_property_read_bool(np, "broken-hpi");
358 of_node_put(np);
359
352 /* 360 /*
353 * The EXT_CSD format is meant to be forward compatible. As long 361 * The EXT_CSD format is meant to be forward compatible. As long
354 * as CSD_STRUCTURE does not change, all values for EXT_CSD_REV 362 * as CSD_STRUCTURE does not change, all values for EXT_CSD_REV
@@ -494,7 +502,7 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd)
494 } 502 }
495 503
496 /* check whether the eMMC card supports HPI */ 504 /* check whether the eMMC card supports HPI */
497 if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x1) { 505 if (!broken_hpi && (ext_csd[EXT_CSD_HPI_FEATURES] & 0x1)) {
498 card->ext_csd.hpi = 1; 506 card->ext_csd.hpi = 1;
499 if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x2) 507 if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x2)
500 card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION; 508 card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION;
diff --git a/drivers/mmc/core/pwrseq.c b/drivers/mmc/core/pwrseq.c
index 862356123d78..ab2129781161 100644
--- a/drivers/mmc/core/pwrseq.c
+++ b/drivers/mmc/core/pwrseq.c
@@ -19,7 +19,7 @@
19 19
20struct mmc_pwrseq_match { 20struct mmc_pwrseq_match {
21 const char *compatible; 21 const char *compatible;
22 int (*alloc)(struct mmc_host *host, struct device *dev); 22 struct mmc_pwrseq *(*alloc)(struct mmc_host *host, struct device *dev);
23}; 23};
24 24
25static struct mmc_pwrseq_match pwrseq_match[] = { 25static struct mmc_pwrseq_match pwrseq_match[] = {
@@ -52,6 +52,7 @@ int mmc_pwrseq_alloc(struct mmc_host *host)
52 struct platform_device *pdev; 52 struct platform_device *pdev;
53 struct device_node *np; 53 struct device_node *np;
54 struct mmc_pwrseq_match *match; 54 struct mmc_pwrseq_match *match;
55 struct mmc_pwrseq *pwrseq;
55 int ret = 0; 56 int ret = 0;
56 57
57 np = of_parse_phandle(host->parent->of_node, "mmc-pwrseq", 0); 58 np = of_parse_phandle(host->parent->of_node, "mmc-pwrseq", 0);
@@ -70,9 +71,14 @@ int mmc_pwrseq_alloc(struct mmc_host *host)
70 goto err; 71 goto err;
71 } 72 }
72 73
73 ret = match->alloc(host, &pdev->dev); 74 pwrseq = match->alloc(host, &pdev->dev);
74 if (!ret) 75 if (IS_ERR(pwrseq)) {
75 dev_info(host->parent, "allocated mmc-pwrseq\n"); 76 ret = PTR_ERR(host->pwrseq);
77 goto err;
78 }
79
80 host->pwrseq = pwrseq;
81 dev_info(host->parent, "allocated mmc-pwrseq\n");
76 82
77err: 83err:
78 of_node_put(np); 84 of_node_put(np);
@@ -109,4 +115,6 @@ void mmc_pwrseq_free(struct mmc_host *host)
109 115
110 if (pwrseq && pwrseq->ops && pwrseq->ops->free) 116 if (pwrseq && pwrseq->ops && pwrseq->ops->free)
111 pwrseq->ops->free(host); 117 pwrseq->ops->free(host);
118
119 host->pwrseq = NULL;
112} 120}
diff --git a/drivers/mmc/core/pwrseq.h b/drivers/mmc/core/pwrseq.h
index aba3409e8d6e..096da48c6a7e 100644
--- a/drivers/mmc/core/pwrseq.h
+++ b/drivers/mmc/core/pwrseq.h
@@ -27,8 +27,10 @@ void mmc_pwrseq_post_power_on(struct mmc_host *host);
27void mmc_pwrseq_power_off(struct mmc_host *host); 27void mmc_pwrseq_power_off(struct mmc_host *host);
28void mmc_pwrseq_free(struct mmc_host *host); 28void mmc_pwrseq_free(struct mmc_host *host);
29 29
30int mmc_pwrseq_simple_alloc(struct mmc_host *host, struct device *dev); 30struct mmc_pwrseq *mmc_pwrseq_simple_alloc(struct mmc_host *host,
31int mmc_pwrseq_emmc_alloc(struct mmc_host *host, struct device *dev); 31 struct device *dev);
32struct mmc_pwrseq *mmc_pwrseq_emmc_alloc(struct mmc_host *host,
33 struct device *dev);
32 34
33#else 35#else
34 36
diff --git a/drivers/mmc/core/pwrseq_emmc.c b/drivers/mmc/core/pwrseq_emmc.c
index a2d545904fbf..9d6d2fb21796 100644
--- a/drivers/mmc/core/pwrseq_emmc.c
+++ b/drivers/mmc/core/pwrseq_emmc.c
@@ -49,7 +49,6 @@ static void mmc_pwrseq_emmc_free(struct mmc_host *host)
49 unregister_restart_handler(&pwrseq->reset_nb); 49 unregister_restart_handler(&pwrseq->reset_nb);
50 gpiod_put(pwrseq->reset_gpio); 50 gpiod_put(pwrseq->reset_gpio);
51 kfree(pwrseq); 51 kfree(pwrseq);
52 host->pwrseq = NULL;
53} 52}
54 53
55static struct mmc_pwrseq_ops mmc_pwrseq_emmc_ops = { 54static struct mmc_pwrseq_ops mmc_pwrseq_emmc_ops = {
@@ -67,14 +66,15 @@ static int mmc_pwrseq_emmc_reset_nb(struct notifier_block *this,
67 return NOTIFY_DONE; 66 return NOTIFY_DONE;
68} 67}
69 68
70int mmc_pwrseq_emmc_alloc(struct mmc_host *host, struct device *dev) 69struct mmc_pwrseq *mmc_pwrseq_emmc_alloc(struct mmc_host *host,
70 struct device *dev)
71{ 71{
72 struct mmc_pwrseq_emmc *pwrseq; 72 struct mmc_pwrseq_emmc *pwrseq;
73 int ret = 0; 73 int ret = 0;
74 74
75 pwrseq = kzalloc(sizeof(struct mmc_pwrseq_emmc), GFP_KERNEL); 75 pwrseq = kzalloc(sizeof(struct mmc_pwrseq_emmc), GFP_KERNEL);
76 if (!pwrseq) 76 if (!pwrseq)
77 return -ENOMEM; 77 return ERR_PTR(-ENOMEM);
78 78
79 pwrseq->reset_gpio = gpiod_get_index(dev, "reset", 0, GPIOD_OUT_LOW); 79 pwrseq->reset_gpio = gpiod_get_index(dev, "reset", 0, GPIOD_OUT_LOW);
80 if (IS_ERR(pwrseq->reset_gpio)) { 80 if (IS_ERR(pwrseq->reset_gpio)) {
@@ -92,10 +92,9 @@ int mmc_pwrseq_emmc_alloc(struct mmc_host *host, struct device *dev)
92 register_restart_handler(&pwrseq->reset_nb); 92 register_restart_handler(&pwrseq->reset_nb);
93 93
94 pwrseq->pwrseq.ops = &mmc_pwrseq_emmc_ops; 94 pwrseq->pwrseq.ops = &mmc_pwrseq_emmc_ops;
95 host->pwrseq = &pwrseq->pwrseq;
96 95
97 return 0; 96 return &pwrseq->pwrseq;
98free: 97free:
99 kfree(pwrseq); 98 kfree(pwrseq);
100 return ret; 99 return ERR_PTR(ret);
101} 100}
diff --git a/drivers/mmc/core/pwrseq_simple.c b/drivers/mmc/core/pwrseq_simple.c
index c53f14a7ce54..0b14b83a53d6 100644
--- a/drivers/mmc/core/pwrseq_simple.c
+++ b/drivers/mmc/core/pwrseq_simple.c
@@ -85,7 +85,6 @@ static void mmc_pwrseq_simple_free(struct mmc_host *host)
85 clk_put(pwrseq->ext_clk); 85 clk_put(pwrseq->ext_clk);
86 86
87 kfree(pwrseq); 87 kfree(pwrseq);
88 host->pwrseq = NULL;
89} 88}
90 89
91static struct mmc_pwrseq_ops mmc_pwrseq_simple_ops = { 90static struct mmc_pwrseq_ops mmc_pwrseq_simple_ops = {
@@ -95,7 +94,8 @@ static struct mmc_pwrseq_ops mmc_pwrseq_simple_ops = {
95 .free = mmc_pwrseq_simple_free, 94 .free = mmc_pwrseq_simple_free,
96}; 95};
97 96
98int mmc_pwrseq_simple_alloc(struct mmc_host *host, struct device *dev) 97struct mmc_pwrseq *mmc_pwrseq_simple_alloc(struct mmc_host *host,
98 struct device *dev)
99{ 99{
100 struct mmc_pwrseq_simple *pwrseq; 100 struct mmc_pwrseq_simple *pwrseq;
101 int i, nr_gpios, ret = 0; 101 int i, nr_gpios, ret = 0;
@@ -107,7 +107,7 @@ int mmc_pwrseq_simple_alloc(struct mmc_host *host, struct device *dev)
107 pwrseq = kzalloc(sizeof(struct mmc_pwrseq_simple) + nr_gpios * 107 pwrseq = kzalloc(sizeof(struct mmc_pwrseq_simple) + nr_gpios *
108 sizeof(struct gpio_desc *), GFP_KERNEL); 108 sizeof(struct gpio_desc *), GFP_KERNEL);
109 if (!pwrseq) 109 if (!pwrseq)
110 return -ENOMEM; 110 return ERR_PTR(-ENOMEM);
111 111
112 pwrseq->ext_clk = clk_get(dev, "ext_clock"); 112 pwrseq->ext_clk = clk_get(dev, "ext_clock");
113 if (IS_ERR(pwrseq->ext_clk) && 113 if (IS_ERR(pwrseq->ext_clk) &&
@@ -133,13 +133,12 @@ int mmc_pwrseq_simple_alloc(struct mmc_host *host, struct device *dev)
133 133
134 pwrseq->nr_gpios = nr_gpios; 134 pwrseq->nr_gpios = nr_gpios;
135 pwrseq->pwrseq.ops = &mmc_pwrseq_simple_ops; 135 pwrseq->pwrseq.ops = &mmc_pwrseq_simple_ops;
136 host->pwrseq = &pwrseq->pwrseq;
137 136
138 return 0; 137 return &pwrseq->pwrseq;
139clk_put: 138clk_put:
140 if (!IS_ERR(pwrseq->ext_clk)) 139 if (!IS_ERR(pwrseq->ext_clk))
141 clk_put(pwrseq->ext_clk); 140 clk_put(pwrseq->ext_clk);
142free: 141free:
143 kfree(pwrseq); 142 kfree(pwrseq);
144 return ret; 143 return ERR_PTR(ret);
145} 144}
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index ce6cc47206b0..5bc6c7dbbd60 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -293,19 +293,22 @@ static int sdio_enable_4bit_bus(struct mmc_card *card)
293 int err; 293 int err;
294 294
295 if (card->type == MMC_TYPE_SDIO) 295 if (card->type == MMC_TYPE_SDIO)
296 return sdio_enable_wide(card); 296 err = sdio_enable_wide(card);
297 297 else if ((card->host->caps & MMC_CAP_4_BIT_DATA) &&
298 if ((card->host->caps & MMC_CAP_4_BIT_DATA) && 298 (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
299 (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
300 err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4); 299 err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4);
301 if (err) 300 if (err)
302 return err; 301 return err;
302 err = sdio_enable_wide(card);
303 if (err <= 0)
304 mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1);
303 } else 305 } else
304 return 0; 306 return 0;
305 307
306 err = sdio_enable_wide(card); 308 if (err > 0) {
307 if (err <= 0) 309 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
308 mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1); 310 err = 0;
311 }
309 312
310 return err; 313 return err;
311} 314}
@@ -547,13 +550,8 @@ static int mmc_sdio_init_uhs_card(struct mmc_card *card)
547 /* 550 /*
548 * Switch to wider bus (if supported). 551 * Switch to wider bus (if supported).
549 */ 552 */
550 if (card->host->caps & MMC_CAP_4_BIT_DATA) { 553 if (card->host->caps & MMC_CAP_4_BIT_DATA)
551 err = sdio_enable_4bit_bus(card); 554 err = sdio_enable_4bit_bus(card);
552 if (err > 0) {
553 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
554 err = 0;
555 }
556 }
557 555
558 /* Set the driver strength for the card */ 556 /* Set the driver strength for the card */
559 sdio_select_driver_type(card); 557 sdio_select_driver_type(card);
@@ -803,9 +801,7 @@ try_again:
803 * Switch to wider bus (if supported). 801 * Switch to wider bus (if supported).
804 */ 802 */
805 err = sdio_enable_4bit_bus(card); 803 err = sdio_enable_4bit_bus(card);
806 if (err > 0) 804 if (err)
807 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
808 else if (err)
809 goto remove; 805 goto remove;
810 } 806 }
811finish: 807finish:
@@ -983,10 +979,6 @@ static int mmc_sdio_resume(struct mmc_host *host)
983 } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) { 979 } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
984 /* We may have switched to 1-bit mode during suspend */ 980 /* We may have switched to 1-bit mode during suspend */
985 err = sdio_enable_4bit_bus(host->card); 981 err = sdio_enable_4bit_bus(host->card);
986 if (err > 0) {
987 mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
988 err = 0;
989 }
990 } 982 }
991 983
992 if (!err && host->sdio_irqs) { 984 if (!err && host->sdio_irqs) {
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 61ac63a3776a..7f4db908f89b 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -132,7 +132,7 @@ config MMC_SDHCI_OF_ARASAN
132config MMC_SDHCI_OF_ESDHC 132config MMC_SDHCI_OF_ESDHC
133 tristate "SDHCI OF support for the Freescale eSDHC controller" 133 tristate "SDHCI OF support for the Freescale eSDHC controller"
134 depends on MMC_SDHCI_PLTFM 134 depends on MMC_SDHCI_PLTFM
135 depends on PPC_OF 135 depends on PPC
136 select MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER 136 select MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER
137 help 137 help
138 This selects the Freescale eSDHC controller support. 138 This selects the Freescale eSDHC controller support.
@@ -144,7 +144,7 @@ config MMC_SDHCI_OF_ESDHC
144config MMC_SDHCI_OF_HLWD 144config MMC_SDHCI_OF_HLWD
145 tristate "SDHCI OF support for the Nintendo Wii SDHCI controllers" 145 tristate "SDHCI OF support for the Nintendo Wii SDHCI controllers"
146 depends on MMC_SDHCI_PLTFM 146 depends on MMC_SDHCI_PLTFM
147 depends on PPC_OF 147 depends on PPC
148 select MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER 148 select MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER
149 help 149 help
150 This selects the Secure Digital Host Controller Interface (SDHCI) 150 This selects the Secure Digital Host Controller Interface (SDHCI)
@@ -230,7 +230,7 @@ config MMC_SDHCI_PXAV3
230 tristate "Marvell MMP2 SD Host Controller support (PXAV3)" 230 tristate "Marvell MMP2 SD Host Controller support (PXAV3)"
231 depends on CLKDEV_LOOKUP 231 depends on CLKDEV_LOOKUP
232 depends on MMC_SDHCI_PLTFM 232 depends on MMC_SDHCI_PLTFM
233 depends on ARCH_MMP || COMPILE_TEST 233 depends on ARCH_BERLIN || ARCH_MMP || ARCH_MVEBU || COMPILE_TEST
234 default CPU_MMP2 234 default CPU_MMP2
235 help 235 help
236 This selects the Marvell(R) PXAV3 SD Host Controller. 236 This selects the Marvell(R) PXAV3 SD Host Controller.
@@ -255,6 +255,7 @@ config MMC_SDHCI_PXAV2
255config MMC_SDHCI_SPEAR 255config MMC_SDHCI_SPEAR
256 tristate "SDHCI support on ST SPEAr platform" 256 tristate "SDHCI support on ST SPEAr platform"
257 depends on MMC_SDHCI && PLAT_SPEAR 257 depends on MMC_SDHCI && PLAT_SPEAR
258 depends on OF
258 help 259 help
259 This selects the Secure Digital Host Controller Interface (SDHCI) 260 This selects the Secure Digital Host Controller Interface (SDHCI)
260 often referrered to as the HSMMC block in some of the ST SPEAR range 261 often referrered to as the HSMMC block in some of the ST SPEAR range
@@ -307,6 +308,20 @@ config MMC_SDHCI_F_SDH30
307 308
308 If unsure, say N. 309 If unsure, say N.
309 310
311config MMC_SDHCI_IPROC
312 tristate "SDHCI platform support for the iProc SD/MMC Controller"
313 depends on ARCH_BCM_IPROC || COMPILE_TEST
314 depends on MMC_SDHCI_PLTFM
315 default ARCH_BCM_IPROC
316 select MMC_SDHCI_IO_ACCESSORS
317 help
318 This selects the iProc SD/MMC controller.
319
320 If you have an IPROC platform with SD or MMC devices,
321 say Y or M here.
322
323 If unsure, say N.
324
310config MMC_MOXART 325config MMC_MOXART
311 tristate "MOXART SD/MMC Host Controller support" 326 tristate "MOXART SD/MMC Host Controller support"
312 depends on ARCH_MOXART && MMC 327 depends on ARCH_MOXART && MMC
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index 6a7cfe0de332..711e913450f5 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o
71obj-$(CONFIG_MMC_SDHCI_OF_HLWD) += sdhci-of-hlwd.o 71obj-$(CONFIG_MMC_SDHCI_OF_HLWD) += sdhci-of-hlwd.o
72obj-$(CONFIG_MMC_SDHCI_BCM_KONA) += sdhci-bcm-kona.o 72obj-$(CONFIG_MMC_SDHCI_BCM_KONA) += sdhci-bcm-kona.o
73obj-$(CONFIG_MMC_SDHCI_BCM2835) += sdhci-bcm2835.o 73obj-$(CONFIG_MMC_SDHCI_BCM2835) += sdhci-bcm2835.o
74obj-$(CONFIG_MMC_SDHCI_IPROC) += sdhci-iproc.o
74obj-$(CONFIG_MMC_SDHCI_MSM) += sdhci-msm.o 75obj-$(CONFIG_MMC_SDHCI_MSM) += sdhci-msm.o
75obj-$(CONFIG_MMC_SDHCI_ST) += sdhci-st.o 76obj-$(CONFIG_MMC_SDHCI_ST) += sdhci-st.o
76 77
diff --git a/drivers/mmc/host/atmel-mci-regs.h b/drivers/mmc/host/atmel-mci-regs.h
index c97001e15227..0aa44e679df4 100644
--- a/drivers/mmc/host/atmel-mci-regs.h
+++ b/drivers/mmc/host/atmel-mci-regs.h
@@ -135,10 +135,17 @@
135#define ATMCI_REGS_SIZE 0x100 135#define ATMCI_REGS_SIZE 0x100
136 136
137/* Register access macros */ 137/* Register access macros */
138#define atmci_readl(port,reg) \ 138#ifdef CONFIG_AVR32
139#define atmci_readl(port, reg) \
139 __raw_readl((port)->regs + reg) 140 __raw_readl((port)->regs + reg)
140#define atmci_writel(port,reg,value) \ 141#define atmci_writel(port, reg, value) \
141 __raw_writel((value), (port)->regs + reg) 142 __raw_writel((value), (port)->regs + reg)
143#else
144#define atmci_readl(port, reg) \
145 readl_relaxed((port)->regs + reg)
146#define atmci_writel(port, reg, value) \
147 writel_relaxed((value), (port)->regs + reg)
148#endif
142 149
143/* On AVR chips the Peripheral DMA Controller is not connected to MCI. */ 150/* On AVR chips the Peripheral DMA Controller is not connected to MCI. */
144#ifdef CONFIG_AVR32 151#ifdef CONFIG_AVR32
diff --git a/drivers/mmc/host/dw_mmc-exynos.c b/drivers/mmc/host/dw_mmc-exynos.c
index fe32948c6114..e761eb1b1441 100644
--- a/drivers/mmc/host/dw_mmc-exynos.c
+++ b/drivers/mmc/host/dw_mmc-exynos.c
@@ -40,7 +40,12 @@ struct dw_mci_exynos_priv_data {
40 u8 ciu_div; 40 u8 ciu_div;
41 u32 sdr_timing; 41 u32 sdr_timing;
42 u32 ddr_timing; 42 u32 ddr_timing;
43 u32 hs400_timing;
44 u32 tuned_sample;
43 u32 cur_speed; 45 u32 cur_speed;
46 u32 dqs_delay;
47 u32 saved_dqs_en;
48 u32 saved_strobe_ctrl;
44}; 49};
45 50
46static struct dw_mci_exynos_compatible { 51static struct dw_mci_exynos_compatible {
@@ -71,6 +76,21 @@ static struct dw_mci_exynos_compatible {
71 }, 76 },
72}; 77};
73 78
79static inline u8 dw_mci_exynos_get_ciu_div(struct dw_mci *host)
80{
81 struct dw_mci_exynos_priv_data *priv = host->priv;
82
83 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412)
84 return EXYNOS4412_FIXED_CIU_CLK_DIV;
85 else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210)
86 return EXYNOS4210_FIXED_CIU_CLK_DIV;
87 else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
88 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
89 return SDMMC_CLKSEL_GET_DIV(mci_readl(host, CLKSEL64)) + 1;
90 else
91 return SDMMC_CLKSEL_GET_DIV(mci_readl(host, CLKSEL)) + 1;
92}
93
74static int dw_mci_exynos_priv_init(struct dw_mci *host) 94static int dw_mci_exynos_priv_init(struct dw_mci *host)
75{ 95{
76 struct dw_mci_exynos_priv_data *priv = host->priv; 96 struct dw_mci_exynos_priv_data *priv = host->priv;
@@ -85,6 +105,16 @@ static int dw_mci_exynos_priv_init(struct dw_mci *host)
85 SDMMC_MPSCTRL_NON_SECURE_WRITE_BIT); 105 SDMMC_MPSCTRL_NON_SECURE_WRITE_BIT);
86 } 106 }
87 107
108 if (priv->ctrl_type >= DW_MCI_TYPE_EXYNOS5420) {
109 priv->saved_strobe_ctrl = mci_readl(host, HS400_DLINE_CTRL);
110 priv->saved_dqs_en = mci_readl(host, HS400_DQS_EN);
111 priv->saved_dqs_en |= AXI_NON_BLOCKING_WR;
112 mci_writel(host, HS400_DQS_EN, priv->saved_dqs_en);
113 if (!priv->dqs_delay)
114 priv->dqs_delay =
115 DQS_CTRL_GET_RD_DELAY(priv->saved_strobe_ctrl);
116 }
117
88 return 0; 118 return 0;
89} 119}
90 120
@@ -97,6 +127,26 @@ static int dw_mci_exynos_setup_clock(struct dw_mci *host)
97 return 0; 127 return 0;
98} 128}
99 129
130static void dw_mci_exynos_set_clksel_timing(struct dw_mci *host, u32 timing)
131{
132 struct dw_mci_exynos_priv_data *priv = host->priv;
133 u32 clksel;
134
135 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
136 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
137 clksel = mci_readl(host, CLKSEL64);
138 else
139 clksel = mci_readl(host, CLKSEL);
140
141 clksel = (clksel & ~SDMMC_CLKSEL_TIMING_MASK) | timing;
142
143 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
144 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
145 mci_writel(host, CLKSEL64, clksel);
146 else
147 mci_writel(host, CLKSEL, clksel);
148}
149
100#ifdef CONFIG_PM_SLEEP 150#ifdef CONFIG_PM_SLEEP
101static int dw_mci_exynos_suspend(struct device *dev) 151static int dw_mci_exynos_suspend(struct device *dev)
102{ 152{
@@ -172,30 +222,38 @@ static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr)
172 } 222 }
173} 223}
174 224
175static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios) 225static void dw_mci_exynos_config_hs400(struct dw_mci *host, u32 timing)
176{ 226{
177 struct dw_mci_exynos_priv_data *priv = host->priv; 227 struct dw_mci_exynos_priv_data *priv = host->priv;
178 unsigned int wanted = ios->clock; 228 u32 dqs, strobe;
179 unsigned long actual;
180 u8 div = priv->ciu_div + 1;
181 229
182 if (ios->timing == MMC_TIMING_MMC_DDR52) { 230 /*
183 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || 231 * Not supported to configure register
184 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) 232 * related to HS400
185 mci_writel(host, CLKSEL64, priv->ddr_timing); 233 */
186 else 234 if (priv->ctrl_type < DW_MCI_TYPE_EXYNOS5420)
187 mci_writel(host, CLKSEL, priv->ddr_timing); 235 return;
188 /* Should be double rate for DDR mode */ 236
189 if (ios->bus_width == MMC_BUS_WIDTH_8) 237 dqs = priv->saved_dqs_en;
190 wanted <<= 1; 238 strobe = priv->saved_strobe_ctrl;
239
240 if (timing == MMC_TIMING_MMC_HS400) {
241 dqs |= DATA_STROBE_EN;
242 strobe = DQS_CTRL_RD_DELAY(strobe, priv->dqs_delay);
191 } else { 243 } else {
192 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || 244 dqs &= ~DATA_STROBE_EN;
193 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
194 mci_writel(host, CLKSEL64, priv->sdr_timing);
195 else
196 mci_writel(host, CLKSEL, priv->sdr_timing);
197 } 245 }
198 246
247 mci_writel(host, HS400_DQS_EN, dqs);
248 mci_writel(host, HS400_DLINE_CTRL, strobe);
249}
250
251static void dw_mci_exynos_adjust_clock(struct dw_mci *host, unsigned int wanted)
252{
253 struct dw_mci_exynos_priv_data *priv = host->priv;
254 unsigned long actual;
255 u8 div;
256 int ret;
199 /* 257 /*
200 * Don't care if wanted clock is zero or 258 * Don't care if wanted clock is zero or
201 * ciu clock is unavailable 259 * ciu clock is unavailable
@@ -207,17 +265,52 @@ static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios)
207 if (wanted < EXYNOS_CCLKIN_MIN) 265 if (wanted < EXYNOS_CCLKIN_MIN)
208 wanted = EXYNOS_CCLKIN_MIN; 266 wanted = EXYNOS_CCLKIN_MIN;
209 267
210 if (wanted != priv->cur_speed) { 268 if (wanted == priv->cur_speed)
211 int ret = clk_set_rate(host->ciu_clk, wanted * div); 269 return;
212 if (ret) 270
213 dev_warn(host->dev, 271 div = dw_mci_exynos_get_ciu_div(host);
214 "failed to set clk-rate %u error: %d\n", 272 ret = clk_set_rate(host->ciu_clk, wanted * div);
215 wanted * div, ret); 273 if (ret)
216 actual = clk_get_rate(host->ciu_clk); 274 dev_warn(host->dev,
217 host->bus_hz = actual / div; 275 "failed to set clk-rate %u error: %d\n",
218 priv->cur_speed = wanted; 276 wanted * div, ret);
219 host->current_speed = 0; 277 actual = clk_get_rate(host->ciu_clk);
278 host->bus_hz = actual / div;
279 priv->cur_speed = wanted;
280 host->current_speed = 0;
281}
282
283static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios)
284{
285 struct dw_mci_exynos_priv_data *priv = host->priv;
286 unsigned int wanted = ios->clock;
287 u32 timing = ios->timing, clksel;
288
289 switch (timing) {
290 case MMC_TIMING_MMC_HS400:
291 /* Update tuned sample timing */
292 clksel = SDMMC_CLKSEL_UP_SAMPLE(
293 priv->hs400_timing, priv->tuned_sample);
294 wanted <<= 1;
295 break;
296 case MMC_TIMING_MMC_DDR52:
297 clksel = priv->ddr_timing;
298 /* Should be double rate for DDR mode */
299 if (ios->bus_width == MMC_BUS_WIDTH_8)
300 wanted <<= 1;
301 break;
302 default:
303 clksel = priv->sdr_timing;
220 } 304 }
305
306 /* Set clock timing for the requested speed mode*/
307 dw_mci_exynos_set_clksel_timing(host, clksel);
308
309 /* Configure setting for HS400 */
310 dw_mci_exynos_config_hs400(host, timing);
311
312 /* Configure clock rate */
313 dw_mci_exynos_adjust_clock(host, wanted);
221} 314}
222 315
223static int dw_mci_exynos_parse_dt(struct dw_mci *host) 316static int dw_mci_exynos_parse_dt(struct dw_mci *host)
@@ -260,6 +353,16 @@ static int dw_mci_exynos_parse_dt(struct dw_mci *host)
260 return ret; 353 return ret;
261 354
262 priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div); 355 priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div);
356
357 ret = of_property_read_u32_array(np,
358 "samsung,dw-mshc-hs400-timing", timing, 2);
359 if (!ret && of_property_read_u32(np,
360 "samsung,read-strobe-delay", &priv->dqs_delay))
361 dev_dbg(host->dev,
362 "read-strobe-delay is not found, assuming usage of default value\n");
363
364 priv->hs400_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1],
365 HS400_FIXED_CIU_CLK_DIV);
263 host->priv = priv; 366 host->priv = priv;
264 return 0; 367 return 0;
265} 368}
@@ -285,7 +388,7 @@ static inline void dw_mci_exynos_set_clksmpl(struct dw_mci *host, u8 sample)
285 clksel = mci_readl(host, CLKSEL64); 388 clksel = mci_readl(host, CLKSEL64);
286 else 389 else
287 clksel = mci_readl(host, CLKSEL); 390 clksel = mci_readl(host, CLKSEL);
288 clksel = (clksel & ~0x7) | SDMMC_CLKSEL_CCLK_SAMPLE(sample); 391 clksel = SDMMC_CLKSEL_UP_SAMPLE(clksel, sample);
289 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || 392 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
290 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) 393 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
291 mci_writel(host, CLKSEL64, clksel); 394 mci_writel(host, CLKSEL64, clksel);
@@ -304,13 +407,16 @@ static inline u8 dw_mci_exynos_move_next_clksmpl(struct dw_mci *host)
304 clksel = mci_readl(host, CLKSEL64); 407 clksel = mci_readl(host, CLKSEL64);
305 else 408 else
306 clksel = mci_readl(host, CLKSEL); 409 clksel = mci_readl(host, CLKSEL);
410
307 sample = (clksel + 1) & 0x7; 411 sample = (clksel + 1) & 0x7;
308 clksel = (clksel & ~0x7) | sample; 412 clksel = SDMMC_CLKSEL_UP_SAMPLE(clksel, sample);
413
309 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || 414 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
310 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) 415 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
311 mci_writel(host, CLKSEL64, clksel); 416 mci_writel(host, CLKSEL64, clksel);
312 else 417 else
313 mci_writel(host, CLKSEL, clksel); 418 mci_writel(host, CLKSEL, clksel);
419
314 return sample; 420 return sample;
315} 421}
316 422
@@ -343,6 +449,7 @@ out:
343static int dw_mci_exynos_execute_tuning(struct dw_mci_slot *slot) 449static int dw_mci_exynos_execute_tuning(struct dw_mci_slot *slot)
344{ 450{
345 struct dw_mci *host = slot->host; 451 struct dw_mci *host = slot->host;
452 struct dw_mci_exynos_priv_data *priv = host->priv;
346 struct mmc_host *mmc = slot->mmc; 453 struct mmc_host *mmc = slot->mmc;
347 u8 start_smpl, smpl, candiates = 0; 454 u8 start_smpl, smpl, candiates = 0;
348 s8 found = -1; 455 s8 found = -1;
@@ -360,14 +467,27 @@ static int dw_mci_exynos_execute_tuning(struct dw_mci_slot *slot)
360 } while (start_smpl != smpl); 467 } while (start_smpl != smpl);
361 468
362 found = dw_mci_exynos_get_best_clksmpl(candiates); 469 found = dw_mci_exynos_get_best_clksmpl(candiates);
363 if (found >= 0) 470 if (found >= 0) {
364 dw_mci_exynos_set_clksmpl(host, found); 471 dw_mci_exynos_set_clksmpl(host, found);
365 else 472 priv->tuned_sample = found;
473 } else {
366 ret = -EIO; 474 ret = -EIO;
475 }
367 476
368 return ret; 477 return ret;
369} 478}
370 479
480static int dw_mci_exynos_prepare_hs400_tuning(struct dw_mci *host,
481 struct mmc_ios *ios)
482{
483 struct dw_mci_exynos_priv_data *priv = host->priv;
484
485 dw_mci_exynos_set_clksel_timing(host, priv->hs400_timing);
486 dw_mci_exynos_adjust_clock(host, (ios->clock) << 1);
487
488 return 0;
489}
490
371/* Common capabilities of Exynos4/Exynos5 SoC */ 491/* Common capabilities of Exynos4/Exynos5 SoC */
372static unsigned long exynos_dwmmc_caps[4] = { 492static unsigned long exynos_dwmmc_caps[4] = {
373 MMC_CAP_1_8V_DDR | MMC_CAP_8_BIT_DATA | MMC_CAP_CMD23, 493 MMC_CAP_1_8V_DDR | MMC_CAP_8_BIT_DATA | MMC_CAP_CMD23,
@@ -384,6 +504,7 @@ static const struct dw_mci_drv_data exynos_drv_data = {
384 .set_ios = dw_mci_exynos_set_ios, 504 .set_ios = dw_mci_exynos_set_ios,
385 .parse_dt = dw_mci_exynos_parse_dt, 505 .parse_dt = dw_mci_exynos_parse_dt,
386 .execute_tuning = dw_mci_exynos_execute_tuning, 506 .execute_tuning = dw_mci_exynos_execute_tuning,
507 .prepare_hs400_tuning = dw_mci_exynos_prepare_hs400_tuning,
387}; 508};
388 509
389static const struct of_device_id dw_mci_exynos_match[] = { 510static const struct of_device_id dw_mci_exynos_match[] = {
diff --git a/drivers/mmc/host/dw_mmc-exynos.h b/drivers/mmc/host/dw_mmc-exynos.h
index 7872ce586b55..595c934e6166 100644
--- a/drivers/mmc/host/dw_mmc-exynos.h
+++ b/drivers/mmc/host/dw_mmc-exynos.h
@@ -12,20 +12,36 @@
12#ifndef _DW_MMC_EXYNOS_H_ 12#ifndef _DW_MMC_EXYNOS_H_
13#define _DW_MMC_EXYNOS_H_ 13#define _DW_MMC_EXYNOS_H_
14 14
15/* Extended Register's Offset */
16#define SDMMC_CLKSEL 0x09C 15#define SDMMC_CLKSEL 0x09C
17#define SDMMC_CLKSEL64 0x0A8 16#define SDMMC_CLKSEL64 0x0A8
18 17
18/* Extended Register's Offset */
19#define SDMMC_HS400_DQS_EN 0x180
20#define SDMMC_HS400_ASYNC_FIFO_CTRL 0x184
21#define SDMMC_HS400_DLINE_CTRL 0x188
22
19/* CLKSEL register defines */ 23/* CLKSEL register defines */
20#define SDMMC_CLKSEL_CCLK_SAMPLE(x) (((x) & 7) << 0) 24#define SDMMC_CLKSEL_CCLK_SAMPLE(x) (((x) & 7) << 0)
21#define SDMMC_CLKSEL_CCLK_DRIVE(x) (((x) & 7) << 16) 25#define SDMMC_CLKSEL_CCLK_DRIVE(x) (((x) & 7) << 16)
22#define SDMMC_CLKSEL_CCLK_DIVIDER(x) (((x) & 7) << 24) 26#define SDMMC_CLKSEL_CCLK_DIVIDER(x) (((x) & 7) << 24)
23#define SDMMC_CLKSEL_GET_DRV_WD3(x) (((x) >> 16) & 0x7) 27#define SDMMC_CLKSEL_GET_DRV_WD3(x) (((x) >> 16) & 0x7)
28#define SDMMC_CLKSEL_GET_DIV(x) (((x) >> 24) & 0x7)
29#define SDMMC_CLKSEL_UP_SAMPLE(x, y) (((x) & ~SDMMC_CLKSEL_CCLK_SAMPLE(7)) |\
30 SDMMC_CLKSEL_CCLK_SAMPLE(y))
24#define SDMMC_CLKSEL_TIMING(x, y, z) (SDMMC_CLKSEL_CCLK_SAMPLE(x) | \ 31#define SDMMC_CLKSEL_TIMING(x, y, z) (SDMMC_CLKSEL_CCLK_SAMPLE(x) | \
25 SDMMC_CLKSEL_CCLK_DRIVE(y) | \ 32 SDMMC_CLKSEL_CCLK_DRIVE(y) | \
26 SDMMC_CLKSEL_CCLK_DIVIDER(z)) 33 SDMMC_CLKSEL_CCLK_DIVIDER(z))
34#define SDMMC_CLKSEL_TIMING_MASK SDMMC_CLKSEL_TIMING(0x7, 0x7, 0x7)
27#define SDMMC_CLKSEL_WAKEUP_INT BIT(11) 35#define SDMMC_CLKSEL_WAKEUP_INT BIT(11)
28 36
37/* RCLK_EN register defines */
38#define DATA_STROBE_EN BIT(0)
39#define AXI_NON_BLOCKING_WR BIT(7)
40
41/* DLINE_CTRL register defines */
42#define DQS_CTRL_RD_DELAY(x, y) (((x) & ~0x3FF) | ((y) & 0x3FF))
43#define DQS_CTRL_GET_RD_DELAY(x) ((x) & 0x3FF)
44
29/* Protector Register */ 45/* Protector Register */
30#define SDMMC_EMMCP_BASE 0x1000 46#define SDMMC_EMMCP_BASE 0x1000
31#define SDMMC_MPSECURITY (SDMMC_EMMCP_BASE + 0x0010) 47#define SDMMC_MPSECURITY (SDMMC_EMMCP_BASE + 0x0010)
@@ -49,6 +65,7 @@
49/* Fixed clock divider */ 65/* Fixed clock divider */
50#define EXYNOS4210_FIXED_CIU_CLK_DIV 2 66#define EXYNOS4210_FIXED_CIU_CLK_DIV 2
51#define EXYNOS4412_FIXED_CIU_CLK_DIV 4 67#define EXYNOS4412_FIXED_CIU_CLK_DIV 4
68#define HS400_FIXED_CIU_CLK_DIV 1
52 69
53/* Minimal required clock frequency for cclkin, unit: HZ */ 70/* Minimal required clock frequency for cclkin, unit: HZ */
54#define EXYNOS_CCLKIN_MIN 50000000 71#define EXYNOS_CCLKIN_MIN 50000000
diff --git a/drivers/mmc/host/dw_mmc-rockchip.c b/drivers/mmc/host/dw_mmc-rockchip.c
index e2a726a503ee..dbf166f94f1b 100644
--- a/drivers/mmc/host/dw_mmc-rockchip.c
+++ b/drivers/mmc/host/dw_mmc-rockchip.c
@@ -76,12 +76,20 @@ static int dw_mci_rockchip_init(struct dw_mci *host)
76 return 0; 76 return 0;
77} 77}
78 78
79/* Common capabilities of RK3288 SoC */
80static unsigned long dw_mci_rk3288_dwmmc_caps[4] = {
81 MMC_CAP_RUNTIME_RESUME, /* emmc */
82 MMC_CAP_RUNTIME_RESUME, /* sdmmc */
83 MMC_CAP_RUNTIME_RESUME, /* sdio0 */
84 MMC_CAP_RUNTIME_RESUME, /* sdio1 */
85};
79static const struct dw_mci_drv_data rk2928_drv_data = { 86static const struct dw_mci_drv_data rk2928_drv_data = {
80 .prepare_command = dw_mci_rockchip_prepare_command, 87 .prepare_command = dw_mci_rockchip_prepare_command,
81 .init = dw_mci_rockchip_init, 88 .init = dw_mci_rockchip_init,
82}; 89};
83 90
84static const struct dw_mci_drv_data rk3288_drv_data = { 91static const struct dw_mci_drv_data rk3288_drv_data = {
92 .caps = dw_mci_rk3288_dwmmc_caps,
85 .prepare_command = dw_mci_rockchip_prepare_command, 93 .prepare_command = dw_mci_rockchip_prepare_command,
86 .set_ios = dw_mci_rk3288_set_ios, 94 .set_ios = dw_mci_rk3288_set_ios,
87 .setup_clock = dw_mci_rk3288_setup_clock, 95 .setup_clock = dw_mci_rk3288_setup_clock,
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 4d2e3c2e1830..38b29265cc7c 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -69,7 +69,8 @@ struct idmac_desc_64addr {
69 69
70 u32 des2; /*Buffer sizes */ 70 u32 des2; /*Buffer sizes */
71#define IDMAC_64ADDR_SET_BUFFER1_SIZE(d, s) \ 71#define IDMAC_64ADDR_SET_BUFFER1_SIZE(d, s) \
72 ((d)->des2 = ((d)->des2 & 0x03ffe000) | ((s) & 0x1fff)) 72 ((d)->des2 = ((d)->des2 & cpu_to_le32(0x03ffe000)) | \
73 ((cpu_to_le32(s)) & cpu_to_le32(0x1fff)))
73 74
74 u32 des3; /* Reserved */ 75 u32 des3; /* Reserved */
75 76
@@ -81,7 +82,7 @@ struct idmac_desc_64addr {
81}; 82};
82 83
83struct idmac_desc { 84struct idmac_desc {
84 u32 des0; /* Control Descriptor */ 85 __le32 des0; /* Control Descriptor */
85#define IDMAC_DES0_DIC BIT(1) 86#define IDMAC_DES0_DIC BIT(1)
86#define IDMAC_DES0_LD BIT(2) 87#define IDMAC_DES0_LD BIT(2)
87#define IDMAC_DES0_FD BIT(3) 88#define IDMAC_DES0_FD BIT(3)
@@ -90,18 +91,19 @@ struct idmac_desc {
90#define IDMAC_DES0_CES BIT(30) 91#define IDMAC_DES0_CES BIT(30)
91#define IDMAC_DES0_OWN BIT(31) 92#define IDMAC_DES0_OWN BIT(31)
92 93
93 u32 des1; /* Buffer sizes */ 94 __le32 des1; /* Buffer sizes */
94#define IDMAC_SET_BUFFER1_SIZE(d, s) \ 95#define IDMAC_SET_BUFFER1_SIZE(d, s) \
95 ((d)->des1 = ((d)->des1 & 0x03ffe000) | ((s) & 0x1fff)) 96 ((d)->des1 = ((d)->des1 & 0x03ffe000) | ((s) & 0x1fff))
96 97
97 u32 des2; /* buffer 1 physical address */ 98 __le32 des2; /* buffer 1 physical address */
98 99
99 u32 des3; /* buffer 2 physical address */ 100 __le32 des3; /* buffer 2 physical address */
100}; 101};
101#endif /* CONFIG_MMC_DW_IDMAC */ 102#endif /* CONFIG_MMC_DW_IDMAC */
102 103
103static bool dw_mci_reset(struct dw_mci *host); 104static bool dw_mci_reset(struct dw_mci *host);
104static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset); 105static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset);
106static int dw_mci_card_busy(struct mmc_host *mmc);
105 107
106#if defined(CONFIG_DEBUG_FS) 108#if defined(CONFIG_DEBUG_FS)
107static int dw_mci_req_show(struct seq_file *s, void *v) 109static int dw_mci_req_show(struct seq_file *s, void *v)
@@ -335,6 +337,31 @@ static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd)
335 return cmdr; 337 return cmdr;
336} 338}
337 339
340static void dw_mci_wait_while_busy(struct dw_mci *host, u32 cmd_flags)
341{
342 unsigned long timeout = jiffies + msecs_to_jiffies(500);
343
344 /*
345 * Databook says that before issuing a new data transfer command
346 * we need to check to see if the card is busy. Data transfer commands
347 * all have SDMMC_CMD_PRV_DAT_WAIT set, so we'll key off that.
348 *
349 * ...also allow sending for SDMMC_CMD_VOLT_SWITCH where busy is
350 * expected.
351 */
352 if ((cmd_flags & SDMMC_CMD_PRV_DAT_WAIT) &&
353 !(cmd_flags & SDMMC_CMD_VOLT_SWITCH)) {
354 while (mci_readl(host, STATUS) & SDMMC_STATUS_BUSY) {
355 if (time_after(jiffies, timeout)) {
356 /* Command will fail; we'll pass error then */
357 dev_err(host->dev, "Busy; trying anyway\n");
358 break;
359 }
360 udelay(10);
361 }
362 }
363}
364
338static void dw_mci_start_command(struct dw_mci *host, 365static void dw_mci_start_command(struct dw_mci *host,
339 struct mmc_command *cmd, u32 cmd_flags) 366 struct mmc_command *cmd, u32 cmd_flags)
340{ 367{
@@ -345,6 +372,7 @@ static void dw_mci_start_command(struct dw_mci *host,
345 372
346 mci_writel(host, CMDARG, cmd->arg); 373 mci_writel(host, CMDARG, cmd->arg);
347 wmb(); 374 wmb();
375 dw_mci_wait_while_busy(host, cmd_flags);
348 376
349 mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START); 377 mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START);
350} 378}
@@ -477,23 +505,23 @@ static void dw_mci_translate_sglist(struct dw_mci *host, struct mmc_data *data,
477 * Set the OWN bit and disable interrupts for this 505 * Set the OWN bit and disable interrupts for this
478 * descriptor 506 * descriptor
479 */ 507 */
480 desc->des0 = IDMAC_DES0_OWN | IDMAC_DES0_DIC | 508 desc->des0 = cpu_to_le32(IDMAC_DES0_OWN |
481 IDMAC_DES0_CH; 509 IDMAC_DES0_DIC | IDMAC_DES0_CH);
482 /* Buffer length */ 510 /* Buffer length */
483 IDMAC_SET_BUFFER1_SIZE(desc, length); 511 IDMAC_SET_BUFFER1_SIZE(desc, length);
484 512
485 /* Physical address to DMA to/from */ 513 /* Physical address to DMA to/from */
486 desc->des2 = mem_addr; 514 desc->des2 = cpu_to_le32(mem_addr);
487 } 515 }
488 516
489 /* Set first descriptor */ 517 /* Set first descriptor */
490 desc = host->sg_cpu; 518 desc = host->sg_cpu;
491 desc->des0 |= IDMAC_DES0_FD; 519 desc->des0 |= cpu_to_le32(IDMAC_DES0_FD);
492 520
493 /* Set last descriptor */ 521 /* Set last descriptor */
494 desc = host->sg_cpu + (i - 1) * sizeof(struct idmac_desc); 522 desc = host->sg_cpu + (i - 1) * sizeof(struct idmac_desc);
495 desc->des0 &= ~(IDMAC_DES0_CH | IDMAC_DES0_DIC); 523 desc->des0 &= cpu_to_le32(~(IDMAC_DES0_CH | IDMAC_DES0_DIC));
496 desc->des0 |= IDMAC_DES0_LD; 524 desc->des0 |= cpu_to_le32(IDMAC_DES0_LD);
497 } 525 }
498 526
499 wmb(); 527 wmb();
@@ -562,12 +590,12 @@ static int dw_mci_idmac_init(struct dw_mci *host)
562 590
563 /* Forward link the descriptor list */ 591 /* Forward link the descriptor list */
564 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++) 592 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++)
565 p->des3 = host->sg_dma + (sizeof(struct idmac_desc) * 593 p->des3 = cpu_to_le32(host->sg_dma +
566 (i + 1)); 594 (sizeof(struct idmac_desc) * (i + 1)));
567 595
568 /* Set the last descriptor as the end-of-ring descriptor */ 596 /* Set the last descriptor as the end-of-ring descriptor */
569 p->des3 = host->sg_dma; 597 p->des3 = cpu_to_le32(host->sg_dma);
570 p->des0 = IDMAC_DES0_ER; 598 p->des0 = cpu_to_le32(IDMAC_DES0_ER);
571 } 599 }
572 600
573 dw_mci_idmac_reset(host); 601 dw_mci_idmac_reset(host);
@@ -737,6 +765,7 @@ static void dw_mci_ctrl_rd_thld(struct dw_mci *host, struct mmc_data *data)
737 return; 765 return;
738 766
739 if (host->timing != MMC_TIMING_MMC_HS200 && 767 if (host->timing != MMC_TIMING_MMC_HS200 &&
768 host->timing != MMC_TIMING_MMC_HS400 &&
740 host->timing != MMC_TIMING_UHS_SDR104) 769 host->timing != MMC_TIMING_UHS_SDR104)
741 goto disable; 770 goto disable;
742 771
@@ -876,6 +905,7 @@ static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg)
876 905
877 mci_writel(host, CMDARG, arg); 906 mci_writel(host, CMDARG, arg);
878 wmb(); 907 wmb();
908 dw_mci_wait_while_busy(host, cmd);
879 mci_writel(host, CMD, SDMMC_CMD_START | cmd); 909 mci_writel(host, CMD, SDMMC_CMD_START | cmd);
880 910
881 while (time_before(jiffies, timeout)) { 911 while (time_before(jiffies, timeout)) {
@@ -992,6 +1022,26 @@ static void __dw_mci_start_request(struct dw_mci *host,
992 1022
993 dw_mci_start_command(host, cmd, cmdflags); 1023 dw_mci_start_command(host, cmd, cmdflags);
994 1024
1025 if (cmd->opcode == SD_SWITCH_VOLTAGE) {
1026 unsigned long irqflags;
1027
1028 /*
1029 * Databook says to fail after 2ms w/ no response, but evidence
1030 * shows that sometimes the cmd11 interrupt takes over 130ms.
1031 * We'll set to 500ms, plus an extra jiffy just in case jiffies
1032 * is just about to roll over.
1033 *
1034 * We do this whole thing under spinlock and only if the
1035 * command hasn't already completed (indicating the the irq
1036 * already ran so we don't want the timeout).
1037 */
1038 spin_lock_irqsave(&host->irq_lock, irqflags);
1039 if (!test_bit(EVENT_CMD_COMPLETE, &host->pending_events))
1040 mod_timer(&host->cmd11_timer,
1041 jiffies + msecs_to_jiffies(500) + 1);
1042 spin_unlock_irqrestore(&host->irq_lock, irqflags);
1043 }
1044
995 if (mrq->stop) 1045 if (mrq->stop)
996 host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop); 1046 host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop);
997 else 1047 else
@@ -1084,7 +1134,8 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1084 regs = mci_readl(slot->host, UHS_REG); 1134 regs = mci_readl(slot->host, UHS_REG);
1085 1135
1086 /* DDR mode set */ 1136 /* DDR mode set */
1087 if (ios->timing == MMC_TIMING_MMC_DDR52) 1137 if (ios->timing == MMC_TIMING_MMC_DDR52 ||
1138 ios->timing == MMC_TIMING_MMC_HS400)
1088 regs |= ((0x1 << slot->id) << 16); 1139 regs |= ((0x1 << slot->id) << 16);
1089 else 1140 else
1090 regs &= ~((0x1 << slot->id) << 16); 1141 regs &= ~((0x1 << slot->id) << 16);
@@ -1101,12 +1152,6 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1101 if (drv_data && drv_data->set_ios) 1152 if (drv_data && drv_data->set_ios)
1102 drv_data->set_ios(slot->host, ios); 1153 drv_data->set_ios(slot->host, ios);
1103 1154
1104 /* Slot specific timing and width adjustment */
1105 dw_mci_setup_bus(slot, false);
1106
1107 if (slot->host->state == STATE_WAITING_CMD11_DONE && ios->clock != 0)
1108 slot->host->state = STATE_IDLE;
1109
1110 switch (ios->power_mode) { 1155 switch (ios->power_mode) {
1111 case MMC_POWER_UP: 1156 case MMC_POWER_UP:
1112 if (!IS_ERR(mmc->supply.vmmc)) { 1157 if (!IS_ERR(mmc->supply.vmmc)) {
@@ -1125,23 +1170,39 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1125 mci_writel(slot->host, PWREN, regs); 1170 mci_writel(slot->host, PWREN, regs);
1126 break; 1171 break;
1127 case MMC_POWER_ON: 1172 case MMC_POWER_ON:
1128 if (!IS_ERR(mmc->supply.vqmmc) && !slot->host->vqmmc_enabled) { 1173 if (!slot->host->vqmmc_enabled) {
1129 ret = regulator_enable(mmc->supply.vqmmc); 1174 if (!IS_ERR(mmc->supply.vqmmc)) {
1130 if (ret < 0) 1175 ret = regulator_enable(mmc->supply.vqmmc);
1131 dev_err(slot->host->dev, 1176 if (ret < 0)
1132 "failed to enable vqmmc regulator\n"); 1177 dev_err(slot->host->dev,
1133 else 1178 "failed to enable vqmmc\n");
1179 else
1180 slot->host->vqmmc_enabled = true;
1181
1182 } else {
1183 /* Keep track so we don't reset again */
1134 slot->host->vqmmc_enabled = true; 1184 slot->host->vqmmc_enabled = true;
1185 }
1186
1187 /* Reset our state machine after powering on */
1188 dw_mci_ctrl_reset(slot->host,
1189 SDMMC_CTRL_ALL_RESET_FLAGS);
1135 } 1190 }
1191
1192 /* Adjust clock / bus width after power is up */
1193 dw_mci_setup_bus(slot, false);
1194
1136 break; 1195 break;
1137 case MMC_POWER_OFF: 1196 case MMC_POWER_OFF:
1197 /* Turn clock off before power goes down */
1198 dw_mci_setup_bus(slot, false);
1199
1138 if (!IS_ERR(mmc->supply.vmmc)) 1200 if (!IS_ERR(mmc->supply.vmmc))
1139 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); 1201 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
1140 1202
1141 if (!IS_ERR(mmc->supply.vqmmc) && slot->host->vqmmc_enabled) { 1203 if (!IS_ERR(mmc->supply.vqmmc) && slot->host->vqmmc_enabled)
1142 regulator_disable(mmc->supply.vqmmc); 1204 regulator_disable(mmc->supply.vqmmc);
1143 slot->host->vqmmc_enabled = false; 1205 slot->host->vqmmc_enabled = false;
1144 }
1145 1206
1146 regs = mci_readl(slot->host, PWREN); 1207 regs = mci_readl(slot->host, PWREN);
1147 regs &= ~(1 << slot->id); 1208 regs &= ~(1 << slot->id);
@@ -1150,6 +1211,9 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1150 default: 1211 default:
1151 break; 1212 break;
1152 } 1213 }
1214
1215 if (slot->host->state == STATE_WAITING_CMD11_DONE && ios->clock != 0)
1216 slot->host->state = STATE_IDLE;
1153} 1217}
1154 1218
1155static int dw_mci_card_busy(struct mmc_host *mmc) 1219static int dw_mci_card_busy(struct mmc_host *mmc)
@@ -1323,6 +1387,18 @@ static int dw_mci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1323 return err; 1387 return err;
1324} 1388}
1325 1389
1390static int dw_mci_prepare_hs400_tuning(struct mmc_host *mmc, struct mmc_ios *ios)
1391{
1392 struct dw_mci_slot *slot = mmc_priv(mmc);
1393 struct dw_mci *host = slot->host;
1394 const struct dw_mci_drv_data *drv_data = host->drv_data;
1395
1396 if (drv_data && drv_data->prepare_hs400_tuning)
1397 return drv_data->prepare_hs400_tuning(host, ios);
1398
1399 return 0;
1400}
1401
1326static const struct mmc_host_ops dw_mci_ops = { 1402static const struct mmc_host_ops dw_mci_ops = {
1327 .request = dw_mci_request, 1403 .request = dw_mci_request,
1328 .pre_req = dw_mci_pre_req, 1404 .pre_req = dw_mci_pre_req,
@@ -1335,6 +1411,7 @@ static const struct mmc_host_ops dw_mci_ops = {
1335 .card_busy = dw_mci_card_busy, 1411 .card_busy = dw_mci_card_busy,
1336 .start_signal_voltage_switch = dw_mci_switch_voltage, 1412 .start_signal_voltage_switch = dw_mci_switch_voltage,
1337 .init_card = dw_mci_init_card, 1413 .init_card = dw_mci_init_card,
1414 .prepare_hs400_tuning = dw_mci_prepare_hs400_tuning,
1338}; 1415};
1339 1416
1340static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq) 1417static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
@@ -1520,7 +1597,10 @@ static void dw_mci_tasklet_func(unsigned long priv)
1520 if (test_and_clear_bit(EVENT_DATA_ERROR, 1597 if (test_and_clear_bit(EVENT_DATA_ERROR,
1521 &host->pending_events)) { 1598 &host->pending_events)) {
1522 dw_mci_stop_dma(host); 1599 dw_mci_stop_dma(host);
1523 send_stop_abort(host, data); 1600 if (data->stop ||
1601 !(host->data_status & (SDMMC_INT_DRTO |
1602 SDMMC_INT_EBE)))
1603 send_stop_abort(host, data);
1524 state = STATE_DATA_ERROR; 1604 state = STATE_DATA_ERROR;
1525 break; 1605 break;
1526 } 1606 }
@@ -1547,7 +1627,10 @@ static void dw_mci_tasklet_func(unsigned long priv)
1547 if (test_and_clear_bit(EVENT_DATA_ERROR, 1627 if (test_and_clear_bit(EVENT_DATA_ERROR,
1548 &host->pending_events)) { 1628 &host->pending_events)) {
1549 dw_mci_stop_dma(host); 1629 dw_mci_stop_dma(host);
1550 send_stop_abort(host, data); 1630 if (data->stop ||
1631 !(host->data_status & (SDMMC_INT_DRTO |
1632 SDMMC_INT_EBE)))
1633 send_stop_abort(host, data);
1551 state = STATE_DATA_ERROR; 1634 state = STATE_DATA_ERROR;
1552 break; 1635 break;
1553 } 1636 }
@@ -1685,8 +1768,7 @@ static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
1685 buf += len; 1768 buf += len;
1686 cnt -= len; 1769 cnt -= len;
1687 if (host->part_buf_count == 2) { 1770 if (host->part_buf_count == 2) {
1688 mci_writew(host, DATA(host->data_offset), 1771 mci_fifo_writew(host->fifo_reg, host->part_buf16);
1689 host->part_buf16);
1690 host->part_buf_count = 0; 1772 host->part_buf_count = 0;
1691 } 1773 }
1692 } 1774 }
@@ -1703,15 +1785,14 @@ static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
1703 cnt -= len; 1785 cnt -= len;
1704 /* push data from aligned buffer into fifo */ 1786 /* push data from aligned buffer into fifo */
1705 for (i = 0; i < items; ++i) 1787 for (i = 0; i < items; ++i)
1706 mci_writew(host, DATA(host->data_offset), 1788 mci_fifo_writew(host->fifo_reg, aligned_buf[i]);
1707 aligned_buf[i]);
1708 } 1789 }
1709 } else 1790 } else
1710#endif 1791#endif
1711 { 1792 {
1712 u16 *pdata = buf; 1793 u16 *pdata = buf;
1713 for (; cnt >= 2; cnt -= 2) 1794 for (; cnt >= 2; cnt -= 2)
1714 mci_writew(host, DATA(host->data_offset), *pdata++); 1795 mci_fifo_writew(host->fifo_reg, *pdata++);
1715 buf = pdata; 1796 buf = pdata;
1716 } 1797 }
1717 /* put anything remaining in the part_buf */ 1798 /* put anything remaining in the part_buf */
@@ -1720,8 +1801,7 @@ static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
1720 /* Push data if we have reached the expected data length */ 1801 /* Push data if we have reached the expected data length */
1721 if ((data->bytes_xfered + init_cnt) == 1802 if ((data->bytes_xfered + init_cnt) ==
1722 (data->blksz * data->blocks)) 1803 (data->blksz * data->blocks))
1723 mci_writew(host, DATA(host->data_offset), 1804 mci_fifo_writew(host->fifo_reg, host->part_buf16);
1724 host->part_buf16);
1725 } 1805 }
1726} 1806}
1727 1807
@@ -1736,8 +1816,7 @@ static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
1736 int items = len >> 1; 1816 int items = len >> 1;
1737 int i; 1817 int i;
1738 for (i = 0; i < items; ++i) 1818 for (i = 0; i < items; ++i)
1739 aligned_buf[i] = mci_readw(host, 1819 aligned_buf[i] = mci_fifo_readw(host->fifo_reg);
1740 DATA(host->data_offset));
1741 /* memcpy from aligned buffer into output buffer */ 1820 /* memcpy from aligned buffer into output buffer */
1742 memcpy(buf, aligned_buf, len); 1821 memcpy(buf, aligned_buf, len);
1743 buf += len; 1822 buf += len;
@@ -1748,11 +1827,11 @@ static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
1748 { 1827 {
1749 u16 *pdata = buf; 1828 u16 *pdata = buf;
1750 for (; cnt >= 2; cnt -= 2) 1829 for (; cnt >= 2; cnt -= 2)
1751 *pdata++ = mci_readw(host, DATA(host->data_offset)); 1830 *pdata++ = mci_fifo_readw(host->fifo_reg);
1752 buf = pdata; 1831 buf = pdata;
1753 } 1832 }
1754 if (cnt) { 1833 if (cnt) {
1755 host->part_buf16 = mci_readw(host, DATA(host->data_offset)); 1834 host->part_buf16 = mci_fifo_readw(host->fifo_reg);
1756 dw_mci_pull_final_bytes(host, buf, cnt); 1835 dw_mci_pull_final_bytes(host, buf, cnt);
1757 } 1836 }
1758} 1837}
@@ -1768,8 +1847,7 @@ static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
1768 buf += len; 1847 buf += len;
1769 cnt -= len; 1848 cnt -= len;
1770 if (host->part_buf_count == 4) { 1849 if (host->part_buf_count == 4) {
1771 mci_writel(host, DATA(host->data_offset), 1850 mci_fifo_writel(host->fifo_reg, host->part_buf32);
1772 host->part_buf32);
1773 host->part_buf_count = 0; 1851 host->part_buf_count = 0;
1774 } 1852 }
1775 } 1853 }
@@ -1786,15 +1864,14 @@ static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
1786 cnt -= len; 1864 cnt -= len;
1787 /* push data from aligned buffer into fifo */ 1865 /* push data from aligned buffer into fifo */
1788 for (i = 0; i < items; ++i) 1866 for (i = 0; i < items; ++i)
1789 mci_writel(host, DATA(host->data_offset), 1867 mci_fifo_writel(host->fifo_reg, aligned_buf[i]);
1790 aligned_buf[i]);
1791 } 1868 }
1792 } else 1869 } else
1793#endif 1870#endif
1794 { 1871 {
1795 u32 *pdata = buf; 1872 u32 *pdata = buf;
1796 for (; cnt >= 4; cnt -= 4) 1873 for (; cnt >= 4; cnt -= 4)
1797 mci_writel(host, DATA(host->data_offset), *pdata++); 1874 mci_fifo_writel(host->fifo_reg, *pdata++);
1798 buf = pdata; 1875 buf = pdata;
1799 } 1876 }
1800 /* put anything remaining in the part_buf */ 1877 /* put anything remaining in the part_buf */
@@ -1803,8 +1880,7 @@ static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
1803 /* Push data if we have reached the expected data length */ 1880 /* Push data if we have reached the expected data length */
1804 if ((data->bytes_xfered + init_cnt) == 1881 if ((data->bytes_xfered + init_cnt) ==
1805 (data->blksz * data->blocks)) 1882 (data->blksz * data->blocks))
1806 mci_writel(host, DATA(host->data_offset), 1883 mci_fifo_writel(host->fifo_reg, host->part_buf32);
1807 host->part_buf32);
1808 } 1884 }
1809} 1885}
1810 1886
@@ -1819,8 +1895,7 @@ static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
1819 int items = len >> 2; 1895 int items = len >> 2;
1820 int i; 1896 int i;
1821 for (i = 0; i < items; ++i) 1897 for (i = 0; i < items; ++i)
1822 aligned_buf[i] = mci_readl(host, 1898 aligned_buf[i] = mci_fifo_readl(host->fifo_reg);
1823 DATA(host->data_offset));
1824 /* memcpy from aligned buffer into output buffer */ 1899 /* memcpy from aligned buffer into output buffer */
1825 memcpy(buf, aligned_buf, len); 1900 memcpy(buf, aligned_buf, len);
1826 buf += len; 1901 buf += len;
@@ -1831,11 +1906,11 @@ static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
1831 { 1906 {
1832 u32 *pdata = buf; 1907 u32 *pdata = buf;
1833 for (; cnt >= 4; cnt -= 4) 1908 for (; cnt >= 4; cnt -= 4)
1834 *pdata++ = mci_readl(host, DATA(host->data_offset)); 1909 *pdata++ = mci_fifo_readl(host->fifo_reg);
1835 buf = pdata; 1910 buf = pdata;
1836 } 1911 }
1837 if (cnt) { 1912 if (cnt) {
1838 host->part_buf32 = mci_readl(host, DATA(host->data_offset)); 1913 host->part_buf32 = mci_fifo_readl(host->fifo_reg);
1839 dw_mci_pull_final_bytes(host, buf, cnt); 1914 dw_mci_pull_final_bytes(host, buf, cnt);
1840 } 1915 }
1841} 1916}
@@ -1852,8 +1927,7 @@ static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
1852 cnt -= len; 1927 cnt -= len;
1853 1928
1854 if (host->part_buf_count == 8) { 1929 if (host->part_buf_count == 8) {
1855 mci_writeq(host, DATA(host->data_offset), 1930 mci_fifo_writeq(host->fifo_reg, host->part_buf);
1856 host->part_buf);
1857 host->part_buf_count = 0; 1931 host->part_buf_count = 0;
1858 } 1932 }
1859 } 1933 }
@@ -1870,15 +1944,14 @@ static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
1870 cnt -= len; 1944 cnt -= len;
1871 /* push data from aligned buffer into fifo */ 1945 /* push data from aligned buffer into fifo */
1872 for (i = 0; i < items; ++i) 1946 for (i = 0; i < items; ++i)
1873 mci_writeq(host, DATA(host->data_offset), 1947 mci_fifo_writeq(host->fifo_reg, aligned_buf[i]);
1874 aligned_buf[i]);
1875 } 1948 }
1876 } else 1949 } else
1877#endif 1950#endif
1878 { 1951 {
1879 u64 *pdata = buf; 1952 u64 *pdata = buf;
1880 for (; cnt >= 8; cnt -= 8) 1953 for (; cnt >= 8; cnt -= 8)
1881 mci_writeq(host, DATA(host->data_offset), *pdata++); 1954 mci_fifo_writeq(host->fifo_reg, *pdata++);
1882 buf = pdata; 1955 buf = pdata;
1883 } 1956 }
1884 /* put anything remaining in the part_buf */ 1957 /* put anything remaining in the part_buf */
@@ -1887,8 +1960,7 @@ static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
1887 /* Push data if we have reached the expected data length */ 1960 /* Push data if we have reached the expected data length */
1888 if ((data->bytes_xfered + init_cnt) == 1961 if ((data->bytes_xfered + init_cnt) ==
1889 (data->blksz * data->blocks)) 1962 (data->blksz * data->blocks))
1890 mci_writeq(host, DATA(host->data_offset), 1963 mci_fifo_writeq(host->fifo_reg, host->part_buf);
1891 host->part_buf);
1892 } 1964 }
1893} 1965}
1894 1966
@@ -1903,8 +1975,8 @@ static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
1903 int items = len >> 3; 1975 int items = len >> 3;
1904 int i; 1976 int i;
1905 for (i = 0; i < items; ++i) 1977 for (i = 0; i < items; ++i)
1906 aligned_buf[i] = mci_readq(host, 1978 aligned_buf[i] = mci_fifo_readq(host->fifo_reg);
1907 DATA(host->data_offset)); 1979
1908 /* memcpy from aligned buffer into output buffer */ 1980 /* memcpy from aligned buffer into output buffer */
1909 memcpy(buf, aligned_buf, len); 1981 memcpy(buf, aligned_buf, len);
1910 buf += len; 1982 buf += len;
@@ -1915,11 +1987,11 @@ static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
1915 { 1987 {
1916 u64 *pdata = buf; 1988 u64 *pdata = buf;
1917 for (; cnt >= 8; cnt -= 8) 1989 for (; cnt >= 8; cnt -= 8)
1918 *pdata++ = mci_readq(host, DATA(host->data_offset)); 1990 *pdata++ = mci_fifo_readq(host->fifo_reg);
1919 buf = pdata; 1991 buf = pdata;
1920 } 1992 }
1921 if (cnt) { 1993 if (cnt) {
1922 host->part_buf = mci_readq(host, DATA(host->data_offset)); 1994 host->part_buf = mci_fifo_readq(host->fifo_reg);
1923 dw_mci_pull_final_bytes(host, buf, cnt); 1995 dw_mci_pull_final_bytes(host, buf, cnt);
1924 } 1996 }
1925} 1997}
@@ -2097,9 +2169,20 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
2097 /* Check volt switch first, since it can look like an error */ 2169 /* Check volt switch first, since it can look like an error */
2098 if ((host->state == STATE_SENDING_CMD11) && 2170 if ((host->state == STATE_SENDING_CMD11) &&
2099 (pending & SDMMC_INT_VOLT_SWITCH)) { 2171 (pending & SDMMC_INT_VOLT_SWITCH)) {
2172 unsigned long irqflags;
2173
2100 mci_writel(host, RINTSTS, SDMMC_INT_VOLT_SWITCH); 2174 mci_writel(host, RINTSTS, SDMMC_INT_VOLT_SWITCH);
2101 pending &= ~SDMMC_INT_VOLT_SWITCH; 2175 pending &= ~SDMMC_INT_VOLT_SWITCH;
2176
2177 /*
2178 * Hold the lock; we know cmd11_timer can't be kicked
2179 * off after the lock is released, so safe to delete.
2180 */
2181 spin_lock_irqsave(&host->irq_lock, irqflags);
2102 dw_mci_cmd_interrupt(host, pending); 2182 dw_mci_cmd_interrupt(host, pending);
2183 spin_unlock_irqrestore(&host->irq_lock, irqflags);
2184
2185 del_timer(&host->cmd11_timer);
2103 } 2186 }
2104 2187
2105 if (pending & DW_MCI_CMD_ERROR_FLAGS) { 2188 if (pending & DW_MCI_CMD_ERROR_FLAGS) {
@@ -2156,6 +2239,10 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
2156 /* Handle SDIO Interrupts */ 2239 /* Handle SDIO Interrupts */
2157 for (i = 0; i < host->num_slots; i++) { 2240 for (i = 0; i < host->num_slots; i++) {
2158 struct dw_mci_slot *slot = host->slot[i]; 2241 struct dw_mci_slot *slot = host->slot[i];
2242
2243 if (!slot)
2244 continue;
2245
2159 if (pending & SDMMC_INT_SDIO(slot->sdio_id)) { 2246 if (pending & SDMMC_INT_SDIO(slot->sdio_id)) {
2160 mci_writel(host, RINTSTS, 2247 mci_writel(host, RINTSTS,
2161 SDMMC_INT_SDIO(slot->sdio_id)); 2248 SDMMC_INT_SDIO(slot->sdio_id));
@@ -2506,6 +2593,20 @@ ciu_out:
2506 return ret; 2593 return ret;
2507} 2594}
2508 2595
2596static void dw_mci_cmd11_timer(unsigned long arg)
2597{
2598 struct dw_mci *host = (struct dw_mci *)arg;
2599
2600 if (host->state != STATE_SENDING_CMD11) {
2601 dev_warn(host->dev, "Unexpected CMD11 timeout\n");
2602 return;
2603 }
2604
2605 host->cmd_status = SDMMC_INT_RTO;
2606 set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
2607 tasklet_schedule(&host->tasklet);
2608}
2609
2509#ifdef CONFIG_OF 2610#ifdef CONFIG_OF
2510static struct dw_mci_of_quirks { 2611static struct dw_mci_of_quirks {
2511 char *quirk; 2612 char *quirk;
@@ -2574,6 +2675,34 @@ static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
2574} 2675}
2575#endif /* CONFIG_OF */ 2676#endif /* CONFIG_OF */
2576 2677
2678static void dw_mci_enable_cd(struct dw_mci *host)
2679{
2680 struct dw_mci_board *brd = host->pdata;
2681 unsigned long irqflags;
2682 u32 temp;
2683 int i;
2684
2685 /* No need for CD if broken card detection */
2686 if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION)
2687 return;
2688
2689 /* No need for CD if all slots have a non-error GPIO */
2690 for (i = 0; i < host->num_slots; i++) {
2691 struct dw_mci_slot *slot = host->slot[i];
2692
2693 if (IS_ERR_VALUE(mmc_gpio_get_cd(slot->mmc)))
2694 break;
2695 }
2696 if (i == host->num_slots)
2697 return;
2698
2699 spin_lock_irqsave(&host->irq_lock, irqflags);
2700 temp = mci_readl(host, INTMASK);
2701 temp |= SDMMC_INT_CD;
2702 mci_writel(host, INTMASK, temp);
2703 spin_unlock_irqrestore(&host->irq_lock, irqflags);
2704}
2705
2577int dw_mci_probe(struct dw_mci *host) 2706int dw_mci_probe(struct dw_mci *host)
2578{ 2707{
2579 const struct dw_mci_drv_data *drv_data = host->drv_data; 2708 const struct dw_mci_drv_data *drv_data = host->drv_data;
@@ -2652,6 +2781,9 @@ int dw_mci_probe(struct dw_mci *host)
2652 } 2781 }
2653 } 2782 }
2654 2783
2784 setup_timer(&host->cmd11_timer,
2785 dw_mci_cmd11_timer, (unsigned long)host);
2786
2655 host->quirks = host->pdata->quirks; 2787 host->quirks = host->pdata->quirks;
2656 2788
2657 spin_lock_init(&host->lock); 2789 spin_lock_init(&host->lock);
@@ -2731,9 +2863,9 @@ int dw_mci_probe(struct dw_mci *host)
2731 dev_info(host->dev, "Version ID is %04x\n", host->verid); 2863 dev_info(host->dev, "Version ID is %04x\n", host->verid);
2732 2864
2733 if (host->verid < DW_MMC_240A) 2865 if (host->verid < DW_MMC_240A)
2734 host->data_offset = DATA_OFFSET; 2866 host->fifo_reg = host->regs + DATA_OFFSET;
2735 else 2867 else
2736 host->data_offset = DATA_240A_OFFSET; 2868 host->fifo_reg = host->regs + DATA_240A_OFFSET;
2737 2869
2738 tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host); 2870 tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host);
2739 ret = devm_request_irq(host->dev, host->irq, dw_mci_interrupt, 2871 ret = devm_request_irq(host->dev, host->irq, dw_mci_interrupt,
@@ -2747,13 +2879,13 @@ int dw_mci_probe(struct dw_mci *host)
2747 host->num_slots = ((mci_readl(host, HCON) >> 1) & 0x1F) + 1; 2879 host->num_slots = ((mci_readl(host, HCON) >> 1) & 0x1F) + 1;
2748 2880
2749 /* 2881 /*
2750 * Enable interrupts for command done, data over, data empty, card det, 2882 * Enable interrupts for command done, data over, data empty,
2751 * receive ready and error such as transmit, receive timeout, crc error 2883 * receive ready and error such as transmit, receive timeout, crc error
2752 */ 2884 */
2753 mci_writel(host, RINTSTS, 0xFFFFFFFF); 2885 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2754 mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER | 2886 mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
2755 SDMMC_INT_TXDR | SDMMC_INT_RXDR | 2887 SDMMC_INT_TXDR | SDMMC_INT_RXDR |
2756 DW_MCI_ERROR_FLAGS | SDMMC_INT_CD); 2888 DW_MCI_ERROR_FLAGS);
2757 mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); /* Enable mci interrupt */ 2889 mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); /* Enable mci interrupt */
2758 2890
2759 dev_info(host->dev, "DW MMC controller at irq %d, " 2891 dev_info(host->dev, "DW MMC controller at irq %d, "
@@ -2778,6 +2910,9 @@ int dw_mci_probe(struct dw_mci *host)
2778 goto err_dmaunmap; 2910 goto err_dmaunmap;
2779 } 2911 }
2780 2912
2913 /* Now that slots are all setup, we can enable card detect */
2914 dw_mci_enable_cd(host);
2915
2781 if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO) 2916 if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO)
2782 dev_info(host->dev, "Internal DMAC interrupt fix enabled.\n"); 2917 dev_info(host->dev, "Internal DMAC interrupt fix enabled.\n");
2783 2918
@@ -2864,7 +2999,7 @@ int dw_mci_resume(struct dw_mci *host)
2864 mci_writel(host, RINTSTS, 0xFFFFFFFF); 2999 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2865 mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER | 3000 mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
2866 SDMMC_INT_TXDR | SDMMC_INT_RXDR | 3001 SDMMC_INT_TXDR | SDMMC_INT_RXDR |
2867 DW_MCI_ERROR_FLAGS | SDMMC_INT_CD); 3002 DW_MCI_ERROR_FLAGS);
2868 mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); 3003 mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
2869 3004
2870 for (i = 0; i < host->num_slots; i++) { 3005 for (i = 0; i < host->num_slots; i++) {
@@ -2876,6 +3011,10 @@ int dw_mci_resume(struct dw_mci *host)
2876 dw_mci_setup_bus(slot, true); 3011 dw_mci_setup_bus(slot, true);
2877 } 3012 }
2878 } 3013 }
3014
3015 /* Now that slots are all setup, we can enable card detect */
3016 dw_mci_enable_cd(host);
3017
2879 return 0; 3018 return 0;
2880} 3019}
2881EXPORT_SYMBOL(dw_mci_resume); 3020EXPORT_SYMBOL(dw_mci_resume);
diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
index 18c4afe683b8..f45ab91de339 100644
--- a/drivers/mmc/host/dw_mmc.h
+++ b/drivers/mmc/host/dw_mmc.h
@@ -169,24 +169,34 @@
169#define SDMMC_CTRL_ALL_RESET_FLAGS \ 169#define SDMMC_CTRL_ALL_RESET_FLAGS \
170 (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | SDMMC_CTRL_DMA_RESET) 170 (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | SDMMC_CTRL_DMA_RESET)
171 171
172/* FIFO register access macros. These should not change the data endian-ness
173 * as they are written to memory to be dealt with by the upper layers */
174#define mci_fifo_readw(__reg) __raw_readw(__reg)
175#define mci_fifo_readl(__reg) __raw_readl(__reg)
176#define mci_fifo_readq(__reg) __raw_readq(__reg)
177
178#define mci_fifo_writew(__value, __reg) __raw_writew(__reg, __value)
179#define mci_fifo_writel(__value, __reg) __raw_writel(__reg, __value)
180#define mci_fifo_writeq(__value, __reg) __raw_writeq(__reg, __value)
181
172/* Register access macros */ 182/* Register access macros */
173#define mci_readl(dev, reg) \ 183#define mci_readl(dev, reg) \
174 __raw_readl((dev)->regs + SDMMC_##reg) 184 readl_relaxed((dev)->regs + SDMMC_##reg)
175#define mci_writel(dev, reg, value) \ 185#define mci_writel(dev, reg, value) \
176 __raw_writel((value), (dev)->regs + SDMMC_##reg) 186 writel_relaxed((value), (dev)->regs + SDMMC_##reg)
177 187
178/* 16-bit FIFO access macros */ 188/* 16-bit FIFO access macros */
179#define mci_readw(dev, reg) \ 189#define mci_readw(dev, reg) \
180 __raw_readw((dev)->regs + SDMMC_##reg) 190 readw_relaxed((dev)->regs + SDMMC_##reg)
181#define mci_writew(dev, reg, value) \ 191#define mci_writew(dev, reg, value) \
182 __raw_writew((value), (dev)->regs + SDMMC_##reg) 192 writew_relaxed((value), (dev)->regs + SDMMC_##reg)
183 193
184/* 64-bit FIFO access macros */ 194/* 64-bit FIFO access macros */
185#ifdef readq 195#ifdef readq
186#define mci_readq(dev, reg) \ 196#define mci_readq(dev, reg) \
187 __raw_readq((dev)->regs + SDMMC_##reg) 197 readq_relaxed((dev)->regs + SDMMC_##reg)
188#define mci_writeq(dev, reg, value) \ 198#define mci_writeq(dev, reg, value) \
189 __raw_writeq((value), (dev)->regs + SDMMC_##reg) 199 writeq_relaxed((value), (dev)->regs + SDMMC_##reg)
190#else 200#else
191/* 201/*
192 * Dummy readq implementation for architectures that don't define it. 202 * Dummy readq implementation for architectures that don't define it.
@@ -200,6 +210,10 @@
200 (*(volatile u64 __force *)((dev)->regs + SDMMC_##reg)) 210 (*(volatile u64 __force *)((dev)->regs + SDMMC_##reg))
201#define mci_writeq(dev, reg, value) \ 211#define mci_writeq(dev, reg, value) \
202 (*(volatile u64 __force *)((dev)->regs + SDMMC_##reg) = (value)) 212 (*(volatile u64 __force *)((dev)->regs + SDMMC_##reg) = (value))
213
214#define __raw_writeq(__value, __reg) \
215 (*(volatile u64 __force *)(__reg) = (__value))
216#define __raw_readq(__reg) (*(volatile u64 __force *)(__reg))
203#endif 217#endif
204 218
205extern int dw_mci_probe(struct dw_mci *host); 219extern int dw_mci_probe(struct dw_mci *host);
@@ -271,5 +285,7 @@ struct dw_mci_drv_data {
271 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios); 285 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
272 int (*parse_dt)(struct dw_mci *host); 286 int (*parse_dt)(struct dw_mci *host);
273 int (*execute_tuning)(struct dw_mci_slot *slot); 287 int (*execute_tuning)(struct dw_mci_slot *slot);
288 int (*prepare_hs400_tuning)(struct dw_mci *host,
289 struct mmc_ios *ios);
274}; 290};
275#endif /* _DW_MMC_H_ */ 291#endif /* _DW_MMC_H_ */
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index e4a07546f8b6..ae19d83bb9de 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -1507,7 +1507,7 @@ static int mmc_spi_remove(struct spi_device *spi)
1507 return 0; 1507 return 0;
1508} 1508}
1509 1509
1510static struct of_device_id mmc_spi_of_match_table[] = { 1510static const struct of_device_id mmc_spi_of_match_table[] = {
1511 { .compatible = "mmc-spi-slot", }, 1511 { .compatible = "mmc-spi-slot", },
1512 {}, 1512 {},
1513}; 1513};
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index 7fe16194ebc8..fb266745f824 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -1613,7 +1613,10 @@ static int mmci_probe(struct amba_device *dev,
1613 dev_dbg(mmc_dev(mmc), "clocking block at %u Hz\n", mmc->f_max); 1613 dev_dbg(mmc_dev(mmc), "clocking block at %u Hz\n", mmc->f_max);
1614 1614
1615 /* Get regulators and the supported OCR mask */ 1615 /* Get regulators and the supported OCR mask */
1616 mmc_regulator_get_supply(mmc); 1616 ret = mmc_regulator_get_supply(mmc);
1617 if (ret == -EPROBE_DEFER)
1618 goto clk_disable;
1619
1617 if (!mmc->ocr_avail) 1620 if (!mmc->ocr_avail)
1618 mmc->ocr_avail = plat->ocr_mask; 1621 mmc->ocr_avail = plat->ocr_mask;
1619 else if (plat->ocr_mask) 1622 else if (plat->ocr_mask)
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index f84cfb01716d..9df2b6801f76 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -222,10 +222,6 @@ struct omap_hsmmc_host {
222 struct omap_hsmmc_next next_data; 222 struct omap_hsmmc_next next_data;
223 struct omap_hsmmc_platform_data *pdata; 223 struct omap_hsmmc_platform_data *pdata;
224 224
225 /* To handle board related suspend/resume functionality for MMC */
226 int (*suspend)(struct device *dev);
227 int (*resume)(struct device *dev);
228
229 /* return MMC cover switch state, can be NULL if not supported. 225 /* return MMC cover switch state, can be NULL if not supported.
230 * 226 *
231 * possible return values: 227 * possible return values:
@@ -234,12 +230,7 @@ struct omap_hsmmc_host {
234 */ 230 */
235 int (*get_cover_state)(struct device *dev); 231 int (*get_cover_state)(struct device *dev);
236 232
237 /* Card detection IRQs */
238 int card_detect_irq;
239
240 int (*card_detect)(struct device *dev); 233 int (*card_detect)(struct device *dev);
241 int (*get_ro)(struct device *dev);
242
243}; 234};
244 235
245struct omap_mmc_of_data { 236struct omap_mmc_of_data {
@@ -256,13 +247,6 @@ static int omap_hsmmc_card_detect(struct device *dev)
256 return mmc_gpio_get_cd(host->mmc); 247 return mmc_gpio_get_cd(host->mmc);
257} 248}
258 249
259static int omap_hsmmc_get_wp(struct device *dev)
260{
261 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
262
263 return mmc_gpio_get_ro(host->mmc);
264}
265
266static int omap_hsmmc_get_cover_state(struct device *dev) 250static int omap_hsmmc_get_cover_state(struct device *dev)
267{ 251{
268 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 252 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
@@ -434,7 +418,7 @@ static inline int omap_hsmmc_have_reg(void)
434 418
435#endif 419#endif
436 420
437static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id); 421static irqreturn_t omap_hsmmc_cover_irq(int irq, void *dev_id);
438 422
439static int omap_hsmmc_gpio_init(struct mmc_host *mmc, 423static int omap_hsmmc_gpio_init(struct mmc_host *mmc,
440 struct omap_hsmmc_host *host, 424 struct omap_hsmmc_host *host,
@@ -442,29 +426,25 @@ static int omap_hsmmc_gpio_init(struct mmc_host *mmc,
442{ 426{
443 int ret; 427 int ret;
444 428
445 if (gpio_is_valid(pdata->switch_pin)) { 429 if (gpio_is_valid(pdata->gpio_cod)) {
446 if (pdata->cover) 430 ret = mmc_gpio_request_cd(mmc, pdata->gpio_cod, 0);
447 host->get_cover_state =
448 omap_hsmmc_get_cover_state;
449 else
450 host->card_detect = omap_hsmmc_card_detect;
451 host->card_detect_irq =
452 gpio_to_irq(pdata->switch_pin);
453 mmc_gpio_set_cd_isr(mmc, omap_hsmmc_detect);
454 ret = mmc_gpio_request_cd(mmc, pdata->switch_pin, 0);
455 if (ret) 431 if (ret)
456 return ret; 432 return ret;
457 } else { 433
458 pdata->switch_pin = -EINVAL; 434 host->get_cover_state = omap_hsmmc_get_cover_state;
435 mmc_gpio_set_cd_isr(mmc, omap_hsmmc_cover_irq);
436 } else if (gpio_is_valid(pdata->gpio_cd)) {
437 ret = mmc_gpio_request_cd(mmc, pdata->gpio_cd, 0);
438 if (ret)
439 return ret;
440
441 host->card_detect = omap_hsmmc_card_detect;
459 } 442 }
460 443
461 if (gpio_is_valid(pdata->gpio_wp)) { 444 if (gpio_is_valid(pdata->gpio_wp)) {
462 host->get_ro = omap_hsmmc_get_wp;
463 ret = mmc_gpio_request_ro(mmc, pdata->gpio_wp); 445 ret = mmc_gpio_request_ro(mmc, pdata->gpio_wp);
464 if (ret) 446 if (ret)
465 return ret; 447 return ret;
466 } else {
467 pdata->gpio_wp = -EINVAL;
468 } 448 }
469 449
470 return 0; 450 return 0;
@@ -882,6 +862,8 @@ static void omap_hsmmc_request_done(struct omap_hsmmc_host *host, struct mmc_req
882 return; 862 return;
883 host->mrq = NULL; 863 host->mrq = NULL;
884 mmc_request_done(host->mmc, mrq); 864 mmc_request_done(host->mmc, mrq);
865 pm_runtime_mark_last_busy(host->dev);
866 pm_runtime_put_autosuspend(host->dev);
885} 867}
886 868
887/* 869/*
@@ -1252,26 +1234,16 @@ static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)
1252} 1234}
1253 1235
1254/* 1236/*
1255 * irq handler to notify the core about card insertion/removal 1237 * irq handler when (cell-phone) cover is mounted/removed
1256 */ 1238 */
1257static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id) 1239static irqreturn_t omap_hsmmc_cover_irq(int irq, void *dev_id)
1258{ 1240{
1259 struct omap_hsmmc_host *host = dev_id; 1241 struct omap_hsmmc_host *host = dev_id;
1260 int carddetect;
1261 1242
1262 sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch"); 1243 sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
1263 1244
1264 if (host->card_detect) 1245 omap_hsmmc_protect_card(host);
1265 carddetect = host->card_detect(host->dev); 1246 mmc_detect_change(host->mmc, (HZ * 200) / 1000);
1266 else {
1267 omap_hsmmc_protect_card(host);
1268 carddetect = -ENOSYS;
1269 }
1270
1271 if (carddetect)
1272 mmc_detect_change(host->mmc, (HZ * 200) / 1000);
1273 else
1274 mmc_detect_change(host->mmc, (HZ * 50) / 1000);
1275 return IRQ_HANDLED; 1247 return IRQ_HANDLED;
1276} 1248}
1277 1249
@@ -1305,6 +1277,8 @@ static void omap_hsmmc_dma_callback(void *param)
1305 1277
1306 host->mrq = NULL; 1278 host->mrq = NULL;
1307 mmc_request_done(host->mmc, mrq); 1279 mmc_request_done(host->mmc, mrq);
1280 pm_runtime_mark_last_busy(host->dev);
1281 pm_runtime_put_autosuspend(host->dev);
1308 } 1282 }
1309} 1283}
1310 1284
@@ -1537,6 +1511,7 @@ static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req)
1537 1511
1538 BUG_ON(host->req_in_progress); 1512 BUG_ON(host->req_in_progress);
1539 BUG_ON(host->dma_ch != -1); 1513 BUG_ON(host->dma_ch != -1);
1514 pm_runtime_get_sync(host->dev);
1540 if (host->protect_card) { 1515 if (host->protect_card) {
1541 if (host->reqs_blocked < 3) { 1516 if (host->reqs_blocked < 3) {
1542 /* 1517 /*
@@ -1553,6 +1528,8 @@ static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req)
1553 req->data->error = -EBADF; 1528 req->data->error = -EBADF;
1554 req->cmd->retries = 0; 1529 req->cmd->retries = 0;
1555 mmc_request_done(mmc, req); 1530 mmc_request_done(mmc, req);
1531 pm_runtime_mark_last_busy(host->dev);
1532 pm_runtime_put_autosuspend(host->dev);
1556 return; 1533 return;
1557 } else if (host->reqs_blocked) 1534 } else if (host->reqs_blocked)
1558 host->reqs_blocked = 0; 1535 host->reqs_blocked = 0;
@@ -1566,6 +1543,8 @@ static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req)
1566 req->data->error = err; 1543 req->data->error = err;
1567 host->mrq = NULL; 1544 host->mrq = NULL;
1568 mmc_request_done(mmc, req); 1545 mmc_request_done(mmc, req);
1546 pm_runtime_mark_last_busy(host->dev);
1547 pm_runtime_put_autosuspend(host->dev);
1569 return; 1548 return;
1570 } 1549 }
1571 if (req->sbc && !(host->flags & AUTO_CMD23)) { 1550 if (req->sbc && !(host->flags & AUTO_CMD23)) {
@@ -1641,15 +1620,6 @@ static int omap_hsmmc_get_cd(struct mmc_host *mmc)
1641 return host->card_detect(host->dev); 1620 return host->card_detect(host->dev);
1642} 1621}
1643 1622
1644static int omap_hsmmc_get_ro(struct mmc_host *mmc)
1645{
1646 struct omap_hsmmc_host *host = mmc_priv(mmc);
1647
1648 if (!host->get_ro)
1649 return -ENOSYS;
1650 return host->get_ro(host->dev);
1651}
1652
1653static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card) 1623static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card)
1654{ 1624{
1655 struct omap_hsmmc_host *host = mmc_priv(mmc); 1625 struct omap_hsmmc_host *host = mmc_priv(mmc);
@@ -1778,25 +1748,6 @@ static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host *host)
1778 set_sd_bus_power(host); 1748 set_sd_bus_power(host);
1779} 1749}
1780 1750
1781static int omap_hsmmc_enable_fclk(struct mmc_host *mmc)
1782{
1783 struct omap_hsmmc_host *host = mmc_priv(mmc);
1784
1785 pm_runtime_get_sync(host->dev);
1786
1787 return 0;
1788}
1789
1790static int omap_hsmmc_disable_fclk(struct mmc_host *mmc)
1791{
1792 struct omap_hsmmc_host *host = mmc_priv(mmc);
1793
1794 pm_runtime_mark_last_busy(host->dev);
1795 pm_runtime_put_autosuspend(host->dev);
1796
1797 return 0;
1798}
1799
1800static int omap_hsmmc_multi_io_quirk(struct mmc_card *card, 1751static int omap_hsmmc_multi_io_quirk(struct mmc_card *card,
1801 unsigned int direction, int blk_size) 1752 unsigned int direction, int blk_size)
1802{ 1753{
@@ -1808,14 +1759,12 @@ static int omap_hsmmc_multi_io_quirk(struct mmc_card *card,
1808} 1759}
1809 1760
1810static struct mmc_host_ops omap_hsmmc_ops = { 1761static struct mmc_host_ops omap_hsmmc_ops = {
1811 .enable = omap_hsmmc_enable_fclk,
1812 .disable = omap_hsmmc_disable_fclk,
1813 .post_req = omap_hsmmc_post_req, 1762 .post_req = omap_hsmmc_post_req,
1814 .pre_req = omap_hsmmc_pre_req, 1763 .pre_req = omap_hsmmc_pre_req,
1815 .request = omap_hsmmc_request, 1764 .request = omap_hsmmc_request,
1816 .set_ios = omap_hsmmc_set_ios, 1765 .set_ios = omap_hsmmc_set_ios,
1817 .get_cd = omap_hsmmc_get_cd, 1766 .get_cd = omap_hsmmc_get_cd,
1818 .get_ro = omap_hsmmc_get_ro, 1767 .get_ro = mmc_gpio_get_ro,
1819 .init_card = omap_hsmmc_init_card, 1768 .init_card = omap_hsmmc_init_card,
1820 .enable_sdio_irq = omap_hsmmc_enable_sdio_irq, 1769 .enable_sdio_irq = omap_hsmmc_enable_sdio_irq,
1821}; 1770};
@@ -1937,7 +1886,8 @@ static struct omap_hsmmc_platform_data *of_get_hsmmc_pdata(struct device *dev)
1937 if (of_find_property(np, "ti,dual-volt", NULL)) 1886 if (of_find_property(np, "ti,dual-volt", NULL))
1938 pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT; 1887 pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT;
1939 1888
1940 pdata->switch_pin = -EINVAL; 1889 pdata->gpio_cd = -EINVAL;
1890 pdata->gpio_cod = -EINVAL;
1941 pdata->gpio_wp = -EINVAL; 1891 pdata->gpio_wp = -EINVAL;
1942 1892
1943 if (of_find_property(np, "ti,non-removable", NULL)) { 1893 if (of_find_property(np, "ti,non-removable", NULL)) {
@@ -2179,9 +2129,9 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2179 if (ret < 0) 2129 if (ret < 0)
2180 goto err_slot_name; 2130 goto err_slot_name;
2181 } 2131 }
2182 if (host->card_detect_irq && host->get_cover_state) { 2132 if (host->get_cover_state) {
2183 ret = device_create_file(&mmc->class_dev, 2133 ret = device_create_file(&mmc->class_dev,
2184 &dev_attr_cover_switch); 2134 &dev_attr_cover_switch);
2185 if (ret < 0) 2135 if (ret < 0)
2186 goto err_slot_name; 2136 goto err_slot_name;
2187 } 2137 }
@@ -2236,7 +2186,7 @@ static int omap_hsmmc_remove(struct platform_device *pdev)
2236 return 0; 2186 return 0;
2237} 2187}
2238 2188
2239#ifdef CONFIG_PM 2189#ifdef CONFIG_PM_SLEEP
2240static int omap_hsmmc_suspend(struct device *dev) 2190static int omap_hsmmc_suspend(struct device *dev)
2241{ 2191{
2242 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 2192 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
@@ -2292,10 +2242,6 @@ static int omap_hsmmc_resume(struct device *dev)
2292 pm_runtime_put_autosuspend(host->dev); 2242 pm_runtime_put_autosuspend(host->dev);
2293 return 0; 2243 return 0;
2294} 2244}
2295
2296#else
2297#define omap_hsmmc_suspend NULL
2298#define omap_hsmmc_resume NULL
2299#endif 2245#endif
2300 2246
2301static int omap_hsmmc_runtime_suspend(struct device *dev) 2247static int omap_hsmmc_runtime_suspend(struct device *dev)
@@ -2376,8 +2322,7 @@ static int omap_hsmmc_runtime_resume(struct device *dev)
2376} 2322}
2377 2323
2378static struct dev_pm_ops omap_hsmmc_dev_pm_ops = { 2324static struct dev_pm_ops omap_hsmmc_dev_pm_ops = {
2379 .suspend = omap_hsmmc_suspend, 2325 SET_SYSTEM_SLEEP_PM_OPS(omap_hsmmc_suspend, omap_hsmmc_resume)
2380 .resume = omap_hsmmc_resume,
2381 .runtime_suspend = omap_hsmmc_runtime_suspend, 2326 .runtime_suspend = omap_hsmmc_runtime_suspend,
2382 .runtime_resume = omap_hsmmc_runtime_resume, 2327 .runtime_resume = omap_hsmmc_runtime_resume,
2383}; 2328};
diff --git a/drivers/mmc/host/sdhci-acpi.c b/drivers/mmc/host/sdhci-acpi.c
index a45ed39d062c..22d929fa3371 100644
--- a/drivers/mmc/host/sdhci-acpi.c
+++ b/drivers/mmc/host/sdhci-acpi.c
@@ -40,7 +40,6 @@
40#include <linux/mmc/host.h> 40#include <linux/mmc/host.h>
41#include <linux/mmc/pm.h> 41#include <linux/mmc/pm.h>
42#include <linux/mmc/slot-gpio.h> 42#include <linux/mmc/slot-gpio.h>
43#include <linux/mmc/sdhci.h>
44 43
45#include "sdhci.h" 44#include "sdhci.h"
46 45
diff --git a/drivers/mmc/host/sdhci-bcm-kona.c b/drivers/mmc/host/sdhci-bcm-kona.c
index 34bb8f92586e..2bd90fb35c75 100644
--- a/drivers/mmc/host/sdhci-bcm-kona.c
+++ b/drivers/mmc/host/sdhci-bcm-kona.c
@@ -54,7 +54,6 @@
54 54
55struct sdhci_bcm_kona_dev { 55struct sdhci_bcm_kona_dev {
56 struct mutex write_lock; /* protect back to back writes */ 56 struct mutex write_lock; /* protect back to back writes */
57 struct clk *external_clk;
58}; 57};
59 58
60 59
@@ -175,24 +174,6 @@ static void sdhci_bcm_kona_card_event(struct sdhci_host *host)
175 } 174 }
176} 175}
177 176
178/*
179 * Get the base clock. Use central clock source for now. Not sure if different
180 * clock speed to each dev is allowed
181 */
182static unsigned int sdhci_bcm_kona_get_max_clk(struct sdhci_host *host)
183{
184 struct sdhci_bcm_kona_dev *kona_dev;
185 struct sdhci_pltfm_host *pltfm_priv = sdhci_priv(host);
186 kona_dev = sdhci_pltfm_priv(pltfm_priv);
187
188 return host->mmc->f_max;
189}
190
191static unsigned int sdhci_bcm_kona_get_timeout_clock(struct sdhci_host *host)
192{
193 return sdhci_bcm_kona_get_max_clk(host);
194}
195
196static void sdhci_bcm_kona_init_74_clocks(struct sdhci_host *host, 177static void sdhci_bcm_kona_init_74_clocks(struct sdhci_host *host,
197 u8 power_mode) 178 u8 power_mode)
198{ 179{
@@ -207,8 +188,8 @@ static void sdhci_bcm_kona_init_74_clocks(struct sdhci_host *host,
207 188
208static struct sdhci_ops sdhci_bcm_kona_ops = { 189static struct sdhci_ops sdhci_bcm_kona_ops = {
209 .set_clock = sdhci_set_clock, 190 .set_clock = sdhci_set_clock,
210 .get_max_clock = sdhci_bcm_kona_get_max_clk, 191 .get_max_clock = sdhci_pltfm_clk_get_max_clock,
211 .get_timeout_clock = sdhci_bcm_kona_get_timeout_clock, 192 .get_timeout_clock = sdhci_pltfm_clk_get_max_clock,
212 .platform_send_init_74_clocks = sdhci_bcm_kona_init_74_clocks, 193 .platform_send_init_74_clocks = sdhci_bcm_kona_init_74_clocks,
213 .set_bus_width = sdhci_set_bus_width, 194 .set_bus_width = sdhci_set_bus_width,
214 .reset = sdhci_reset, 195 .reset = sdhci_reset,
@@ -264,21 +245,21 @@ static int sdhci_bcm_kona_probe(struct platform_device *pdev)
264 goto err_pltfm_free; 245 goto err_pltfm_free;
265 } 246 }
266 247
267 /* Get and enable the external clock */ 248 /* Get and enable the core clock */
268 kona_dev->external_clk = devm_clk_get(dev, NULL); 249 pltfm_priv->clk = devm_clk_get(dev, NULL);
269 if (IS_ERR(kona_dev->external_clk)) { 250 if (IS_ERR(pltfm_priv->clk)) {
270 dev_err(dev, "Failed to get external clock\n"); 251 dev_err(dev, "Failed to get core clock\n");
271 ret = PTR_ERR(kona_dev->external_clk); 252 ret = PTR_ERR(pltfm_priv->clk);
272 goto err_pltfm_free; 253 goto err_pltfm_free;
273 } 254 }
274 255
275 if (clk_set_rate(kona_dev->external_clk, host->mmc->f_max) != 0) { 256 if (clk_set_rate(pltfm_priv->clk, host->mmc->f_max) != 0) {
276 dev_err(dev, "Failed to set rate external clock\n"); 257 dev_err(dev, "Failed to set rate core clock\n");
277 goto err_pltfm_free; 258 goto err_pltfm_free;
278 } 259 }
279 260
280 if (clk_prepare_enable(kona_dev->external_clk) != 0) { 261 if (clk_prepare_enable(pltfm_priv->clk) != 0) {
281 dev_err(dev, "Failed to enable external clock\n"); 262 dev_err(dev, "Failed to enable core clock\n");
282 goto err_pltfm_free; 263 goto err_pltfm_free;
283 } 264 }
284 265
@@ -333,7 +314,7 @@ err_reset:
333 sdhci_bcm_kona_sd_reset(host); 314 sdhci_bcm_kona_sd_reset(host);
334 315
335err_clk_disable: 316err_clk_disable:
336 clk_disable_unprepare(kona_dev->external_clk); 317 clk_disable_unprepare(pltfm_priv->clk);
337 318
338err_pltfm_free: 319err_pltfm_free:
339 sdhci_pltfm_free(pdev); 320 sdhci_pltfm_free(pdev);
@@ -342,22 +323,6 @@ err_pltfm_free:
342 return ret; 323 return ret;
343} 324}
344 325
345static int sdhci_bcm_kona_remove(struct platform_device *pdev)
346{
347 struct sdhci_host *host = platform_get_drvdata(pdev);
348 struct sdhci_pltfm_host *pltfm_priv = sdhci_priv(host);
349 struct sdhci_bcm_kona_dev *kona_dev = sdhci_pltfm_priv(pltfm_priv);
350 int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
351
352 sdhci_remove_host(host, dead);
353
354 clk_disable_unprepare(kona_dev->external_clk);
355
356 sdhci_pltfm_free(pdev);
357
358 return 0;
359}
360
361static struct platform_driver sdhci_bcm_kona_driver = { 326static struct platform_driver sdhci_bcm_kona_driver = {
362 .driver = { 327 .driver = {
363 .name = "sdhci-kona", 328 .name = "sdhci-kona",
@@ -365,7 +330,7 @@ static struct platform_driver sdhci_bcm_kona_driver = {
365 .of_match_table = sdhci_bcm_kona_of_match, 330 .of_match_table = sdhci_bcm_kona_of_match,
366 }, 331 },
367 .probe = sdhci_bcm_kona_probe, 332 .probe = sdhci_bcm_kona_probe,
368 .remove = sdhci_bcm_kona_remove, 333 .remove = sdhci_pltfm_unregister,
369}; 334};
370module_platform_driver(sdhci_bcm_kona_driver); 335module_platform_driver(sdhci_bcm_kona_driver);
371 336
diff --git a/drivers/mmc/host/sdhci-bcm2835.c b/drivers/mmc/host/sdhci-bcm2835.c
index 439d259fdf1d..0ef0343c603a 100644
--- a/drivers/mmc/host/sdhci-bcm2835.c
+++ b/drivers/mmc/host/sdhci-bcm2835.c
@@ -180,11 +180,6 @@ err:
180 return ret; 180 return ret;
181} 181}
182 182
183static int bcm2835_sdhci_remove(struct platform_device *pdev)
184{
185 return sdhci_pltfm_unregister(pdev);
186}
187
188static const struct of_device_id bcm2835_sdhci_of_match[] = { 183static const struct of_device_id bcm2835_sdhci_of_match[] = {
189 { .compatible = "brcm,bcm2835-sdhci" }, 184 { .compatible = "brcm,bcm2835-sdhci" },
190 { } 185 { }
@@ -198,7 +193,7 @@ static struct platform_driver bcm2835_sdhci_driver = {
198 .pm = SDHCI_PLTFM_PMOPS, 193 .pm = SDHCI_PLTFM_PMOPS,
199 }, 194 },
200 .probe = bcm2835_sdhci_probe, 195 .probe = bcm2835_sdhci_probe,
201 .remove = bcm2835_sdhci_remove, 196 .remove = sdhci_pltfm_unregister,
202}; 197};
203module_platform_driver(bcm2835_sdhci_driver); 198module_platform_driver(bcm2835_sdhci_driver);
204 199
diff --git a/drivers/mmc/host/sdhci-cns3xxx.c b/drivers/mmc/host/sdhci-cns3xxx.c
index a7935a8d0922..59f2923f8054 100644
--- a/drivers/mmc/host/sdhci-cns3xxx.c
+++ b/drivers/mmc/host/sdhci-cns3xxx.c
@@ -98,18 +98,13 @@ static int sdhci_cns3xxx_probe(struct platform_device *pdev)
98 return sdhci_pltfm_register(pdev, &sdhci_cns3xxx_pdata, 0); 98 return sdhci_pltfm_register(pdev, &sdhci_cns3xxx_pdata, 0);
99} 99}
100 100
101static int sdhci_cns3xxx_remove(struct platform_device *pdev)
102{
103 return sdhci_pltfm_unregister(pdev);
104}
105
106static struct platform_driver sdhci_cns3xxx_driver = { 101static struct platform_driver sdhci_cns3xxx_driver = {
107 .driver = { 102 .driver = {
108 .name = "sdhci-cns3xxx", 103 .name = "sdhci-cns3xxx",
109 .pm = SDHCI_PLTFM_PMOPS, 104 .pm = SDHCI_PLTFM_PMOPS,
110 }, 105 },
111 .probe = sdhci_cns3xxx_probe, 106 .probe = sdhci_cns3xxx_probe,
112 .remove = sdhci_cns3xxx_remove, 107 .remove = sdhci_pltfm_unregister,
113}; 108};
114 109
115module_platform_driver(sdhci_cns3xxx_driver); 110module_platform_driver(sdhci_cns3xxx_driver);
diff --git a/drivers/mmc/host/sdhci-dove.c b/drivers/mmc/host/sdhci-dove.c
index ca969d271a27..407c21f152b2 100644
--- a/drivers/mmc/host/sdhci-dove.c
+++ b/drivers/mmc/host/sdhci-dove.c
@@ -28,10 +28,6 @@
28 28
29#include "sdhci-pltfm.h" 29#include "sdhci-pltfm.h"
30 30
31struct sdhci_dove_priv {
32 struct clk *clk;
33};
34
35static u16 sdhci_dove_readw(struct sdhci_host *host, int reg) 31static u16 sdhci_dove_readw(struct sdhci_host *host, int reg)
36{ 32{
37 u16 ret; 33 u16 ret;
@@ -84,27 +80,17 @@ static int sdhci_dove_probe(struct platform_device *pdev)
84{ 80{
85 struct sdhci_host *host; 81 struct sdhci_host *host;
86 struct sdhci_pltfm_host *pltfm_host; 82 struct sdhci_pltfm_host *pltfm_host;
87 struct sdhci_dove_priv *priv;
88 int ret; 83 int ret;
89 84
90 priv = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_dove_priv),
91 GFP_KERNEL);
92 if (!priv) {
93 dev_err(&pdev->dev, "unable to allocate private data");
94 return -ENOMEM;
95 }
96
97 priv->clk = devm_clk_get(&pdev->dev, NULL);
98
99 host = sdhci_pltfm_init(pdev, &sdhci_dove_pdata, 0); 85 host = sdhci_pltfm_init(pdev, &sdhci_dove_pdata, 0);
100 if (IS_ERR(host)) 86 if (IS_ERR(host))
101 return PTR_ERR(host); 87 return PTR_ERR(host);
102 88
103 pltfm_host = sdhci_priv(host); 89 pltfm_host = sdhci_priv(host);
104 pltfm_host->priv = priv; 90 pltfm_host->clk = devm_clk_get(&pdev->dev, NULL);
105 91
106 if (!IS_ERR(priv->clk)) 92 if (!IS_ERR(pltfm_host->clk))
107 clk_prepare_enable(priv->clk); 93 clk_prepare_enable(pltfm_host->clk);
108 94
109 ret = mmc_of_parse(host->mmc); 95 ret = mmc_of_parse(host->mmc);
110 if (ret) 96 if (ret)
@@ -117,26 +103,11 @@ static int sdhci_dove_probe(struct platform_device *pdev)
117 return 0; 103 return 0;
118 104
119err_sdhci_add: 105err_sdhci_add:
120 if (!IS_ERR(priv->clk)) 106 clk_disable_unprepare(pltfm_host->clk);
121 clk_disable_unprepare(priv->clk);
122 sdhci_pltfm_free(pdev); 107 sdhci_pltfm_free(pdev);
123 return ret; 108 return ret;
124} 109}
125 110
126static int sdhci_dove_remove(struct platform_device *pdev)
127{
128 struct sdhci_host *host = platform_get_drvdata(pdev);
129 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
130 struct sdhci_dove_priv *priv = pltfm_host->priv;
131
132 sdhci_pltfm_unregister(pdev);
133
134 if (!IS_ERR(priv->clk))
135 clk_disable_unprepare(priv->clk);
136
137 return 0;
138}
139
140static const struct of_device_id sdhci_dove_of_match_table[] = { 111static const struct of_device_id sdhci_dove_of_match_table[] = {
141 { .compatible = "marvell,dove-sdhci", }, 112 { .compatible = "marvell,dove-sdhci", },
142 {} 113 {}
@@ -150,7 +121,7 @@ static struct platform_driver sdhci_dove_driver = {
150 .of_match_table = sdhci_dove_of_match_table, 121 .of_match_table = sdhci_dove_of_match_table,
151 }, 122 },
152 .probe = sdhci_dove_probe, 123 .probe = sdhci_dove_probe,
153 .remove = sdhci_dove_remove, 124 .remove = sdhci_pltfm_unregister,
154}; 125};
155 126
156module_platform_driver(sdhci_dove_driver); 127module_platform_driver(sdhci_dove_driver);
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index 10ef8244a239..82f512d87cb8 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -416,7 +416,7 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
416 new_val |= ESDHC_VENDOR_SPEC_FRC_SDCLK_ON; 416 new_val |= ESDHC_VENDOR_SPEC_FRC_SDCLK_ON;
417 else 417 else
418 new_val &= ~ESDHC_VENDOR_SPEC_FRC_SDCLK_ON; 418 new_val &= ~ESDHC_VENDOR_SPEC_FRC_SDCLK_ON;
419 writel(new_val, host->ioaddr + ESDHC_VENDOR_SPEC); 419 writel(new_val, host->ioaddr + ESDHC_VENDOR_SPEC);
420 return; 420 return;
421 case SDHCI_HOST_CONTROL2: 421 case SDHCI_HOST_CONTROL2:
422 new_val = readl(host->ioaddr + ESDHC_VENDOR_SPEC); 422 new_val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
@@ -864,6 +864,7 @@ static const struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
864#ifdef CONFIG_OF 864#ifdef CONFIG_OF
865static int 865static int
866sdhci_esdhc_imx_probe_dt(struct platform_device *pdev, 866sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
867 struct sdhci_host *host,
867 struct esdhc_platform_data *boarddata) 868 struct esdhc_platform_data *boarddata)
868{ 869{
869 struct device_node *np = pdev->dev.of_node; 870 struct device_node *np = pdev->dev.of_node;
@@ -900,11 +901,14 @@ sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
900 if (of_property_read_u32(np, "fsl,delay-line", &boarddata->delay_line)) 901 if (of_property_read_u32(np, "fsl,delay-line", &boarddata->delay_line))
901 boarddata->delay_line = 0; 902 boarddata->delay_line = 0;
902 903
904 mmc_of_parse_voltage(np, &host->ocr_mask);
905
903 return 0; 906 return 0;
904} 907}
905#else 908#else
906static inline int 909static inline int
907sdhci_esdhc_imx_probe_dt(struct platform_device *pdev, 910sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
911 struct sdhci_host *host,
908 struct esdhc_platform_data *boarddata) 912 struct esdhc_platform_data *boarddata)
909{ 913{
910 return -ENODEV; 914 return -ENODEV;
@@ -999,7 +1003,7 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
999 host->ioaddr + ESDHC_TUNING_CTRL); 1003 host->ioaddr + ESDHC_TUNING_CTRL);
1000 1004
1001 boarddata = &imx_data->boarddata; 1005 boarddata = &imx_data->boarddata;
1002 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) { 1006 if (sdhci_esdhc_imx_probe_dt(pdev, host, boarddata) < 0) {
1003 if (!host->mmc->parent->platform_data) { 1007 if (!host->mmc->parent->platform_data) {
1004 dev_err(mmc_dev(host->mmc), "no board data!\n"); 1008 dev_err(mmc_dev(host->mmc), "no board data!\n");
1005 err = -EINVAL; 1009 err = -EINVAL;
@@ -1009,40 +1013,9 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
1009 host->mmc->parent->platform_data); 1013 host->mmc->parent->platform_data);
1010 } 1014 }
1011 1015
1012 /* write_protect */
1013 if (boarddata->wp_type == ESDHC_WP_GPIO) {
1014 err = mmc_gpio_request_ro(host->mmc, boarddata->wp_gpio);
1015 if (err) {
1016 dev_err(mmc_dev(host->mmc),
1017 "failed to request write-protect gpio!\n");
1018 goto disable_clk;
1019 }
1020 host->mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
1021 }
1022
1023 /* card_detect */ 1016 /* card_detect */
1024 switch (boarddata->cd_type) { 1017 if (boarddata->cd_type == ESDHC_CD_CONTROLLER)
1025 case ESDHC_CD_GPIO:
1026 err = mmc_gpio_request_cd(host->mmc, boarddata->cd_gpio, 0);
1027 if (err) {
1028 dev_err(mmc_dev(host->mmc),
1029 "failed to request card-detect gpio!\n");
1030 goto disable_clk;
1031 }
1032 /* fall through */
1033
1034 case ESDHC_CD_CONTROLLER:
1035 /* we have a working card_detect back */
1036 host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; 1018 host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
1037 break;
1038
1039 case ESDHC_CD_PERMANENT:
1040 host->mmc->caps |= MMC_CAP_NONREMOVABLE;
1041 break;
1042
1043 case ESDHC_CD_NONE:
1044 break;
1045 }
1046 1019
1047 switch (boarddata->max_bus_width) { 1020 switch (boarddata->max_bus_width) {
1048 case 8: 1021 case 8:
@@ -1075,6 +1048,11 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
1075 host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V; 1048 host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V;
1076 } 1049 }
1077 1050
1051 /* call to generic mmc_of_parse to support additional capabilities */
1052 err = mmc_of_parse(host->mmc);
1053 if (err)
1054 goto disable_clk;
1055
1078 err = sdhci_add_host(host); 1056 err = sdhci_add_host(host);
1079 if (err) 1057 if (err)
1080 goto disable_clk; 1058 goto disable_clk;
diff --git a/drivers/mmc/host/sdhci-iproc.c b/drivers/mmc/host/sdhci-iproc.c
new file mode 100644
index 000000000000..3b423b0ad8e7
--- /dev/null
+++ b/drivers/mmc/host/sdhci-iproc.c
@@ -0,0 +1,241 @@
1/*
2 * Copyright (C) 2014 Broadcom Corporation
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
9 * kind, whether express or implied; without even the implied warranty
10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14/*
15 * iProc SDHCI platform driver
16 */
17
18#include <linux/delay.h>
19#include <linux/module.h>
20#include <linux/mmc/host.h>
21#include <linux/of.h>
22#include <linux/of_device.h>
23#include "sdhci-pltfm.h"
24
25struct sdhci_iproc_data {
26 const struct sdhci_pltfm_data *pdata;
27 u32 caps;
28 u32 caps1;
29};
30
31struct sdhci_iproc_host {
32 const struct sdhci_iproc_data *data;
33 u32 shadow_cmd;
34 u32 shadow_blk;
35};
36
37#define REG_OFFSET_IN_BITS(reg) ((reg) << 3 & 0x18)
38
39static inline u32 sdhci_iproc_readl(struct sdhci_host *host, int reg)
40{
41 u32 val = readl(host->ioaddr + reg);
42
43 pr_debug("%s: readl [0x%02x] 0x%08x\n",
44 mmc_hostname(host->mmc), reg, val);
45 return val;
46}
47
48static u16 sdhci_iproc_readw(struct sdhci_host *host, int reg)
49{
50 u32 val = sdhci_iproc_readl(host, (reg & ~3));
51 u16 word = val >> REG_OFFSET_IN_BITS(reg) & 0xffff;
52 return word;
53}
54
55static u8 sdhci_iproc_readb(struct sdhci_host *host, int reg)
56{
57 u32 val = sdhci_iproc_readl(host, (reg & ~3));
58 u8 byte = val >> REG_OFFSET_IN_BITS(reg) & 0xff;
59 return byte;
60}
61
62static inline void sdhci_iproc_writel(struct sdhci_host *host, u32 val, int reg)
63{
64 pr_debug("%s: writel [0x%02x] 0x%08x\n",
65 mmc_hostname(host->mmc), reg, val);
66
67 writel(val, host->ioaddr + reg);
68
69 if (host->clock <= 400000) {
70 /* Round up to micro-second four SD clock delay */
71 if (host->clock)
72 udelay((4 * 1000000 + host->clock - 1) / host->clock);
73 else
74 udelay(10);
75 }
76}
77
78/*
79 * The Arasan has a bugette whereby it may lose the content of successive
80 * writes to the same register that are within two SD-card clock cycles of
81 * each other (a clock domain crossing problem). The data
82 * register does not have this problem, which is just as well - otherwise we'd
83 * have to nobble the DMA engine too.
84 *
85 * This wouldn't be a problem with the code except that we can only write the
86 * controller with 32-bit writes. So two different 16-bit registers are
87 * written back to back creates the problem.
88 *
89 * In reality, this only happens when SDHCI_BLOCK_SIZE and SDHCI_BLOCK_COUNT
90 * are written followed by SDHCI_TRANSFER_MODE and SDHCI_COMMAND.
91 * The BLOCK_SIZE and BLOCK_COUNT are meaningless until a command issued so
92 * the work around can be further optimized. We can keep shadow values of
93 * BLOCK_SIZE, BLOCK_COUNT, and TRANSFER_MODE until a COMMAND is issued.
94 * Then, write the BLOCK_SIZE+BLOCK_COUNT in a single 32-bit write followed
95 * by the TRANSFER+COMMAND in another 32-bit write.
96 */
97static void sdhci_iproc_writew(struct sdhci_host *host, u16 val, int reg)
98{
99 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
100 struct sdhci_iproc_host *iproc_host = sdhci_pltfm_priv(pltfm_host);
101 u32 word_shift = REG_OFFSET_IN_BITS(reg);
102 u32 mask = 0xffff << word_shift;
103 u32 oldval, newval;
104
105 if (reg == SDHCI_COMMAND) {
106 /* Write the block now as we are issuing a command */
107 if (iproc_host->shadow_blk != 0) {
108 sdhci_iproc_writel(host, iproc_host->shadow_blk,
109 SDHCI_BLOCK_SIZE);
110 iproc_host->shadow_blk = 0;
111 }
112 oldval = iproc_host->shadow_cmd;
113 } else if (reg == SDHCI_BLOCK_SIZE || reg == SDHCI_BLOCK_COUNT) {
114 /* Block size and count are stored in shadow reg */
115 oldval = iproc_host->shadow_blk;
116 } else {
117 /* Read reg, all other registers are not shadowed */
118 oldval = sdhci_iproc_readl(host, (reg & ~3));
119 }
120 newval = (oldval & ~mask) | (val << word_shift);
121
122 if (reg == SDHCI_TRANSFER_MODE) {
123 /* Save the transfer mode until the command is issued */
124 iproc_host->shadow_cmd = newval;
125 } else if (reg == SDHCI_BLOCK_SIZE || reg == SDHCI_BLOCK_COUNT) {
126 /* Save the block info until the command is issued */
127 iproc_host->shadow_blk = newval;
128 } else {
129 /* Command or other regular 32-bit write */
130 sdhci_iproc_writel(host, newval, reg & ~3);
131 }
132}
133
134static void sdhci_iproc_writeb(struct sdhci_host *host, u8 val, int reg)
135{
136 u32 oldval = sdhci_iproc_readl(host, (reg & ~3));
137 u32 byte_shift = REG_OFFSET_IN_BITS(reg);
138 u32 mask = 0xff << byte_shift;
139 u32 newval = (oldval & ~mask) | (val << byte_shift);
140
141 sdhci_iproc_writel(host, newval, reg & ~3);
142}
143
144static const struct sdhci_ops sdhci_iproc_ops = {
145 .read_l = sdhci_iproc_readl,
146 .read_w = sdhci_iproc_readw,
147 .read_b = sdhci_iproc_readb,
148 .write_l = sdhci_iproc_writel,
149 .write_w = sdhci_iproc_writew,
150 .write_b = sdhci_iproc_writeb,
151 .set_clock = sdhci_set_clock,
152 .get_max_clock = sdhci_pltfm_clk_get_max_clock,
153 .set_bus_width = sdhci_set_bus_width,
154 .reset = sdhci_reset,
155 .set_uhs_signaling = sdhci_set_uhs_signaling,
156};
157
158static const struct sdhci_pltfm_data sdhci_iproc_pltfm_data = {
159 .quirks = SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK,
160 .quirks2 = SDHCI_QUIRK2_ACMD23_BROKEN,
161 .ops = &sdhci_iproc_ops,
162};
163
164static const struct sdhci_iproc_data iproc_data = {
165 .pdata = &sdhci_iproc_pltfm_data,
166 .caps = 0x05E90000,
167 .caps1 = 0x00000064,
168};
169
170static const struct of_device_id sdhci_iproc_of_match[] = {
171 { .compatible = "brcm,sdhci-iproc-cygnus", .data = &iproc_data },
172 { }
173};
174MODULE_DEVICE_TABLE(of, sdhci_iproc_of_match);
175
176static int sdhci_iproc_probe(struct platform_device *pdev)
177{
178 const struct of_device_id *match;
179 const struct sdhci_iproc_data *iproc_data;
180 struct sdhci_host *host;
181 struct sdhci_iproc_host *iproc_host;
182 struct sdhci_pltfm_host *pltfm_host;
183 int ret;
184
185 match = of_match_device(sdhci_iproc_of_match, &pdev->dev);
186 if (!match)
187 return -EINVAL;
188 iproc_data = match->data;
189
190 host = sdhci_pltfm_init(pdev, iproc_data->pdata, sizeof(*iproc_host));
191 if (IS_ERR(host))
192 return PTR_ERR(host);
193
194 pltfm_host = sdhci_priv(host);
195 iproc_host = sdhci_pltfm_priv(pltfm_host);
196
197 iproc_host->data = iproc_data;
198
199 mmc_of_parse(host->mmc);
200 sdhci_get_of_property(pdev);
201
202 /* Enable EMMC 1/8V DDR capable */
203 host->mmc->caps |= MMC_CAP_1_8V_DDR;
204
205 pltfm_host->clk = devm_clk_get(&pdev->dev, NULL);
206 if (IS_ERR(pltfm_host->clk)) {
207 ret = PTR_ERR(pltfm_host->clk);
208 goto err;
209 }
210
211 if (iproc_host->data->pdata->quirks & SDHCI_QUIRK_MISSING_CAPS) {
212 host->caps = iproc_host->data->caps;
213 host->caps1 = iproc_host->data->caps1;
214 }
215
216 return sdhci_add_host(host);
217
218err:
219 sdhci_pltfm_free(pdev);
220 return ret;
221}
222
223static int sdhci_iproc_remove(struct platform_device *pdev)
224{
225 return sdhci_pltfm_unregister(pdev);
226}
227
228static struct platform_driver sdhci_iproc_driver = {
229 .driver = {
230 .name = "sdhci-iproc",
231 .of_match_table = sdhci_iproc_of_match,
232 .pm = SDHCI_PLTFM_PMOPS,
233 },
234 .probe = sdhci_iproc_probe,
235 .remove = sdhci_iproc_remove,
236};
237module_platform_driver(sdhci_iproc_driver);
238
239MODULE_AUTHOR("Broadcom");
240MODULE_DESCRIPTION("IPROC SDHCI driver");
241MODULE_LICENSE("GPL v2");
diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
index 3d32ce896b09..4a09f7608c66 100644
--- a/drivers/mmc/host/sdhci-msm.c
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -22,6 +22,11 @@
22 22
23#include "sdhci-pltfm.h" 23#include "sdhci-pltfm.h"
24 24
25#define CORE_MCI_VERSION 0x50
26#define CORE_VERSION_MAJOR_SHIFT 28
27#define CORE_VERSION_MAJOR_MASK (0xf << CORE_VERSION_MAJOR_SHIFT)
28#define CORE_VERSION_MINOR_MASK 0xff
29
25#define CORE_HC_MODE 0x78 30#define CORE_HC_MODE 0x78
26#define HC_MODE_EN 0x1 31#define HC_MODE_EN 0x1
27#define CORE_POWER 0x0 32#define CORE_POWER 0x0
@@ -41,6 +46,8 @@
41#define CORE_VENDOR_SPEC 0x10c 46#define CORE_VENDOR_SPEC 0x10c
42#define CORE_CLK_PWRSAVE BIT(1) 47#define CORE_CLK_PWRSAVE BIT(1)
43 48
49#define CORE_VENDOR_SPEC_CAPABILITIES0 0x11c
50
44#define CDR_SELEXT_SHIFT 20 51#define CDR_SELEXT_SHIFT 20
45#define CDR_SELEXT_MASK (0xf << CDR_SELEXT_SHIFT) 52#define CDR_SELEXT_MASK (0xf << CDR_SELEXT_SHIFT)
46#define CMUX_SHIFT_PHASE_SHIFT 24 53#define CMUX_SHIFT_PHASE_SHIFT 24
@@ -426,7 +433,9 @@ static int sdhci_msm_probe(struct platform_device *pdev)
426 struct sdhci_msm_host *msm_host; 433 struct sdhci_msm_host *msm_host;
427 struct resource *core_memres; 434 struct resource *core_memres;
428 int ret; 435 int ret;
429 u16 host_version; 436 u16 host_version, core_minor;
437 u32 core_version, caps;
438 u8 core_major;
430 439
431 msm_host = devm_kzalloc(&pdev->dev, sizeof(*msm_host), GFP_KERNEL); 440 msm_host = devm_kzalloc(&pdev->dev, sizeof(*msm_host), GFP_KERNEL);
432 if (!msm_host) 441 if (!msm_host)
@@ -516,6 +525,24 @@ static int sdhci_msm_probe(struct platform_device *pdev)
516 host_version, ((host_version & SDHCI_VENDOR_VER_MASK) >> 525 host_version, ((host_version & SDHCI_VENDOR_VER_MASK) >>
517 SDHCI_VENDOR_VER_SHIFT)); 526 SDHCI_VENDOR_VER_SHIFT));
518 527
528 core_version = readl_relaxed(msm_host->core_mem + CORE_MCI_VERSION);
529 core_major = (core_version & CORE_VERSION_MAJOR_MASK) >>
530 CORE_VERSION_MAJOR_SHIFT;
531 core_minor = core_version & CORE_VERSION_MINOR_MASK;
532 dev_dbg(&pdev->dev, "MCI Version: 0x%08x, major: 0x%04x, minor: 0x%02x\n",
533 core_version, core_major, core_minor);
534
535 /*
536 * Support for some capabilities is not advertised by newer
537 * controller versions and must be explicitly enabled.
538 */
539 if (core_major >= 1 && core_minor != 0x11 && core_minor != 0x12) {
540 caps = readl_relaxed(host->ioaddr + SDHCI_CAPABILITIES);
541 caps |= SDHCI_CAN_VDD_300 | SDHCI_CAN_DO_8BIT;
542 writel_relaxed(caps, host->ioaddr +
543 CORE_VENDOR_SPEC_CAPABILITIES0);
544 }
545
519 ret = sdhci_add_host(host); 546 ret = sdhci_add_host(host);
520 if (ret) 547 if (ret)
521 goto clk_disable; 548 goto clk_disable;
diff --git a/drivers/mmc/host/sdhci-of-arasan.c b/drivers/mmc/host/sdhci-of-arasan.c
index bcb51e9dfdcd..6287d426c96b 100644
--- a/drivers/mmc/host/sdhci-of-arasan.c
+++ b/drivers/mmc/host/sdhci-of-arasan.c
@@ -173,6 +173,12 @@ static int sdhci_arasan_probe(struct platform_device *pdev)
173 pltfm_host->priv = sdhci_arasan; 173 pltfm_host->priv = sdhci_arasan;
174 pltfm_host->clk = clk_xin; 174 pltfm_host->clk = clk_xin;
175 175
176 ret = mmc_of_parse(host->mmc);
177 if (ret) {
178 dev_err(&pdev->dev, "parsing dt failed (%u)\n", ret);
179 goto clk_disable_all;
180 }
181
176 ret = sdhci_add_host(host); 182 ret = sdhci_add_host(host);
177 if (ret) 183 if (ret)
178 goto err_pltfm_free; 184 goto err_pltfm_free;
@@ -195,7 +201,6 @@ static int sdhci_arasan_remove(struct platform_device *pdev)
195 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 201 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
196 struct sdhci_arasan_data *sdhci_arasan = pltfm_host->priv; 202 struct sdhci_arasan_data *sdhci_arasan = pltfm_host->priv;
197 203
198 clk_disable_unprepare(pltfm_host->clk);
199 clk_disable_unprepare(sdhci_arasan->clk_ahb); 204 clk_disable_unprepare(sdhci_arasan->clk_ahb);
200 205
201 return sdhci_pltfm_unregister(pdev); 206 return sdhci_pltfm_unregister(pdev);
diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c
index 17fe02ed6672..22e9111b11ff 100644
--- a/drivers/mmc/host/sdhci-of-esdhc.c
+++ b/drivers/mmc/host/sdhci-of-esdhc.c
@@ -386,11 +386,6 @@ static int sdhci_esdhc_probe(struct platform_device *pdev)
386 return ret; 386 return ret;
387} 387}
388 388
389static int sdhci_esdhc_remove(struct platform_device *pdev)
390{
391 return sdhci_pltfm_unregister(pdev);
392}
393
394static const struct of_device_id sdhci_esdhc_of_match[] = { 389static const struct of_device_id sdhci_esdhc_of_match[] = {
395 { .compatible = "fsl,mpc8379-esdhc" }, 390 { .compatible = "fsl,mpc8379-esdhc" },
396 { .compatible = "fsl,mpc8536-esdhc" }, 391 { .compatible = "fsl,mpc8536-esdhc" },
@@ -406,7 +401,7 @@ static struct platform_driver sdhci_esdhc_driver = {
406 .pm = ESDHC_PMOPS, 401 .pm = ESDHC_PMOPS,
407 }, 402 },
408 .probe = sdhci_esdhc_probe, 403 .probe = sdhci_esdhc_probe,
409 .remove = sdhci_esdhc_remove, 404 .remove = sdhci_pltfm_unregister,
410}; 405};
411 406
412module_platform_driver(sdhci_esdhc_driver); 407module_platform_driver(sdhci_esdhc_driver);
diff --git a/drivers/mmc/host/sdhci-of-hlwd.c b/drivers/mmc/host/sdhci-of-hlwd.c
index be479279a1d5..4079a96ad37e 100644
--- a/drivers/mmc/host/sdhci-of-hlwd.c
+++ b/drivers/mmc/host/sdhci-of-hlwd.c
@@ -75,11 +75,6 @@ static int sdhci_hlwd_probe(struct platform_device *pdev)
75 return sdhci_pltfm_register(pdev, &sdhci_hlwd_pdata, 0); 75 return sdhci_pltfm_register(pdev, &sdhci_hlwd_pdata, 0);
76} 76}
77 77
78static int sdhci_hlwd_remove(struct platform_device *pdev)
79{
80 return sdhci_pltfm_unregister(pdev);
81}
82
83static const struct of_device_id sdhci_hlwd_of_match[] = { 78static const struct of_device_id sdhci_hlwd_of_match[] = {
84 { .compatible = "nintendo,hollywood-sdhci" }, 79 { .compatible = "nintendo,hollywood-sdhci" },
85 { } 80 { }
@@ -93,7 +88,7 @@ static struct platform_driver sdhci_hlwd_driver = {
93 .pm = SDHCI_PLTFM_PMOPS, 88 .pm = SDHCI_PLTFM_PMOPS,
94 }, 89 },
95 .probe = sdhci_hlwd_probe, 90 .probe = sdhci_hlwd_probe,
96 .remove = sdhci_hlwd_remove, 91 .remove = sdhci_pltfm_unregister,
97}; 92};
98 93
99module_platform_driver(sdhci_hlwd_driver); 94module_platform_driver(sdhci_hlwd_driver);
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index 29eaff78238e..7a3fc16d0a6c 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -650,6 +650,7 @@ static int rtsx_probe_slot(struct sdhci_pci_slot *slot)
650 650
651static const struct sdhci_pci_fixes sdhci_rtsx = { 651static const struct sdhci_pci_fixes sdhci_rtsx = {
652 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | 652 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
653 SDHCI_QUIRK2_BROKEN_64_BIT_DMA |
653 SDHCI_QUIRK2_BROKEN_DDR50, 654 SDHCI_QUIRK2_BROKEN_DDR50,
654 .probe_slot = rtsx_probe_slot, 655 .probe_slot = rtsx_probe_slot,
655}; 656};
diff --git a/drivers/mmc/host/sdhci-pltfm.c b/drivers/mmc/host/sdhci-pltfm.c
index c5b01d6bb85d..a207f5aaf62f 100644
--- a/drivers/mmc/host/sdhci-pltfm.c
+++ b/drivers/mmc/host/sdhci-pltfm.c
@@ -75,43 +75,41 @@ void sdhci_get_of_property(struct platform_device *pdev)
75 u32 bus_width; 75 u32 bus_width;
76 int size; 76 int size;
77 77
78 if (of_device_is_available(np)) { 78 if (of_get_property(np, "sdhci,auto-cmd12", NULL))
79 if (of_get_property(np, "sdhci,auto-cmd12", NULL)) 79 host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12;
80 host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12;
81 80
82 if (of_get_property(np, "sdhci,1-bit-only", NULL) || 81 if (of_get_property(np, "sdhci,1-bit-only", NULL) ||
83 (of_property_read_u32(np, "bus-width", &bus_width) == 0 && 82 (of_property_read_u32(np, "bus-width", &bus_width) == 0 &&
84 bus_width == 1)) 83 bus_width == 1))
85 host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA; 84 host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA;
86 85
87 if (sdhci_of_wp_inverted(np)) 86 if (sdhci_of_wp_inverted(np))
88 host->quirks |= SDHCI_QUIRK_INVERTED_WRITE_PROTECT; 87 host->quirks |= SDHCI_QUIRK_INVERTED_WRITE_PROTECT;
89 88
90 if (of_get_property(np, "broken-cd", NULL)) 89 if (of_get_property(np, "broken-cd", NULL))
91 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION; 90 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
92 91
93 if (of_get_property(np, "no-1-8-v", NULL)) 92 if (of_get_property(np, "no-1-8-v", NULL))
94 host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V; 93 host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V;
95 94
96 if (of_device_is_compatible(np, "fsl,p2020-rev1-esdhc")) 95 if (of_device_is_compatible(np, "fsl,p2020-rev1-esdhc"))
97 host->quirks |= SDHCI_QUIRK_BROKEN_DMA; 96 host->quirks |= SDHCI_QUIRK_BROKEN_DMA;
98 97
99 if (of_device_is_compatible(np, "fsl,p2020-esdhc") || 98 if (of_device_is_compatible(np, "fsl,p2020-esdhc") ||
100 of_device_is_compatible(np, "fsl,p1010-esdhc") || 99 of_device_is_compatible(np, "fsl,p1010-esdhc") ||
101 of_device_is_compatible(np, "fsl,t4240-esdhc") || 100 of_device_is_compatible(np, "fsl,t4240-esdhc") ||
102 of_device_is_compatible(np, "fsl,mpc8536-esdhc")) 101 of_device_is_compatible(np, "fsl,mpc8536-esdhc"))
103 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL; 102 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
104 103
105 clk = of_get_property(np, "clock-frequency", &size); 104 clk = of_get_property(np, "clock-frequency", &size);
106 if (clk && size == sizeof(*clk) && *clk) 105 if (clk && size == sizeof(*clk) && *clk)
107 pltfm_host->clock = be32_to_cpup(clk); 106 pltfm_host->clock = be32_to_cpup(clk);
108 107
109 if (of_find_property(np, "keep-power-in-suspend", NULL)) 108 if (of_find_property(np, "keep-power-in-suspend", NULL))
110 host->mmc->pm_caps |= MMC_PM_KEEP_POWER; 109 host->mmc->pm_caps |= MMC_PM_KEEP_POWER;
111 110
112 if (of_find_property(np, "enable-sdio-wakeup", NULL)) 111 if (of_find_property(np, "enable-sdio-wakeup", NULL))
113 host->mmc->pm_caps |= MMC_PM_WAKE_SDIO_IRQ; 112 host->mmc->pm_caps |= MMC_PM_WAKE_SDIO_IRQ;
114 }
115} 113}
116#else 114#else
117void sdhci_get_of_property(struct platform_device *pdev) {} 115void sdhci_get_of_property(struct platform_device *pdev) {}
@@ -225,9 +223,11 @@ EXPORT_SYMBOL_GPL(sdhci_pltfm_register);
225int sdhci_pltfm_unregister(struct platform_device *pdev) 223int sdhci_pltfm_unregister(struct platform_device *pdev)
226{ 224{
227 struct sdhci_host *host = platform_get_drvdata(pdev); 225 struct sdhci_host *host = platform_get_drvdata(pdev);
226 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
228 int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff); 227 int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
229 228
230 sdhci_remove_host(host, dead); 229 sdhci_remove_host(host, dead);
230 clk_disable_unprepare(pltfm_host->clk);
231 sdhci_pltfm_free(pdev); 231 sdhci_pltfm_free(pdev);
232 232
233 return 0; 233 return 0;
diff --git a/drivers/mmc/host/sdhci-sirf.c b/drivers/mmc/host/sdhci-sirf.c
index f6f82ec3618d..32848eb7ad80 100644
--- a/drivers/mmc/host/sdhci-sirf.c
+++ b/drivers/mmc/host/sdhci-sirf.c
@@ -20,17 +20,9 @@
20#define SIRF_TUNING_COUNT 128 20#define SIRF_TUNING_COUNT 128
21 21
22struct sdhci_sirf_priv { 22struct sdhci_sirf_priv {
23 struct clk *clk;
24 int gpio_cd; 23 int gpio_cd;
25}; 24};
26 25
27static unsigned int sdhci_sirf_get_max_clk(struct sdhci_host *host)
28{
29 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
30 struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
31 return clk_get_rate(priv->clk);
32}
33
34static void sdhci_sirf_set_bus_width(struct sdhci_host *host, int width) 26static void sdhci_sirf_set_bus_width(struct sdhci_host *host, int width)
35{ 27{
36 u8 ctrl; 28 u8 ctrl;
@@ -56,7 +48,7 @@ static int sdhci_sirf_execute_tuning(struct sdhci_host *host, u32 opcode)
56 int tuning_seq_cnt = 3; 48 int tuning_seq_cnt = 3;
57 u8 phase, tuned_phases[SIRF_TUNING_COUNT]; 49 u8 phase, tuned_phases[SIRF_TUNING_COUNT];
58 u8 tuned_phase_cnt = 0; 50 u8 tuned_phase_cnt = 0;
59 int rc, longest_range = 0; 51 int rc = 0, longest_range = 0;
60 int start = -1, end = 0, tuning_value = -1, range = 0; 52 int start = -1, end = 0, tuning_value = -1, range = 0;
61 u16 clock_setting; 53 u16 clock_setting;
62 struct mmc_host *mmc = host->mmc; 54 struct mmc_host *mmc = host->mmc;
@@ -68,7 +60,7 @@ retry:
68 phase = 0; 60 phase = 0;
69 do { 61 do {
70 sdhci_writel(host, 62 sdhci_writel(host,
71 clock_setting | phase | (phase << 7) | (phase << 16), 63 clock_setting | phase,
72 SDHCI_CLK_DELAY_SETTING); 64 SDHCI_CLK_DELAY_SETTING);
73 65
74 if (!mmc_send_tuning(mmc)) { 66 if (!mmc_send_tuning(mmc)) {
@@ -102,7 +94,7 @@ retry:
102 */ 94 */
103 phase = tuning_value; 95 phase = tuning_value;
104 sdhci_writel(host, 96 sdhci_writel(host,
105 clock_setting | phase | (phase << 7) | (phase << 16), 97 clock_setting | phase,
106 SDHCI_CLK_DELAY_SETTING); 98 SDHCI_CLK_DELAY_SETTING);
107 99
108 dev_dbg(mmc_dev(mmc), "%s: Setting the tuning phase to %d\n", 100 dev_dbg(mmc_dev(mmc), "%s: Setting the tuning phase to %d\n",
@@ -122,7 +114,7 @@ retry:
122static struct sdhci_ops sdhci_sirf_ops = { 114static struct sdhci_ops sdhci_sirf_ops = {
123 .platform_execute_tuning = sdhci_sirf_execute_tuning, 115 .platform_execute_tuning = sdhci_sirf_execute_tuning,
124 .set_clock = sdhci_set_clock, 116 .set_clock = sdhci_set_clock,
125 .get_max_clock = sdhci_sirf_get_max_clk, 117 .get_max_clock = sdhci_pltfm_clk_get_max_clock,
126 .set_bus_width = sdhci_sirf_set_bus_width, 118 .set_bus_width = sdhci_sirf_set_bus_width,
127 .reset = sdhci_reset, 119 .reset = sdhci_reset,
128 .set_uhs_signaling = sdhci_set_uhs_signaling, 120 .set_uhs_signaling = sdhci_set_uhs_signaling,
@@ -162,13 +154,13 @@ static int sdhci_sirf_probe(struct platform_device *pdev)
162 return PTR_ERR(host); 154 return PTR_ERR(host);
163 155
164 pltfm_host = sdhci_priv(host); 156 pltfm_host = sdhci_priv(host);
157 pltfm_host->clk = clk;
165 priv = sdhci_pltfm_priv(pltfm_host); 158 priv = sdhci_pltfm_priv(pltfm_host);
166 priv->clk = clk;
167 priv->gpio_cd = gpio_cd; 159 priv->gpio_cd = gpio_cd;
168 160
169 sdhci_get_of_property(pdev); 161 sdhci_get_of_property(pdev);
170 162
171 ret = clk_prepare_enable(priv->clk); 163 ret = clk_prepare_enable(pltfm_host->clk);
172 if (ret) 164 if (ret)
173 goto err_clk_prepare; 165 goto err_clk_prepare;
174 166
@@ -195,37 +187,24 @@ static int sdhci_sirf_probe(struct platform_device *pdev)
195err_request_cd: 187err_request_cd:
196 sdhci_remove_host(host, 0); 188 sdhci_remove_host(host, 0);
197err_sdhci_add: 189err_sdhci_add:
198 clk_disable_unprepare(priv->clk); 190 clk_disable_unprepare(pltfm_host->clk);
199err_clk_prepare: 191err_clk_prepare:
200 sdhci_pltfm_free(pdev); 192 sdhci_pltfm_free(pdev);
201 return ret; 193 return ret;
202} 194}
203 195
204static int sdhci_sirf_remove(struct platform_device *pdev)
205{
206 struct sdhci_host *host = platform_get_drvdata(pdev);
207 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
208 struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
209
210 sdhci_pltfm_unregister(pdev);
211
212 clk_disable_unprepare(priv->clk);
213 return 0;
214}
215
216#ifdef CONFIG_PM_SLEEP 196#ifdef CONFIG_PM_SLEEP
217static int sdhci_sirf_suspend(struct device *dev) 197static int sdhci_sirf_suspend(struct device *dev)
218{ 198{
219 struct sdhci_host *host = dev_get_drvdata(dev); 199 struct sdhci_host *host = dev_get_drvdata(dev);
220 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 200 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
221 struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
222 int ret; 201 int ret;
223 202
224 ret = sdhci_suspend_host(host); 203 ret = sdhci_suspend_host(host);
225 if (ret) 204 if (ret)
226 return ret; 205 return ret;
227 206
228 clk_disable(priv->clk); 207 clk_disable(pltfm_host->clk);
229 208
230 return 0; 209 return 0;
231} 210}
@@ -234,10 +213,9 @@ static int sdhci_sirf_resume(struct device *dev)
234{ 213{
235 struct sdhci_host *host = dev_get_drvdata(dev); 214 struct sdhci_host *host = dev_get_drvdata(dev);
236 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 215 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
237 struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
238 int ret; 216 int ret;
239 217
240 ret = clk_enable(priv->clk); 218 ret = clk_enable(pltfm_host->clk);
241 if (ret) { 219 if (ret) {
242 dev_dbg(dev, "Resume: Error enabling clock\n"); 220 dev_dbg(dev, "Resume: Error enabling clock\n");
243 return ret; 221 return ret;
@@ -264,7 +242,7 @@ static struct platform_driver sdhci_sirf_driver = {
264#endif 242#endif
265 }, 243 },
266 .probe = sdhci_sirf_probe, 244 .probe = sdhci_sirf_probe,
267 .remove = sdhci_sirf_remove, 245 .remove = sdhci_pltfm_unregister,
268}; 246};
269 247
270module_platform_driver(sdhci_sirf_driver); 248module_platform_driver(sdhci_sirf_driver);
diff --git a/drivers/mmc/host/sdhci-spear.c b/drivers/mmc/host/sdhci-spear.c
index 22e58268545f..df088343d60f 100644
--- a/drivers/mmc/host/sdhci-spear.c
+++ b/drivers/mmc/host/sdhci-spear.c
@@ -26,14 +26,13 @@
26#include <linux/pm.h> 26#include <linux/pm.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/mmc/host.h> 28#include <linux/mmc/host.h>
29#include <linux/mmc/sdhci-spear.h>
30#include <linux/mmc/slot-gpio.h> 29#include <linux/mmc/slot-gpio.h>
31#include <linux/io.h> 30#include <linux/io.h>
32#include "sdhci.h" 31#include "sdhci.h"
33 32
34struct spear_sdhci { 33struct spear_sdhci {
35 struct clk *clk; 34 struct clk *clk;
36 struct sdhci_plat_data *data; 35 int card_int_gpio;
37}; 36};
38 37
39/* sdhci ops */ 38/* sdhci ops */
@@ -44,38 +43,20 @@ static const struct sdhci_ops sdhci_pltfm_ops = {
44 .set_uhs_signaling = sdhci_set_uhs_signaling, 43 .set_uhs_signaling = sdhci_set_uhs_signaling,
45}; 44};
46 45
47#ifdef CONFIG_OF 46static void sdhci_probe_config_dt(struct device_node *np,
48static struct sdhci_plat_data *sdhci_probe_config_dt(struct platform_device *pdev) 47 struct spear_sdhci *host)
49{ 48{
50 struct device_node *np = pdev->dev.of_node;
51 struct sdhci_plat_data *pdata = NULL;
52 int cd_gpio; 49 int cd_gpio;
53 50
54 cd_gpio = of_get_named_gpio(np, "cd-gpios", 0); 51 cd_gpio = of_get_named_gpio(np, "cd-gpios", 0);
55 if (!gpio_is_valid(cd_gpio)) 52 if (!gpio_is_valid(cd_gpio))
56 cd_gpio = -1; 53 cd_gpio = -1;
57 54
58 /* If pdata is required */ 55 host->card_int_gpio = cd_gpio;
59 if (cd_gpio != -1) {
60 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
61 if (!pdata)
62 dev_err(&pdev->dev, "DT: kzalloc failed\n");
63 else
64 pdata->card_int_gpio = cd_gpio;
65 }
66
67 return pdata;
68}
69#else
70static struct sdhci_plat_data *sdhci_probe_config_dt(struct platform_device *pdev)
71{
72 return ERR_PTR(-ENOSYS);
73} 56}
74#endif
75 57
76static int sdhci_probe(struct platform_device *pdev) 58static int sdhci_probe(struct platform_device *pdev)
77{ 59{
78 struct device_node *np = pdev->dev.of_node;
79 struct sdhci_host *host; 60 struct sdhci_host *host;
80 struct resource *iomem; 61 struct resource *iomem;
81 struct spear_sdhci *sdhci; 62 struct spear_sdhci *sdhci;
@@ -124,28 +105,18 @@ static int sdhci_probe(struct platform_device *pdev)
124 dev_dbg(&pdev->dev, "Error setting desired clk, clk=%lu\n", 105 dev_dbg(&pdev->dev, "Error setting desired clk, clk=%lu\n",
125 clk_get_rate(sdhci->clk)); 106 clk_get_rate(sdhci->clk));
126 107
127 if (np) { 108 sdhci_probe_config_dt(pdev->dev.of_node, sdhci);
128 sdhci->data = sdhci_probe_config_dt(pdev);
129 if (IS_ERR(sdhci->data)) {
130 dev_err(&pdev->dev, "DT: Failed to get pdata\n");
131 goto disable_clk;
132 }
133 } else {
134 sdhci->data = dev_get_platdata(&pdev->dev);
135 }
136
137 /* 109 /*
138 * It is optional to use GPIOs for sdhci card detection. If 110 * It is optional to use GPIOs for sdhci card detection. If
139 * sdhci->data is NULL, then use original sdhci lines otherwise 111 * sdhci->card_int_gpio < 0, then use original sdhci lines otherwise
140 * GPIO lines. We use the built-in GPIO support for this. 112 * GPIO lines. We use the built-in GPIO support for this.
141 */ 113 */
142 if (sdhci->data && sdhci->data->card_int_gpio >= 0) { 114 if (sdhci->card_int_gpio >= 0) {
143 ret = mmc_gpio_request_cd(host->mmc, 115 ret = mmc_gpio_request_cd(host->mmc, sdhci->card_int_gpio, 0);
144 sdhci->data->card_int_gpio, 0);
145 if (ret < 0) { 116 if (ret < 0) {
146 dev_dbg(&pdev->dev, 117 dev_dbg(&pdev->dev,
147 "failed to request card-detect gpio%d\n", 118 "failed to request card-detect gpio%d\n",
148 sdhci->data->card_int_gpio); 119 sdhci->card_int_gpio);
149 goto disable_clk; 120 goto disable_clk;
150 } 121 }
151 } 122 }
diff --git a/drivers/mmc/host/sdhci-st.c b/drivers/mmc/host/sdhci-st.c
index 882b07e9667e..682f2bb0f4bf 100644
--- a/drivers/mmc/host/sdhci-st.c
+++ b/drivers/mmc/host/sdhci-st.c
@@ -23,9 +23,295 @@
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/mmc/host.h> 25#include <linux/mmc/host.h>
26 26#include <linux/reset.h>
27#include "sdhci-pltfm.h" 27#include "sdhci-pltfm.h"
28 28
29struct st_mmc_platform_data {
30 struct reset_control *rstc;
31 void __iomem *top_ioaddr;
32};
33
34/* MMCSS glue logic to setup the HC on some ST SoCs (e.g. STiH407 family) */
35
36#define ST_MMC_CCONFIG_REG_1 0x400
37#define ST_MMC_CCONFIG_TIMEOUT_CLK_UNIT BIT(24)
38#define ST_MMC_CCONFIG_TIMEOUT_CLK_FREQ BIT(12)
39#define ST_MMC_CCONFIG_TUNING_COUNT_DEFAULT BIT(8)
40#define ST_MMC_CCONFIG_ASYNC_WAKEUP BIT(0)
41#define ST_MMC_CCONFIG_1_DEFAULT \
42 ((ST_MMC_CCONFIG_TIMEOUT_CLK_UNIT) | \
43 (ST_MMC_CCONFIG_TIMEOUT_CLK_FREQ) | \
44 (ST_MMC_CCONFIG_TUNING_COUNT_DEFAULT))
45
46#define ST_MMC_CCONFIG_REG_2 0x404
47#define ST_MMC_CCONFIG_HIGH_SPEED BIT(28)
48#define ST_MMC_CCONFIG_ADMA2 BIT(24)
49#define ST_MMC_CCONFIG_8BIT BIT(20)
50#define ST_MMC_CCONFIG_MAX_BLK_LEN 16
51#define MAX_BLK_LEN_1024 1
52#define MAX_BLK_LEN_2048 2
53#define BASE_CLK_FREQ_200 0xc8
54#define BASE_CLK_FREQ_100 0x64
55#define BASE_CLK_FREQ_50 0x32
56#define ST_MMC_CCONFIG_2_DEFAULT \
57 (ST_MMC_CCONFIG_HIGH_SPEED | ST_MMC_CCONFIG_ADMA2 | \
58 ST_MMC_CCONFIG_8BIT | \
59 (MAX_BLK_LEN_1024 << ST_MMC_CCONFIG_MAX_BLK_LEN))
60
61#define ST_MMC_CCONFIG_REG_3 0x408
62#define ST_MMC_CCONFIG_EMMC_SLOT_TYPE BIT(28)
63#define ST_MMC_CCONFIG_64BIT BIT(24)
64#define ST_MMC_CCONFIG_ASYNCH_INTR_SUPPORT BIT(20)
65#define ST_MMC_CCONFIG_1P8_VOLT BIT(16)
66#define ST_MMC_CCONFIG_3P0_VOLT BIT(12)
67#define ST_MMC_CCONFIG_3P3_VOLT BIT(8)
68#define ST_MMC_CCONFIG_SUSP_RES_SUPPORT BIT(4)
69#define ST_MMC_CCONFIG_SDMA BIT(0)
70#define ST_MMC_CCONFIG_3_DEFAULT \
71 (ST_MMC_CCONFIG_ASYNCH_INTR_SUPPORT | \
72 ST_MMC_CCONFIG_3P3_VOLT | \
73 ST_MMC_CCONFIG_SUSP_RES_SUPPORT | \
74 ST_MMC_CCONFIG_SDMA)
75
76#define ST_MMC_CCONFIG_REG_4 0x40c
77#define ST_MMC_CCONFIG_D_DRIVER BIT(20)
78#define ST_MMC_CCONFIG_C_DRIVER BIT(16)
79#define ST_MMC_CCONFIG_A_DRIVER BIT(12)
80#define ST_MMC_CCONFIG_DDR50 BIT(8)
81#define ST_MMC_CCONFIG_SDR104 BIT(4)
82#define ST_MMC_CCONFIG_SDR50 BIT(0)
83#define ST_MMC_CCONFIG_4_DEFAULT 0
84
85#define ST_MMC_CCONFIG_REG_5 0x410
86#define ST_MMC_CCONFIG_TUNING_FOR_SDR50 BIT(8)
87#define RETUNING_TIMER_CNT_MAX 0xf
88#define ST_MMC_CCONFIG_5_DEFAULT 0
89
90/* I/O configuration for Arasan IP */
91#define ST_MMC_GP_OUTPUT 0x450
92#define ST_MMC_GP_OUTPUT_CD BIT(12)
93
94#define ST_MMC_STATUS_R 0x460
95
96#define ST_TOP_MMC_DLY_FIX_OFF(x) (x - 0x8)
97
98/* TOP config registers to manage static and dynamic delay */
99#define ST_TOP_MMC_TX_CLK_DLY ST_TOP_MMC_DLY_FIX_OFF(0x8)
100#define ST_TOP_MMC_RX_CLK_DLY ST_TOP_MMC_DLY_FIX_OFF(0xc)
101/* MMC delay control register */
102#define ST_TOP_MMC_DLY_CTRL ST_TOP_MMC_DLY_FIX_OFF(0x18)
103#define ST_TOP_MMC_DLY_CTRL_DLL_BYPASS_CMD BIT(0)
104#define ST_TOP_MMC_DLY_CTRL_DLL_BYPASS_PH_SEL BIT(1)
105#define ST_TOP_MMC_DLY_CTRL_TX_DLL_ENABLE BIT(8)
106#define ST_TOP_MMC_DLY_CTRL_RX_DLL_ENABLE BIT(9)
107#define ST_TOP_MMC_DLY_CTRL_ATUNE_NOT_CFG_DLY BIT(10)
108#define ST_TOP_MMC_START_DLL_LOCK BIT(11)
109
110/* register to provide the phase-shift value for DLL */
111#define ST_TOP_MMC_TX_DLL_STEP_DLY ST_TOP_MMC_DLY_FIX_OFF(0x1c)
112#define ST_TOP_MMC_RX_DLL_STEP_DLY ST_TOP_MMC_DLY_FIX_OFF(0x20)
113#define ST_TOP_MMC_RX_CMD_STEP_DLY ST_TOP_MMC_DLY_FIX_OFF(0x24)
114
115/* phase shift delay on the tx clk 2.188ns */
116#define ST_TOP_MMC_TX_DLL_STEP_DLY_VALID 0x6
117
118#define ST_TOP_MMC_DLY_MAX 0xf
119
120#define ST_TOP_MMC_DYN_DLY_CONF \
121 (ST_TOP_MMC_DLY_CTRL_TX_DLL_ENABLE | \
122 ST_TOP_MMC_DLY_CTRL_ATUNE_NOT_CFG_DLY | \
123 ST_TOP_MMC_START_DLL_LOCK)
124
125/*
126 * For clock speeds greater than 90MHz, we need to check that the
127 * DLL procedure has finished before switching to ultra-speed modes.
128 */
129#define CLK_TO_CHECK_DLL_LOCK 90000000
130
131static inline void st_mmcss_set_static_delay(void __iomem *ioaddr)
132{
133 if (!ioaddr)
134 return;
135
136 writel_relaxed(0x0, ioaddr + ST_TOP_MMC_DLY_CTRL);
137 writel_relaxed(ST_TOP_MMC_DLY_MAX,
138 ioaddr + ST_TOP_MMC_TX_CLK_DLY);
139}
140
141/**
142 * st_mmcss_cconfig: configure the Arasan HC inside the flashSS.
143 * @np: dt device node.
144 * @host: sdhci host
145 * Description: this function is to configure the Arasan host controller.
146 * On some ST SoCs, i.e. STiH407 family, the MMC devices inside a dedicated
147 * flashSS sub-system which needs to be configured to be compliant to eMMC 4.5
148 * or eMMC4.3. This has to be done before registering the sdhci host.
149 */
150static void st_mmcss_cconfig(struct device_node *np, struct sdhci_host *host)
151{
152 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
153 struct mmc_host *mhost = host->mmc;
154 u32 cconf2, cconf3, cconf4, cconf5;
155
156 if (!of_device_is_compatible(np, "st,sdhci-stih407"))
157 return;
158
159 cconf2 = ST_MMC_CCONFIG_2_DEFAULT;
160 cconf3 = ST_MMC_CCONFIG_3_DEFAULT;
161 cconf4 = ST_MMC_CCONFIG_4_DEFAULT;
162 cconf5 = ST_MMC_CCONFIG_5_DEFAULT;
163
164 writel_relaxed(ST_MMC_CCONFIG_1_DEFAULT,
165 host->ioaddr + ST_MMC_CCONFIG_REG_1);
166
167 /* Set clock frequency, default to 50MHz if max-frequency is not
168 * provided */
169
170 switch (mhost->f_max) {
171 case 200000000:
172 clk_set_rate(pltfm_host->clk, mhost->f_max);
173 cconf2 |= BASE_CLK_FREQ_200;
174 break;
175 case 100000000:
176 clk_set_rate(pltfm_host->clk, mhost->f_max);
177 cconf2 |= BASE_CLK_FREQ_100;
178 break;
179 default:
180 clk_set_rate(pltfm_host->clk, 50000000);
181 cconf2 |= BASE_CLK_FREQ_50;
182 }
183
184 writel_relaxed(cconf2, host->ioaddr + ST_MMC_CCONFIG_REG_2);
185
186 if (mhost->caps & MMC_CAP_NONREMOVABLE)
187 cconf3 |= ST_MMC_CCONFIG_EMMC_SLOT_TYPE;
188 else
189 /* CARD _D ET_CTRL */
190 writel_relaxed(ST_MMC_GP_OUTPUT_CD,
191 host->ioaddr + ST_MMC_GP_OUTPUT);
192
193 if (mhost->caps & MMC_CAP_UHS_SDR50) {
194 /* use 1.8V */
195 cconf3 |= ST_MMC_CCONFIG_1P8_VOLT;
196 cconf4 |= ST_MMC_CCONFIG_SDR50;
197 /* Use tuning */
198 cconf5 |= ST_MMC_CCONFIG_TUNING_FOR_SDR50;
199 /* Max timeout for retuning */
200 cconf5 |= RETUNING_TIMER_CNT_MAX;
201 }
202
203 if (mhost->caps & MMC_CAP_UHS_SDR104) {
204 /*
205 * SDR104 implies the HC can support HS200 mode, so
206 * it's mandatory to use 1.8V
207 */
208 cconf3 |= ST_MMC_CCONFIG_1P8_VOLT;
209 cconf4 |= ST_MMC_CCONFIG_SDR104;
210 /* Max timeout for retuning */
211 cconf5 |= RETUNING_TIMER_CNT_MAX;
212 }
213
214 if (mhost->caps & MMC_CAP_UHS_DDR50)
215 cconf4 |= ST_MMC_CCONFIG_DDR50;
216
217 writel_relaxed(cconf3, host->ioaddr + ST_MMC_CCONFIG_REG_3);
218 writel_relaxed(cconf4, host->ioaddr + ST_MMC_CCONFIG_REG_4);
219 writel_relaxed(cconf5, host->ioaddr + ST_MMC_CCONFIG_REG_5);
220}
221
222static inline void st_mmcss_set_dll(void __iomem *ioaddr)
223{
224 if (!ioaddr)
225 return;
226
227 writel_relaxed(ST_TOP_MMC_DYN_DLY_CONF, ioaddr + ST_TOP_MMC_DLY_CTRL);
228 writel_relaxed(ST_TOP_MMC_TX_DLL_STEP_DLY_VALID,
229 ioaddr + ST_TOP_MMC_TX_DLL_STEP_DLY);
230}
231
232static int st_mmcss_lock_dll(void __iomem *ioaddr)
233{
234 unsigned long curr, value;
235 unsigned long finish = jiffies + HZ;
236
237 /* Checks if the DLL procedure is finished */
238 do {
239 curr = jiffies;
240 value = readl(ioaddr + ST_MMC_STATUS_R);
241 if (value & 0x1)
242 return 0;
243
244 cpu_relax();
245 } while (!time_after_eq(curr, finish));
246
247 return -EBUSY;
248}
249
250static int sdhci_st_set_dll_for_clock(struct sdhci_host *host)
251{
252 int ret = 0;
253 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
254 struct st_mmc_platform_data *pdata = pltfm_host->priv;
255
256 if (host->clock > CLK_TO_CHECK_DLL_LOCK) {
257 st_mmcss_set_dll(pdata->top_ioaddr);
258 ret = st_mmcss_lock_dll(host->ioaddr);
259 }
260
261 return ret;
262}
263
264static void sdhci_st_set_uhs_signaling(struct sdhci_host *host,
265 unsigned int uhs)
266{
267 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
268 struct st_mmc_platform_data *pdata = pltfm_host->priv;
269 u16 ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2);
270 int ret = 0;
271
272 /* Select Bus Speed Mode for host */
273 ctrl_2 &= ~SDHCI_CTRL_UHS_MASK;
274 switch (uhs) {
275 /*
276 * Set V18_EN -- UHS modes do not work without this.
277 * does not change signaling voltage
278 */
279
280 case MMC_TIMING_UHS_SDR12:
281 st_mmcss_set_static_delay(pdata->top_ioaddr);
282 ctrl_2 |= SDHCI_CTRL_UHS_SDR12 | SDHCI_CTRL_VDD_180;
283 break;
284 case MMC_TIMING_UHS_SDR25:
285 st_mmcss_set_static_delay(pdata->top_ioaddr);
286 ctrl_2 |= SDHCI_CTRL_UHS_SDR25 | SDHCI_CTRL_VDD_180;
287 break;
288 case MMC_TIMING_UHS_SDR50:
289 st_mmcss_set_static_delay(pdata->top_ioaddr);
290 ctrl_2 |= SDHCI_CTRL_UHS_SDR50 | SDHCI_CTRL_VDD_180;
291 ret = sdhci_st_set_dll_for_clock(host);
292 break;
293 case MMC_TIMING_UHS_SDR104:
294 case MMC_TIMING_MMC_HS200:
295 st_mmcss_set_static_delay(pdata->top_ioaddr);
296 ctrl_2 |= SDHCI_CTRL_UHS_SDR104 | SDHCI_CTRL_VDD_180;
297 ret = sdhci_st_set_dll_for_clock(host);
298 break;
299 case MMC_TIMING_UHS_DDR50:
300 case MMC_TIMING_MMC_DDR52:
301 st_mmcss_set_static_delay(pdata->top_ioaddr);
302 ctrl_2 |= SDHCI_CTRL_UHS_DDR50 | SDHCI_CTRL_VDD_180;
303 break;
304 }
305
306 if (ret)
307 dev_warn(mmc_dev(host->mmc), "Error setting dll for clock "
308 "(uhs %d)\n", uhs);
309
310 dev_dbg(mmc_dev(host->mmc), "uhs %d, ctrl_2 %04X\n", uhs, ctrl_2);
311
312 sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2);
313}
314
29static u32 sdhci_st_readl(struct sdhci_host *host, int reg) 315static u32 sdhci_st_readl(struct sdhci_host *host, int reg)
30{ 316{
31 u32 ret; 317 u32 ret;
@@ -48,22 +334,33 @@ static const struct sdhci_ops sdhci_st_ops = {
48 .set_bus_width = sdhci_set_bus_width, 334 .set_bus_width = sdhci_set_bus_width,
49 .read_l = sdhci_st_readl, 335 .read_l = sdhci_st_readl,
50 .reset = sdhci_reset, 336 .reset = sdhci_reset,
337 .set_uhs_signaling = sdhci_st_set_uhs_signaling,
51}; 338};
52 339
53static const struct sdhci_pltfm_data sdhci_st_pdata = { 340static const struct sdhci_pltfm_data sdhci_st_pdata = {
54 .ops = &sdhci_st_ops, 341 .ops = &sdhci_st_ops,
55 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC | 342 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC |
56 SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN, 343 SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN |
344 SDHCI_QUIRK_NO_HISPD_BIT,
345 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
346 SDHCI_QUIRK2_STOP_WITH_TC,
57}; 347};
58 348
59 349
60static int sdhci_st_probe(struct platform_device *pdev) 350static int sdhci_st_probe(struct platform_device *pdev)
61{ 351{
352 struct device_node *np = pdev->dev.of_node;
62 struct sdhci_host *host; 353 struct sdhci_host *host;
354 struct st_mmc_platform_data *pdata;
63 struct sdhci_pltfm_host *pltfm_host; 355 struct sdhci_pltfm_host *pltfm_host;
64 struct clk *clk; 356 struct clk *clk;
65 int ret = 0; 357 int ret = 0;
66 u16 host_version; 358 u16 host_version;
359 struct resource *res;
360
361 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
362 if (!pdata)
363 return -ENOMEM;
67 364
68 clk = devm_clk_get(&pdev->dev, "mmc"); 365 clk = devm_clk_get(&pdev->dev, "mmc");
69 if (IS_ERR(clk)) { 366 if (IS_ERR(clk)) {
@@ -71,10 +368,17 @@ static int sdhci_st_probe(struct platform_device *pdev)
71 return PTR_ERR(clk); 368 return PTR_ERR(clk);
72 } 369 }
73 370
371 pdata->rstc = devm_reset_control_get(&pdev->dev, NULL);
372 if (IS_ERR(pdata->rstc))
373 pdata->rstc = NULL;
374 else
375 reset_control_deassert(pdata->rstc);
376
74 host = sdhci_pltfm_init(pdev, &sdhci_st_pdata, 0); 377 host = sdhci_pltfm_init(pdev, &sdhci_st_pdata, 0);
75 if (IS_ERR(host)) { 378 if (IS_ERR(host)) {
76 dev_err(&pdev->dev, "Failed sdhci_pltfm_init\n"); 379 dev_err(&pdev->dev, "Failed sdhci_pltfm_init\n");
77 return PTR_ERR(host); 380 ret = PTR_ERR(host);
381 goto err_pltfm_init;
78 } 382 }
79 383
80 ret = mmc_of_parse(host->mmc); 384 ret = mmc_of_parse(host->mmc);
@@ -85,9 +389,22 @@ static int sdhci_st_probe(struct platform_device *pdev)
85 389
86 clk_prepare_enable(clk); 390 clk_prepare_enable(clk);
87 391
392 /* Configure the FlashSS Top registers for setting eMMC TX/RX delay */
393 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
394 "top-mmc-delay");
395 pdata->top_ioaddr = devm_ioremap_resource(&pdev->dev, res);
396 if (IS_ERR(pdata->top_ioaddr)) {
397 dev_warn(&pdev->dev, "FlashSS Top Dly registers not available");
398 pdata->top_ioaddr = NULL;
399 }
400
88 pltfm_host = sdhci_priv(host); 401 pltfm_host = sdhci_priv(host);
402 pltfm_host->priv = pdata;
89 pltfm_host->clk = clk; 403 pltfm_host->clk = clk;
90 404
405 /* Configure the Arasan HC inside the flashSS */
406 st_mmcss_cconfig(np, host);
407
91 ret = sdhci_add_host(host); 408 ret = sdhci_add_host(host);
92 if (ret) { 409 if (ret) {
93 dev_err(&pdev->dev, "Failed sdhci_add_host\n"); 410 dev_err(&pdev->dev, "Failed sdhci_add_host\n");
@@ -109,6 +426,9 @@ err_out:
109 clk_disable_unprepare(clk); 426 clk_disable_unprepare(clk);
110err_of: 427err_of:
111 sdhci_pltfm_free(pdev); 428 sdhci_pltfm_free(pdev);
429err_pltfm_init:
430 if (pdata->rstc)
431 reset_control_assert(pdata->rstc);
112 432
113 return ret; 433 return ret;
114} 434}
@@ -117,10 +437,15 @@ static int sdhci_st_remove(struct platform_device *pdev)
117{ 437{
118 struct sdhci_host *host = platform_get_drvdata(pdev); 438 struct sdhci_host *host = platform_get_drvdata(pdev);
119 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 439 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
440 struct st_mmc_platform_data *pdata = pltfm_host->priv;
441 int ret;
120 442
121 clk_disable_unprepare(pltfm_host->clk); 443 ret = sdhci_pltfm_unregister(pdev);
444
445 if (pdata->rstc)
446 reset_control_assert(pdata->rstc);
122 447
123 return sdhci_pltfm_unregister(pdev); 448 return ret;
124} 449}
125 450
126#ifdef CONFIG_PM_SLEEP 451#ifdef CONFIG_PM_SLEEP
@@ -128,11 +453,15 @@ static int sdhci_st_suspend(struct device *dev)
128{ 453{
129 struct sdhci_host *host = dev_get_drvdata(dev); 454 struct sdhci_host *host = dev_get_drvdata(dev);
130 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 455 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
456 struct st_mmc_platform_data *pdata = pltfm_host->priv;
131 int ret = sdhci_suspend_host(host); 457 int ret = sdhci_suspend_host(host);
132 458
133 if (ret) 459 if (ret)
134 goto out; 460 goto out;
135 461
462 if (pdata->rstc)
463 reset_control_assert(pdata->rstc);
464
136 clk_disable_unprepare(pltfm_host->clk); 465 clk_disable_unprepare(pltfm_host->clk);
137out: 466out:
138 return ret; 467 return ret;
@@ -142,9 +471,16 @@ static int sdhci_st_resume(struct device *dev)
142{ 471{
143 struct sdhci_host *host = dev_get_drvdata(dev); 472 struct sdhci_host *host = dev_get_drvdata(dev);
144 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 473 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
474 struct st_mmc_platform_data *pdata = pltfm_host->priv;
475 struct device_node *np = dev->of_node;
145 476
146 clk_prepare_enable(pltfm_host->clk); 477 clk_prepare_enable(pltfm_host->clk);
147 478
479 if (pdata->rstc)
480 reset_control_deassert(pdata->rstc);
481
482 st_mmcss_cconfig(np, host);
483
148 return sdhci_resume_host(host); 484 return sdhci_resume_host(host);
149} 485}
150#endif 486#endif
diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c
index f3778d58d1cd..ad28b49f0203 100644
--- a/drivers/mmc/host/sdhci-tegra.c
+++ b/drivers/mmc/host/sdhci-tegra.c
@@ -20,11 +20,10 @@
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/of.h> 21#include <linux/of.h>
22#include <linux/of_device.h> 22#include <linux/of_device.h>
23#include <linux/of_gpio.h>
24#include <linux/gpio.h>
25#include <linux/mmc/card.h> 23#include <linux/mmc/card.h>
26#include <linux/mmc/host.h> 24#include <linux/mmc/host.h>
27#include <linux/mmc/slot-gpio.h> 25#include <linux/mmc/slot-gpio.h>
26#include <linux/gpio/consumer.h>
28 27
29#include "sdhci-pltfm.h" 28#include "sdhci-pltfm.h"
30 29
@@ -41,7 +40,6 @@
41#define NVQUIRK_DISABLE_SDR50 BIT(3) 40#define NVQUIRK_DISABLE_SDR50 BIT(3)
42#define NVQUIRK_DISABLE_SDR104 BIT(4) 41#define NVQUIRK_DISABLE_SDR104 BIT(4)
43#define NVQUIRK_DISABLE_DDR50 BIT(5) 42#define NVQUIRK_DISABLE_DDR50 BIT(5)
44#define NVQUIRK_SHADOW_XFER_MODE_REG BIT(6)
45 43
46struct sdhci_tegra_soc_data { 44struct sdhci_tegra_soc_data {
47 const struct sdhci_pltfm_data *pdata; 45 const struct sdhci_pltfm_data *pdata;
@@ -50,7 +48,7 @@ struct sdhci_tegra_soc_data {
50 48
51struct sdhci_tegra { 49struct sdhci_tegra {
52 const struct sdhci_tegra_soc_data *soc_data; 50 const struct sdhci_tegra_soc_data *soc_data;
53 int power_gpio; 51 struct gpio_desc *power_gpio;
54}; 52};
55 53
56static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg) 54static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg)
@@ -71,23 +69,19 @@ static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg)
71static void tegra_sdhci_writew(struct sdhci_host *host, u16 val, int reg) 69static void tegra_sdhci_writew(struct sdhci_host *host, u16 val, int reg)
72{ 70{
73 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 71 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
74 struct sdhci_tegra *tegra_host = pltfm_host->priv;
75 const struct sdhci_tegra_soc_data *soc_data = tegra_host->soc_data;
76 72
77 if (soc_data->nvquirks & NVQUIRK_SHADOW_XFER_MODE_REG) { 73 switch (reg) {
78 switch (reg) { 74 case SDHCI_TRANSFER_MODE:
79 case SDHCI_TRANSFER_MODE: 75 /*
80 /* 76 * Postpone this write, we must do it together with a
81 * Postpone this write, we must do it together with a 77 * command write that is down below.
82 * command write that is down below. 78 */
83 */ 79 pltfm_host->xfer_mode_shadow = val;
84 pltfm_host->xfer_mode_shadow = val; 80 return;
85 return; 81 case SDHCI_COMMAND:
86 case SDHCI_COMMAND: 82 writel((val << 16) | pltfm_host->xfer_mode_shadow,
87 writel((val << 16) | pltfm_host->xfer_mode_shadow, 83 host->ioaddr + SDHCI_TRANSFER_MODE);
88 host->ioaddr + SDHCI_TRANSFER_MODE); 84 return;
89 return;
90 }
91 } 85 }
92 86
93 writew(val, host->ioaddr + reg); 87 writew(val, host->ioaddr + reg);
@@ -173,7 +167,6 @@ static void tegra_sdhci_set_bus_width(struct sdhci_host *host, int bus_width)
173static const struct sdhci_ops tegra_sdhci_ops = { 167static const struct sdhci_ops tegra_sdhci_ops = {
174 .get_ro = tegra_sdhci_get_ro, 168 .get_ro = tegra_sdhci_get_ro,
175 .read_w = tegra_sdhci_readw, 169 .read_w = tegra_sdhci_readw,
176 .write_w = tegra_sdhci_writew,
177 .write_l = tegra_sdhci_writel, 170 .write_l = tegra_sdhci_writel,
178 .set_clock = sdhci_set_clock, 171 .set_clock = sdhci_set_clock,
179 .set_bus_width = tegra_sdhci_set_bus_width, 172 .set_bus_width = tegra_sdhci_set_bus_width,
@@ -214,6 +207,18 @@ static struct sdhci_tegra_soc_data soc_data_tegra30 = {
214 NVQUIRK_DISABLE_SDR104, 207 NVQUIRK_DISABLE_SDR104,
215}; 208};
216 209
210static const struct sdhci_ops tegra114_sdhci_ops = {
211 .get_ro = tegra_sdhci_get_ro,
212 .read_w = tegra_sdhci_readw,
213 .write_w = tegra_sdhci_writew,
214 .write_l = tegra_sdhci_writel,
215 .set_clock = sdhci_set_clock,
216 .set_bus_width = tegra_sdhci_set_bus_width,
217 .reset = tegra_sdhci_reset,
218 .set_uhs_signaling = sdhci_set_uhs_signaling,
219 .get_max_clock = sdhci_pltfm_clk_get_max_clock,
220};
221
217static const struct sdhci_pltfm_data sdhci_tegra114_pdata = { 222static const struct sdhci_pltfm_data sdhci_tegra114_pdata = {
218 .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL | 223 .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
219 SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK | 224 SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
@@ -221,15 +226,14 @@ static const struct sdhci_pltfm_data sdhci_tegra114_pdata = {
221 SDHCI_QUIRK_NO_HISPD_BIT | 226 SDHCI_QUIRK_NO_HISPD_BIT |
222 SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC | 227 SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
223 SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN, 228 SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
224 .ops = &tegra_sdhci_ops, 229 .ops = &tegra114_sdhci_ops,
225}; 230};
226 231
227static struct sdhci_tegra_soc_data soc_data_tegra114 = { 232static struct sdhci_tegra_soc_data soc_data_tegra114 = {
228 .pdata = &sdhci_tegra114_pdata, 233 .pdata = &sdhci_tegra114_pdata,
229 .nvquirks = NVQUIRK_DISABLE_SDR50 | 234 .nvquirks = NVQUIRK_DISABLE_SDR50 |
230 NVQUIRK_DISABLE_DDR50 | 235 NVQUIRK_DISABLE_DDR50 |
231 NVQUIRK_DISABLE_SDR104 | 236 NVQUIRK_DISABLE_SDR104,
232 NVQUIRK_SHADOW_XFER_MODE_REG,
233}; 237};
234 238
235static const struct of_device_id sdhci_tegra_dt_match[] = { 239static const struct of_device_id sdhci_tegra_dt_match[] = {
@@ -241,17 +245,6 @@ static const struct of_device_id sdhci_tegra_dt_match[] = {
241}; 245};
242MODULE_DEVICE_TABLE(of, sdhci_tegra_dt_match); 246MODULE_DEVICE_TABLE(of, sdhci_tegra_dt_match);
243 247
244static int sdhci_tegra_parse_dt(struct device *dev)
245{
246 struct device_node *np = dev->of_node;
247 struct sdhci_host *host = dev_get_drvdata(dev);
248 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
249 struct sdhci_tegra *tegra_host = pltfm_host->priv;
250
251 tegra_host->power_gpio = of_get_named_gpio(np, "power-gpios", 0);
252 return mmc_of_parse(host->mmc);
253}
254
255static int sdhci_tegra_probe(struct platform_device *pdev) 248static int sdhci_tegra_probe(struct platform_device *pdev)
256{ 249{
257 const struct of_device_id *match; 250 const struct of_device_id *match;
@@ -281,21 +274,18 @@ static int sdhci_tegra_probe(struct platform_device *pdev)
281 tegra_host->soc_data = soc_data; 274 tegra_host->soc_data = soc_data;
282 pltfm_host->priv = tegra_host; 275 pltfm_host->priv = tegra_host;
283 276
284 rc = sdhci_tegra_parse_dt(&pdev->dev); 277 rc = mmc_of_parse(host->mmc);
285 if (rc) 278 if (rc)
286 goto err_parse_dt; 279 goto err_parse_dt;
287 280
288 if (gpio_is_valid(tegra_host->power_gpio)) { 281 tegra_host->power_gpio = devm_gpiod_get_optional(&pdev->dev, "power",
289 rc = gpio_request(tegra_host->power_gpio, "sdhci_power"); 282 GPIOD_OUT_HIGH);
290 if (rc) { 283 if (IS_ERR(tegra_host->power_gpio)) {
291 dev_err(mmc_dev(host->mmc), 284 rc = PTR_ERR(tegra_host->power_gpio);
292 "failed to allocate power gpio\n"); 285 goto err_power_req;
293 goto err_power_req;
294 }
295 gpio_direction_output(tegra_host->power_gpio, 1);
296 } 286 }
297 287
298 clk = clk_get(mmc_dev(host->mmc), NULL); 288 clk = devm_clk_get(mmc_dev(host->mmc), NULL);
299 if (IS_ERR(clk)) { 289 if (IS_ERR(clk)) {
300 dev_err(mmc_dev(host->mmc), "clk err\n"); 290 dev_err(mmc_dev(host->mmc), "clk err\n");
301 rc = PTR_ERR(clk); 291 rc = PTR_ERR(clk);
@@ -312,10 +302,7 @@ static int sdhci_tegra_probe(struct platform_device *pdev)
312 302
313err_add_host: 303err_add_host:
314 clk_disable_unprepare(pltfm_host->clk); 304 clk_disable_unprepare(pltfm_host->clk);
315 clk_put(pltfm_host->clk);
316err_clk_get: 305err_clk_get:
317 if (gpio_is_valid(tegra_host->power_gpio))
318 gpio_free(tegra_host->power_gpio);
319err_power_req: 306err_power_req:
320err_parse_dt: 307err_parse_dt:
321err_alloc_tegra_host: 308err_alloc_tegra_host:
@@ -323,26 +310,6 @@ err_alloc_tegra_host:
323 return rc; 310 return rc;
324} 311}
325 312
326static int sdhci_tegra_remove(struct platform_device *pdev)
327{
328 struct sdhci_host *host = platform_get_drvdata(pdev);
329 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
330 struct sdhci_tegra *tegra_host = pltfm_host->priv;
331 int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
332
333 sdhci_remove_host(host, dead);
334
335 if (gpio_is_valid(tegra_host->power_gpio))
336 gpio_free(tegra_host->power_gpio);
337
338 clk_disable_unprepare(pltfm_host->clk);
339 clk_put(pltfm_host->clk);
340
341 sdhci_pltfm_free(pdev);
342
343 return 0;
344}
345
346static struct platform_driver sdhci_tegra_driver = { 313static struct platform_driver sdhci_tegra_driver = {
347 .driver = { 314 .driver = {
348 .name = "sdhci-tegra", 315 .name = "sdhci-tegra",
@@ -350,7 +317,7 @@ static struct platform_driver sdhci_tegra_driver = {
350 .pm = SDHCI_PLTFM_PMOPS, 317 .pm = SDHCI_PLTFM_PMOPS,
351 }, 318 },
352 .probe = sdhci_tegra_probe, 319 .probe = sdhci_tegra_probe,
353 .remove = sdhci_tegra_remove, 320 .remove = sdhci_pltfm_unregister,
354}; 321};
355 322
356module_platform_driver(sdhci_tegra_driver); 323module_platform_driver(sdhci_tegra_driver);
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 0ad412a4876f..c80287a02735 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -28,6 +28,7 @@
28#include <linux/mmc/mmc.h> 28#include <linux/mmc/mmc.h>
29#include <linux/mmc/host.h> 29#include <linux/mmc/host.h>
30#include <linux/mmc/card.h> 30#include <linux/mmc/card.h>
31#include <linux/mmc/sdio.h>
31#include <linux/mmc/slot-gpio.h> 32#include <linux/mmc/slot-gpio.h>
32 33
33#include "sdhci.h" 34#include "sdhci.h"
@@ -56,6 +57,7 @@ static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable);
56static int sdhci_pre_dma_transfer(struct sdhci_host *host, 57static int sdhci_pre_dma_transfer(struct sdhci_host *host,
57 struct mmc_data *data, 58 struct mmc_data *data,
58 struct sdhci_host_next *next); 59 struct sdhci_host_next *next);
60static int sdhci_do_get_cd(struct sdhci_host *host);
59 61
60#ifdef CONFIG_PM 62#ifdef CONFIG_PM
61static int sdhci_runtime_pm_get(struct sdhci_host *host); 63static int sdhci_runtime_pm_get(struct sdhci_host *host);
@@ -931,7 +933,8 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host,
931 * If we are sending CMD23, CMD12 never gets sent 933 * If we are sending CMD23, CMD12 never gets sent
932 * on successful completion (so no Auto-CMD12). 934 * on successful completion (so no Auto-CMD12).
933 */ 935 */
934 if (!host->mrq->sbc && (host->flags & SDHCI_AUTO_CMD12)) 936 if (!host->mrq->sbc && (host->flags & SDHCI_AUTO_CMD12) &&
937 (cmd->opcode != SD_IO_RW_EXTENDED))
935 mode |= SDHCI_TRNS_AUTO_CMD12; 938 mode |= SDHCI_TRNS_AUTO_CMD12;
936 else if (host->mrq->sbc && (host->flags & SDHCI_AUTO_CMD23)) { 939 else if (host->mrq->sbc && (host->flags & SDHCI_AUTO_CMD23)) {
937 mode |= SDHCI_TRNS_AUTO_CMD23; 940 mode |= SDHCI_TRNS_AUTO_CMD23;
@@ -1356,7 +1359,8 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1356 1359
1357 sdhci_runtime_pm_get(host); 1360 sdhci_runtime_pm_get(host);
1358 1361
1359 present = mmc_gpio_get_cd(host->mmc); 1362 /* Firstly check card presence */
1363 present = sdhci_do_get_cd(host);
1360 1364
1361 spin_lock_irqsave(&host->lock, flags); 1365 spin_lock_irqsave(&host->lock, flags);
1362 1366
@@ -1379,22 +1383,6 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1379 1383
1380 host->mrq = mrq; 1384 host->mrq = mrq;
1381 1385
1382 /*
1383 * Firstly check card presence from cd-gpio. The return could
1384 * be one of the following possibilities:
1385 * negative: cd-gpio is not available
1386 * zero: cd-gpio is used, and card is removed
1387 * one: cd-gpio is used, and card is present
1388 */
1389 if (present < 0) {
1390 /* If polling, assume that the card is always present. */
1391 if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
1392 present = 1;
1393 else
1394 present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
1395 SDHCI_CARD_PRESENT;
1396 }
1397
1398 if (!present || host->flags & SDHCI_DEVICE_DEAD) { 1386 if (!present || host->flags & SDHCI_DEVICE_DEAD) {
1399 host->mrq->cmd->error = -ENOMEDIUM; 1387 host->mrq->cmd->error = -ENOMEDIUM;
1400 tasklet_schedule(&host->finish_tasklet); 1388 tasklet_schedule(&host->finish_tasklet);
@@ -3164,7 +3152,8 @@ int sdhci_add_host(struct sdhci_host *host)
3164 /* Auto-CMD23 stuff only works in ADMA or PIO. */ 3152 /* Auto-CMD23 stuff only works in ADMA or PIO. */
3165 if ((host->version >= SDHCI_SPEC_300) && 3153 if ((host->version >= SDHCI_SPEC_300) &&
3166 ((host->flags & SDHCI_USE_ADMA) || 3154 ((host->flags & SDHCI_USE_ADMA) ||
3167 !(host->flags & SDHCI_USE_SDMA))) { 3155 !(host->flags & SDHCI_USE_SDMA)) &&
3156 !(host->quirks2 & SDHCI_QUIRK2_ACMD23_BROKEN)) {
3168 host->flags |= SDHCI_AUTO_CMD23; 3157 host->flags |= SDHCI_AUTO_CMD23;
3169 DBG("%s: Auto-CMD23 available\n", mmc_hostname(mmc)); 3158 DBG("%s: Auto-CMD23 available\n", mmc_hostname(mmc));
3170 } else { 3159 } else {
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index 0315e1844330..e639b7f435e5 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -18,7 +18,7 @@
18#include <linux/types.h> 18#include <linux/types.h>
19#include <linux/io.h> 19#include <linux/io.h>
20 20
21#include <linux/mmc/sdhci.h> 21#include <linux/mmc/host.h>
22 22
23/* 23/*
24 * Controller registers 24 * Controller registers
@@ -309,6 +309,207 @@ struct sdhci_adma2_64_desc {
309 */ 309 */
310#define SDHCI_MAX_SEGS 128 310#define SDHCI_MAX_SEGS 128
311 311
312struct sdhci_host_next {
313 unsigned int sg_count;
314 s32 cookie;
315};
316
317struct sdhci_host {
318 /* Data set by hardware interface driver */
319 const char *hw_name; /* Hardware bus name */
320
321 unsigned int quirks; /* Deviations from spec. */
322
323/* Controller doesn't honor resets unless we touch the clock register */
324#define SDHCI_QUIRK_CLOCK_BEFORE_RESET (1<<0)
325/* Controller has bad caps bits, but really supports DMA */
326#define SDHCI_QUIRK_FORCE_DMA (1<<1)
327/* Controller doesn't like to be reset when there is no card inserted. */
328#define SDHCI_QUIRK_NO_CARD_NO_RESET (1<<2)
329/* Controller doesn't like clearing the power reg before a change */
330#define SDHCI_QUIRK_SINGLE_POWER_WRITE (1<<3)
331/* Controller has flaky internal state so reset it on each ios change */
332#define SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS (1<<4)
333/* Controller has an unusable DMA engine */
334#define SDHCI_QUIRK_BROKEN_DMA (1<<5)
335/* Controller has an unusable ADMA engine */
336#define SDHCI_QUIRK_BROKEN_ADMA (1<<6)
337/* Controller can only DMA from 32-bit aligned addresses */
338#define SDHCI_QUIRK_32BIT_DMA_ADDR (1<<7)
339/* Controller can only DMA chunk sizes that are a multiple of 32 bits */
340#define SDHCI_QUIRK_32BIT_DMA_SIZE (1<<8)
341/* Controller can only ADMA chunks that are a multiple of 32 bits */
342#define SDHCI_QUIRK_32BIT_ADMA_SIZE (1<<9)
343/* Controller needs to be reset after each request to stay stable */
344#define SDHCI_QUIRK_RESET_AFTER_REQUEST (1<<10)
345/* Controller needs voltage and power writes to happen separately */
346#define SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER (1<<11)
347/* Controller provides an incorrect timeout value for transfers */
348#define SDHCI_QUIRK_BROKEN_TIMEOUT_VAL (1<<12)
349/* Controller has an issue with buffer bits for small transfers */
350#define SDHCI_QUIRK_BROKEN_SMALL_PIO (1<<13)
351/* Controller does not provide transfer-complete interrupt when not busy */
352#define SDHCI_QUIRK_NO_BUSY_IRQ (1<<14)
353/* Controller has unreliable card detection */
354#define SDHCI_QUIRK_BROKEN_CARD_DETECTION (1<<15)
355/* Controller reports inverted write-protect state */
356#define SDHCI_QUIRK_INVERTED_WRITE_PROTECT (1<<16)
357/* Controller does not like fast PIO transfers */
358#define SDHCI_QUIRK_PIO_NEEDS_DELAY (1<<18)
359/* Controller has to be forced to use block size of 2048 bytes */
360#define SDHCI_QUIRK_FORCE_BLK_SZ_2048 (1<<20)
361/* Controller cannot do multi-block transfers */
362#define SDHCI_QUIRK_NO_MULTIBLOCK (1<<21)
363/* Controller can only handle 1-bit data transfers */
364#define SDHCI_QUIRK_FORCE_1_BIT_DATA (1<<22)
365/* Controller needs 10ms delay between applying power and clock */
366#define SDHCI_QUIRK_DELAY_AFTER_POWER (1<<23)
367/* Controller uses SDCLK instead of TMCLK for data timeouts */
368#define SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK (1<<24)
369/* Controller reports wrong base clock capability */
370#define SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN (1<<25)
371/* Controller cannot support End Attribute in NOP ADMA descriptor */
372#define SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC (1<<26)
373/* Controller is missing device caps. Use caps provided by host */
374#define SDHCI_QUIRK_MISSING_CAPS (1<<27)
375/* Controller uses Auto CMD12 command to stop the transfer */
376#define SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12 (1<<28)
377/* Controller doesn't have HISPD bit field in HI-SPEED SD card */
378#define SDHCI_QUIRK_NO_HISPD_BIT (1<<29)
379/* Controller treats ADMA descriptors with length 0000h incorrectly */
380#define SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC (1<<30)
381/* The read-only detection via SDHCI_PRESENT_STATE register is unstable */
382#define SDHCI_QUIRK_UNSTABLE_RO_DETECT (1<<31)
383
384 unsigned int quirks2; /* More deviations from spec. */
385
386#define SDHCI_QUIRK2_HOST_OFF_CARD_ON (1<<0)
387#define SDHCI_QUIRK2_HOST_NO_CMD23 (1<<1)
388/* The system physically doesn't support 1.8v, even if the host does */
389#define SDHCI_QUIRK2_NO_1_8_V (1<<2)
390#define SDHCI_QUIRK2_PRESET_VALUE_BROKEN (1<<3)
391#define SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON (1<<4)
392/* Controller has a non-standard host control register */
393#define SDHCI_QUIRK2_BROKEN_HOST_CONTROL (1<<5)
394/* Controller does not support HS200 */
395#define SDHCI_QUIRK2_BROKEN_HS200 (1<<6)
396/* Controller does not support DDR50 */
397#define SDHCI_QUIRK2_BROKEN_DDR50 (1<<7)
398/* Stop command (CMD12) can set Transfer Complete when not using MMC_RSP_BUSY */
399#define SDHCI_QUIRK2_STOP_WITH_TC (1<<8)
400/* Controller does not support 64-bit DMA */
401#define SDHCI_QUIRK2_BROKEN_64_BIT_DMA (1<<9)
402/* need clear transfer mode register before send cmd */
403#define SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD (1<<10)
404/* Capability register bit-63 indicates HS400 support */
405#define SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 (1<<11)
406/* forced tuned clock */
407#define SDHCI_QUIRK2_TUNING_WORK_AROUND (1<<12)
408/* disable the block count for single block transactions */
409#define SDHCI_QUIRK2_SUPPORT_SINGLE (1<<13)
410/* Controller broken with using ACMD23 */
411#define SDHCI_QUIRK2_ACMD23_BROKEN (1<<14)
412
413 int irq; /* Device IRQ */
414 void __iomem *ioaddr; /* Mapped address */
415
416 const struct sdhci_ops *ops; /* Low level hw interface */
417
418 /* Internal data */
419 struct mmc_host *mmc; /* MMC structure */
420 u64 dma_mask; /* custom DMA mask */
421
422#if defined(CONFIG_LEDS_CLASS) || defined(CONFIG_LEDS_CLASS_MODULE)
423 struct led_classdev led; /* LED control */
424 char led_name[32];
425#endif
426
427 spinlock_t lock; /* Mutex */
428
429 int flags; /* Host attributes */
430#define SDHCI_USE_SDMA (1<<0) /* Host is SDMA capable */
431#define SDHCI_USE_ADMA (1<<1) /* Host is ADMA capable */
432#define SDHCI_REQ_USE_DMA (1<<2) /* Use DMA for this req. */
433#define SDHCI_DEVICE_DEAD (1<<3) /* Device unresponsive */
434#define SDHCI_SDR50_NEEDS_TUNING (1<<4) /* SDR50 needs tuning */
435#define SDHCI_NEEDS_RETUNING (1<<5) /* Host needs retuning */
436#define SDHCI_AUTO_CMD12 (1<<6) /* Auto CMD12 support */
437#define SDHCI_AUTO_CMD23 (1<<7) /* Auto CMD23 support */
438#define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */
439#define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
440#define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
441#define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
442#define SDHCI_USE_64_BIT_DMA (1<<12) /* Use 64-bit DMA */
443#define SDHCI_HS400_TUNING (1<<13) /* Tuning for HS400 */
444
445 unsigned int version; /* SDHCI spec. version */
446
447 unsigned int max_clk; /* Max possible freq (MHz) */
448 unsigned int timeout_clk; /* Timeout freq (KHz) */
449 unsigned int clk_mul; /* Clock Muliplier value */
450
451 unsigned int clock; /* Current clock (MHz) */
452 u8 pwr; /* Current voltage */
453
454 bool runtime_suspended; /* Host is runtime suspended */
455 bool bus_on; /* Bus power prevents runtime suspend */
456 bool preset_enabled; /* Preset is enabled */
457
458 struct mmc_request *mrq; /* Current request */
459 struct mmc_command *cmd; /* Current command */
460 struct mmc_data *data; /* Current data request */
461 unsigned int data_early:1; /* Data finished before cmd */
462 unsigned int busy_handle:1; /* Handling the order of Busy-end */
463
464 struct sg_mapping_iter sg_miter; /* SG state for PIO */
465 unsigned int blocks; /* remaining PIO blocks */
466
467 int sg_count; /* Mapped sg entries */
468
469 void *adma_table; /* ADMA descriptor table */
470 void *align_buffer; /* Bounce buffer */
471
472 size_t adma_table_sz; /* ADMA descriptor table size */
473 size_t align_buffer_sz; /* Bounce buffer size */
474
475 dma_addr_t adma_addr; /* Mapped ADMA descr. table */
476 dma_addr_t align_addr; /* Mapped bounce buffer */
477
478 unsigned int desc_sz; /* ADMA descriptor size */
479 unsigned int align_sz; /* ADMA alignment */
480 unsigned int align_mask; /* ADMA alignment mask */
481
482 struct tasklet_struct finish_tasklet; /* Tasklet structures */
483
484 struct timer_list timer; /* Timer for timeouts */
485
486 u32 caps; /* Alternative CAPABILITY_0 */
487 u32 caps1; /* Alternative CAPABILITY_1 */
488
489 unsigned int ocr_avail_sdio; /* OCR bit masks */
490 unsigned int ocr_avail_sd;
491 unsigned int ocr_avail_mmc;
492 u32 ocr_mask; /* available voltages */
493
494 unsigned timing; /* Current timing */
495
496 u32 thread_isr;
497
498 /* cached registers */
499 u32 ier;
500
501 wait_queue_head_t buf_ready_int; /* Waitqueue for Buffer Read Ready interrupt */
502 unsigned int tuning_done; /* Condition flag set when CMD19 succeeds */
503
504 unsigned int tuning_count; /* Timer count for re-tuning */
505 unsigned int tuning_mode; /* Re-tuning mode supported by host */
506#define SDHCI_TUNING_MODE_1 0
507 struct timer_list tuning_timer; /* Timer for tuning */
508
509 struct sdhci_host_next next_data;
510 unsigned long private[0] ____cacheline_aligned;
511};
512
312struct sdhci_ops { 513struct sdhci_ops {
313#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS 514#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
314 u32 (*read_l)(struct sdhci_host *host, int reg); 515 u32 (*read_l)(struct sdhci_host *host, int reg);
diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
index 7d9d6a321521..072f67066df3 100644
--- a/drivers/mmc/host/sh_mmcif.c
+++ b/drivers/mmc/host/sh_mmcif.c
@@ -875,6 +875,7 @@ static void sh_mmcif_start_cmd(struct sh_mmcif_host *host,
875 struct mmc_command *cmd = mrq->cmd; 875 struct mmc_command *cmd = mrq->cmd;
876 u32 opc = cmd->opcode; 876 u32 opc = cmd->opcode;
877 u32 mask; 877 u32 mask;
878 unsigned long flags;
878 879
879 switch (opc) { 880 switch (opc) {
880 /* response busy check */ 881 /* response busy check */
@@ -909,10 +910,12 @@ static void sh_mmcif_start_cmd(struct sh_mmcif_host *host,
909 /* set arg */ 910 /* set arg */
910 sh_mmcif_writel(host->addr, MMCIF_CE_ARG, cmd->arg); 911 sh_mmcif_writel(host->addr, MMCIF_CE_ARG, cmd->arg);
911 /* set cmd */ 912 /* set cmd */
913 spin_lock_irqsave(&host->lock, flags);
912 sh_mmcif_writel(host->addr, MMCIF_CE_CMD_SET, opc); 914 sh_mmcif_writel(host->addr, MMCIF_CE_CMD_SET, opc);
913 915
914 host->wait_for = MMCIF_WAIT_FOR_CMD; 916 host->wait_for = MMCIF_WAIT_FOR_CMD;
915 schedule_delayed_work(&host->timeout_work, host->timeout); 917 schedule_delayed_work(&host->timeout_work, host->timeout);
918 spin_unlock_irqrestore(&host->lock, flags);
916} 919}
917 920
918static void sh_mmcif_stop_cmd(struct sh_mmcif_host *host, 921static void sh_mmcif_stop_cmd(struct sh_mmcif_host *host,
@@ -1171,6 +1174,12 @@ static irqreturn_t sh_mmcif_irqt(int irq, void *dev_id)
1171 struct sh_mmcif_host *host = dev_id; 1174 struct sh_mmcif_host *host = dev_id;
1172 struct mmc_request *mrq; 1175 struct mmc_request *mrq;
1173 bool wait = false; 1176 bool wait = false;
1177 unsigned long flags;
1178 int wait_work;
1179
1180 spin_lock_irqsave(&host->lock, flags);
1181 wait_work = host->wait_for;
1182 spin_unlock_irqrestore(&host->lock, flags);
1174 1183
1175 cancel_delayed_work_sync(&host->timeout_work); 1184 cancel_delayed_work_sync(&host->timeout_work);
1176 1185
@@ -1188,7 +1197,7 @@ static irqreturn_t sh_mmcif_irqt(int irq, void *dev_id)
1188 * All handlers return true, if processing continues, and false, if the 1197 * All handlers return true, if processing continues, and false, if the
1189 * request has to be completed - successfully or not 1198 * request has to be completed - successfully or not
1190 */ 1199 */
1191 switch (host->wait_for) { 1200 switch (wait_work) {
1192 case MMCIF_WAIT_FOR_REQUEST: 1201 case MMCIF_WAIT_FOR_REQUEST:
1193 /* We're too late, the timeout has already kicked in */ 1202 /* We're too late, the timeout has already kicked in */
1194 mutex_unlock(&host->thread_lock); 1203 mutex_unlock(&host->thread_lock);
@@ -1312,15 +1321,15 @@ static void mmcif_timeout_work(struct work_struct *work)
1312 /* Don't run after mmc_remove_host() */ 1321 /* Don't run after mmc_remove_host() */
1313 return; 1322 return;
1314 1323
1315 dev_err(&host->pd->dev, "Timeout waiting for %u on CMD%u\n",
1316 host->wait_for, mrq->cmd->opcode);
1317
1318 spin_lock_irqsave(&host->lock, flags); 1324 spin_lock_irqsave(&host->lock, flags);
1319 if (host->state == STATE_IDLE) { 1325 if (host->state == STATE_IDLE) {
1320 spin_unlock_irqrestore(&host->lock, flags); 1326 spin_unlock_irqrestore(&host->lock, flags);
1321 return; 1327 return;
1322 } 1328 }
1323 1329
1330 dev_err(&host->pd->dev, "Timeout waiting for %u on CMD%u\n",
1331 host->wait_for, mrq->cmd->opcode);
1332
1324 host->state = STATE_TIMEOUT; 1333 host->state = STATE_TIMEOUT;
1325 spin_unlock_irqrestore(&host->lock, flags); 1334 spin_unlock_irqrestore(&host->lock, flags);
1326 1335
diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index e8a4218b5726..4d3e1ffe5508 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -293,7 +293,7 @@ static void sunxi_mmc_init_idma_des(struct sunxi_mmc_host *host,
293 struct mmc_data *data) 293 struct mmc_data *data)
294{ 294{
295 struct sunxi_idma_des *pdes = (struct sunxi_idma_des *)host->sg_cpu; 295 struct sunxi_idma_des *pdes = (struct sunxi_idma_des *)host->sg_cpu;
296 struct sunxi_idma_des *pdes_pa = (struct sunxi_idma_des *)host->sg_dma; 296 dma_addr_t next_desc = host->sg_dma;
297 int i, max_len = (1 << host->idma_des_size_bits); 297 int i, max_len = (1 << host->idma_des_size_bits);
298 298
299 for (i = 0; i < data->sg_len; i++) { 299 for (i = 0; i < data->sg_len; i++) {
@@ -305,8 +305,9 @@ static void sunxi_mmc_init_idma_des(struct sunxi_mmc_host *host,
305 else 305 else
306 pdes[i].buf_size = data->sg[i].length; 306 pdes[i].buf_size = data->sg[i].length;
307 307
308 next_desc += sizeof(struct sunxi_idma_des);
308 pdes[i].buf_addr_ptr1 = sg_dma_address(&data->sg[i]); 309 pdes[i].buf_addr_ptr1 = sg_dma_address(&data->sg[i]);
309 pdes[i].buf_addr_ptr2 = (u32)&pdes_pa[i + 1]; 310 pdes[i].buf_addr_ptr2 = (u32)next_desc;
310 } 311 }
311 312
312 pdes[0].config |= SDXC_IDMAC_DES0_FD; 313 pdes[0].config |= SDXC_IDMAC_DES0_FD;
@@ -930,7 +931,9 @@ static int sunxi_mmc_resource_request(struct sunxi_mmc_host *host,
930 return PTR_ERR(host->clk_sample); 931 return PTR_ERR(host->clk_sample);
931 } 932 }
932 933
933 host->reset = devm_reset_control_get(&pdev->dev, "ahb"); 934 host->reset = devm_reset_control_get_optional(&pdev->dev, "ahb");
935 if (PTR_ERR(host->reset) == -EPROBE_DEFER)
936 return PTR_ERR(host->reset);
934 937
935 ret = clk_prepare_enable(host->clk_ahb); 938 ret = clk_prepare_enable(host->clk_ahb);
936 if (ret) { 939 if (ret) {
@@ -1028,7 +1031,7 @@ static int sunxi_mmc_probe(struct platform_device *pdev)
1028 mmc->f_min = 400000; 1031 mmc->f_min = 400000;
1029 mmc->f_max = 50000000; 1032 mmc->f_max = 50000000;
1030 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED | 1033 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
1031 MMC_CAP_ERASE; 1034 MMC_CAP_ERASE | MMC_CAP_SDIO_IRQ;
1032 1035
1033 ret = mmc_of_parse(mmc); 1036 ret = mmc_of_parse(mmc);
1034 if (ret) 1037 if (ret)
diff --git a/drivers/mmc/host/tmio_mmc_pio.c b/drivers/mmc/host/tmio_mmc_pio.c
index a31c3573d386..dba7e1c19dd7 100644
--- a/drivers/mmc/host/tmio_mmc_pio.c
+++ b/drivers/mmc/host/tmio_mmc_pio.c
@@ -1073,8 +1073,6 @@ EXPORT_SYMBOL(tmio_mmc_host_alloc);
1073void tmio_mmc_host_free(struct tmio_mmc_host *host) 1073void tmio_mmc_host_free(struct tmio_mmc_host *host)
1074{ 1074{
1075 mmc_free_host(host->mmc); 1075 mmc_free_host(host->mmc);
1076
1077 host->mmc = NULL;
1078} 1076}
1079EXPORT_SYMBOL(tmio_mmc_host_free); 1077EXPORT_SYMBOL(tmio_mmc_host_free);
1080 1078
diff --git a/drivers/mmc/host/wmt-sdmmc.c b/drivers/mmc/host/wmt-sdmmc.c
index dd2e1aa95ba3..5af00559e9d6 100644
--- a/drivers/mmc/host/wmt-sdmmc.c
+++ b/drivers/mmc/host/wmt-sdmmc.c
@@ -744,7 +744,7 @@ static struct wmt_mci_caps wm8505_caps = {
744 .max_blk_size = 2048, 744 .max_blk_size = 2048,
745}; 745};
746 746
747static struct of_device_id wmt_mci_dt_ids[] = { 747static const struct of_device_id wmt_mci_dt_ids[] = {
748 { .compatible = "wm,wm8505-sdhc", .data = &wm8505_caps }, 748 { .compatible = "wm,wm8505-sdhc", .data = &wm8505_caps },
749 { /* Sentinel */ }, 749 { /* Sentinel */ },
750}; 750};
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index 160448f920ac..de722d4e9d61 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -79,7 +79,7 @@ struct mmc_command {
79#define mmc_cmd_type(cmd) ((cmd)->flags & MMC_CMD_MASK) 79#define mmc_cmd_type(cmd) ((cmd)->flags & MMC_CMD_MASK)
80 80
81 unsigned int retries; /* max number of retries */ 81 unsigned int retries; /* max number of retries */
82 unsigned int error; /* command error */ 82 int error; /* command error */
83 83
84/* 84/*
85 * Standard errno values are used for errors, but some have specific 85 * Standard errno values are used for errors, but some have specific
@@ -108,7 +108,7 @@ struct mmc_data {
108 unsigned int timeout_clks; /* data timeout (in clocks) */ 108 unsigned int timeout_clks; /* data timeout (in clocks) */
109 unsigned int blksz; /* data block size */ 109 unsigned int blksz; /* data block size */
110 unsigned int blocks; /* number of blocks */ 110 unsigned int blocks; /* number of blocks */
111 unsigned int error; /* data error */ 111 int error; /* data error */
112 unsigned int flags; 112 unsigned int flags;
113 113
114#define MMC_DATA_WRITE (1 << 8) 114#define MMC_DATA_WRITE (1 << 8)
diff --git a/include/linux/mmc/dw_mmc.h b/include/linux/mmc/dw_mmc.h
index 471fb3116dbe..12111993a317 100644
--- a/include/linux/mmc/dw_mmc.h
+++ b/include/linux/mmc/dw_mmc.h
@@ -44,6 +44,7 @@ struct mmc_data;
44 * struct dw_mci - MMC controller state shared between all slots 44 * struct dw_mci - MMC controller state shared between all slots
45 * @lock: Spinlock protecting the queue and associated data. 45 * @lock: Spinlock protecting the queue and associated data.
46 * @regs: Pointer to MMIO registers. 46 * @regs: Pointer to MMIO registers.
47 * @fifo_reg: Pointer to MMIO registers for data FIFO
47 * @sg: Scatterlist entry currently being processed by PIO code, if any. 48 * @sg: Scatterlist entry currently being processed by PIO code, if any.
48 * @sg_miter: PIO mapping scatterlist iterator. 49 * @sg_miter: PIO mapping scatterlist iterator.
49 * @cur_slot: The slot which is currently using the controller. 50 * @cur_slot: The slot which is currently using the controller.
@@ -79,7 +80,6 @@ struct mmc_data;
79 * @current_speed: Configured rate of the controller. 80 * @current_speed: Configured rate of the controller.
80 * @num_slots: Number of slots available. 81 * @num_slots: Number of slots available.
81 * @verid: Denote Version ID. 82 * @verid: Denote Version ID.
82 * @data_offset: Set the offset of DATA register according to VERID.
83 * @dev: Device associated with the MMC controller. 83 * @dev: Device associated with the MMC controller.
84 * @pdata: Platform data associated with the MMC controller. 84 * @pdata: Platform data associated with the MMC controller.
85 * @drv_data: Driver specific data for identified variant of the controller 85 * @drv_data: Driver specific data for identified variant of the controller
@@ -132,6 +132,7 @@ struct dw_mci {
132 spinlock_t lock; 132 spinlock_t lock;
133 spinlock_t irq_lock; 133 spinlock_t irq_lock;
134 void __iomem *regs; 134 void __iomem *regs;
135 void __iomem *fifo_reg;
135 136
136 struct scatterlist *sg; 137 struct scatterlist *sg;
137 struct sg_mapping_iter sg_miter; 138 struct sg_mapping_iter sg_miter;
@@ -172,7 +173,6 @@ struct dw_mci {
172 u32 num_slots; 173 u32 num_slots;
173 u32 fifoth_val; 174 u32 fifoth_val;
174 u16 verid; 175 u16 verid;
175 u16 data_offset;
176 struct device *dev; 176 struct device *dev;
177 struct dw_mci_board *pdata; 177 struct dw_mci_board *pdata;
178 const struct dw_mci_drv_data *drv_data; 178 const struct dw_mci_drv_data *drv_data;
@@ -202,6 +202,8 @@ struct dw_mci {
202 int irq; 202 int irq;
203 203
204 int sdio_id0; 204 int sdio_id0;
205
206 struct timer_list cmd11_timer;
205}; 207};
206 208
207/* DMA ops for Internal/External DMAC interface */ 209/* DMA ops for Internal/External DMAC interface */
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 0c8cbe5d1550..b5bedaec6223 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -80,12 +80,6 @@ struct mmc_ios {
80 80
81struct mmc_host_ops { 81struct mmc_host_ops {
82 /* 82 /*
83 * 'enable' is called when the host is claimed and 'disable' is called
84 * when the host is released. 'enable' and 'disable' are deprecated.
85 */
86 int (*enable)(struct mmc_host *host);
87 int (*disable)(struct mmc_host *host);
88 /*
89 * It is optional for the host to implement pre_req and post_req in 83 * It is optional for the host to implement pre_req and post_req in
90 * order to support double buffering of requests (prepare one 84 * order to support double buffering of requests (prepare one
91 * request while another request is active). 85 * request while another request is active).
diff --git a/include/linux/mmc/sdhci-spear.h b/include/linux/mmc/sdhci-spear.h
deleted file mode 100644
index 8cc095a76cf8..000000000000
--- a/include/linux/mmc/sdhci-spear.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/*
2 * include/linux/mmc/sdhci-spear.h
3 *
4 * SDHCI declarations specific to ST SPEAr platform
5 *
6 * Copyright (C) 2010 ST Microelectronics
7 * Viresh Kumar <viresh.linux@gmail.com>
8 *
9 * This file is licensed under the terms of the GNU General Public
10 * License version 2. This program is licensed "as is" without any
11 * warranty of any kind, whether express or implied.
12 */
13
14#ifndef LINUX_MMC_SDHCI_SPEAR_H
15#define LINUX_MMC_SDHCI_SPEAR_H
16
17#include <linux/platform_device.h>
18/*
19 * struct sdhci_plat_data: spear sdhci platform data structure
20 *
21 * card_int_gpio: gpio pin used for card detection
22 */
23struct sdhci_plat_data {
24 int card_int_gpio;
25};
26
27/* This function is used to set platform_data field of pdev->dev */
28static inline void
29sdhci_set_plat_data(struct platform_device *pdev, struct sdhci_plat_data *data)
30{
31 pdev->dev.platform_data = data;
32}
33
34#endif /* LINUX_MMC_SDHCI_SPEAR_H */
diff --git a/include/linux/mmc/sdhci.h b/include/linux/mmc/sdhci.h
deleted file mode 100644
index c3e3db196738..000000000000
--- a/include/linux/mmc/sdhci.h
+++ /dev/null
@@ -1,218 +0,0 @@
1/*
2 * linux/include/linux/mmc/sdhci.h - Secure Digital Host Controller Interface
3 *
4 * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved.
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 (at
9 * your option) any later version.
10 */
11#ifndef LINUX_MMC_SDHCI_H
12#define LINUX_MMC_SDHCI_H
13
14#include <linux/scatterlist.h>
15#include <linux/compiler.h>
16#include <linux/types.h>
17#include <linux/io.h>
18#include <linux/mmc/host.h>
19
20struct sdhci_host_next {
21 unsigned int sg_count;
22 s32 cookie;
23};
24
25struct sdhci_host {
26 /* Data set by hardware interface driver */
27 const char *hw_name; /* Hardware bus name */
28
29 unsigned int quirks; /* Deviations from spec. */
30
31/* Controller doesn't honor resets unless we touch the clock register */
32#define SDHCI_QUIRK_CLOCK_BEFORE_RESET (1<<0)
33/* Controller has bad caps bits, but really supports DMA */
34#define SDHCI_QUIRK_FORCE_DMA (1<<1)
35/* Controller doesn't like to be reset when there is no card inserted. */
36#define SDHCI_QUIRK_NO_CARD_NO_RESET (1<<2)
37/* Controller doesn't like clearing the power reg before a change */
38#define SDHCI_QUIRK_SINGLE_POWER_WRITE (1<<3)
39/* Controller has flaky internal state so reset it on each ios change */
40#define SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS (1<<4)
41/* Controller has an unusable DMA engine */
42#define SDHCI_QUIRK_BROKEN_DMA (1<<5)
43/* Controller has an unusable ADMA engine */
44#define SDHCI_QUIRK_BROKEN_ADMA (1<<6)
45/* Controller can only DMA from 32-bit aligned addresses */
46#define SDHCI_QUIRK_32BIT_DMA_ADDR (1<<7)
47/* Controller can only DMA chunk sizes that are a multiple of 32 bits */
48#define SDHCI_QUIRK_32BIT_DMA_SIZE (1<<8)
49/* Controller can only ADMA chunks that are a multiple of 32 bits */
50#define SDHCI_QUIRK_32BIT_ADMA_SIZE (1<<9)
51/* Controller needs to be reset after each request to stay stable */
52#define SDHCI_QUIRK_RESET_AFTER_REQUEST (1<<10)
53/* Controller needs voltage and power writes to happen separately */
54#define SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER (1<<11)
55/* Controller provides an incorrect timeout value for transfers */
56#define SDHCI_QUIRK_BROKEN_TIMEOUT_VAL (1<<12)
57/* Controller has an issue with buffer bits for small transfers */
58#define SDHCI_QUIRK_BROKEN_SMALL_PIO (1<<13)
59/* Controller does not provide transfer-complete interrupt when not busy */
60#define SDHCI_QUIRK_NO_BUSY_IRQ (1<<14)
61/* Controller has unreliable card detection */
62#define SDHCI_QUIRK_BROKEN_CARD_DETECTION (1<<15)
63/* Controller reports inverted write-protect state */
64#define SDHCI_QUIRK_INVERTED_WRITE_PROTECT (1<<16)
65/* Controller does not like fast PIO transfers */
66#define SDHCI_QUIRK_PIO_NEEDS_DELAY (1<<18)
67/* Controller has to be forced to use block size of 2048 bytes */
68#define SDHCI_QUIRK_FORCE_BLK_SZ_2048 (1<<20)
69/* Controller cannot do multi-block transfers */
70#define SDHCI_QUIRK_NO_MULTIBLOCK (1<<21)
71/* Controller can only handle 1-bit data transfers */
72#define SDHCI_QUIRK_FORCE_1_BIT_DATA (1<<22)
73/* Controller needs 10ms delay between applying power and clock */
74#define SDHCI_QUIRK_DELAY_AFTER_POWER (1<<23)
75/* Controller uses SDCLK instead of TMCLK for data timeouts */
76#define SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK (1<<24)
77/* Controller reports wrong base clock capability */
78#define SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN (1<<25)
79/* Controller cannot support End Attribute in NOP ADMA descriptor */
80#define SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC (1<<26)
81/* Controller is missing device caps. Use caps provided by host */
82#define SDHCI_QUIRK_MISSING_CAPS (1<<27)
83/* Controller uses Auto CMD12 command to stop the transfer */
84#define SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12 (1<<28)
85/* Controller doesn't have HISPD bit field in HI-SPEED SD card */
86#define SDHCI_QUIRK_NO_HISPD_BIT (1<<29)
87/* Controller treats ADMA descriptors with length 0000h incorrectly */
88#define SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC (1<<30)
89/* The read-only detection via SDHCI_PRESENT_STATE register is unstable */
90#define SDHCI_QUIRK_UNSTABLE_RO_DETECT (1<<31)
91
92 unsigned int quirks2; /* More deviations from spec. */
93
94#define SDHCI_QUIRK2_HOST_OFF_CARD_ON (1<<0)
95#define SDHCI_QUIRK2_HOST_NO_CMD23 (1<<1)
96/* The system physically doesn't support 1.8v, even if the host does */
97#define SDHCI_QUIRK2_NO_1_8_V (1<<2)
98#define SDHCI_QUIRK2_PRESET_VALUE_BROKEN (1<<3)
99#define SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON (1<<4)
100/* Controller has a non-standard host control register */
101#define SDHCI_QUIRK2_BROKEN_HOST_CONTROL (1<<5)
102/* Controller does not support HS200 */
103#define SDHCI_QUIRK2_BROKEN_HS200 (1<<6)
104/* Controller does not support DDR50 */
105#define SDHCI_QUIRK2_BROKEN_DDR50 (1<<7)
106/* Stop command (CMD12) can set Transfer Complete when not using MMC_RSP_BUSY */
107#define SDHCI_QUIRK2_STOP_WITH_TC (1<<8)
108/* Controller does not support 64-bit DMA */
109#define SDHCI_QUIRK2_BROKEN_64_BIT_DMA (1<<9)
110/* need clear transfer mode register before send cmd */
111#define SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD (1<<10)
112/* Capability register bit-63 indicates HS400 support */
113#define SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 (1<<11)
114/* forced tuned clock */
115#define SDHCI_QUIRK2_TUNING_WORK_AROUND (1<<12)
116/* disable the block count for single block transactions */
117#define SDHCI_QUIRK2_SUPPORT_SINGLE (1<<13)
118
119 int irq; /* Device IRQ */
120 void __iomem *ioaddr; /* Mapped address */
121
122 const struct sdhci_ops *ops; /* Low level hw interface */
123
124 /* Internal data */
125 struct mmc_host *mmc; /* MMC structure */
126 u64 dma_mask; /* custom DMA mask */
127
128#if defined(CONFIG_LEDS_CLASS) || defined(CONFIG_LEDS_CLASS_MODULE)
129 struct led_classdev led; /* LED control */
130 char led_name[32];
131#endif
132
133 spinlock_t lock; /* Mutex */
134
135 int flags; /* Host attributes */
136#define SDHCI_USE_SDMA (1<<0) /* Host is SDMA capable */
137#define SDHCI_USE_ADMA (1<<1) /* Host is ADMA capable */
138#define SDHCI_REQ_USE_DMA (1<<2) /* Use DMA for this req. */
139#define SDHCI_DEVICE_DEAD (1<<3) /* Device unresponsive */
140#define SDHCI_SDR50_NEEDS_TUNING (1<<4) /* SDR50 needs tuning */
141#define SDHCI_NEEDS_RETUNING (1<<5) /* Host needs retuning */
142#define SDHCI_AUTO_CMD12 (1<<6) /* Auto CMD12 support */
143#define SDHCI_AUTO_CMD23 (1<<7) /* Auto CMD23 support */
144#define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */
145#define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
146#define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
147#define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
148#define SDHCI_USE_64_BIT_DMA (1<<12) /* Use 64-bit DMA */
149#define SDHCI_HS400_TUNING (1<<13) /* Tuning for HS400 */
150
151 unsigned int version; /* SDHCI spec. version */
152
153 unsigned int max_clk; /* Max possible freq (MHz) */
154 unsigned int timeout_clk; /* Timeout freq (KHz) */
155 unsigned int clk_mul; /* Clock Muliplier value */
156
157 unsigned int clock; /* Current clock (MHz) */
158 u8 pwr; /* Current voltage */
159
160 bool runtime_suspended; /* Host is runtime suspended */
161 bool bus_on; /* Bus power prevents runtime suspend */
162 bool preset_enabled; /* Preset is enabled */
163
164 struct mmc_request *mrq; /* Current request */
165 struct mmc_command *cmd; /* Current command */
166 struct mmc_data *data; /* Current data request */
167 unsigned int data_early:1; /* Data finished before cmd */
168 unsigned int busy_handle:1; /* Handling the order of Busy-end */
169
170 struct sg_mapping_iter sg_miter; /* SG state for PIO */
171 unsigned int blocks; /* remaining PIO blocks */
172
173 int sg_count; /* Mapped sg entries */
174
175 void *adma_table; /* ADMA descriptor table */
176 void *align_buffer; /* Bounce buffer */
177
178 size_t adma_table_sz; /* ADMA descriptor table size */
179 size_t align_buffer_sz; /* Bounce buffer size */
180
181 dma_addr_t adma_addr; /* Mapped ADMA descr. table */
182 dma_addr_t align_addr; /* Mapped bounce buffer */
183
184 unsigned int desc_sz; /* ADMA descriptor size */
185 unsigned int align_sz; /* ADMA alignment */
186 unsigned int align_mask; /* ADMA alignment mask */
187
188 struct tasklet_struct finish_tasklet; /* Tasklet structures */
189
190 struct timer_list timer; /* Timer for timeouts */
191
192 u32 caps; /* Alternative CAPABILITY_0 */
193 u32 caps1; /* Alternative CAPABILITY_1 */
194
195 unsigned int ocr_avail_sdio; /* OCR bit masks */
196 unsigned int ocr_avail_sd;
197 unsigned int ocr_avail_mmc;
198 u32 ocr_mask; /* available voltages */
199
200 unsigned timing; /* Current timing */
201
202 u32 thread_isr;
203
204 /* cached registers */
205 u32 ier;
206
207 wait_queue_head_t buf_ready_int; /* Waitqueue for Buffer Read Ready interrupt */
208 unsigned int tuning_done; /* Condition flag set when CMD19 succeeds */
209
210 unsigned int tuning_count; /* Timer count for re-tuning */
211 unsigned int tuning_mode; /* Re-tuning mode supported by host */
212#define SDHCI_TUNING_MODE_1 0
213 struct timer_list tuning_timer; /* Timer for tuning */
214
215 struct sdhci_host_next next_data;
216 unsigned long private[0] ____cacheline_aligned;
217};
218#endif /* LINUX_MMC_SDHCI_H */
diff --git a/include/linux/platform_data/hsmmc-omap.h b/include/linux/platform_data/hsmmc-omap.h
index 67bbcf0785f6..8e981be2e2c2 100644
--- a/include/linux/platform_data/hsmmc-omap.h
+++ b/include/linux/platform_data/hsmmc-omap.h
@@ -55,9 +55,6 @@ struct omap_hsmmc_platform_data {
55 u32 caps; /* Used for the MMC driver on 2430 and later */ 55 u32 caps; /* Used for the MMC driver on 2430 and later */
56 u32 pm_caps; /* PM capabilities of the mmc */ 56 u32 pm_caps; /* PM capabilities of the mmc */
57 57
58 /* switch pin can be for card detect (default) or card cover */
59 unsigned cover:1;
60
61 /* use the internal clock */ 58 /* use the internal clock */
62 unsigned internal_clock:1; 59 unsigned internal_clock:1;
63 60
@@ -73,7 +70,8 @@ struct omap_hsmmc_platform_data {
73#define HSMMC_HAS_HSPE_SUPPORT (1 << 2) 70#define HSMMC_HAS_HSPE_SUPPORT (1 << 2)
74 unsigned features; 71 unsigned features;
75 72
76 int switch_pin; /* gpio (card detect) */ 73 int gpio_cd; /* gpio (card detect) */
74 int gpio_cod; /* gpio (cover detect) */
77 int gpio_wp; /* gpio (write protect) */ 75 int gpio_wp; /* gpio (write protect) */
78 76
79 int (*set_power)(struct device *dev, int power_on, int vdd); 77 int (*set_power)(struct device *dev, int power_on, int vdd);