1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* linux/drivers/mmc/host/sdhci-pci.c - SDHCI on PCI bus interface
4 * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved.
6 * Thanks to the following companies for their support:
8 * - JMicron (hardware and technical support)
11 #include <linux/bitfield.h>
12 #include <linux/string.h>
13 #include <linux/delay.h>
14 #include <linux/highmem.h>
15 #include <linux/module.h>
16 #include <linux/pci.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/slab.h>
19 #include <linux/device.h>
20 #include <linux/scatterlist.h>
22 #include <linux/iopoll.h>
23 #include <linux/gpio.h>
24 #include <linux/pm_runtime.h>
25 #include <linux/pm_qos.h>
26 #include <linux/debugfs.h>
27 #include <linux/acpi.h>
28 #include <linux/dmi.h>
30 #include <linux/mmc/host.h>
31 #include <linux/mmc/mmc.h>
32 #include <linux/mmc/slot-gpio.h>
35 #include <asm/iosf_mbi.h>
41 #include "sdhci-cqhci.h"
42 #include "sdhci-pci.h"
43 #include "sdhci-uhs2.h"
45 static void sdhci_pci_hw_reset(struct sdhci_host
*host
);
47 #ifdef CONFIG_PM_SLEEP
48 static int sdhci_pci_init_wakeup(struct sdhci_pci_chip
*chip
)
50 mmc_pm_flag_t pm_flags
= 0;
51 bool cap_cd_wake
= false;
54 for (i
= 0; i
< chip
->num_slots
; i
++) {
55 struct sdhci_pci_slot
*slot
= chip
->slots
[i
];
58 pm_flags
|= slot
->host
->mmc
->pm_flags
;
59 if (slot
->host
->mmc
->caps
& MMC_CAP_CD_WAKE
)
64 if ((pm_flags
& MMC_PM_KEEP_POWER
) && (pm_flags
& MMC_PM_WAKE_SDIO_IRQ
))
65 return device_wakeup_enable(&chip
->pdev
->dev
);
66 else if (!cap_cd_wake
)
67 device_wakeup_disable(&chip
->pdev
->dev
);
72 static int sdhci_pci_suspend_host(struct sdhci_pci_chip
*chip
)
76 sdhci_pci_init_wakeup(chip
);
78 for (i
= 0; i
< chip
->num_slots
; i
++) {
79 struct sdhci_pci_slot
*slot
= chip
->slots
[i
];
80 struct sdhci_host
*host
;
87 if (chip
->pm_retune
&& host
->tuning_mode
!= SDHCI_TUNING_MODE_3
)
88 mmc_retune_needed(host
->mmc
);
90 ret
= sdhci_suspend_host(host
);
94 if (device_may_wakeup(&chip
->pdev
->dev
))
95 mmc_gpio_set_cd_wake(host
->mmc
, true);
102 sdhci_resume_host(chip
->slots
[i
]->host
);
106 int sdhci_pci_resume_host(struct sdhci_pci_chip
*chip
)
108 struct sdhci_pci_slot
*slot
;
111 for (i
= 0; i
< chip
->num_slots
; i
++) {
112 slot
= chip
->slots
[i
];
116 ret
= sdhci_resume_host(slot
->host
);
120 mmc_gpio_set_cd_wake(slot
->host
->mmc
, false);
126 static int sdhci_cqhci_suspend(struct sdhci_pci_chip
*chip
)
130 ret
= cqhci_suspend(chip
->slots
[0]->host
->mmc
);
134 return sdhci_pci_suspend_host(chip
);
137 static int sdhci_cqhci_resume(struct sdhci_pci_chip
*chip
)
141 ret
= sdhci_pci_resume_host(chip
);
145 return cqhci_resume(chip
->slots
[0]->host
->mmc
);
150 static int sdhci_pci_runtime_suspend_host(struct sdhci_pci_chip
*chip
)
152 struct sdhci_pci_slot
*slot
;
153 struct sdhci_host
*host
;
156 for (i
= 0; i
< chip
->num_slots
; i
++) {
157 slot
= chip
->slots
[i
];
163 ret
= sdhci_runtime_suspend_host(host
);
165 goto err_pci_runtime_suspend
;
167 if (chip
->rpm_retune
&&
168 host
->tuning_mode
!= SDHCI_TUNING_MODE_3
)
169 mmc_retune_needed(host
->mmc
);
174 err_pci_runtime_suspend
:
176 sdhci_runtime_resume_host(chip
->slots
[i
]->host
, 0);
180 static int sdhci_pci_runtime_resume_host(struct sdhci_pci_chip
*chip
)
182 struct sdhci_pci_slot
*slot
;
185 for (i
= 0; i
< chip
->num_slots
; i
++) {
186 slot
= chip
->slots
[i
];
190 ret
= sdhci_runtime_resume_host(slot
->host
, 0);
198 static int sdhci_cqhci_runtime_suspend(struct sdhci_pci_chip
*chip
)
202 ret
= cqhci_suspend(chip
->slots
[0]->host
->mmc
);
206 return sdhci_pci_runtime_suspend_host(chip
);
209 static int sdhci_cqhci_runtime_resume(struct sdhci_pci_chip
*chip
)
213 ret
= sdhci_pci_runtime_resume_host(chip
);
217 return cqhci_resume(chip
->slots
[0]->host
->mmc
);
221 static u32
sdhci_cqhci_irq(struct sdhci_host
*host
, u32 intmask
)
226 if (!sdhci_cqe_irq(host
, intmask
, &cmd_error
, &data_error
))
229 cqhci_irq(host
->mmc
, intmask
, cmd_error
, data_error
);
234 static void sdhci_pci_dumpregs(struct mmc_host
*mmc
)
236 sdhci_dumpregs(mmc_priv(mmc
));
239 /*****************************************************************************\
241 * Hardware specific quirk handling *
243 \*****************************************************************************/
245 static int ricoh_probe(struct sdhci_pci_chip
*chip
)
247 if (chip
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_SAMSUNG
||
248 chip
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_SONY
)
249 chip
->quirks
|= SDHCI_QUIRK_NO_CARD_NO_RESET
;
253 static int ricoh_mmc_probe_slot(struct sdhci_pci_slot
*slot
)
256 FIELD_PREP(SDHCI_TIMEOUT_CLK_MASK
, 0x21) |
257 FIELD_PREP(SDHCI_CLOCK_BASE_MASK
, 0x21) |
258 SDHCI_TIMEOUT_CLK_UNIT
|
264 __sdhci_read_caps(slot
->host
, NULL
, &caps
, &caps1
);
268 #ifdef CONFIG_PM_SLEEP
269 static int ricoh_mmc_resume(struct sdhci_pci_chip
*chip
)
271 /* Apply a delay to allow controller to settle */
272 /* Otherwise it becomes confused if card state changed
275 return sdhci_pci_resume_host(chip
);
279 static const struct sdhci_pci_fixes sdhci_ricoh
= {
280 .probe
= ricoh_probe
,
281 .quirks
= SDHCI_QUIRK_32BIT_DMA_ADDR
|
282 SDHCI_QUIRK_FORCE_DMA
|
283 SDHCI_QUIRK_CLOCK_BEFORE_RESET
,
286 static const struct sdhci_pci_fixes sdhci_ricoh_mmc
= {
287 .probe_slot
= ricoh_mmc_probe_slot
,
288 #ifdef CONFIG_PM_SLEEP
289 .resume
= ricoh_mmc_resume
,
291 .quirks
= SDHCI_QUIRK_32BIT_DMA_ADDR
|
292 SDHCI_QUIRK_CLOCK_BEFORE_RESET
|
293 SDHCI_QUIRK_NO_CARD_NO_RESET
,
296 static void ene_714_set_ios(struct mmc_host
*mmc
, struct mmc_ios
*ios
)
298 struct sdhci_host
*host
= mmc_priv(mmc
);
300 sdhci_set_ios(mmc
, ios
);
303 * Some (ENE) controllers misbehave on some ios operations,
304 * signalling timeout and CRC errors even on CMD0. Resetting
305 * it on each ios seems to solve the problem.
307 if (!(host
->flags
& SDHCI_DEVICE_DEAD
))
308 sdhci_reset(host
, SDHCI_RESET_CMD
| SDHCI_RESET_DATA
);
311 static int ene_714_probe_slot(struct sdhci_pci_slot
*slot
)
313 slot
->host
->mmc_host_ops
.set_ios
= ene_714_set_ios
;
317 static const struct sdhci_pci_fixes sdhci_ene_712
= {
318 .quirks
= SDHCI_QUIRK_SINGLE_POWER_WRITE
|
319 SDHCI_QUIRK_BROKEN_DMA
,
322 static const struct sdhci_pci_fixes sdhci_ene_714
= {
323 .quirks
= SDHCI_QUIRK_SINGLE_POWER_WRITE
|
324 SDHCI_QUIRK_BROKEN_DMA
,
325 .probe_slot
= ene_714_probe_slot
,
328 static const struct sdhci_pci_fixes sdhci_cafe
= {
329 .quirks
= SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER
|
330 SDHCI_QUIRK_NO_BUSY_IRQ
|
331 SDHCI_QUIRK_BROKEN_CARD_DETECTION
|
332 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL
,
335 static const struct sdhci_pci_fixes sdhci_intel_qrk
= {
336 .quirks
= SDHCI_QUIRK_NO_HISPD_BIT
,
339 static int mrst_hc_probe_slot(struct sdhci_pci_slot
*slot
)
341 slot
->host
->mmc
->caps
|= MMC_CAP_8_BIT_DATA
;
346 * ADMA operation is disabled for Moorestown platform due to
349 static int mrst_hc_probe(struct sdhci_pci_chip
*chip
)
352 * slots number is fixed here for MRST as SDIO3/5 are never used and
353 * have hardware bugs.
359 static int pch_hc_probe_slot(struct sdhci_pci_slot
*slot
)
361 slot
->host
->mmc
->caps
|= MMC_CAP_8_BIT_DATA
;
365 static int mfd_emmc_probe_slot(struct sdhci_pci_slot
*slot
)
367 slot
->host
->mmc
->caps
|= MMC_CAP_8_BIT_DATA
| MMC_CAP_NONREMOVABLE
;
368 slot
->host
->mmc
->caps2
|= MMC_CAP2_BOOTPART_NOACC
;
372 static int mfd_sdio_probe_slot(struct sdhci_pci_slot
*slot
)
374 slot
->host
->mmc
->caps
|= MMC_CAP_POWER_OFF_CARD
| MMC_CAP_NONREMOVABLE
;
378 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0
= {
379 .quirks
= SDHCI_QUIRK_BROKEN_ADMA
| SDHCI_QUIRK_NO_HISPD_BIT
,
380 .probe_slot
= mrst_hc_probe_slot
,
383 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2
= {
384 .quirks
= SDHCI_QUIRK_BROKEN_ADMA
| SDHCI_QUIRK_NO_HISPD_BIT
,
385 .probe
= mrst_hc_probe
,
388 static const struct sdhci_pci_fixes sdhci_intel_mfd_sd
= {
389 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
390 .allow_runtime_pm
= true,
391 .own_cd_for_runtime_pm
= true,
394 static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio
= {
395 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
396 .quirks2
= SDHCI_QUIRK2_HOST_OFF_CARD_ON
,
397 .allow_runtime_pm
= true,
398 .probe_slot
= mfd_sdio_probe_slot
,
401 static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc
= {
402 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
403 .allow_runtime_pm
= true,
404 .probe_slot
= mfd_emmc_probe_slot
,
407 static const struct sdhci_pci_fixes sdhci_intel_pch_sdio
= {
408 .quirks
= SDHCI_QUIRK_BROKEN_ADMA
,
409 .probe_slot
= pch_hc_probe_slot
,
414 #define BYT_IOSF_SCCEP 0x63
415 #define BYT_IOSF_OCP_NETCTRL0 0x1078
416 #define BYT_IOSF_OCP_TIMEOUT_BASE GENMASK(10, 8)
418 static void byt_ocp_setting(struct pci_dev
*pdev
)
422 if (pdev
->device
!= PCI_DEVICE_ID_INTEL_BYT_EMMC
&&
423 pdev
->device
!= PCI_DEVICE_ID_INTEL_BYT_SDIO
&&
424 pdev
->device
!= PCI_DEVICE_ID_INTEL_BYT_SD
&&
425 pdev
->device
!= PCI_DEVICE_ID_INTEL_BYT_EMMC2
)
428 if (iosf_mbi_read(BYT_IOSF_SCCEP
, MBI_CR_READ
, BYT_IOSF_OCP_NETCTRL0
,
430 dev_err(&pdev
->dev
, "%s read error\n", __func__
);
434 if (!(val
& BYT_IOSF_OCP_TIMEOUT_BASE
))
437 val
&= ~BYT_IOSF_OCP_TIMEOUT_BASE
;
439 if (iosf_mbi_write(BYT_IOSF_SCCEP
, MBI_CR_WRITE
, BYT_IOSF_OCP_NETCTRL0
,
441 dev_err(&pdev
->dev
, "%s write error\n", __func__
);
445 dev_dbg(&pdev
->dev
, "%s completed\n", __func__
);
450 static inline void byt_ocp_setting(struct pci_dev
*pdev
)
458 INTEL_DSM_V18_SWITCH
= 3,
459 INTEL_DSM_V33_SWITCH
= 4,
460 INTEL_DSM_DRV_STRENGTH
= 9,
461 INTEL_DSM_D3_RETUNE
= 10,
476 static const guid_t intel_dsm_guid
=
477 GUID_INIT(0xF6C13EA5, 0x65CD, 0x461F,
478 0xAB, 0x7A, 0x29, 0xF7, 0xE8, 0xD5, 0xBD, 0x61);
480 static int __intel_dsm(struct intel_host
*intel_host
, struct device
*dev
,
481 unsigned int fn
, u32
*result
)
483 union acpi_object
*obj
;
487 obj
= acpi_evaluate_dsm_typed(ACPI_HANDLE(dev
), &intel_dsm_guid
, 0, fn
, NULL
,
492 if (obj
->buffer
.length
< 1) {
497 len
= min_t(size_t, obj
->buffer
.length
, 4);
500 memcpy(result
, obj
->buffer
.pointer
, len
);
507 static int intel_dsm(struct intel_host
*intel_host
, struct device
*dev
,
508 unsigned int fn
, u32
*result
)
510 if (fn
> 31 || !(intel_host
->dsm_fns
& (1 << fn
)))
513 return __intel_dsm(intel_host
, dev
, fn
, result
);
516 static void intel_dsm_init(struct intel_host
*intel_host
, struct device
*dev
,
517 struct mmc_host
*mmc
)
522 intel_host
->d3_retune
= true;
524 err
= __intel_dsm(intel_host
, dev
, INTEL_DSM_FNS
, &intel_host
->dsm_fns
);
526 pr_debug("%s: DSM not supported, error %d\n",
527 mmc_hostname(mmc
), err
);
531 pr_debug("%s: DSM function mask %#x\n",
532 mmc_hostname(mmc
), intel_host
->dsm_fns
);
534 err
= intel_dsm(intel_host
, dev
, INTEL_DSM_DRV_STRENGTH
, &val
);
535 intel_host
->drv_strength
= err
? 0 : val
;
537 err
= intel_dsm(intel_host
, dev
, INTEL_DSM_D3_RETUNE
, &val
);
538 intel_host
->d3_retune
= err
? true : !!val
;
541 static void sdhci_pci_int_hw_reset(struct sdhci_host
*host
)
545 reg
= sdhci_readb(host
, SDHCI_POWER_CONTROL
);
547 sdhci_writeb(host
, reg
, SDHCI_POWER_CONTROL
);
548 /* For eMMC, minimum is 1us but give it 9us for good measure */
551 sdhci_writeb(host
, reg
, SDHCI_POWER_CONTROL
);
552 /* For eMMC, minimum is 200us but give it 300us for good measure */
553 usleep_range(300, 1000);
556 static int intel_select_drive_strength(struct mmc_card
*card
,
557 unsigned int max_dtr
, int host_drv
,
558 int card_drv
, int *drv_type
)
560 struct sdhci_host
*host
= mmc_priv(card
->host
);
561 struct sdhci_pci_slot
*slot
= sdhci_priv(host
);
562 struct intel_host
*intel_host
= sdhci_pci_priv(slot
);
564 if (!(mmc_driver_type_mask(intel_host
->drv_strength
) & card_drv
))
567 return intel_host
->drv_strength
;
570 static int bxt_get_cd(struct mmc_host
*mmc
)
572 int gpio_cd
= mmc_gpio_get_cd(mmc
);
577 return sdhci_get_cd_nogpio(mmc
);
580 static int mrfld_get_cd(struct mmc_host
*mmc
)
582 return sdhci_get_cd_nogpio(mmc
);
585 #define SDHCI_INTEL_PWR_TIMEOUT_CNT 20
586 #define SDHCI_INTEL_PWR_TIMEOUT_UDELAY 100
588 static void sdhci_intel_set_power(struct sdhci_host
*host
, unsigned char mode
,
591 struct sdhci_pci_slot
*slot
= sdhci_priv(host
);
592 struct intel_host
*intel_host
= sdhci_pci_priv(slot
);
597 * Bus power may control card power, but a full reset still may not
598 * reset the power, whereas a direct write to SDHCI_POWER_CONTROL can.
599 * That might be needed to initialize correctly, if the card was left
600 * powered on previously.
602 if (intel_host
->needs_pwr_off
) {
603 intel_host
->needs_pwr_off
= false;
604 if (mode
!= MMC_POWER_OFF
) {
605 sdhci_writeb(host
, 0, SDHCI_POWER_CONTROL
);
606 usleep_range(10000, 12500);
610 sdhci_set_power(host
, mode
, vdd
);
612 if (mode
== MMC_POWER_OFF
)
616 * Bus power might not enable after D3 -> D0 transition due to the
617 * present state not yet having propagated. Retry for up to 2ms.
619 for (cntr
= 0; cntr
< SDHCI_INTEL_PWR_TIMEOUT_CNT
; cntr
++) {
620 reg
= sdhci_readb(host
, SDHCI_POWER_CONTROL
);
621 if (reg
& SDHCI_POWER_ON
)
623 udelay(SDHCI_INTEL_PWR_TIMEOUT_UDELAY
);
624 reg
|= SDHCI_POWER_ON
;
625 sdhci_writeb(host
, reg
, SDHCI_POWER_CONTROL
);
629 static void sdhci_intel_set_uhs_signaling(struct sdhci_host
*host
,
632 /* Set UHS timing to SDR25 for High Speed mode */
633 if (timing
== MMC_TIMING_MMC_HS
|| timing
== MMC_TIMING_SD_HS
)
634 timing
= MMC_TIMING_UHS_SDR25
;
635 sdhci_set_uhs_signaling(host
, timing
);
638 #define INTEL_HS400_ES_REG 0x78
639 #define INTEL_HS400_ES_BIT BIT(0)
641 static void intel_hs400_enhanced_strobe(struct mmc_host
*mmc
,
644 struct sdhci_host
*host
= mmc_priv(mmc
);
647 val
= sdhci_readl(host
, INTEL_HS400_ES_REG
);
648 if (ios
->enhanced_strobe
)
649 val
|= INTEL_HS400_ES_BIT
;
651 val
&= ~INTEL_HS400_ES_BIT
;
652 sdhci_writel(host
, val
, INTEL_HS400_ES_REG
);
655 static int intel_start_signal_voltage_switch(struct mmc_host
*mmc
,
658 struct device
*dev
= mmc_dev(mmc
);
659 struct sdhci_host
*host
= mmc_priv(mmc
);
660 struct sdhci_pci_slot
*slot
= sdhci_priv(host
);
661 struct intel_host
*intel_host
= sdhci_pci_priv(slot
);
666 err
= sdhci_start_signal_voltage_switch(mmc
, ios
);
670 switch (ios
->signal_voltage
) {
671 case MMC_SIGNAL_VOLTAGE_330
:
672 fn
= INTEL_DSM_V33_SWITCH
;
674 case MMC_SIGNAL_VOLTAGE_180
:
675 fn
= INTEL_DSM_V18_SWITCH
;
681 err
= intel_dsm(intel_host
, dev
, fn
, &result
);
682 pr_debug("%s: %s DSM fn %u error %d result %u\n",
683 mmc_hostname(mmc
), __func__
, fn
, err
, result
);
688 static const struct sdhci_ops sdhci_intel_byt_ops
= {
689 .set_clock
= sdhci_set_clock
,
690 .set_power
= sdhci_intel_set_power
,
691 .enable_dma
= sdhci_pci_enable_dma
,
692 .set_bus_width
= sdhci_set_bus_width
,
693 .reset
= sdhci_reset
,
694 .set_uhs_signaling
= sdhci_intel_set_uhs_signaling
,
695 .hw_reset
= sdhci_pci_hw_reset
,
698 static const struct sdhci_ops sdhci_intel_glk_ops
= {
699 .set_clock
= sdhci_set_clock
,
700 .set_power
= sdhci_intel_set_power
,
701 .enable_dma
= sdhci_pci_enable_dma
,
702 .set_bus_width
= sdhci_set_bus_width
,
703 .reset
= sdhci_and_cqhci_reset
,
704 .set_uhs_signaling
= sdhci_intel_set_uhs_signaling
,
705 .hw_reset
= sdhci_pci_hw_reset
,
706 .irq
= sdhci_cqhci_irq
,
709 static void byt_read_dsm(struct sdhci_pci_slot
*slot
)
711 struct intel_host
*intel_host
= sdhci_pci_priv(slot
);
712 struct device
*dev
= &slot
->chip
->pdev
->dev
;
713 struct mmc_host
*mmc
= slot
->host
->mmc
;
715 intel_dsm_init(intel_host
, dev
, mmc
);
716 slot
->chip
->rpm_retune
= intel_host
->d3_retune
;
719 static int intel_execute_tuning(struct mmc_host
*mmc
, u32 opcode
)
721 int err
= sdhci_execute_tuning(mmc
, opcode
);
722 struct sdhci_host
*host
= mmc_priv(mmc
);
728 * Tuning can leave the IP in an active state (Buffer Read Enable bit
729 * set) which prevents the entry to low power states (i.e. S0i3). Data
730 * reset will clear it.
732 sdhci_reset(host
, SDHCI_RESET_DATA
);
737 #define INTEL_ACTIVELTR 0x804
738 #define INTEL_IDLELTR 0x808
740 #define INTEL_LTR_REQ BIT(15)
741 #define INTEL_LTR_SCALE_MASK GENMASK(11, 10)
742 #define INTEL_LTR_SCALE_1US (2 << 10)
743 #define INTEL_LTR_SCALE_32US (3 << 10)
744 #define INTEL_LTR_VALUE_MASK GENMASK(9, 0)
746 static void intel_cache_ltr(struct sdhci_pci_slot
*slot
)
748 struct intel_host
*intel_host
= sdhci_pci_priv(slot
);
749 struct sdhci_host
*host
= slot
->host
;
751 intel_host
->active_ltr
= readl(host
->ioaddr
+ INTEL_ACTIVELTR
);
752 intel_host
->idle_ltr
= readl(host
->ioaddr
+ INTEL_IDLELTR
);
755 static void intel_ltr_set(struct device
*dev
, s32 val
)
757 struct sdhci_pci_chip
*chip
= dev_get_drvdata(dev
);
758 struct sdhci_pci_slot
*slot
= chip
->slots
[0];
759 struct intel_host
*intel_host
= sdhci_pci_priv(slot
);
760 struct sdhci_host
*host
= slot
->host
;
763 pm_runtime_get_sync(dev
);
766 * Program latency tolerance (LTR) accordingly what has been asked
767 * by the PM QoS layer or disable it in case we were passed
768 * negative value or PM_QOS_LATENCY_ANY.
770 ltr
= readl(host
->ioaddr
+ INTEL_ACTIVELTR
);
772 if (val
== PM_QOS_LATENCY_ANY
|| val
< 0) {
773 ltr
&= ~INTEL_LTR_REQ
;
775 ltr
|= INTEL_LTR_REQ
;
776 ltr
&= ~INTEL_LTR_SCALE_MASK
;
777 ltr
&= ~INTEL_LTR_VALUE_MASK
;
779 if (val
> INTEL_LTR_VALUE_MASK
) {
781 if (val
> INTEL_LTR_VALUE_MASK
)
782 val
= INTEL_LTR_VALUE_MASK
;
783 ltr
|= INTEL_LTR_SCALE_32US
| val
;
785 ltr
|= INTEL_LTR_SCALE_1US
| val
;
789 if (ltr
== intel_host
->active_ltr
)
792 writel(ltr
, host
->ioaddr
+ INTEL_ACTIVELTR
);
793 writel(ltr
, host
->ioaddr
+ INTEL_IDLELTR
);
795 /* Cache the values into lpss structure */
796 intel_cache_ltr(slot
);
798 pm_runtime_put_autosuspend(dev
);
801 static bool intel_use_ltr(struct sdhci_pci_chip
*chip
)
803 switch (chip
->pdev
->device
) {
804 case PCI_DEVICE_ID_INTEL_BYT_EMMC
:
805 case PCI_DEVICE_ID_INTEL_BYT_EMMC2
:
806 case PCI_DEVICE_ID_INTEL_BYT_SDIO
:
807 case PCI_DEVICE_ID_INTEL_BYT_SD
:
808 case PCI_DEVICE_ID_INTEL_BSW_EMMC
:
809 case PCI_DEVICE_ID_INTEL_BSW_SDIO
:
810 case PCI_DEVICE_ID_INTEL_BSW_SD
:
817 static void intel_ltr_expose(struct sdhci_pci_chip
*chip
)
819 struct device
*dev
= &chip
->pdev
->dev
;
821 if (!intel_use_ltr(chip
))
824 dev
->power
.set_latency_tolerance
= intel_ltr_set
;
825 dev_pm_qos_expose_latency_tolerance(dev
);
828 static void intel_ltr_hide(struct sdhci_pci_chip
*chip
)
830 struct device
*dev
= &chip
->pdev
->dev
;
832 if (!intel_use_ltr(chip
))
835 dev_pm_qos_hide_latency_tolerance(dev
);
836 dev
->power
.set_latency_tolerance
= NULL
;
839 static void byt_probe_slot(struct sdhci_pci_slot
*slot
)
841 struct mmc_host_ops
*ops
= &slot
->host
->mmc_host_ops
;
842 struct device
*dev
= &slot
->chip
->pdev
->dev
;
843 struct mmc_host
*mmc
= slot
->host
->mmc
;
847 byt_ocp_setting(slot
->chip
->pdev
);
849 ops
->execute_tuning
= intel_execute_tuning
;
850 ops
->start_signal_voltage_switch
= intel_start_signal_voltage_switch
;
852 device_property_read_u32(dev
, "max-frequency", &mmc
->f_max
);
855 slot
->chip
->slots
[mmc
->slotno
] = slot
;
856 intel_ltr_expose(slot
->chip
);
860 static void byt_add_debugfs(struct sdhci_pci_slot
*slot
)
862 struct intel_host
*intel_host
= sdhci_pci_priv(slot
);
863 struct mmc_host
*mmc
= slot
->host
->mmc
;
864 struct dentry
*dir
= mmc
->debugfs_root
;
866 if (!intel_use_ltr(slot
->chip
))
869 debugfs_create_x32("active_ltr", 0444, dir
, &intel_host
->active_ltr
);
870 debugfs_create_x32("idle_ltr", 0444, dir
, &intel_host
->idle_ltr
);
872 intel_cache_ltr(slot
);
875 static int byt_add_host(struct sdhci_pci_slot
*slot
)
877 int ret
= sdhci_add_host(slot
->host
);
880 byt_add_debugfs(slot
);
884 static void byt_remove_slot(struct sdhci_pci_slot
*slot
, int dead
)
886 struct mmc_host
*mmc
= slot
->host
->mmc
;
889 intel_ltr_hide(slot
->chip
);
892 static int byt_emmc_probe_slot(struct sdhci_pci_slot
*slot
)
894 byt_probe_slot(slot
);
895 slot
->host
->mmc
->caps
|= MMC_CAP_8_BIT_DATA
| MMC_CAP_NONREMOVABLE
|
896 MMC_CAP_HW_RESET
| MMC_CAP_1_8V_DDR
|
897 MMC_CAP_CMD_DURING_TFR
|
898 MMC_CAP_WAIT_WHILE_BUSY
;
899 slot
->hw_reset
= sdhci_pci_int_hw_reset
;
900 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_INTEL_BSW_EMMC
)
901 slot
->host
->timeout_clk
= 1000; /* 1000 kHz i.e. 1 MHz */
902 slot
->host
->mmc_host_ops
.select_drive_strength
=
903 intel_select_drive_strength
;
907 static bool glk_broken_cqhci(struct sdhci_pci_slot
*slot
)
909 return slot
->chip
->pdev
->device
== PCI_DEVICE_ID_INTEL_GLK_EMMC
&&
910 (dmi_match(DMI_BIOS_VENDOR
, "LENOVO") ||
911 dmi_match(DMI_SYS_VENDOR
, "IRBIS"));
914 static bool jsl_broken_hs400es(struct sdhci_pci_slot
*slot
)
916 return slot
->chip
->pdev
->device
== PCI_DEVICE_ID_INTEL_JSL_EMMC
&&
917 dmi_match(DMI_BIOS_VENDOR
, "ASUSTeK COMPUTER INC.");
920 static int glk_emmc_probe_slot(struct sdhci_pci_slot
*slot
)
922 int ret
= byt_emmc_probe_slot(slot
);
924 if (!glk_broken_cqhci(slot
))
925 slot
->host
->mmc
->caps2
|= MMC_CAP2_CQE
;
927 if (slot
->chip
->pdev
->device
!= PCI_DEVICE_ID_INTEL_GLK_EMMC
) {
928 if (!jsl_broken_hs400es(slot
)) {
929 slot
->host
->mmc
->caps2
|= MMC_CAP2_HS400_ES
;
930 slot
->host
->mmc_host_ops
.hs400_enhanced_strobe
=
931 intel_hs400_enhanced_strobe
;
933 slot
->host
->mmc
->caps2
|= MMC_CAP2_CQE_DCMD
;
939 static const struct cqhci_host_ops glk_cqhci_ops
= {
940 .enable
= sdhci_cqe_enable
,
941 .disable
= sdhci_cqe_disable
,
942 .dumpregs
= sdhci_pci_dumpregs
,
945 static int glk_emmc_add_host(struct sdhci_pci_slot
*slot
)
947 struct device
*dev
= &slot
->chip
->pdev
->dev
;
948 struct sdhci_host
*host
= slot
->host
;
949 struct cqhci_host
*cq_host
;
953 ret
= sdhci_setup_host(host
);
957 cq_host
= devm_kzalloc(dev
, sizeof(*cq_host
), GFP_KERNEL
);
963 cq_host
->mmio
= host
->ioaddr
+ 0x200;
964 cq_host
->quirks
|= CQHCI_QUIRK_SHORT_TXFR_DESC_SZ
;
965 cq_host
->ops
= &glk_cqhci_ops
;
967 dma64
= host
->flags
& SDHCI_USE_64_BIT_DMA
;
969 cq_host
->caps
|= CQHCI_TASK_DESC_SZ_128
;
971 ret
= cqhci_init(cq_host
, host
->mmc
, dma64
);
975 ret
= __sdhci_add_host(host
);
979 byt_add_debugfs(slot
);
984 sdhci_cleanup_host(host
);
989 #define GLK_RX_CTRL1 0x834
990 #define GLK_TUN_VAL 0x840
991 #define GLK_PATH_PLL GENMASK(13, 8)
992 #define GLK_DLY GENMASK(6, 0)
993 /* Workaround firmware failing to restore the tuning value */
994 static void glk_rpm_retune_wa(struct sdhci_pci_chip
*chip
, bool susp
)
996 struct sdhci_pci_slot
*slot
= chip
->slots
[0];
997 struct intel_host
*intel_host
= sdhci_pci_priv(slot
);
998 struct sdhci_host
*host
= slot
->host
;
1003 if (intel_host
->rpm_retune_ok
|| !mmc_can_retune(host
->mmc
))
1006 glk_rx_ctrl1
= sdhci_readl(host
, GLK_RX_CTRL1
);
1007 glk_tun_val
= sdhci_readl(host
, GLK_TUN_VAL
);
1010 intel_host
->glk_rx_ctrl1
= glk_rx_ctrl1
;
1011 intel_host
->glk_tun_val
= glk_tun_val
;
1015 if (!intel_host
->glk_tun_val
)
1018 if (glk_rx_ctrl1
!= intel_host
->glk_rx_ctrl1
) {
1019 intel_host
->rpm_retune_ok
= true;
1023 dly
= FIELD_PREP(GLK_DLY
, FIELD_GET(GLK_PATH_PLL
, glk_rx_ctrl1
) +
1024 (intel_host
->glk_tun_val
<< 1));
1025 if (dly
== FIELD_GET(GLK_DLY
, glk_rx_ctrl1
))
1028 glk_rx_ctrl1
= (glk_rx_ctrl1
& ~GLK_DLY
) | dly
;
1029 sdhci_writel(host
, glk_rx_ctrl1
, GLK_RX_CTRL1
);
1031 intel_host
->rpm_retune_ok
= true;
1032 chip
->rpm_retune
= true;
1033 mmc_retune_needed(host
->mmc
);
1034 pr_info("%s: Requiring re-tune after rpm resume", mmc_hostname(host
->mmc
));
1037 static void glk_rpm_retune_chk(struct sdhci_pci_chip
*chip
, bool susp
)
1039 if (chip
->pdev
->device
== PCI_DEVICE_ID_INTEL_GLK_EMMC
&&
1041 glk_rpm_retune_wa(chip
, susp
);
1044 static int glk_runtime_suspend(struct sdhci_pci_chip
*chip
)
1046 glk_rpm_retune_chk(chip
, true);
1048 return sdhci_cqhci_runtime_suspend(chip
);
1051 static int glk_runtime_resume(struct sdhci_pci_chip
*chip
)
1053 glk_rpm_retune_chk(chip
, false);
1055 return sdhci_cqhci_runtime_resume(chip
);
1060 static int ni_set_max_freq(struct sdhci_pci_slot
*slot
)
1063 unsigned long long max_freq
;
1065 status
= acpi_evaluate_integer(ACPI_HANDLE(&slot
->chip
->pdev
->dev
),
1066 "MXFQ", NULL
, &max_freq
);
1067 if (ACPI_FAILURE(status
)) {
1068 dev_err(&slot
->chip
->pdev
->dev
,
1069 "MXFQ not found in acpi table\n");
1073 slot
->host
->mmc
->f_max
= max_freq
* 1000000;
1078 static inline int ni_set_max_freq(struct sdhci_pci_slot
*slot
)
1084 static int ni_byt_sdio_probe_slot(struct sdhci_pci_slot
*slot
)
1088 byt_probe_slot(slot
);
1090 err
= ni_set_max_freq(slot
);
1094 slot
->host
->mmc
->caps
|= MMC_CAP_POWER_OFF_CARD
| MMC_CAP_NONREMOVABLE
|
1095 MMC_CAP_WAIT_WHILE_BUSY
;
1099 static int byt_sdio_probe_slot(struct sdhci_pci_slot
*slot
)
1101 byt_probe_slot(slot
);
1102 slot
->host
->mmc
->caps
|= MMC_CAP_POWER_OFF_CARD
| MMC_CAP_NONREMOVABLE
|
1103 MMC_CAP_WAIT_WHILE_BUSY
;
1107 static void byt_needs_pwr_off(struct sdhci_pci_slot
*slot
)
1109 struct intel_host
*intel_host
= sdhci_pci_priv(slot
);
1110 u8 reg
= sdhci_readb(slot
->host
, SDHCI_POWER_CONTROL
);
1112 intel_host
->needs_pwr_off
= reg
& SDHCI_POWER_ON
;
1115 static int byt_sd_probe_slot(struct sdhci_pci_slot
*slot
)
1117 byt_probe_slot(slot
);
1118 slot
->host
->mmc
->caps
|= MMC_CAP_WAIT_WHILE_BUSY
|
1119 MMC_CAP_AGGRESSIVE_PM
| MMC_CAP_CD_WAKE
;
1121 slot
->cd_override_level
= true;
1122 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_INTEL_BXT_SD
||
1123 slot
->chip
->pdev
->device
== PCI_DEVICE_ID_INTEL_BXTM_SD
||
1124 slot
->chip
->pdev
->device
== PCI_DEVICE_ID_INTEL_APL_SD
||
1125 slot
->chip
->pdev
->device
== PCI_DEVICE_ID_INTEL_GLK_SD
)
1126 slot
->host
->mmc_host_ops
.get_cd
= bxt_get_cd
;
1128 if (slot
->chip
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_NI
&&
1129 slot
->chip
->pdev
->subsystem_device
== PCI_SUBDEVICE_ID_NI_78E3
)
1130 slot
->host
->mmc
->caps2
|= MMC_CAP2_AVOID_3_3V
;
1132 byt_needs_pwr_off(slot
);
1137 #ifdef CONFIG_PM_SLEEP
1139 static int byt_resume(struct sdhci_pci_chip
*chip
)
1141 byt_ocp_setting(chip
->pdev
);
1143 return sdhci_pci_resume_host(chip
);
1150 static int byt_runtime_resume(struct sdhci_pci_chip
*chip
)
1152 byt_ocp_setting(chip
->pdev
);
1154 return sdhci_pci_runtime_resume_host(chip
);
1159 static const struct sdhci_pci_fixes sdhci_intel_byt_emmc
= {
1160 #ifdef CONFIG_PM_SLEEP
1161 .resume
= byt_resume
,
1164 .runtime_resume
= byt_runtime_resume
,
1166 .allow_runtime_pm
= true,
1167 .probe_slot
= byt_emmc_probe_slot
,
1168 .add_host
= byt_add_host
,
1169 .remove_slot
= byt_remove_slot
,
1170 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
|
1172 .quirks2
= SDHCI_QUIRK2_PRESET_VALUE_BROKEN
|
1173 SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400
|
1174 SDHCI_QUIRK2_STOP_WITH_TC
,
1175 .ops
= &sdhci_intel_byt_ops
,
1176 .priv_size
= sizeof(struct intel_host
),
1179 static const struct sdhci_pci_fixes sdhci_intel_glk_emmc
= {
1180 .allow_runtime_pm
= true,
1181 .probe_slot
= glk_emmc_probe_slot
,
1182 .add_host
= glk_emmc_add_host
,
1183 .remove_slot
= byt_remove_slot
,
1184 #ifdef CONFIG_PM_SLEEP
1185 .suspend
= sdhci_cqhci_suspend
,
1186 .resume
= sdhci_cqhci_resume
,
1189 .runtime_suspend
= glk_runtime_suspend
,
1190 .runtime_resume
= glk_runtime_resume
,
1192 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
|
1194 .quirks2
= SDHCI_QUIRK2_PRESET_VALUE_BROKEN
|
1195 SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400
|
1196 SDHCI_QUIRK2_STOP_WITH_TC
,
1197 .ops
= &sdhci_intel_glk_ops
,
1198 .priv_size
= sizeof(struct intel_host
),
1201 static const struct sdhci_pci_fixes sdhci_ni_byt_sdio
= {
1202 #ifdef CONFIG_PM_SLEEP
1203 .resume
= byt_resume
,
1206 .runtime_resume
= byt_runtime_resume
,
1208 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
|
1210 .quirks2
= SDHCI_QUIRK2_HOST_OFF_CARD_ON
|
1211 SDHCI_QUIRK2_PRESET_VALUE_BROKEN
,
1212 .allow_runtime_pm
= true,
1213 .probe_slot
= ni_byt_sdio_probe_slot
,
1214 .add_host
= byt_add_host
,
1215 .remove_slot
= byt_remove_slot
,
1216 .ops
= &sdhci_intel_byt_ops
,
1217 .priv_size
= sizeof(struct intel_host
),
1220 static const struct sdhci_pci_fixes sdhci_intel_byt_sdio
= {
1221 #ifdef CONFIG_PM_SLEEP
1222 .resume
= byt_resume
,
1225 .runtime_resume
= byt_runtime_resume
,
1227 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
|
1229 .quirks2
= SDHCI_QUIRK2_HOST_OFF_CARD_ON
|
1230 SDHCI_QUIRK2_PRESET_VALUE_BROKEN
,
1231 .allow_runtime_pm
= true,
1232 .probe_slot
= byt_sdio_probe_slot
,
1233 .add_host
= byt_add_host
,
1234 .remove_slot
= byt_remove_slot
,
1235 .ops
= &sdhci_intel_byt_ops
,
1236 .priv_size
= sizeof(struct intel_host
),
1239 static const struct sdhci_pci_fixes sdhci_intel_byt_sd
= {
1240 #ifdef CONFIG_PM_SLEEP
1241 .resume
= byt_resume
,
1244 .runtime_resume
= byt_runtime_resume
,
1246 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
|
1248 .quirks2
= SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON
|
1249 SDHCI_QUIRK2_PRESET_VALUE_BROKEN
|
1250 SDHCI_QUIRK2_STOP_WITH_TC
,
1251 .allow_runtime_pm
= true,
1252 .own_cd_for_runtime_pm
= true,
1253 .probe_slot
= byt_sd_probe_slot
,
1254 .add_host
= byt_add_host
,
1255 .remove_slot
= byt_remove_slot
,
1256 .ops
= &sdhci_intel_byt_ops
,
1257 .priv_size
= sizeof(struct intel_host
),
1260 /* Define Host controllers for Intel Merrifield platform */
1261 #define INTEL_MRFLD_EMMC_0 0
1262 #define INTEL_MRFLD_EMMC_1 1
1263 #define INTEL_MRFLD_SD 2
1264 #define INTEL_MRFLD_SDIO 3
1267 static void intel_mrfld_mmc_fix_up_power_slot(struct sdhci_pci_slot
*slot
)
1269 struct acpi_device
*device
;
1271 device
= ACPI_COMPANION(&slot
->chip
->pdev
->dev
);
1273 acpi_device_fix_up_power_extended(device
);
1276 static inline void intel_mrfld_mmc_fix_up_power_slot(struct sdhci_pci_slot
*slot
) {}
1279 static int intel_mrfld_mmc_probe_slot(struct sdhci_pci_slot
*slot
)
1281 unsigned int func
= PCI_FUNC(slot
->chip
->pdev
->devfn
);
1284 case INTEL_MRFLD_EMMC_0
:
1285 case INTEL_MRFLD_EMMC_1
:
1286 slot
->host
->mmc
->caps
|= MMC_CAP_NONREMOVABLE
|
1287 MMC_CAP_8_BIT_DATA
|
1290 case INTEL_MRFLD_SD
:
1292 slot
->cd_override_level
= true;
1294 * There are two PCB designs of SD card slot with the opposite
1295 * card detection sense. Quirk this out by ignoring GPIO state
1296 * completely in the custom ->get_cd() callback.
1298 slot
->host
->mmc_host_ops
.get_cd
= mrfld_get_cd
;
1299 slot
->host
->quirks2
|= SDHCI_QUIRK2_NO_1_8_V
;
1301 case INTEL_MRFLD_SDIO
:
1302 /* Advertise 2.0v for compatibility with the SDIO card's OCR */
1303 slot
->host
->ocr_mask
= MMC_VDD_20_21
| MMC_VDD_165_195
;
1304 slot
->host
->mmc
->caps
|= MMC_CAP_NONREMOVABLE
|
1305 MMC_CAP_POWER_OFF_CARD
;
1311 intel_mrfld_mmc_fix_up_power_slot(slot
);
1315 static const struct sdhci_pci_fixes sdhci_intel_mrfld_mmc
= {
1316 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
1317 .quirks2
= SDHCI_QUIRK2_BROKEN_HS200
|
1318 SDHCI_QUIRK2_PRESET_VALUE_BROKEN
,
1319 .allow_runtime_pm
= true,
1320 .probe_slot
= intel_mrfld_mmc_probe_slot
,
1323 #define JMB388_SAMPLE_COUNT 5
1325 static int jmicron_jmb388_get_ro(struct mmc_host
*mmc
)
1330 for (i
= 0; i
< JMB388_SAMPLE_COUNT
; i
++) {
1331 if (sdhci_get_ro(mmc
) > 0) {
1332 if (++ro_count
> JMB388_SAMPLE_COUNT
/ 2)
1340 static int jmicron_pmos(struct sdhci_pci_chip
*chip
, int on
)
1345 ret
= pci_read_config_byte(chip
->pdev
, 0xAE, &scratch
);
1350 * Turn PMOS on [bit 0], set over current detection to 2.4 V
1351 * [bit 1:2] and enable over current debouncing [bit 6].
1358 ret
= pci_write_config_byte(chip
->pdev
, 0xAE, scratch
);
1361 return pcibios_err_to_errno(ret
);
1364 static int jmicron_probe(struct sdhci_pci_chip
*chip
)
1369 if (chip
->pdev
->revision
== 0) {
1370 chip
->quirks
|= SDHCI_QUIRK_32BIT_DMA_ADDR
|
1371 SDHCI_QUIRK_32BIT_DMA_SIZE
|
1372 SDHCI_QUIRK_32BIT_ADMA_SIZE
|
1373 SDHCI_QUIRK_RESET_AFTER_REQUEST
|
1374 SDHCI_QUIRK_BROKEN_SMALL_PIO
;
1378 * JMicron chips can have two interfaces to the same hardware
1379 * in order to work around limitations in Microsoft's driver.
1380 * We need to make sure we only bind to one of them.
1382 * This code assumes two things:
1384 * 1. The PCI code adds subfunctions in order.
1386 * 2. The MMC interface has a lower subfunction number
1387 * than the SD interface.
1389 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_SD
)
1390 mmcdev
= PCI_DEVICE_ID_JMICRON_JMB38X_MMC
;
1391 else if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_SD
)
1392 mmcdev
= PCI_DEVICE_ID_JMICRON_JMB388_ESD
;
1395 struct pci_dev
*sd_dev
;
1398 while ((sd_dev
= pci_get_device(PCI_VENDOR_ID_JMICRON
,
1399 mmcdev
, sd_dev
)) != NULL
) {
1400 if ((PCI_SLOT(chip
->pdev
->devfn
) ==
1401 PCI_SLOT(sd_dev
->devfn
)) &&
1402 (chip
->pdev
->bus
== sd_dev
->bus
))
1407 pci_dev_put(sd_dev
);
1408 dev_info(&chip
->pdev
->dev
, "Refusing to bind to "
1409 "secondary interface.\n");
1415 * JMicron chips need a bit of a nudge to enable the power
1418 ret
= jmicron_pmos(chip
, 1);
1420 dev_err(&chip
->pdev
->dev
, "Failure enabling card power\n");
1427 static void jmicron_enable_mmc(struct sdhci_host
*host
, int on
)
1431 scratch
= readb(host
->ioaddr
+ 0xC0);
1438 writeb(scratch
, host
->ioaddr
+ 0xC0);
1441 static int jmicron_probe_slot(struct sdhci_pci_slot
*slot
)
1443 if (slot
->chip
->pdev
->revision
== 0) {
1446 version
= readl(slot
->host
->ioaddr
+ SDHCI_HOST_VERSION
);
1447 version
= (version
& SDHCI_VENDOR_VER_MASK
) >>
1448 SDHCI_VENDOR_VER_SHIFT
;
1451 * Older versions of the chip have lots of nasty glitches
1452 * in the ADMA engine. It's best just to avoid it
1456 slot
->host
->quirks
|= SDHCI_QUIRK_BROKEN_ADMA
;
1459 /* JM388 MMC doesn't support 1.8V while SD supports it */
1460 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
) {
1461 slot
->host
->ocr_avail_sd
= MMC_VDD_32_33
| MMC_VDD_33_34
|
1462 MMC_VDD_29_30
| MMC_VDD_30_31
|
1463 MMC_VDD_165_195
; /* allow 1.8V */
1464 slot
->host
->ocr_avail_mmc
= MMC_VDD_32_33
| MMC_VDD_33_34
|
1465 MMC_VDD_29_30
| MMC_VDD_30_31
; /* no 1.8V for MMC */
1469 * The secondary interface requires a bit set to get the
1472 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
1473 slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
)
1474 jmicron_enable_mmc(slot
->host
, 1);
1476 slot
->host
->mmc
->caps
|= MMC_CAP_BUS_WIDTH_TEST
;
1478 /* Handle unstable RO-detection on JM388 chips */
1479 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_SD
||
1480 slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
)
1481 slot
->host
->mmc_host_ops
.get_ro
= jmicron_jmb388_get_ro
;
1486 static void jmicron_remove_slot(struct sdhci_pci_slot
*slot
, int dead
)
1491 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
1492 slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
)
1493 jmicron_enable_mmc(slot
->host
, 0);
1496 #ifdef CONFIG_PM_SLEEP
1497 static int jmicron_suspend(struct sdhci_pci_chip
*chip
)
1501 ret
= sdhci_pci_suspend_host(chip
);
1505 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
1506 chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
) {
1507 for (i
= 0; i
< chip
->num_slots
; i
++)
1508 jmicron_enable_mmc(chip
->slots
[i
]->host
, 0);
1514 static int jmicron_resume(struct sdhci_pci_chip
*chip
)
1518 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
1519 chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
) {
1520 for (i
= 0; i
< chip
->num_slots
; i
++)
1521 jmicron_enable_mmc(chip
->slots
[i
]->host
, 1);
1524 ret
= jmicron_pmos(chip
, 1);
1526 dev_err(&chip
->pdev
->dev
, "Failure enabling card power\n");
1530 return sdhci_pci_resume_host(chip
);
1534 static const struct sdhci_pci_fixes sdhci_jmicron
= {
1535 .probe
= jmicron_probe
,
1537 .probe_slot
= jmicron_probe_slot
,
1538 .remove_slot
= jmicron_remove_slot
,
1540 #ifdef CONFIG_PM_SLEEP
1541 .suspend
= jmicron_suspend
,
1542 .resume
= jmicron_resume
,
1546 /* SysKonnect CardBus2SDIO extra registers */
1547 #define SYSKT_CTRL 0x200
1548 #define SYSKT_RDFIFO_STAT 0x204
1549 #define SYSKT_WRFIFO_STAT 0x208
1550 #define SYSKT_POWER_DATA 0x20c
1551 #define SYSKT_POWER_330 0xef
1552 #define SYSKT_POWER_300 0xf8
1553 #define SYSKT_POWER_184 0xcc
1554 #define SYSKT_POWER_CMD 0x20d
1555 #define SYSKT_POWER_START (1 << 7)
1556 #define SYSKT_POWER_STATUS 0x20e
1557 #define SYSKT_POWER_STATUS_OK (1 << 0)
1558 #define SYSKT_BOARD_REV 0x210
1559 #define SYSKT_CHIP_REV 0x211
1560 #define SYSKT_CONF_DATA 0x212
1561 #define SYSKT_CONF_DATA_1V8 (1 << 2)
1562 #define SYSKT_CONF_DATA_2V5 (1 << 1)
1563 #define SYSKT_CONF_DATA_3V3 (1 << 0)
1565 static int syskt_probe(struct sdhci_pci_chip
*chip
)
1567 if ((chip
->pdev
->class & 0x0000FF) == PCI_SDHCI_IFVENDOR
) {
1568 chip
->pdev
->class &= ~0x0000FF;
1569 chip
->pdev
->class |= PCI_SDHCI_IFDMA
;
1574 static int syskt_probe_slot(struct sdhci_pci_slot
*slot
)
1578 u8 board_rev
= readb(slot
->host
->ioaddr
+ SYSKT_BOARD_REV
);
1579 u8 chip_rev
= readb(slot
->host
->ioaddr
+ SYSKT_CHIP_REV
);
1580 dev_info(&slot
->chip
->pdev
->dev
, "SysKonnect CardBus2SDIO, "
1581 "board rev %d.%d, chip rev %d.%d\n",
1582 board_rev
>> 4, board_rev
& 0xf,
1583 chip_rev
>> 4, chip_rev
& 0xf);
1584 if (chip_rev
>= 0x20)
1585 slot
->host
->quirks
|= SDHCI_QUIRK_FORCE_DMA
;
1587 writeb(SYSKT_POWER_330
, slot
->host
->ioaddr
+ SYSKT_POWER_DATA
);
1588 writeb(SYSKT_POWER_START
, slot
->host
->ioaddr
+ SYSKT_POWER_CMD
);
1590 tm
= 10; /* Wait max 1 ms */
1592 ps
= readw(slot
->host
->ioaddr
+ SYSKT_POWER_STATUS
);
1593 if (ps
& SYSKT_POWER_STATUS_OK
)
1598 dev_err(&slot
->chip
->pdev
->dev
,
1599 "power regulator never stabilized");
1600 writeb(0, slot
->host
->ioaddr
+ SYSKT_POWER_CMD
);
1607 static const struct sdhci_pci_fixes sdhci_syskt
= {
1608 .quirks
= SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER
,
1609 .probe
= syskt_probe
,
1610 .probe_slot
= syskt_probe_slot
,
1613 static int via_probe(struct sdhci_pci_chip
*chip
)
1615 if (chip
->pdev
->revision
== 0x10)
1616 chip
->quirks
|= SDHCI_QUIRK_DELAY_AFTER_POWER
;
1621 static const struct sdhci_pci_fixes sdhci_via
= {
1625 static int rtsx_probe_slot(struct sdhci_pci_slot
*slot
)
1627 slot
->host
->mmc
->caps2
|= MMC_CAP2_HS200
;
1631 static const struct sdhci_pci_fixes sdhci_rtsx
= {
1632 .quirks2
= SDHCI_QUIRK2_PRESET_VALUE_BROKEN
|
1633 SDHCI_QUIRK2_BROKEN_64_BIT_DMA
|
1634 SDHCI_QUIRK2_BROKEN_DDR50
,
1635 .probe_slot
= rtsx_probe_slot
,
1638 /*AMD chipset generation*/
1639 enum amd_chipset_gen
{
1640 AMD_CHIPSET_BEFORE_ML
,
1643 AMD_CHIPSET_UNKNOWN
,
1647 #define AMD_SD_AUTO_PATTERN 0xB8
1648 #define AMD_MSLEEP_DURATION 4
1649 #define AMD_SD_MISC_CONTROL 0xD0
1650 #define AMD_MAX_TUNE_VALUE 0x0B
1651 #define AMD_AUTO_TUNE_SEL 0x10800
1652 #define AMD_FIFO_PTR 0x30
1653 #define AMD_BIT_MASK 0x1F
1655 static void amd_tuning_reset(struct sdhci_host
*host
)
1659 val
= sdhci_readw(host
, SDHCI_HOST_CONTROL2
);
1660 val
|= SDHCI_CTRL_PRESET_VAL_ENABLE
| SDHCI_CTRL_EXEC_TUNING
;
1661 sdhci_writew(host
, val
, SDHCI_HOST_CONTROL2
);
1663 val
= sdhci_readw(host
, SDHCI_HOST_CONTROL2
);
1664 val
&= ~SDHCI_CTRL_EXEC_TUNING
;
1665 sdhci_writew(host
, val
, SDHCI_HOST_CONTROL2
);
1668 static void amd_config_tuning_phase(struct pci_dev
*pdev
, u8 phase
)
1672 pci_read_config_dword(pdev
, AMD_SD_AUTO_PATTERN
, &val
);
1673 val
&= ~AMD_BIT_MASK
;
1674 val
|= (AMD_AUTO_TUNE_SEL
| (phase
<< 1));
1675 pci_write_config_dword(pdev
, AMD_SD_AUTO_PATTERN
, val
);
1678 static void amd_enable_manual_tuning(struct pci_dev
*pdev
)
1682 pci_read_config_dword(pdev
, AMD_SD_MISC_CONTROL
, &val
);
1683 val
|= AMD_FIFO_PTR
;
1684 pci_write_config_dword(pdev
, AMD_SD_MISC_CONTROL
, val
);
1687 static int amd_execute_tuning_hs200(struct sdhci_host
*host
, u32 opcode
)
1689 struct sdhci_pci_slot
*slot
= sdhci_priv(host
);
1690 struct pci_dev
*pdev
= slot
->chip
->pdev
;
1692 u8 valid_win_max
= 0;
1693 u8 valid_win_end
= 0;
1694 u8 ctrl
, tune_around
;
1696 amd_tuning_reset(host
);
1698 for (tune_around
= 0; tune_around
< 12; tune_around
++) {
1699 amd_config_tuning_phase(pdev
, tune_around
);
1701 if (mmc_send_tuning(host
->mmc
, opcode
, NULL
)) {
1703 msleep(AMD_MSLEEP_DURATION
);
1704 ctrl
= SDHCI_RESET_CMD
| SDHCI_RESET_DATA
;
1705 sdhci_writeb(host
, ctrl
, SDHCI_SOFTWARE_RESET
);
1706 } else if (++valid_win
> valid_win_max
) {
1707 valid_win_max
= valid_win
;
1708 valid_win_end
= tune_around
;
1712 if (!valid_win_max
) {
1713 dev_err(&pdev
->dev
, "no tuning point found\n");
1717 amd_config_tuning_phase(pdev
, valid_win_end
- valid_win_max
/ 2);
1719 amd_enable_manual_tuning(pdev
);
1721 host
->mmc
->retune_period
= 0;
1726 static int amd_execute_tuning(struct mmc_host
*mmc
, u32 opcode
)
1728 struct sdhci_host
*host
= mmc_priv(mmc
);
1730 /* AMD requires custom HS200 tuning */
1731 if (host
->timing
== MMC_TIMING_MMC_HS200
)
1732 return amd_execute_tuning_hs200(host
, opcode
);
1734 /* Otherwise perform standard SDHCI tuning */
1735 return sdhci_execute_tuning(mmc
, opcode
);
1738 static int amd_probe_slot(struct sdhci_pci_slot
*slot
)
1740 struct mmc_host_ops
*ops
= &slot
->host
->mmc_host_ops
;
1742 ops
->execute_tuning
= amd_execute_tuning
;
1747 static int amd_probe(struct sdhci_pci_chip
*chip
)
1749 struct pci_dev
*smbus_dev
;
1750 enum amd_chipset_gen gen
;
1752 smbus_dev
= pci_get_device(PCI_VENDOR_ID_AMD
,
1753 PCI_DEVICE_ID_AMD_HUDSON2_SMBUS
, NULL
);
1755 gen
= AMD_CHIPSET_BEFORE_ML
;
1757 smbus_dev
= pci_get_device(PCI_VENDOR_ID_AMD
,
1758 PCI_DEVICE_ID_AMD_KERNCZ_SMBUS
, NULL
);
1760 if (smbus_dev
->revision
< 0x51)
1761 gen
= AMD_CHIPSET_CZ
;
1763 gen
= AMD_CHIPSET_NL
;
1765 gen
= AMD_CHIPSET_UNKNOWN
;
1769 pci_dev_put(smbus_dev
);
1771 if (gen
== AMD_CHIPSET_BEFORE_ML
|| gen
== AMD_CHIPSET_CZ
)
1772 chip
->quirks2
|= SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD
;
1777 static u32
sdhci_read_present_state(struct sdhci_host
*host
)
1779 return sdhci_readl(host
, SDHCI_PRESENT_STATE
);
1782 static void amd_sdhci_reset(struct sdhci_host
*host
, u8 mask
)
1784 struct sdhci_pci_slot
*slot
= sdhci_priv(host
);
1785 struct pci_dev
*pdev
= slot
->chip
->pdev
;
1789 * SDHC 0x7906 requires a hard reset to clear all internal state.
1790 * Otherwise it can get into a bad state where the DATA lines are always
1793 if (pdev
->device
== 0x7906 && (mask
& SDHCI_RESET_ALL
)) {
1794 pci_clear_master(pdev
);
1796 pci_save_state(pdev
);
1798 pci_set_power_state(pdev
, PCI_D3cold
);
1799 pr_debug("%s: power_state=%u\n", mmc_hostname(host
->mmc
),
1800 pdev
->current_state
);
1801 pci_set_power_state(pdev
, PCI_D0
);
1803 pci_restore_state(pdev
);
1806 * SDHCI_RESET_ALL says the card detect logic should not be
1807 * reset, but since we need to reset the entire controller
1808 * we should wait until the card detect logic has stabilized.
1810 * This normally takes about 40ms.
1813 sdhci_read_present_state
,
1816 present_state
& SDHCI_CD_STABLE
,
1822 return sdhci_reset(host
, mask
);
1825 static const struct sdhci_ops amd_sdhci_pci_ops
= {
1826 .set_clock
= sdhci_set_clock
,
1827 .enable_dma
= sdhci_pci_enable_dma
,
1828 .set_bus_width
= sdhci_set_bus_width
,
1829 .reset
= amd_sdhci_reset
,
1830 .set_uhs_signaling
= sdhci_set_uhs_signaling
,
1833 static const struct sdhci_pci_fixes sdhci_amd
= {
1835 .ops
= &amd_sdhci_pci_ops
,
1836 .probe_slot
= amd_probe_slot
,
1839 static const struct pci_device_id pci_ids
[] = {
1840 SDHCI_PCI_DEVICE(RICOH
, R5C822
, ricoh
),
1841 SDHCI_PCI_DEVICE(RICOH
, R5C843
, ricoh_mmc
),
1842 SDHCI_PCI_DEVICE(RICOH
, R5CE822
, ricoh_mmc
),
1843 SDHCI_PCI_DEVICE(RICOH
, R5CE823
, ricoh_mmc
),
1844 SDHCI_PCI_DEVICE(ENE
, CB712_SD
, ene_712
),
1845 SDHCI_PCI_DEVICE(ENE
, CB712_SD_2
, ene_712
),
1846 SDHCI_PCI_DEVICE(ENE
, CB714_SD
, ene_714
),
1847 SDHCI_PCI_DEVICE(ENE
, CB714_SD_2
, ene_714
),
1848 SDHCI_PCI_DEVICE(MARVELL
, 88ALP01_SD
, cafe
),
1849 SDHCI_PCI_DEVICE(JMICRON
, JMB38X_SD
, jmicron
),
1850 SDHCI_PCI_DEVICE(JMICRON
, JMB38X_MMC
, jmicron
),
1851 SDHCI_PCI_DEVICE(JMICRON
, JMB388_SD
, jmicron
),
1852 SDHCI_PCI_DEVICE(JMICRON
, JMB388_ESD
, jmicron
),
1853 SDHCI_PCI_DEVICE(SYSKONNECT
, 8000, syskt
),
1854 SDHCI_PCI_DEVICE(VIA
, 95D0
, via
),
1855 SDHCI_PCI_DEVICE(REALTEK
, 5250, rtsx
),
1856 SDHCI_PCI_DEVICE(INTEL
, QRK_SD
, intel_qrk
),
1857 SDHCI_PCI_DEVICE(INTEL
, MRST_SD0
, intel_mrst_hc0
),
1858 SDHCI_PCI_DEVICE(INTEL
, MRST_SD1
, intel_mrst_hc1_hc2
),
1859 SDHCI_PCI_DEVICE(INTEL
, MRST_SD2
, intel_mrst_hc1_hc2
),
1860 SDHCI_PCI_DEVICE(INTEL
, MFD_SD
, intel_mfd_sd
),
1861 SDHCI_PCI_DEVICE(INTEL
, MFD_SDIO1
, intel_mfd_sdio
),
1862 SDHCI_PCI_DEVICE(INTEL
, MFD_SDIO2
, intel_mfd_sdio
),
1863 SDHCI_PCI_DEVICE(INTEL
, MFD_EMMC0
, intel_mfd_emmc
),
1864 SDHCI_PCI_DEVICE(INTEL
, MFD_EMMC1
, intel_mfd_emmc
),
1865 SDHCI_PCI_DEVICE(INTEL
, PCH_SDIO0
, intel_pch_sdio
),
1866 SDHCI_PCI_DEVICE(INTEL
, PCH_SDIO1
, intel_pch_sdio
),
1867 SDHCI_PCI_DEVICE(INTEL
, BYT_EMMC
, intel_byt_emmc
),
1868 SDHCI_PCI_SUBDEVICE(INTEL
, BYT_SDIO
, NI
, 7884, ni_byt_sdio
),
1869 SDHCI_PCI_DEVICE(INTEL
, BYT_SDIO
, intel_byt_sdio
),
1870 SDHCI_PCI_DEVICE(INTEL
, BYT_SD
, intel_byt_sd
),
1871 SDHCI_PCI_DEVICE(INTEL
, BYT_EMMC2
, intel_byt_emmc
),
1872 SDHCI_PCI_DEVICE(INTEL
, BSW_EMMC
, intel_byt_emmc
),
1873 SDHCI_PCI_DEVICE(INTEL
, BSW_SDIO
, intel_byt_sdio
),
1874 SDHCI_PCI_DEVICE(INTEL
, BSW_SD
, intel_byt_sd
),
1875 SDHCI_PCI_DEVICE(INTEL
, CLV_SDIO0
, intel_mfd_sd
),
1876 SDHCI_PCI_DEVICE(INTEL
, CLV_SDIO1
, intel_mfd_sdio
),
1877 SDHCI_PCI_DEVICE(INTEL
, CLV_SDIO2
, intel_mfd_sdio
),
1878 SDHCI_PCI_DEVICE(INTEL
, CLV_EMMC0
, intel_mfd_emmc
),
1879 SDHCI_PCI_DEVICE(INTEL
, CLV_EMMC1
, intel_mfd_emmc
),
1880 SDHCI_PCI_DEVICE(INTEL
, MRFLD_MMC
, intel_mrfld_mmc
),
1881 SDHCI_PCI_DEVICE(INTEL
, SPT_EMMC
, intel_byt_emmc
),
1882 SDHCI_PCI_DEVICE(INTEL
, SPT_SDIO
, intel_byt_sdio
),
1883 SDHCI_PCI_DEVICE(INTEL
, SPT_SD
, intel_byt_sd
),
1884 SDHCI_PCI_DEVICE(INTEL
, DNV_EMMC
, intel_byt_emmc
),
1885 SDHCI_PCI_DEVICE(INTEL
, CDF_EMMC
, intel_glk_emmc
),
1886 SDHCI_PCI_DEVICE(INTEL
, BXT_EMMC
, intel_byt_emmc
),
1887 SDHCI_PCI_DEVICE(INTEL
, BXT_SDIO
, intel_byt_sdio
),
1888 SDHCI_PCI_DEVICE(INTEL
, BXT_SD
, intel_byt_sd
),
1889 SDHCI_PCI_DEVICE(INTEL
, BXTM_EMMC
, intel_byt_emmc
),
1890 SDHCI_PCI_DEVICE(INTEL
, BXTM_SDIO
, intel_byt_sdio
),
1891 SDHCI_PCI_DEVICE(INTEL
, BXTM_SD
, intel_byt_sd
),
1892 SDHCI_PCI_DEVICE(INTEL
, APL_EMMC
, intel_byt_emmc
),
1893 SDHCI_PCI_DEVICE(INTEL
, APL_SDIO
, intel_byt_sdio
),
1894 SDHCI_PCI_DEVICE(INTEL
, APL_SD
, intel_byt_sd
),
1895 SDHCI_PCI_DEVICE(INTEL
, GLK_EMMC
, intel_glk_emmc
),
1896 SDHCI_PCI_DEVICE(INTEL
, GLK_SDIO
, intel_byt_sdio
),
1897 SDHCI_PCI_DEVICE(INTEL
, GLK_SD
, intel_byt_sd
),
1898 SDHCI_PCI_DEVICE(INTEL
, CNP_EMMC
, intel_glk_emmc
),
1899 SDHCI_PCI_DEVICE(INTEL
, CNP_SD
, intel_byt_sd
),
1900 SDHCI_PCI_DEVICE(INTEL
, CNPH_SD
, intel_byt_sd
),
1901 SDHCI_PCI_DEVICE(INTEL
, ICP_EMMC
, intel_glk_emmc
),
1902 SDHCI_PCI_DEVICE(INTEL
, ICP_SD
, intel_byt_sd
),
1903 SDHCI_PCI_DEVICE(INTEL
, EHL_EMMC
, intel_glk_emmc
),
1904 SDHCI_PCI_DEVICE(INTEL
, EHL_SD
, intel_byt_sd
),
1905 SDHCI_PCI_DEVICE(INTEL
, CML_EMMC
, intel_glk_emmc
),
1906 SDHCI_PCI_DEVICE(INTEL
, CML_SD
, intel_byt_sd
),
1907 SDHCI_PCI_DEVICE(INTEL
, CMLH_SD
, intel_byt_sd
),
1908 SDHCI_PCI_DEVICE(INTEL
, JSL_EMMC
, intel_glk_emmc
),
1909 SDHCI_PCI_DEVICE(INTEL
, JSL_SD
, intel_byt_sd
),
1910 SDHCI_PCI_DEVICE(INTEL
, LKF_EMMC
, intel_glk_emmc
),
1911 SDHCI_PCI_DEVICE(INTEL
, LKF_SD
, intel_byt_sd
),
1912 SDHCI_PCI_DEVICE(INTEL
, ADL_EMMC
, intel_glk_emmc
),
1913 SDHCI_PCI_DEVICE(O2
, 8120, o2
),
1914 SDHCI_PCI_DEVICE(O2
, 8220, o2
),
1915 SDHCI_PCI_DEVICE(O2
, 8221, o2
),
1916 SDHCI_PCI_DEVICE(O2
, 8320, o2
),
1917 SDHCI_PCI_DEVICE(O2
, 8321, o2
),
1918 SDHCI_PCI_DEVICE(O2
, FUJIN2
, o2
),
1919 SDHCI_PCI_DEVICE(O2
, SDS0
, o2
),
1920 SDHCI_PCI_DEVICE(O2
, SDS1
, o2
),
1921 SDHCI_PCI_DEVICE(O2
, SEABIRD0
, o2
),
1922 SDHCI_PCI_DEVICE(O2
, SEABIRD1
, o2
),
1923 SDHCI_PCI_DEVICE(O2
, GG8_9860
, o2
),
1924 SDHCI_PCI_DEVICE(O2
, GG8_9861
, o2
),
1925 SDHCI_PCI_DEVICE(O2
, GG8_9862
, o2
),
1926 SDHCI_PCI_DEVICE(O2
, GG8_9863
, o2
),
1927 SDHCI_PCI_DEVICE(ARASAN
, PHY_EMMC
, arasan
),
1928 SDHCI_PCI_DEVICE(SYNOPSYS
, DWC_MSHC
, snps
),
1929 SDHCI_PCI_DEVICE(GLI
, 9750, gl9750
),
1930 SDHCI_PCI_DEVICE(GLI
, 9755, gl9755
),
1931 SDHCI_PCI_DEVICE(GLI
, 9763E
, gl9763e
),
1932 SDHCI_PCI_DEVICE(GLI
, 9767, gl9767
),
1933 SDHCI_PCI_DEVICE_CLASS(AMD
, SYSTEM_SDHCI
, PCI_CLASS_MASK
, amd
),
1934 /* Generic SD host controller */
1935 {PCI_DEVICE_CLASS(SYSTEM_SDHCI
, PCI_CLASS_MASK
)},
1936 { /* end: all zeroes */ },
1939 MODULE_DEVICE_TABLE(pci
, pci_ids
);
1941 /*****************************************************************************\
1943 * SDHCI core callbacks *
1945 \*****************************************************************************/
1947 int sdhci_pci_enable_dma(struct sdhci_host
*host
)
1949 struct sdhci_pci_slot
*slot
;
1950 struct pci_dev
*pdev
;
1952 slot
= sdhci_priv(host
);
1953 pdev
= slot
->chip
->pdev
;
1955 if (((pdev
->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI
<< 8)) &&
1956 ((pdev
->class & 0x0000FF) != PCI_SDHCI_IFDMA
) &&
1957 (host
->flags
& SDHCI_USE_SDMA
)) {
1958 dev_warn(&pdev
->dev
, "Will use DMA mode even though HW "
1959 "doesn't fully claim to support it.\n");
1962 pci_set_master(pdev
);
1967 static void sdhci_pci_hw_reset(struct sdhci_host
*host
)
1969 struct sdhci_pci_slot
*slot
= sdhci_priv(host
);
1972 slot
->hw_reset(host
);
1975 static const struct sdhci_ops sdhci_pci_ops
= {
1976 .set_clock
= sdhci_set_clock
,
1977 .enable_dma
= sdhci_pci_enable_dma
,
1978 .set_bus_width
= sdhci_set_bus_width
,
1979 .reset
= sdhci_reset
,
1980 .set_uhs_signaling
= sdhci_set_uhs_signaling
,
1981 .hw_reset
= sdhci_pci_hw_reset
,
1984 /*****************************************************************************\
1988 \*****************************************************************************/
1990 #ifdef CONFIG_PM_SLEEP
1991 static int sdhci_pci_suspend(struct device
*dev
)
1993 struct sdhci_pci_chip
*chip
= dev_get_drvdata(dev
);
1998 if (chip
->fixes
&& chip
->fixes
->suspend
)
1999 return chip
->fixes
->suspend(chip
);
2001 return sdhci_pci_suspend_host(chip
);
2004 static int sdhci_pci_resume(struct device
*dev
)
2006 struct sdhci_pci_chip
*chip
= dev_get_drvdata(dev
);
2011 if (chip
->fixes
&& chip
->fixes
->resume
)
2012 return chip
->fixes
->resume(chip
);
2014 return sdhci_pci_resume_host(chip
);
2019 static int sdhci_pci_runtime_suspend(struct device
*dev
)
2021 struct sdhci_pci_chip
*chip
= dev_get_drvdata(dev
);
2026 if (chip
->fixes
&& chip
->fixes
->runtime_suspend
)
2027 return chip
->fixes
->runtime_suspend(chip
);
2029 return sdhci_pci_runtime_suspend_host(chip
);
2032 static int sdhci_pci_runtime_resume(struct device
*dev
)
2034 struct sdhci_pci_chip
*chip
= dev_get_drvdata(dev
);
2039 if (chip
->fixes
&& chip
->fixes
->runtime_resume
)
2040 return chip
->fixes
->runtime_resume(chip
);
2042 return sdhci_pci_runtime_resume_host(chip
);
2046 static const struct dev_pm_ops sdhci_pci_pm_ops
= {
2047 SET_SYSTEM_SLEEP_PM_OPS(sdhci_pci_suspend
, sdhci_pci_resume
)
2048 SET_RUNTIME_PM_OPS(sdhci_pci_runtime_suspend
,
2049 sdhci_pci_runtime_resume
, NULL
)
2052 /*****************************************************************************\
2054 * Device probing/removal *
2056 \*****************************************************************************/
2058 static struct sdhci_pci_slot
*sdhci_pci_probe_slot(
2059 struct pci_dev
*pdev
, struct sdhci_pci_chip
*chip
, int first_bar
,
2062 struct sdhci_pci_slot
*slot
;
2063 struct sdhci_host
*host
;
2064 int ret
, bar
= first_bar
+ slotno
;
2065 size_t priv_size
= chip
->fixes
? chip
->fixes
->priv_size
: 0;
2067 if (!(pci_resource_flags(pdev
, bar
) & IORESOURCE_MEM
)) {
2068 dev_err(&pdev
->dev
, "BAR %d is not iomem. Aborting.\n", bar
);
2069 return ERR_PTR(-ENODEV
);
2072 if (pci_resource_len(pdev
, bar
) < 0x100) {
2073 dev_err(&pdev
->dev
, "Invalid iomem size. You may "
2074 "experience problems.\n");
2077 if ((pdev
->class & 0x0000FF) == PCI_SDHCI_IFVENDOR
) {
2078 dev_err(&pdev
->dev
, "Vendor specific interface. Aborting.\n");
2079 return ERR_PTR(-ENODEV
);
2082 if ((pdev
->class & 0x0000FF) > PCI_SDHCI_IFVENDOR
) {
2083 dev_err(&pdev
->dev
, "Unknown interface. Aborting.\n");
2084 return ERR_PTR(-ENODEV
);
2087 host
= sdhci_alloc_host(&pdev
->dev
, sizeof(*slot
) + priv_size
);
2089 dev_err(&pdev
->dev
, "cannot allocate host\n");
2090 return ERR_CAST(host
);
2093 slot
= sdhci_priv(host
);
2099 host
->hw_name
= "PCI";
2100 host
->ops
= chip
->fixes
&& chip
->fixes
->ops
?
2103 host
->quirks
= chip
->quirks
;
2104 host
->quirks2
= chip
->quirks2
;
2106 host
->irq
= pdev
->irq
;
2108 ret
= pcim_iomap_regions(pdev
, BIT(bar
), mmc_hostname(host
->mmc
));
2110 dev_err(&pdev
->dev
, "cannot request region\n");
2114 host
->ioaddr
= pcim_iomap_table(pdev
)[bar
];
2116 if (chip
->fixes
&& chip
->fixes
->probe_slot
) {
2117 ret
= chip
->fixes
->probe_slot(slot
);
2122 host
->mmc
->pm_caps
= MMC_PM_KEEP_POWER
;
2123 host
->mmc
->slotno
= slotno
;
2124 host
->mmc
->caps2
|= MMC_CAP2_NO_PRESCAN_POWERUP
;
2126 if (device_can_wakeup(&pdev
->dev
))
2127 host
->mmc
->pm_caps
|= MMC_PM_WAKE_SDIO_IRQ
;
2129 if (host
->mmc
->caps
& MMC_CAP_CD_WAKE
)
2130 device_init_wakeup(&pdev
->dev
, true);
2132 if (slot
->cd_idx
>= 0) {
2133 ret
= mmc_gpiod_request_cd(host
->mmc
, "cd", slot
->cd_idx
,
2134 slot
->cd_override_level
, 0);
2135 if (ret
&& ret
!= -EPROBE_DEFER
)
2136 ret
= mmc_gpiod_request_cd(host
->mmc
, NULL
,
2138 slot
->cd_override_level
,
2140 if (ret
== -EPROBE_DEFER
)
2144 dev_warn(&pdev
->dev
, "failed to setup card detect gpio\n");
2149 if (chip
->fixes
&& chip
->fixes
->add_host
)
2150 ret
= chip
->fixes
->add_host(slot
);
2152 ret
= sdhci_add_host(host
);
2157 * Check if the chip needs a separate GPIO for card detect to wake up
2158 * from runtime suspend. If it is not there, don't allow runtime PM.
2160 if (chip
->fixes
&& chip
->fixes
->own_cd_for_runtime_pm
&& slot
->cd_idx
< 0)
2161 chip
->allow_runtime_pm
= false;
2166 if (chip
->fixes
&& chip
->fixes
->remove_slot
)
2167 chip
->fixes
->remove_slot(slot
, 0);
2170 sdhci_free_host(host
);
2172 return ERR_PTR(ret
);
2175 static void sdhci_pci_remove_slot(struct sdhci_pci_slot
*slot
)
2181 scratch
= readl(slot
->host
->ioaddr
+ SDHCI_INT_STATUS
);
2182 if (scratch
== (u32
)-1)
2185 if (slot
->chip
->fixes
&& slot
->chip
->fixes
->remove_host
)
2186 slot
->chip
->fixes
->remove_host(slot
, dead
);
2188 sdhci_remove_host(slot
->host
, dead
);
2190 if (slot
->chip
->fixes
&& slot
->chip
->fixes
->remove_slot
)
2191 slot
->chip
->fixes
->remove_slot(slot
, dead
);
2193 sdhci_free_host(slot
->host
);
2196 int sdhci_pci_uhs2_add_host(struct sdhci_pci_slot
*slot
)
2198 return sdhci_uhs2_add_host(slot
->host
);
2201 void sdhci_pci_uhs2_remove_host(struct sdhci_pci_slot
*slot
, int dead
)
2203 sdhci_uhs2_remove_host(slot
->host
, dead
);
2206 static void sdhci_pci_runtime_pm_allow(struct device
*dev
)
2208 pm_suspend_ignore_children(dev
, 1);
2209 pm_runtime_set_autosuspend_delay(dev
, 50);
2210 pm_runtime_use_autosuspend(dev
);
2211 pm_runtime_allow(dev
);
2212 /* Stay active until mmc core scans for a card */
2213 pm_runtime_put_noidle(dev
);
2216 static void sdhci_pci_runtime_pm_forbid(struct device
*dev
)
2218 pm_runtime_forbid(dev
);
2219 pm_runtime_get_noresume(dev
);
2222 static int sdhci_pci_probe(struct pci_dev
*pdev
,
2223 const struct pci_device_id
*ent
)
2225 struct sdhci_pci_chip
*chip
;
2226 struct sdhci_pci_slot
*slot
;
2228 u8 slots
, first_bar
;
2231 BUG_ON(pdev
== NULL
);
2232 BUG_ON(ent
== NULL
);
2234 dev_info(&pdev
->dev
, "SDHCI controller found [%04x:%04x] (rev %x)\n",
2235 (int)pdev
->vendor
, (int)pdev
->device
, (int)pdev
->revision
);
2237 ret
= pci_read_config_byte(pdev
, PCI_SLOT_INFO
, &slots
);
2239 return pcibios_err_to_errno(ret
);
2241 slots
= PCI_SLOT_INFO_SLOTS(slots
) + 1;
2242 dev_dbg(&pdev
->dev
, "found %d slot(s)\n", slots
);
2244 BUG_ON(slots
> MAX_SLOTS
);
2246 ret
= pci_read_config_byte(pdev
, PCI_SLOT_INFO
, &first_bar
);
2248 return pcibios_err_to_errno(ret
);
2250 first_bar
&= PCI_SLOT_INFO_FIRST_BAR_MASK
;
2252 if (first_bar
> 5) {
2253 dev_err(&pdev
->dev
, "Invalid first BAR. Aborting.\n");
2257 ret
= pcim_enable_device(pdev
);
2261 chip
= devm_kzalloc(&pdev
->dev
, sizeof(*chip
), GFP_KERNEL
);
2266 chip
->fixes
= (const struct sdhci_pci_fixes
*)ent
->driver_data
;
2268 chip
->quirks
= chip
->fixes
->quirks
;
2269 chip
->quirks2
= chip
->fixes
->quirks2
;
2270 chip
->allow_runtime_pm
= chip
->fixes
->allow_runtime_pm
;
2272 chip
->num_slots
= slots
;
2273 chip
->pm_retune
= true;
2274 chip
->rpm_retune
= true;
2276 pci_set_drvdata(pdev
, chip
);
2278 if (chip
->fixes
&& chip
->fixes
->probe
) {
2279 ret
= chip
->fixes
->probe(chip
);
2284 slots
= chip
->num_slots
; /* Quirk may have changed this */
2286 for (i
= 0; i
< slots
; i
++) {
2287 slot
= sdhci_pci_probe_slot(pdev
, chip
, first_bar
, i
);
2289 for (i
--; i
>= 0; i
--)
2290 sdhci_pci_remove_slot(chip
->slots
[i
]);
2291 return PTR_ERR(slot
);
2294 chip
->slots
[i
] = slot
;
2297 if (chip
->allow_runtime_pm
)
2298 sdhci_pci_runtime_pm_allow(&pdev
->dev
);
2303 static void sdhci_pci_remove(struct pci_dev
*pdev
)
2306 struct sdhci_pci_chip
*chip
= pci_get_drvdata(pdev
);
2308 if (chip
->allow_runtime_pm
)
2309 sdhci_pci_runtime_pm_forbid(&pdev
->dev
);
2311 for (i
= 0; i
< chip
->num_slots
; i
++)
2312 sdhci_pci_remove_slot(chip
->slots
[i
]);
2315 static struct pci_driver sdhci_driver
= {
2316 .name
= "sdhci-pci",
2317 .id_table
= pci_ids
,
2318 .probe
= sdhci_pci_probe
,
2319 .remove
= sdhci_pci_remove
,
2321 .pm
= &sdhci_pci_pm_ops
,
2322 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
2326 module_pci_driver(sdhci_driver
);
2328 MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
2329 MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
2330 MODULE_LICENSE("GPL");