1 // SPDX-License-Identifier: GPL-2.0-only
3 * SDHCI Controller driver for TI's OMAP SoCs
5 * Copyright (C) 2017 Texas Instruments
6 * Author: Kishon Vijay Abraham I <kishon@ti.com>
9 #include <linux/delay.h>
10 #include <linux/mmc/mmc.h>
11 #include <linux/mmc/slot-gpio.h>
12 #include <linux/module.h>
14 #include <linux/of_irq.h>
15 #include <linux/platform_device.h>
16 #include <linux/pm_runtime.h>
17 #include <linux/pm_wakeirq.h>
18 #include <linux/regulator/consumer.h>
19 #include <linux/pinctrl/consumer.h>
20 #include <linux/sys_soc.h>
21 #include <linux/thermal.h>
23 #include "sdhci-pltfm.h"
26 * Note that the register offsets used here are from omap_regs
27 * base which is 0x100 for omap4 and later, and 0 for omap3 and
30 #define SDHCI_OMAP_SYSCONFIG 0x10
32 #define SDHCI_OMAP_CON 0x2c
33 #define CON_DW8 BIT(5)
34 #define CON_DMA_MASTER BIT(20)
35 #define CON_DDR BIT(19)
36 #define CON_CLKEXTFREE BIT(16)
37 #define CON_PADEN BIT(15)
38 #define CON_CTPL BIT(11)
39 #define CON_INIT BIT(1)
42 #define SDHCI_OMAP_DLL 0x34
43 #define DLL_SWT BIT(20)
44 #define DLL_FORCE_SR_C_SHIFT 13
45 #define DLL_FORCE_SR_C_MASK (0x7f << DLL_FORCE_SR_C_SHIFT)
46 #define DLL_FORCE_VALUE BIT(12)
47 #define DLL_CALIB BIT(1)
49 #define SDHCI_OMAP_CMD 0x10c
51 #define SDHCI_OMAP_PSTATE 0x124
52 #define PSTATE_DLEV_DAT0 BIT(20)
53 #define PSTATE_DATI BIT(1)
55 #define SDHCI_OMAP_HCTL 0x128
56 #define HCTL_SDBP BIT(8)
57 #define HCTL_SDVS_SHIFT 9
58 #define HCTL_SDVS_MASK (0x7 << HCTL_SDVS_SHIFT)
59 #define HCTL_SDVS_33 (0x7 << HCTL_SDVS_SHIFT)
60 #define HCTL_SDVS_30 (0x6 << HCTL_SDVS_SHIFT)
61 #define HCTL_SDVS_18 (0x5 << HCTL_SDVS_SHIFT)
63 #define SDHCI_OMAP_SYSCTL 0x12c
64 #define SYSCTL_CEN BIT(2)
65 #define SYSCTL_CLKD_SHIFT 6
66 #define SYSCTL_CLKD_MASK 0x3ff
68 #define SDHCI_OMAP_STAT 0x130
70 #define SDHCI_OMAP_IE 0x134
71 #define INT_CC_EN BIT(0)
73 #define SDHCI_OMAP_ISE 0x138
75 #define SDHCI_OMAP_AC12 0x13c
76 #define AC12_V1V8_SIGEN BIT(19)
77 #define AC12_SCLK_SEL BIT(23)
79 #define SDHCI_OMAP_CAPA 0x140
80 #define CAPA_VS33 BIT(24)
81 #define CAPA_VS30 BIT(25)
82 #define CAPA_VS18 BIT(26)
84 #define SDHCI_OMAP_CAPA2 0x144
85 #define CAPA2_TSDR50 BIT(13)
87 #define SDHCI_OMAP_TIMEOUT 1 /* 1 msec */
89 #define SYSCTL_CLKD_MAX 0x3FF
91 #define IOV_1V8 1800000 /* 180000 uV */
92 #define IOV_3V0 3000000 /* 300000 uV */
93 #define IOV_3V3 3300000 /* 330000 uV */
95 #define MAX_PHASE_DELAY 0x7C
97 /* sdhci-omap controller flags */
98 #define SDHCI_OMAP_REQUIRE_IODELAY BIT(0)
99 #define SDHCI_OMAP_SPECIAL_RESET BIT(1)
101 struct sdhci_omap_data
{
102 int omap_offset
; /* Offset for omap regs from base */
103 u32 offset
; /* Offset for SDHCI regs from base */
107 struct sdhci_omap_host
{
111 struct regulator
*pbias
;
113 struct sdhci_host
*host
;
119 struct pinctrl
*pinctrl
;
120 struct pinctrl_state
**pinctrl_state
;
124 /* Offset for omap specific registers from base */
127 /* Omap specific context save */
136 static void sdhci_omap_start_clock(struct sdhci_omap_host
*omap_host
);
137 static void sdhci_omap_stop_clock(struct sdhci_omap_host
*omap_host
);
139 static inline u32
sdhci_omap_readl(struct sdhci_omap_host
*host
,
142 return readl(host
->base
+ host
->omap_offset
+ offset
);
145 static inline void sdhci_omap_writel(struct sdhci_omap_host
*host
,
146 unsigned int offset
, u32 data
)
148 writel(data
, host
->base
+ host
->omap_offset
+ offset
);
151 static int sdhci_omap_set_pbias(struct sdhci_omap_host
*omap_host
,
152 bool power_on
, unsigned int iov
)
155 struct device
*dev
= omap_host
->dev
;
157 if (IS_ERR(omap_host
->pbias
))
161 ret
= regulator_set_voltage(omap_host
->pbias
, iov
, iov
);
163 dev_err(dev
, "pbias set voltage failed\n");
167 if (omap_host
->pbias_enabled
)
170 ret
= regulator_enable(omap_host
->pbias
);
172 dev_err(dev
, "pbias reg enable fail\n");
176 omap_host
->pbias_enabled
= true;
178 if (!omap_host
->pbias_enabled
)
181 ret
= regulator_disable(omap_host
->pbias
);
183 dev_err(dev
, "pbias reg disable fail\n");
186 omap_host
->pbias_enabled
= false;
192 static int sdhci_omap_enable_iov(struct sdhci_omap_host
*omap_host
,
193 unsigned int iov_pbias
)
196 struct sdhci_host
*host
= omap_host
->host
;
197 struct mmc_host
*mmc
= host
->mmc
;
199 ret
= sdhci_omap_set_pbias(omap_host
, false, 0);
203 if (!IS_ERR(mmc
->supply
.vqmmc
)) {
204 /* Pick the right voltage to allow 3.0V for 3.3V nominal PBIAS */
205 ret
= mmc_regulator_set_vqmmc(mmc
, &mmc
->ios
);
207 dev_err(mmc_dev(mmc
), "vqmmc set voltage failed\n");
212 ret
= sdhci_omap_set_pbias(omap_host
, true, iov_pbias
);
219 static void sdhci_omap_conf_bus_power(struct sdhci_omap_host
*omap_host
,
220 unsigned char signal_voltage
)
225 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_HCTL
);
226 reg
&= ~HCTL_SDVS_MASK
;
228 switch (signal_voltage
) {
229 case MMC_SIGNAL_VOLTAGE_330
:
230 capa
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CAPA
);
231 if (capa
& CAPA_VS33
)
233 else if (capa
& CAPA_VS30
)
236 dev_warn(omap_host
->dev
, "misconfigured CAPA: %08x\n",
239 case MMC_SIGNAL_VOLTAGE_180
:
245 sdhci_omap_writel(omap_host
, SDHCI_OMAP_HCTL
, reg
);
248 sdhci_omap_writel(omap_host
, SDHCI_OMAP_HCTL
, reg
);
251 timeout
= ktime_add_ms(ktime_get(), SDHCI_OMAP_TIMEOUT
);
253 bool timedout
= ktime_after(ktime_get(), timeout
);
255 if (sdhci_omap_readl(omap_host
, SDHCI_OMAP_HCTL
) & HCTL_SDBP
)
257 if (WARN_ON(timedout
))
263 static void sdhci_omap_enable_sdio_irq(struct mmc_host
*mmc
, int enable
)
265 struct sdhci_host
*host
= mmc_priv(mmc
);
266 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
267 struct sdhci_omap_host
*omap_host
= sdhci_pltfm_priv(pltfm_host
);
270 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CON
);
272 reg
|= (CON_CTPL
| CON_CLKEXTFREE
);
274 reg
&= ~(CON_CTPL
| CON_CLKEXTFREE
);
275 sdhci_omap_writel(omap_host
, SDHCI_OMAP_CON
, reg
);
277 sdhci_enable_sdio_irq(mmc
, enable
);
280 static inline void sdhci_omap_set_dll(struct sdhci_omap_host
*omap_host
,
286 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_DLL
);
287 reg
|= DLL_FORCE_VALUE
;
288 reg
&= ~DLL_FORCE_SR_C_MASK
;
289 reg
|= (count
<< DLL_FORCE_SR_C_SHIFT
);
290 sdhci_omap_writel(omap_host
, SDHCI_OMAP_DLL
, reg
);
293 sdhci_omap_writel(omap_host
, SDHCI_OMAP_DLL
, reg
);
294 for (i
= 0; i
< 1000; i
++) {
295 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_DLL
);
300 sdhci_omap_writel(omap_host
, SDHCI_OMAP_DLL
, reg
);
303 static void sdhci_omap_disable_tuning(struct sdhci_omap_host
*omap_host
)
307 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_AC12
);
308 reg
&= ~AC12_SCLK_SEL
;
309 sdhci_omap_writel(omap_host
, SDHCI_OMAP_AC12
, reg
);
311 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_DLL
);
312 reg
&= ~(DLL_FORCE_VALUE
| DLL_SWT
);
313 sdhci_omap_writel(omap_host
, SDHCI_OMAP_DLL
, reg
);
316 static int sdhci_omap_execute_tuning(struct mmc_host
*mmc
, u32 opcode
)
318 struct sdhci_host
*host
= mmc_priv(mmc
);
319 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
320 struct sdhci_omap_host
*omap_host
= sdhci_pltfm_priv(pltfm_host
);
321 struct thermal_zone_device
*thermal_dev
;
322 struct device
*dev
= omap_host
->dev
;
323 struct mmc_ios
*ios
= &mmc
->ios
;
324 u32 start_window
= 0, max_window
= 0;
325 bool single_point_failure
= false;
326 bool dcrc_was_enabled
= false;
327 u8 cur_match
, prev_match
= 0;
328 u32 length
= 0, max_len
= 0;
335 /* clock tuning is not needed for upto 52MHz */
336 if (ios
->clock
<= 52000000)
339 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CAPA2
);
340 if (ios
->timing
== MMC_TIMING_UHS_SDR50
&& !(reg
& CAPA2_TSDR50
))
343 thermal_dev
= thermal_zone_get_zone_by_name("cpu_thermal");
344 if (IS_ERR(thermal_dev
)) {
345 dev_err(dev
, "Unable to get thermal zone for tuning\n");
346 return PTR_ERR(thermal_dev
);
349 ret
= thermal_zone_get_temp(thermal_dev
, &temperature
);
353 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_DLL
);
355 sdhci_omap_writel(omap_host
, SDHCI_OMAP_DLL
, reg
);
358 * OMAP5/DRA74X/DRA72x Errata i802:
359 * DCRC error interrupts (MMCHS_STAT[21] DCRC=0x1) can occur
360 * during the tuning procedure. So disable it during the
363 if (host
->ier
& SDHCI_INT_DATA_CRC
) {
364 host
->ier
&= ~SDHCI_INT_DATA_CRC
;
365 dcrc_was_enabled
= true;
368 omap_host
->is_tuning
= true;
371 * Stage 1: Search for a maximum pass window ignoring any
372 * single point failures. If the tuning value ends up
373 * near it, move away from it in stage 2 below
375 while (phase_delay
<= MAX_PHASE_DELAY
) {
376 sdhci_omap_set_dll(omap_host
, phase_delay
);
378 cur_match
= !mmc_send_tuning(mmc
, opcode
, NULL
);
382 } else if (single_point_failure
) {
383 /* ignore single point failure */
386 start_window
= phase_delay
;
390 single_point_failure
= prev_match
;
393 if (length
> max_len
) {
394 max_window
= start_window
;
398 prev_match
= cur_match
;
403 dev_err(dev
, "Unable to find match\n");
409 * Assign tuning value as a ratio of maximum pass window based
412 if (temperature
< -20000)
413 phase_delay
= min(max_window
+ 4 * (max_len
- 1) - 24,
415 DIV_ROUND_UP(13 * max_len
, 16) * 4);
416 else if (temperature
< 20000)
417 phase_delay
= max_window
+ DIV_ROUND_UP(9 * max_len
, 16) * 4;
418 else if (temperature
< 40000)
419 phase_delay
= max_window
+ DIV_ROUND_UP(8 * max_len
, 16) * 4;
420 else if (temperature
< 70000)
421 phase_delay
= max_window
+ DIV_ROUND_UP(7 * max_len
, 16) * 4;
422 else if (temperature
< 90000)
423 phase_delay
= max_window
+ DIV_ROUND_UP(5 * max_len
, 16) * 4;
424 else if (temperature
< 120000)
425 phase_delay
= max_window
+ DIV_ROUND_UP(4 * max_len
, 16) * 4;
427 phase_delay
= max_window
+ DIV_ROUND_UP(3 * max_len
, 16) * 4;
430 * Stage 2: Search for a single point failure near the chosen tuning
431 * value in two steps. First in the +3 to +10 range and then in the
432 * +2 to -10 range. If found, move away from it in the appropriate
433 * direction by the appropriate amount depending on the temperature.
435 for (i
= 3; i
<= 10; i
++) {
436 sdhci_omap_set_dll(omap_host
, phase_delay
+ i
);
438 if (mmc_send_tuning(mmc
, opcode
, NULL
)) {
439 if (temperature
< 10000)
440 phase_delay
+= i
+ 6;
441 else if (temperature
< 20000)
442 phase_delay
+= i
- 12;
443 else if (temperature
< 70000)
444 phase_delay
+= i
- 8;
446 phase_delay
+= i
- 6;
448 goto single_failure_found
;
452 for (i
= 2; i
>= -10; i
--) {
453 sdhci_omap_set_dll(omap_host
, phase_delay
+ i
);
455 if (mmc_send_tuning(mmc
, opcode
, NULL
)) {
456 if (temperature
< 10000)
457 phase_delay
+= i
+ 12;
458 else if (temperature
< 20000)
459 phase_delay
+= i
+ 8;
460 else if (temperature
< 70000)
461 phase_delay
+= i
+ 8;
462 else if (temperature
< 90000)
463 phase_delay
+= i
+ 10;
465 phase_delay
+= i
+ 12;
467 goto single_failure_found
;
471 single_failure_found
:
472 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_AC12
);
473 if (!(reg
& AC12_SCLK_SEL
)) {
478 sdhci_omap_set_dll(omap_host
, phase_delay
);
480 omap_host
->is_tuning
= false;
485 omap_host
->is_tuning
= false;
486 dev_err(dev
, "Tuning failed\n");
487 sdhci_omap_disable_tuning(omap_host
);
490 sdhci_reset(host
, SDHCI_RESET_CMD
| SDHCI_RESET_DATA
);
491 /* Reenable forbidden interrupt */
492 if (dcrc_was_enabled
)
493 host
->ier
|= SDHCI_INT_DATA_CRC
;
494 sdhci_writel(host
, host
->ier
, SDHCI_INT_ENABLE
);
495 sdhci_writel(host
, host
->ier
, SDHCI_SIGNAL_ENABLE
);
499 static int sdhci_omap_card_busy(struct mmc_host
*mmc
)
503 struct sdhci_host
*host
= mmc_priv(mmc
);
504 struct sdhci_pltfm_host
*pltfm_host
;
505 struct sdhci_omap_host
*omap_host
;
508 pltfm_host
= sdhci_priv(host
);
509 omap_host
= sdhci_pltfm_priv(pltfm_host
);
511 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CON
);
512 ac12
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_AC12
);
513 reg
&= ~CON_CLKEXTFREE
;
514 if (ac12
& AC12_V1V8_SIGEN
)
515 reg
|= CON_CLKEXTFREE
;
517 sdhci_omap_writel(omap_host
, SDHCI_OMAP_CON
, reg
);
519 disable_irq(host
->irq
);
520 ier
|= SDHCI_INT_CARD_INT
;
521 sdhci_writel(host
, ier
, SDHCI_INT_ENABLE
);
522 sdhci_writel(host
, ier
, SDHCI_SIGNAL_ENABLE
);
525 * Delay is required for PSTATE to correctly reflect
526 * DLEV/CLEV values after PADEN is set.
528 usleep_range(50, 100);
529 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_PSTATE
);
530 if ((reg
& PSTATE_DATI
) || !(reg
& PSTATE_DLEV_DAT0
))
533 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CON
);
534 reg
&= ~(CON_CLKEXTFREE
| CON_PADEN
);
535 sdhci_omap_writel(omap_host
, SDHCI_OMAP_CON
, reg
);
537 sdhci_writel(host
, host
->ier
, SDHCI_INT_ENABLE
);
538 sdhci_writel(host
, host
->ier
, SDHCI_SIGNAL_ENABLE
);
539 enable_irq(host
->irq
);
544 static int sdhci_omap_start_signal_voltage_switch(struct mmc_host
*mmc
,
550 struct sdhci_host
*host
= mmc_priv(mmc
);
551 struct sdhci_pltfm_host
*pltfm_host
;
552 struct sdhci_omap_host
*omap_host
;
555 pltfm_host
= sdhci_priv(host
);
556 omap_host
= sdhci_pltfm_priv(pltfm_host
);
557 dev
= omap_host
->dev
;
559 if (ios
->signal_voltage
== MMC_SIGNAL_VOLTAGE_330
) {
560 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CAPA
);
561 if (!(reg
& (CAPA_VS30
| CAPA_VS33
)))
569 sdhci_omap_conf_bus_power(omap_host
, ios
->signal_voltage
);
571 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_AC12
);
572 reg
&= ~AC12_V1V8_SIGEN
;
573 sdhci_omap_writel(omap_host
, SDHCI_OMAP_AC12
, reg
);
575 } else if (ios
->signal_voltage
== MMC_SIGNAL_VOLTAGE_180
) {
576 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CAPA
);
577 if (!(reg
& CAPA_VS18
))
582 sdhci_omap_conf_bus_power(omap_host
, ios
->signal_voltage
);
584 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_AC12
);
585 reg
|= AC12_V1V8_SIGEN
;
586 sdhci_omap_writel(omap_host
, SDHCI_OMAP_AC12
, reg
);
591 ret
= sdhci_omap_enable_iov(omap_host
, iov
);
593 dev_err(dev
, "failed to switch IO voltage to %dmV\n", iov
);
597 dev_dbg(dev
, "IO voltage switched to %dmV\n", iov
);
601 static void sdhci_omap_set_timing(struct sdhci_omap_host
*omap_host
, u8 timing
)
604 struct pinctrl_state
*pinctrl_state
;
605 struct device
*dev
= omap_host
->dev
;
607 if (!(omap_host
->flags
& SDHCI_OMAP_REQUIRE_IODELAY
))
610 if (omap_host
->timing
== timing
)
613 sdhci_omap_stop_clock(omap_host
);
615 pinctrl_state
= omap_host
->pinctrl_state
[timing
];
616 ret
= pinctrl_select_state(omap_host
->pinctrl
, pinctrl_state
);
618 dev_err(dev
, "failed to select pinctrl state\n");
622 sdhci_omap_start_clock(omap_host
);
623 omap_host
->timing
= timing
;
626 static void sdhci_omap_set_power_mode(struct sdhci_omap_host
*omap_host
,
629 if (omap_host
->bus_mode
== MMC_POWER_OFF
)
630 sdhci_omap_disable_tuning(omap_host
);
631 omap_host
->power_mode
= power_mode
;
634 static void sdhci_omap_set_bus_mode(struct sdhci_omap_host
*omap_host
,
639 if (omap_host
->bus_mode
== mode
)
642 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CON
);
643 if (mode
== MMC_BUSMODE_OPENDRAIN
)
647 sdhci_omap_writel(omap_host
, SDHCI_OMAP_CON
, reg
);
649 omap_host
->bus_mode
= mode
;
652 static void sdhci_omap_set_ios(struct mmc_host
*mmc
, struct mmc_ios
*ios
)
654 struct sdhci_host
*host
= mmc_priv(mmc
);
655 struct sdhci_pltfm_host
*pltfm_host
;
656 struct sdhci_omap_host
*omap_host
;
658 pltfm_host
= sdhci_priv(host
);
659 omap_host
= sdhci_pltfm_priv(pltfm_host
);
661 sdhci_omap_set_bus_mode(omap_host
, ios
->bus_mode
);
662 sdhci_omap_set_timing(omap_host
, ios
->timing
);
663 sdhci_set_ios(mmc
, ios
);
664 sdhci_omap_set_power_mode(omap_host
, ios
->power_mode
);
667 static u16
sdhci_omap_calc_divisor(struct sdhci_pltfm_host
*host
,
672 dsor
= DIV_ROUND_UP(clk_get_rate(host
->clk
), clock
);
673 if (dsor
> SYSCTL_CLKD_MAX
)
674 dsor
= SYSCTL_CLKD_MAX
;
679 static void sdhci_omap_start_clock(struct sdhci_omap_host
*omap_host
)
683 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_SYSCTL
);
685 sdhci_omap_writel(omap_host
, SDHCI_OMAP_SYSCTL
, reg
);
688 static void sdhci_omap_stop_clock(struct sdhci_omap_host
*omap_host
)
692 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_SYSCTL
);
694 sdhci_omap_writel(omap_host
, SDHCI_OMAP_SYSCTL
, reg
);
697 static void sdhci_omap_set_clock(struct sdhci_host
*host
, unsigned int clock
)
699 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
700 struct sdhci_omap_host
*omap_host
= sdhci_pltfm_priv(pltfm_host
);
701 unsigned long clkdiv
;
703 sdhci_omap_stop_clock(omap_host
);
708 clkdiv
= sdhci_omap_calc_divisor(pltfm_host
, clock
);
709 clkdiv
= (clkdiv
& SYSCTL_CLKD_MASK
) << SYSCTL_CLKD_SHIFT
;
710 sdhci_enable_clk(host
, clkdiv
);
712 sdhci_omap_start_clock(omap_host
);
715 static void sdhci_omap_set_power(struct sdhci_host
*host
, unsigned char mode
,
718 struct mmc_host
*mmc
= host
->mmc
;
720 if (!IS_ERR(mmc
->supply
.vmmc
))
721 mmc_regulator_set_ocr(mmc
, mmc
->supply
.vmmc
, vdd
);
725 * MMCHS_HL_HWINFO has the MADMA_EN bit set if the controller instance
726 * is connected to L3 interconnect and is bus master capable. Note that
727 * the MMCHS_HL_HWINFO register is in the module registers before the
728 * omap registers and sdhci registers. The offset can vary for omap
729 * registers depending on the SoC. Do not use sdhci_omap_readl() here.
731 static bool sdhci_omap_has_adma(struct sdhci_omap_host
*omap_host
, int offset
)
733 /* MMCHS_HL_HWINFO register is only available on omap4 and later */
737 return readl(omap_host
->base
+ 4) & 1;
740 static int sdhci_omap_enable_dma(struct sdhci_host
*host
)
743 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
744 struct sdhci_omap_host
*omap_host
= sdhci_pltfm_priv(pltfm_host
);
746 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CON
);
747 reg
&= ~CON_DMA_MASTER
;
748 /* Switch to DMA slave mode when using external DMA */
749 if (!host
->use_external_dma
)
750 reg
|= CON_DMA_MASTER
;
752 sdhci_omap_writel(omap_host
, SDHCI_OMAP_CON
, reg
);
757 static unsigned int sdhci_omap_get_min_clock(struct sdhci_host
*host
)
759 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
761 return clk_get_rate(pltfm_host
->clk
) / SYSCTL_CLKD_MAX
;
764 static void sdhci_omap_set_bus_width(struct sdhci_host
*host
, int width
)
766 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
767 struct sdhci_omap_host
*omap_host
= sdhci_pltfm_priv(pltfm_host
);
770 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CON
);
771 if (width
== MMC_BUS_WIDTH_8
)
775 sdhci_omap_writel(omap_host
, SDHCI_OMAP_CON
, reg
);
777 sdhci_set_bus_width(host
, width
);
780 static void sdhci_omap_init_74_clocks(struct sdhci_host
*host
, u8 power_mode
)
784 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
785 struct sdhci_omap_host
*omap_host
= sdhci_pltfm_priv(pltfm_host
);
787 if (omap_host
->power_mode
== power_mode
)
790 if (power_mode
!= MMC_POWER_ON
)
793 disable_irq(host
->irq
);
795 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CON
);
797 sdhci_omap_writel(omap_host
, SDHCI_OMAP_CON
, reg
);
798 sdhci_omap_writel(omap_host
, SDHCI_OMAP_CMD
, 0x0);
801 timeout
= ktime_add_ms(ktime_get(), SDHCI_OMAP_TIMEOUT
);
803 bool timedout
= ktime_after(ktime_get(), timeout
);
805 if (sdhci_omap_readl(omap_host
, SDHCI_OMAP_STAT
) & INT_CC_EN
)
807 if (WARN_ON(timedout
))
812 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CON
);
814 sdhci_omap_writel(omap_host
, SDHCI_OMAP_CON
, reg
);
815 sdhci_omap_writel(omap_host
, SDHCI_OMAP_STAT
, INT_CC_EN
);
817 enable_irq(host
->irq
);
820 static void sdhci_omap_set_uhs_signaling(struct sdhci_host
*host
,
824 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
825 struct sdhci_omap_host
*omap_host
= sdhci_pltfm_priv(pltfm_host
);
827 sdhci_omap_stop_clock(omap_host
);
829 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CON
);
830 if (timing
== MMC_TIMING_UHS_DDR50
|| timing
== MMC_TIMING_MMC_DDR52
)
834 sdhci_omap_writel(omap_host
, SDHCI_OMAP_CON
, reg
);
836 sdhci_set_uhs_signaling(host
, timing
);
837 sdhci_omap_start_clock(omap_host
);
840 #define MMC_TIMEOUT_US 20000 /* 20000 micro Sec */
841 static void sdhci_omap_reset(struct sdhci_host
*host
, u8 mask
)
843 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
844 struct sdhci_omap_host
*omap_host
= sdhci_pltfm_priv(pltfm_host
);
845 unsigned long limit
= MMC_TIMEOUT_US
;
849 /* Save target module sysconfig configured by SoC PM layer */
850 if (mask
& SDHCI_RESET_ALL
)
851 sysc
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_SYSCONFIG
);
853 /* Don't reset data lines during tuning operation */
854 if (omap_host
->is_tuning
)
855 mask
&= ~SDHCI_RESET_DATA
;
857 if (omap_host
->flags
& SDHCI_OMAP_SPECIAL_RESET
) {
858 sdhci_writeb(host
, mask
, SDHCI_SOFTWARE_RESET
);
859 while ((!(sdhci_readb(host
, SDHCI_SOFTWARE_RESET
) & mask
)) &&
863 while ((sdhci_readb(host
, SDHCI_SOFTWARE_RESET
) & mask
) &&
867 if (sdhci_readb(host
, SDHCI_SOFTWARE_RESET
) & mask
)
868 dev_err(mmc_dev(host
->mmc
),
869 "Timeout waiting on controller reset in %s\n",
875 sdhci_reset(host
, mask
);
878 if (mask
& SDHCI_RESET_ALL
)
879 sdhci_omap_writel(omap_host
, SDHCI_OMAP_SYSCONFIG
, sysc
);
882 #define CMD_ERR_MASK (SDHCI_INT_CRC | SDHCI_INT_END_BIT | SDHCI_INT_INDEX |\
884 #define CMD_MASK (CMD_ERR_MASK | SDHCI_INT_RESPONSE)
886 static u32
sdhci_omap_irq(struct sdhci_host
*host
, u32 intmask
)
888 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
889 struct sdhci_omap_host
*omap_host
= sdhci_pltfm_priv(pltfm_host
);
891 if (omap_host
->is_tuning
&& host
->cmd
&& !host
->data_early
&&
892 (intmask
& CMD_ERR_MASK
)) {
895 * Since we are not resetting data lines during tuning
896 * operation, data error or data complete interrupts
897 * might still arrive. Mark this request as a failure
898 * but still wait for the data interrupt
900 if (intmask
& SDHCI_INT_TIMEOUT
)
901 host
->cmd
->error
= -ETIMEDOUT
;
903 host
->cmd
->error
= -EILSEQ
;
908 * Sometimes command error interrupts and command complete
909 * interrupt will arrive together. Clear all command related
912 sdhci_writel(host
, intmask
& CMD_MASK
, SDHCI_INT_STATUS
);
913 intmask
&= ~CMD_MASK
;
919 static void sdhci_omap_set_timeout(struct sdhci_host
*host
,
920 struct mmc_command
*cmd
)
922 if (cmd
->opcode
== MMC_ERASE
)
923 sdhci_set_data_timeout_irq(host
, false);
925 __sdhci_set_timeout(host
, cmd
);
928 static const struct sdhci_ops sdhci_omap_ops
= {
929 .set_clock
= sdhci_omap_set_clock
,
930 .set_power
= sdhci_omap_set_power
,
931 .enable_dma
= sdhci_omap_enable_dma
,
932 .get_max_clock
= sdhci_pltfm_clk_get_max_clock
,
933 .get_min_clock
= sdhci_omap_get_min_clock
,
934 .set_bus_width
= sdhci_omap_set_bus_width
,
935 .platform_send_init_74_clocks
= sdhci_omap_init_74_clocks
,
936 .reset
= sdhci_omap_reset
,
937 .set_uhs_signaling
= sdhci_omap_set_uhs_signaling
,
938 .irq
= sdhci_omap_irq
,
939 .set_timeout
= sdhci_omap_set_timeout
,
942 static unsigned int sdhci_omap_regulator_get_caps(struct device
*dev
,
945 struct regulator
*reg
;
946 unsigned int caps
= 0;
948 reg
= regulator_get(dev
, name
);
952 if (regulator_is_supported_voltage(reg
, 1700000, 1950000))
953 caps
|= SDHCI_CAN_VDD_180
;
954 if (regulator_is_supported_voltage(reg
, 2700000, 3150000))
955 caps
|= SDHCI_CAN_VDD_300
;
956 if (regulator_is_supported_voltage(reg
, 3150000, 3600000))
957 caps
|= SDHCI_CAN_VDD_330
;
964 static int sdhci_omap_set_capabilities(struct sdhci_host
*host
)
966 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
967 struct sdhci_omap_host
*omap_host
= sdhci_pltfm_priv(pltfm_host
);
968 struct device
*dev
= omap_host
->dev
;
969 const u32 mask
= SDHCI_CAN_VDD_180
| SDHCI_CAN_VDD_300
| SDHCI_CAN_VDD_330
;
970 unsigned int pbias
, vqmmc
, caps
= 0;
973 pbias
= sdhci_omap_regulator_get_caps(dev
, "pbias");
974 vqmmc
= sdhci_omap_regulator_get_caps(dev
, "vqmmc");
975 caps
= pbias
& vqmmc
;
977 if (pbias
!= ~0U && vqmmc
== ~0U)
978 dev_warn(dev
, "vqmmc regulator missing for pbias\n");
979 else if (caps
== ~0U)
983 * Quirk handling to allow 3.0V vqmmc with a valid 3.3V PBIAS. This is
984 * needed for 3.0V ldo9_reg on omap5 at least.
986 if (pbias
!= ~0U && (pbias
& SDHCI_CAN_VDD_330
) &&
987 (vqmmc
& SDHCI_CAN_VDD_300
))
988 caps
|= SDHCI_CAN_VDD_330
;
990 /* voltage capabilities might be set by boot loader, clear it */
991 reg
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CAPA
);
992 reg
&= ~(CAPA_VS18
| CAPA_VS30
| CAPA_VS33
);
994 if (caps
& SDHCI_CAN_VDD_180
)
997 if (caps
& SDHCI_CAN_VDD_300
)
1000 if (caps
& SDHCI_CAN_VDD_330
)
1003 sdhci_omap_writel(omap_host
, SDHCI_OMAP_CAPA
, reg
);
1005 host
->caps
&= ~mask
;
1011 static const struct sdhci_pltfm_data sdhci_omap_pdata
= {
1012 .quirks
= SDHCI_QUIRK_BROKEN_CARD_DETECTION
|
1013 SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK
|
1014 SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN
|
1015 SDHCI_QUIRK_NO_HISPD_BIT
|
1016 SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC
,
1017 .quirks2
= SDHCI_QUIRK2_ACMD23_BROKEN
|
1018 SDHCI_QUIRK2_PRESET_VALUE_BROKEN
|
1019 SDHCI_QUIRK2_RSP_136_HAS_CRC
|
1020 SDHCI_QUIRK2_DISABLE_HW_TIMEOUT
,
1021 .ops
= &sdhci_omap_ops
,
1024 static const struct sdhci_omap_data omap2430_data
= {
1029 static const struct sdhci_omap_data omap3_data
= {
1034 static const struct sdhci_omap_data omap4_data
= {
1035 .omap_offset
= 0x100,
1037 .flags
= SDHCI_OMAP_SPECIAL_RESET
,
1040 static const struct sdhci_omap_data omap5_data
= {
1041 .omap_offset
= 0x100,
1043 .flags
= SDHCI_OMAP_SPECIAL_RESET
,
1046 static const struct sdhci_omap_data k2g_data
= {
1047 .omap_offset
= 0x100,
1051 static const struct sdhci_omap_data am335_data
= {
1052 .omap_offset
= 0x100,
1054 .flags
= SDHCI_OMAP_SPECIAL_RESET
,
1057 static const struct sdhci_omap_data am437_data
= {
1058 .omap_offset
= 0x100,
1060 .flags
= SDHCI_OMAP_SPECIAL_RESET
,
1063 static const struct sdhci_omap_data dra7_data
= {
1064 .omap_offset
= 0x100,
1066 .flags
= SDHCI_OMAP_REQUIRE_IODELAY
,
1069 static const struct of_device_id omap_sdhci_match
[] = {
1070 { .compatible
= "ti,omap2430-sdhci", .data
= &omap2430_data
},
1071 { .compatible
= "ti,omap3-sdhci", .data
= &omap3_data
},
1072 { .compatible
= "ti,omap4-sdhci", .data
= &omap4_data
},
1073 { .compatible
= "ti,omap5-sdhci", .data
= &omap5_data
},
1074 { .compatible
= "ti,dra7-sdhci", .data
= &dra7_data
},
1075 { .compatible
= "ti,k2g-sdhci", .data
= &k2g_data
},
1076 { .compatible
= "ti,am335-sdhci", .data
= &am335_data
},
1077 { .compatible
= "ti,am437-sdhci", .data
= &am437_data
},
1080 MODULE_DEVICE_TABLE(of
, omap_sdhci_match
);
1082 static struct pinctrl_state
1083 *sdhci_omap_iodelay_pinctrl_state(struct sdhci_omap_host
*omap_host
, char *mode
,
1084 u32
*caps
, u32 capmask
)
1086 struct device
*dev
= omap_host
->dev
;
1087 char *version
= omap_host
->version
;
1088 struct pinctrl_state
*pinctrl_state
= ERR_PTR(-ENODEV
);
1091 if (!(*caps
& capmask
))
1095 snprintf(str
, 20, "%s-%s", mode
, version
);
1096 pinctrl_state
= pinctrl_lookup_state(omap_host
->pinctrl
, str
);
1099 if (IS_ERR(pinctrl_state
))
1100 pinctrl_state
= pinctrl_lookup_state(omap_host
->pinctrl
, mode
);
1102 if (IS_ERR(pinctrl_state
)) {
1103 dev_err(dev
, "no pinctrl state for %s mode", mode
);
1108 return pinctrl_state
;
1111 static int sdhci_omap_config_iodelay_pinctrl_state(struct sdhci_omap_host
1114 struct device
*dev
= omap_host
->dev
;
1115 struct sdhci_host
*host
= omap_host
->host
;
1116 struct mmc_host
*mmc
= host
->mmc
;
1117 u32
*caps
= &mmc
->caps
;
1118 u32
*caps2
= &mmc
->caps2
;
1119 struct pinctrl_state
*state
;
1120 struct pinctrl_state
**pinctrl_state
;
1122 if (!(omap_host
->flags
& SDHCI_OMAP_REQUIRE_IODELAY
))
1125 pinctrl_state
= devm_kcalloc(dev
,
1126 MMC_TIMING_MMC_HS200
+ 1,
1127 sizeof(*pinctrl_state
),
1132 omap_host
->pinctrl
= devm_pinctrl_get(omap_host
->dev
);
1133 if (IS_ERR(omap_host
->pinctrl
)) {
1134 dev_err(dev
, "Cannot get pinctrl\n");
1135 return PTR_ERR(omap_host
->pinctrl
);
1138 state
= pinctrl_lookup_state(omap_host
->pinctrl
, "default");
1139 if (IS_ERR(state
)) {
1140 dev_err(dev
, "no pinctrl state for default mode\n");
1141 return PTR_ERR(state
);
1143 pinctrl_state
[MMC_TIMING_LEGACY
] = state
;
1145 state
= sdhci_omap_iodelay_pinctrl_state(omap_host
, "sdr104", caps
,
1146 MMC_CAP_UHS_SDR104
);
1148 pinctrl_state
[MMC_TIMING_UHS_SDR104
] = state
;
1150 state
= sdhci_omap_iodelay_pinctrl_state(omap_host
, "ddr50", caps
,
1153 pinctrl_state
[MMC_TIMING_UHS_DDR50
] = state
;
1155 state
= sdhci_omap_iodelay_pinctrl_state(omap_host
, "sdr50", caps
,
1158 pinctrl_state
[MMC_TIMING_UHS_SDR50
] = state
;
1160 state
= sdhci_omap_iodelay_pinctrl_state(omap_host
, "sdr25", caps
,
1163 pinctrl_state
[MMC_TIMING_UHS_SDR25
] = state
;
1165 state
= sdhci_omap_iodelay_pinctrl_state(omap_host
, "sdr12", caps
,
1168 pinctrl_state
[MMC_TIMING_UHS_SDR12
] = state
;
1170 state
= sdhci_omap_iodelay_pinctrl_state(omap_host
, "ddr_1_8v", caps
,
1172 if (!IS_ERR(state
)) {
1173 pinctrl_state
[MMC_TIMING_MMC_DDR52
] = state
;
1175 state
= sdhci_omap_iodelay_pinctrl_state(omap_host
, "ddr_3_3v",
1179 pinctrl_state
[MMC_TIMING_MMC_DDR52
] = state
;
1182 state
= sdhci_omap_iodelay_pinctrl_state(omap_host
, "hs", caps
,
1183 MMC_CAP_SD_HIGHSPEED
);
1185 pinctrl_state
[MMC_TIMING_SD_HS
] = state
;
1187 state
= sdhci_omap_iodelay_pinctrl_state(omap_host
, "hs", caps
,
1188 MMC_CAP_MMC_HIGHSPEED
);
1190 pinctrl_state
[MMC_TIMING_MMC_HS
] = state
;
1192 state
= sdhci_omap_iodelay_pinctrl_state(omap_host
, "hs200_1_8v", caps2
,
1193 MMC_CAP2_HS200_1_8V_SDR
);
1195 pinctrl_state
[MMC_TIMING_MMC_HS200
] = state
;
1197 omap_host
->pinctrl_state
= pinctrl_state
;
1202 static const struct soc_device_attribute sdhci_omap_soc_devices
[] = {
1204 .machine
= "DRA7[45]*",
1205 .revision
= "ES1.[01]",
1212 static int sdhci_omap_probe(struct platform_device
*pdev
)
1216 struct device
*dev
= &pdev
->dev
;
1217 struct sdhci_host
*host
;
1218 struct sdhci_pltfm_host
*pltfm_host
;
1219 struct sdhci_omap_host
*omap_host
;
1220 struct mmc_host
*mmc
;
1221 const struct sdhci_omap_data
*data
;
1222 const struct soc_device_attribute
*soc
;
1223 struct resource
*regs
;
1225 data
= of_device_get_match_data(&pdev
->dev
);
1227 dev_err(dev
, "no sdhci omap data\n");
1230 offset
= data
->offset
;
1232 regs
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1236 host
= sdhci_pltfm_init(pdev
, &sdhci_omap_pdata
,
1237 sizeof(*omap_host
));
1239 dev_err(dev
, "Failed sdhci_pltfm_init\n");
1240 return PTR_ERR(host
);
1243 pltfm_host
= sdhci_priv(host
);
1244 omap_host
= sdhci_pltfm_priv(pltfm_host
);
1245 omap_host
->host
= host
;
1246 omap_host
->base
= host
->ioaddr
;
1247 omap_host
->dev
= dev
;
1248 omap_host
->power_mode
= MMC_POWER_UNDEFINED
;
1249 omap_host
->timing
= MMC_TIMING_LEGACY
;
1250 omap_host
->flags
= data
->flags
;
1251 omap_host
->omap_offset
= data
->omap_offset
;
1252 omap_host
->con
= -EINVAL
; /* Prevent invalid restore on first resume */
1253 host
->ioaddr
+= offset
;
1254 host
->mapbase
= regs
->start
+ offset
;
1257 sdhci_get_of_property(pdev
);
1258 ret
= mmc_of_parse(mmc
);
1260 goto err_pltfm_free
;
1262 soc
= soc_device_match(sdhci_omap_soc_devices
);
1264 omap_host
->version
= "rev11";
1265 if (!strcmp(dev_name(dev
), "4809c000.mmc"))
1266 mmc
->f_max
= 96000000;
1267 if (!strcmp(dev_name(dev
), "480b4000.mmc"))
1268 mmc
->f_max
= 48000000;
1269 if (!strcmp(dev_name(dev
), "480ad000.mmc"))
1270 mmc
->f_max
= 48000000;
1273 if (!mmc_can_gpio_ro(mmc
))
1274 mmc
->caps2
|= MMC_CAP2_NO_WRITE_PROTECT
;
1276 pltfm_host
->clk
= devm_clk_get(dev
, "fck");
1277 if (IS_ERR(pltfm_host
->clk
)) {
1278 ret
= PTR_ERR(pltfm_host
->clk
);
1279 goto err_pltfm_free
;
1282 ret
= clk_set_rate(pltfm_host
->clk
, mmc
->f_max
);
1284 dev_err(dev
, "failed to set clock to %d\n", mmc
->f_max
);
1285 goto err_pltfm_free
;
1288 omap_host
->pbias
= devm_regulator_get_optional(dev
, "pbias");
1289 if (IS_ERR(omap_host
->pbias
)) {
1290 ret
= PTR_ERR(omap_host
->pbias
);
1292 goto err_pltfm_free
;
1293 dev_dbg(dev
, "unable to get pbias regulator %d\n", ret
);
1295 omap_host
->pbias_enabled
= false;
1298 * omap_device_pm_domain has callbacks to enable the main
1299 * functional clock, interface clock and also configure the
1300 * SYSCONFIG register to clear any boot loader set voltage
1301 * capabilities before calling sdhci_setup_host(). The
1302 * callback will be invoked as part of pm_runtime_get_sync.
1304 pm_runtime_use_autosuspend(dev
);
1305 pm_runtime_set_autosuspend_delay(dev
, 50);
1306 pm_runtime_enable(dev
);
1307 ret
= pm_runtime_resume_and_get(dev
);
1309 dev_err(dev
, "pm_runtime_get_sync failed\n");
1310 goto err_rpm_disable
;
1313 ret
= sdhci_omap_set_capabilities(host
);
1315 dev_err(dev
, "failed to set system capabilities\n");
1319 host
->mmc_host_ops
.start_signal_voltage_switch
=
1320 sdhci_omap_start_signal_voltage_switch
;
1321 host
->mmc_host_ops
.set_ios
= sdhci_omap_set_ios
;
1322 host
->mmc_host_ops
.card_busy
= sdhci_omap_card_busy
;
1323 host
->mmc_host_ops
.execute_tuning
= sdhci_omap_execute_tuning
;
1324 host
->mmc_host_ops
.enable_sdio_irq
= sdhci_omap_enable_sdio_irq
;
1327 * Switch to external DMA only if there is the "dmas" property and
1328 * ADMA is not available on the controller instance.
1330 if (device_property_present(dev
, "dmas") &&
1331 !sdhci_omap_has_adma(omap_host
, offset
))
1332 sdhci_switch_external_dma(host
, true);
1334 if (device_property_read_bool(dev
, "ti,non-removable")) {
1335 dev_warn_once(dev
, "using old ti,non-removable property\n");
1336 mmc
->caps
|= MMC_CAP_NONREMOVABLE
;
1339 /* R1B responses is required to properly manage HW busy detection. */
1340 mmc
->caps
|= MMC_CAP_NEED_RSP_BUSY
;
1342 /* Allow card power off and runtime PM for eMMC/SD card devices */
1343 mmc
->caps
|= MMC_CAP_POWER_OFF_CARD
| MMC_CAP_AGGRESSIVE_PM
;
1345 ret
= sdhci_setup_host(host
);
1349 ret
= sdhci_omap_config_iodelay_pinctrl_state(omap_host
);
1351 goto err_cleanup_host
;
1353 ret
= __sdhci_add_host(host
);
1355 goto err_cleanup_host
;
1358 * SDIO devices can use the dat1 pin as a wake-up interrupt. Some
1359 * devices like wl1xxx, use an out-of-band GPIO interrupt instead.
1361 omap_host
->wakeirq
= of_irq_get_byname(dev
->of_node
, "wakeup");
1362 if (omap_host
->wakeirq
== -EPROBE_DEFER
) {
1363 ret
= -EPROBE_DEFER
;
1364 goto err_cleanup_host
;
1366 if (omap_host
->wakeirq
> 0) {
1367 device_init_wakeup(dev
, true);
1368 ret
= dev_pm_set_dedicated_wake_irq(dev
, omap_host
->wakeirq
);
1370 device_init_wakeup(dev
, false);
1371 goto err_cleanup_host
;
1373 host
->mmc
->pm_caps
|= MMC_PM_KEEP_POWER
| MMC_PM_WAKE_SDIO_IRQ
;
1376 pm_runtime_mark_last_busy(dev
);
1377 pm_runtime_put_autosuspend(dev
);
1382 sdhci_cleanup_host(host
);
1385 pm_runtime_mark_last_busy(dev
);
1386 pm_runtime_put_autosuspend(dev
);
1388 pm_runtime_dont_use_autosuspend(dev
);
1389 pm_runtime_disable(dev
);
1392 sdhci_pltfm_free(pdev
);
1396 static void sdhci_omap_remove(struct platform_device
*pdev
)
1398 struct device
*dev
= &pdev
->dev
;
1399 struct sdhci_host
*host
= platform_get_drvdata(pdev
);
1401 pm_runtime_get_sync(dev
);
1402 sdhci_remove_host(host
, true);
1403 device_init_wakeup(dev
, false);
1404 dev_pm_clear_wake_irq(dev
);
1405 pm_runtime_dont_use_autosuspend(dev
);
1406 pm_runtime_put_sync(dev
);
1407 /* Ensure device gets disabled despite userspace sysfs config */
1408 pm_runtime_force_suspend(dev
);
1409 sdhci_pltfm_free(pdev
);
1413 static void __maybe_unused
sdhci_omap_context_save(struct sdhci_omap_host
*omap_host
)
1415 omap_host
->con
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CON
);
1416 omap_host
->hctl
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_HCTL
);
1417 omap_host
->sysctl
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_SYSCTL
);
1418 omap_host
->capa
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_CAPA
);
1419 omap_host
->ie
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_IE
);
1420 omap_host
->ise
= sdhci_omap_readl(omap_host
, SDHCI_OMAP_ISE
);
1423 /* Order matters here, HCTL must be restored in two phases */
1424 static void __maybe_unused
sdhci_omap_context_restore(struct sdhci_omap_host
*omap_host
)
1426 sdhci_omap_writel(omap_host
, SDHCI_OMAP_HCTL
, omap_host
->hctl
);
1427 sdhci_omap_writel(omap_host
, SDHCI_OMAP_CAPA
, omap_host
->capa
);
1428 sdhci_omap_writel(omap_host
, SDHCI_OMAP_HCTL
, omap_host
->hctl
);
1430 sdhci_omap_writel(omap_host
, SDHCI_OMAP_SYSCTL
, omap_host
->sysctl
);
1431 sdhci_omap_writel(omap_host
, SDHCI_OMAP_CON
, omap_host
->con
);
1432 sdhci_omap_writel(omap_host
, SDHCI_OMAP_IE
, omap_host
->ie
);
1433 sdhci_omap_writel(omap_host
, SDHCI_OMAP_ISE
, omap_host
->ise
);
1436 static int __maybe_unused
sdhci_omap_runtime_suspend(struct device
*dev
)
1438 struct sdhci_host
*host
= dev_get_drvdata(dev
);
1439 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
1440 struct sdhci_omap_host
*omap_host
= sdhci_pltfm_priv(pltfm_host
);
1442 if (host
->tuning_mode
!= SDHCI_TUNING_MODE_3
)
1443 mmc_retune_needed(host
->mmc
);
1445 if (omap_host
->con
!= -EINVAL
)
1446 sdhci_runtime_suspend_host(host
);
1448 sdhci_omap_context_save(omap_host
);
1450 pinctrl_pm_select_idle_state(dev
);
1455 static int __maybe_unused
sdhci_omap_runtime_resume(struct device
*dev
)
1457 struct sdhci_host
*host
= dev_get_drvdata(dev
);
1458 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
1459 struct sdhci_omap_host
*omap_host
= sdhci_pltfm_priv(pltfm_host
);
1461 pinctrl_pm_select_default_state(dev
);
1463 if (omap_host
->con
!= -EINVAL
) {
1464 sdhci_omap_context_restore(omap_host
);
1465 sdhci_runtime_resume_host(host
, 0);
1472 static const struct dev_pm_ops sdhci_omap_dev_pm_ops
= {
1473 SET_RUNTIME_PM_OPS(sdhci_omap_runtime_suspend
,
1474 sdhci_omap_runtime_resume
, NULL
)
1475 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend
,
1476 pm_runtime_force_resume
)
1479 static struct platform_driver sdhci_omap_driver
= {
1480 .probe
= sdhci_omap_probe
,
1481 .remove
= sdhci_omap_remove
,
1483 .name
= "sdhci-omap",
1484 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
1485 .pm
= &sdhci_omap_dev_pm_ops
,
1486 .of_match_table
= omap_sdhci_match
,
1490 module_platform_driver(sdhci_omap_driver
);
1492 MODULE_DESCRIPTION("SDHCI driver for OMAP SoCs");
1493 MODULE_AUTHOR("Texas Instruments Inc.");
1494 MODULE_LICENSE("GPL v2");
1495 MODULE_ALIAS("platform:sdhci_omap");