1 /* linux/drivers/mmc/host/sdhci-pci.c - SDHCI on PCI bus interface
3 * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * Thanks to the following companies for their support:
12 * - JMicron (hardware and technical support)
15 #include <linux/delay.h>
16 #include <linux/highmem.h>
17 #include <linux/module.h>
18 #include <linux/pci.h>
19 #include <linux/dma-mapping.h>
20 #include <linux/slab.h>
21 #include <linux/device.h>
22 #include <linux/mmc/host.h>
23 #include <linux/mmc/mmc.h>
24 #include <linux/scatterlist.h>
26 #include <linux/gpio.h>
27 #include <linux/pm_runtime.h>
28 #include <linux/mmc/slot-gpio.h>
29 #include <linux/mmc/sdhci-pci-data.h>
32 #include "sdhci-pci.h"
33 #include "sdhci-pci-o2micro.h"
35 static int sdhci_pci_enable_dma(struct sdhci_host *host);
36 static void sdhci_pci_set_bus_width(struct sdhci_host *host, int width);
37 static void sdhci_pci_hw_reset(struct sdhci_host *host);
38 static int sdhci_pci_select_drive_strength(struct sdhci_host *host,
39 struct mmc_card *card,
40 unsigned int max_dtr, int host_drv,
41 int card_drv, int *drv_type);
43 /*****************************************************************************\
45 * Hardware specific quirk handling *
47 \*****************************************************************************/
49 static int ricoh_probe(struct sdhci_pci_chip *chip)
51 if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
52 chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
53 chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
57 static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot)
60 ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT)
61 & SDHCI_TIMEOUT_CLK_MASK) |
63 ((0x21 << SDHCI_CLOCK_BASE_SHIFT)
64 & SDHCI_CLOCK_BASE_MASK) |
66 SDHCI_TIMEOUT_CLK_UNIT |
73 static int ricoh_mmc_resume(struct sdhci_pci_chip *chip)
75 /* Apply a delay to allow controller to settle */
76 /* Otherwise it becomes confused if card state changed
82 static const struct sdhci_pci_fixes sdhci_ricoh = {
84 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
85 SDHCI_QUIRK_FORCE_DMA |
86 SDHCI_QUIRK_CLOCK_BEFORE_RESET,
89 static const struct sdhci_pci_fixes sdhci_ricoh_mmc = {
90 .probe_slot = ricoh_mmc_probe_slot,
91 .resume = ricoh_mmc_resume,
92 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
93 SDHCI_QUIRK_CLOCK_BEFORE_RESET |
94 SDHCI_QUIRK_NO_CARD_NO_RESET |
95 SDHCI_QUIRK_MISSING_CAPS
98 static const struct sdhci_pci_fixes sdhci_ene_712 = {
99 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
100 SDHCI_QUIRK_BROKEN_DMA,
103 static const struct sdhci_pci_fixes sdhci_ene_714 = {
104 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
105 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
106 SDHCI_QUIRK_BROKEN_DMA,
109 static const struct sdhci_pci_fixes sdhci_cafe = {
110 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
111 SDHCI_QUIRK_NO_BUSY_IRQ |
112 SDHCI_QUIRK_BROKEN_CARD_DETECTION |
113 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
116 static const struct sdhci_pci_fixes sdhci_intel_qrk = {
117 .quirks = SDHCI_QUIRK_NO_HISPD_BIT,
120 static int mrst_hc_probe_slot(struct sdhci_pci_slot *slot)
122 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
127 * ADMA operation is disabled for Moorestown platform due to
130 static int mrst_hc_probe(struct sdhci_pci_chip *chip)
133 * slots number is fixed here for MRST as SDIO3/5 are never used and
134 * have hardware bugs.
140 static int pch_hc_probe_slot(struct sdhci_pci_slot *slot)
142 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
148 static irqreturn_t sdhci_pci_sd_cd(int irq, void *dev_id)
150 struct sdhci_pci_slot *slot = dev_id;
151 struct sdhci_host *host = slot->host;
153 mmc_detect_change(host->mmc, msecs_to_jiffies(200));
157 static void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
159 int err, irq, gpio = slot->cd_gpio;
161 slot->cd_gpio = -EINVAL;
162 slot->cd_irq = -EINVAL;
164 if (!gpio_is_valid(gpio))
167 err = devm_gpio_request(&slot->chip->pdev->dev, gpio, "sd_cd");
171 err = gpio_direction_input(gpio);
175 irq = gpio_to_irq(gpio);
179 err = request_irq(irq, sdhci_pci_sd_cd, IRQF_TRIGGER_RISING |
180 IRQF_TRIGGER_FALLING, "sd_cd", slot);
184 slot->cd_gpio = gpio;
190 devm_gpio_free(&slot->chip->pdev->dev, gpio);
192 dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n");
195 static void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
197 if (slot->cd_irq >= 0)
198 free_irq(slot->cd_irq, slot);
203 static inline void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
207 static inline void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
213 static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot)
215 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE;
216 slot->host->mmc->caps2 |= MMC_CAP2_BOOTPART_NOACC |
217 MMC_CAP2_HC_ERASE_SZ;
221 static int mfd_sdio_probe_slot(struct sdhci_pci_slot *slot)
223 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE;
227 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = {
228 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
229 .probe_slot = mrst_hc_probe_slot,
232 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = {
233 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
234 .probe = mrst_hc_probe,
237 static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
238 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
239 .allow_runtime_pm = true,
240 .own_cd_for_runtime_pm = true,
243 static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = {
244 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
245 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
246 .allow_runtime_pm = true,
247 .probe_slot = mfd_sdio_probe_slot,
250 static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = {
251 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
252 .allow_runtime_pm = true,
253 .probe_slot = mfd_emmc_probe_slot,
256 static const struct sdhci_pci_fixes sdhci_intel_pch_sdio = {
257 .quirks = SDHCI_QUIRK_BROKEN_ADMA,
258 .probe_slot = pch_hc_probe_slot,
261 static void sdhci_pci_int_hw_reset(struct sdhci_host *host)
265 reg = sdhci_readb(host, SDHCI_POWER_CONTROL);
267 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
268 /* For eMMC, minimum is 1us but give it 9us for good measure */
271 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
272 /* For eMMC, minimum is 200us but give it 300us for good measure */
273 usleep_range(300, 1000);
276 static int spt_select_drive_strength(struct sdhci_host *host,
277 struct mmc_card *card,
278 unsigned int max_dtr,
279 int host_drv, int card_drv, int *drv_type)
283 if (sdhci_pci_spt_drive_strength > 0)
284 drive_strength = sdhci_pci_spt_drive_strength & 0xf;
286 drive_strength = 0; /* Default 50-ohm */
288 if ((mmc_driver_type_mask(drive_strength) & card_drv) == 0)
289 drive_strength = 0; /* Default 50-ohm */
291 return drive_strength;
294 /* Try to read the drive strength from the card */
295 static void spt_read_drive_strength(struct sdhci_host *host)
300 if (sdhci_pci_spt_drive_strength)
303 sdhci_pci_spt_drive_strength = -1;
305 m = sdhci_readw(host, SDHCI_HOST_CONTROL2) & 0x7;
306 if (m != 3 && m != 5)
308 val = sdhci_readl(host, SDHCI_PRESENT_STATE);
311 sdhci_writel(host, 0x007f0023, SDHCI_INT_ENABLE);
312 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE);
313 sdhci_writew(host, 0x10, SDHCI_TRANSFER_MODE);
314 sdhci_writeb(host, 0xe, SDHCI_TIMEOUT_CONTROL);
315 sdhci_writew(host, 512, SDHCI_BLOCK_SIZE);
316 sdhci_writew(host, 1, SDHCI_BLOCK_COUNT);
317 sdhci_writel(host, 0, SDHCI_ARGUMENT);
318 sdhci_writew(host, 0x83b, SDHCI_COMMAND);
319 for (i = 0; i < 1000; i++) {
320 val = sdhci_readl(host, SDHCI_INT_STATUS);
321 if (val & 0xffff8000)
327 val = sdhci_readl(host, SDHCI_PRESENT_STATE);
330 for (i = 0; i < 47; i++)
331 val = sdhci_readl(host, SDHCI_BUFFER);
333 if (t != 0x200 && t != 0x300)
336 sdhci_pci_spt_drive_strength = 0x10 | ((val >> 12) & 0xf);
339 static int bxt_get_cd(struct mmc_host *mmc)
341 int gpio_cd = mmc_gpio_get_cd(mmc);
342 struct sdhci_host *host = mmc_priv(mmc);
349 spin_lock_irqsave(&host->lock, flags);
351 if (host->flags & SDHCI_DEVICE_DEAD)
354 ret = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
356 spin_unlock_irqrestore(&host->lock, flags);
361 static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot)
363 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
364 MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR |
365 MMC_CAP_CMD_DURING_TFR |
366 MMC_CAP_WAIT_WHILE_BUSY;
367 slot->host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ;
368 slot->hw_reset = sdhci_pci_int_hw_reset;
369 if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BSW_EMMC)
370 slot->host->timeout_clk = 1000; /* 1000 kHz i.e. 1 MHz */
371 if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_SPT_EMMC) {
372 spt_read_drive_strength(slot->host);
373 slot->select_drive_strength = spt_select_drive_strength;
378 static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot)
380 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE |
381 MMC_CAP_WAIT_WHILE_BUSY;
385 static int byt_sd_probe_slot(struct sdhci_pci_slot *slot)
387 slot->host->mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
388 slot->cd_con_id = NULL;
390 slot->cd_override_level = true;
391 if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXT_SD ||
392 slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXTM_SD ||
393 slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_APL_SD) {
394 slot->host->mmc_host_ops.get_cd = bxt_get_cd;
395 slot->host->mmc->caps |= MMC_CAP_AGGRESSIVE_PM;
401 #define SDHCI_INTEL_PWR_TIMEOUT_CNT 20
402 #define SDHCI_INTEL_PWR_TIMEOUT_UDELAY 100
404 static void sdhci_intel_set_power(struct sdhci_host *host, unsigned char mode,
410 sdhci_set_power(host, mode, vdd);
412 if (mode == MMC_POWER_OFF)
416 * Bus power might not enable after D3 -> D0 transition due to the
417 * present state not yet having propagated. Retry for up to 2ms.
419 for (cntr = 0; cntr < SDHCI_INTEL_PWR_TIMEOUT_CNT; cntr++) {
420 reg = sdhci_readb(host, SDHCI_POWER_CONTROL);
421 if (reg & SDHCI_POWER_ON)
423 udelay(SDHCI_INTEL_PWR_TIMEOUT_UDELAY);
424 reg |= SDHCI_POWER_ON;
425 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
429 static const struct sdhci_ops sdhci_intel_byt_ops = {
430 .set_clock = sdhci_set_clock,
431 .set_power = sdhci_intel_set_power,
432 .enable_dma = sdhci_pci_enable_dma,
433 .set_bus_width = sdhci_pci_set_bus_width,
434 .reset = sdhci_reset,
435 .set_uhs_signaling = sdhci_set_uhs_signaling,
436 .hw_reset = sdhci_pci_hw_reset,
437 .select_drive_strength = sdhci_pci_select_drive_strength,
440 static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = {
441 .allow_runtime_pm = true,
442 .probe_slot = byt_emmc_probe_slot,
443 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
444 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
445 SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 |
446 SDHCI_QUIRK2_STOP_WITH_TC,
447 .ops = &sdhci_intel_byt_ops,
450 static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
451 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
452 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON |
453 SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
454 .allow_runtime_pm = true,
455 .probe_slot = byt_sdio_probe_slot,
456 .ops = &sdhci_intel_byt_ops,
459 static const struct sdhci_pci_fixes sdhci_intel_byt_sd = {
460 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
461 .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON |
462 SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
463 SDHCI_QUIRK2_STOP_WITH_TC,
464 .allow_runtime_pm = true,
465 .own_cd_for_runtime_pm = true,
466 .probe_slot = byt_sd_probe_slot,
467 .ops = &sdhci_intel_byt_ops,
470 /* Define Host controllers for Intel Merrifield platform */
471 #define INTEL_MRFLD_EMMC_0 0
472 #define INTEL_MRFLD_EMMC_1 1
473 #define INTEL_MRFLD_SD 2
474 #define INTEL_MRFLD_SDIO 3
476 static int intel_mrfld_mmc_probe_slot(struct sdhci_pci_slot *slot)
478 unsigned int func = PCI_FUNC(slot->chip->pdev->devfn);
481 case INTEL_MRFLD_EMMC_0:
482 case INTEL_MRFLD_EMMC_1:
483 slot->host->mmc->caps |= MMC_CAP_NONREMOVABLE |
488 slot->host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V;
490 case INTEL_MRFLD_SDIO:
491 slot->host->mmc->caps |= MMC_CAP_NONREMOVABLE |
492 MMC_CAP_POWER_OFF_CARD;
500 static const struct sdhci_pci_fixes sdhci_intel_mrfld_mmc = {
501 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
502 .quirks2 = SDHCI_QUIRK2_BROKEN_HS200 |
503 SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
504 .allow_runtime_pm = true,
505 .probe_slot = intel_mrfld_mmc_probe_slot,
508 /* O2Micro extra registers */
509 #define O2_SD_LOCK_WP 0xD3
510 #define O2_SD_MULTI_VCC3V 0xEE
511 #define O2_SD_CLKREQ 0xEC
512 #define O2_SD_CAPS 0xE0
513 #define O2_SD_ADMA1 0xE2
514 #define O2_SD_ADMA2 0xE7
515 #define O2_SD_INF_MOD 0xF1
517 static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
522 ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
527 * Turn PMOS on [bit 0], set over current detection to 2.4 V
528 * [bit 1:2] and enable over current debouncing [bit 6].
535 return pci_write_config_byte(chip->pdev, 0xAE, scratch);
538 static int jmicron_probe(struct sdhci_pci_chip *chip)
543 if (chip->pdev->revision == 0) {
544 chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR |
545 SDHCI_QUIRK_32BIT_DMA_SIZE |
546 SDHCI_QUIRK_32BIT_ADMA_SIZE |
547 SDHCI_QUIRK_RESET_AFTER_REQUEST |
548 SDHCI_QUIRK_BROKEN_SMALL_PIO;
552 * JMicron chips can have two interfaces to the same hardware
553 * in order to work around limitations in Microsoft's driver.
554 * We need to make sure we only bind to one of them.
556 * This code assumes two things:
558 * 1. The PCI code adds subfunctions in order.
560 * 2. The MMC interface has a lower subfunction number
561 * than the SD interface.
563 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD)
564 mmcdev = PCI_DEVICE_ID_JMICRON_JMB38X_MMC;
565 else if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD)
566 mmcdev = PCI_DEVICE_ID_JMICRON_JMB388_ESD;
569 struct pci_dev *sd_dev;
572 while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON,
573 mmcdev, sd_dev)) != NULL) {
574 if ((PCI_SLOT(chip->pdev->devfn) ==
575 PCI_SLOT(sd_dev->devfn)) &&
576 (chip->pdev->bus == sd_dev->bus))
582 dev_info(&chip->pdev->dev, "Refusing to bind to "
583 "secondary interface.\n");
589 * JMicron chips need a bit of a nudge to enable the power
592 ret = jmicron_pmos(chip, 1);
594 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
598 /* quirk for unsable RO-detection on JM388 chips */
599 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD ||
600 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
601 chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT;
606 static void jmicron_enable_mmc(struct sdhci_host *host, int on)
610 scratch = readb(host->ioaddr + 0xC0);
617 writeb(scratch, host->ioaddr + 0xC0);
620 static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
622 if (slot->chip->pdev->revision == 0) {
625 version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
626 version = (version & SDHCI_VENDOR_VER_MASK) >>
627 SDHCI_VENDOR_VER_SHIFT;
630 * Older versions of the chip have lots of nasty glitches
631 * in the ADMA engine. It's best just to avoid it
635 slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
638 /* JM388 MMC doesn't support 1.8V while SD supports it */
639 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
640 slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 |
641 MMC_VDD_29_30 | MMC_VDD_30_31 |
642 MMC_VDD_165_195; /* allow 1.8V */
643 slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 |
644 MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */
648 * The secondary interface requires a bit set to get the
651 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
652 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
653 jmicron_enable_mmc(slot->host, 1);
655 slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST;
660 static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
665 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
666 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
667 jmicron_enable_mmc(slot->host, 0);
670 static int jmicron_suspend(struct sdhci_pci_chip *chip)
674 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
675 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
676 for (i = 0; i < chip->num_slots; i++)
677 jmicron_enable_mmc(chip->slots[i]->host, 0);
683 static int jmicron_resume(struct sdhci_pci_chip *chip)
687 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
688 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
689 for (i = 0; i < chip->num_slots; i++)
690 jmicron_enable_mmc(chip->slots[i]->host, 1);
693 ret = jmicron_pmos(chip, 1);
695 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
702 static const struct sdhci_pci_fixes sdhci_o2 = {
703 .probe = sdhci_pci_o2_probe,
704 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
705 .quirks2 = SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD,
706 .probe_slot = sdhci_pci_o2_probe_slot,
707 .resume = sdhci_pci_o2_resume,
710 static const struct sdhci_pci_fixes sdhci_jmicron = {
711 .probe = jmicron_probe,
713 .probe_slot = jmicron_probe_slot,
714 .remove_slot = jmicron_remove_slot,
716 .suspend = jmicron_suspend,
717 .resume = jmicron_resume,
720 /* SysKonnect CardBus2SDIO extra registers */
721 #define SYSKT_CTRL 0x200
722 #define SYSKT_RDFIFO_STAT 0x204
723 #define SYSKT_WRFIFO_STAT 0x208
724 #define SYSKT_POWER_DATA 0x20c
725 #define SYSKT_POWER_330 0xef
726 #define SYSKT_POWER_300 0xf8
727 #define SYSKT_POWER_184 0xcc
728 #define SYSKT_POWER_CMD 0x20d
729 #define SYSKT_POWER_START (1 << 7)
730 #define SYSKT_POWER_STATUS 0x20e
731 #define SYSKT_POWER_STATUS_OK (1 << 0)
732 #define SYSKT_BOARD_REV 0x210
733 #define SYSKT_CHIP_REV 0x211
734 #define SYSKT_CONF_DATA 0x212
735 #define SYSKT_CONF_DATA_1V8 (1 << 2)
736 #define SYSKT_CONF_DATA_2V5 (1 << 1)
737 #define SYSKT_CONF_DATA_3V3 (1 << 0)
739 static int syskt_probe(struct sdhci_pci_chip *chip)
741 if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
742 chip->pdev->class &= ~0x0000FF;
743 chip->pdev->class |= PCI_SDHCI_IFDMA;
748 static int syskt_probe_slot(struct sdhci_pci_slot *slot)
752 u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV);
753 u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV);
754 dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, "
755 "board rev %d.%d, chip rev %d.%d\n",
756 board_rev >> 4, board_rev & 0xf,
757 chip_rev >> 4, chip_rev & 0xf);
758 if (chip_rev >= 0x20)
759 slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA;
761 writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA);
762 writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD);
764 tm = 10; /* Wait max 1 ms */
766 ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS);
767 if (ps & SYSKT_POWER_STATUS_OK)
772 dev_err(&slot->chip->pdev->dev,
773 "power regulator never stabilized");
774 writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD);
781 static const struct sdhci_pci_fixes sdhci_syskt = {
782 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER,
783 .probe = syskt_probe,
784 .probe_slot = syskt_probe_slot,
787 static int via_probe(struct sdhci_pci_chip *chip)
789 if (chip->pdev->revision == 0x10)
790 chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
795 static const struct sdhci_pci_fixes sdhci_via = {
799 static int rtsx_probe_slot(struct sdhci_pci_slot *slot)
801 slot->host->mmc->caps2 |= MMC_CAP2_HS200;
805 static const struct sdhci_pci_fixes sdhci_rtsx = {
806 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
807 SDHCI_QUIRK2_BROKEN_64_BIT_DMA |
808 SDHCI_QUIRK2_BROKEN_DDR50,
809 .probe_slot = rtsx_probe_slot,
812 /*AMD chipset generation*/
813 enum amd_chipset_gen {
814 AMD_CHIPSET_BEFORE_ML,
820 static int amd_probe(struct sdhci_pci_chip *chip)
822 struct pci_dev *smbus_dev;
823 enum amd_chipset_gen gen;
825 smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
826 PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, NULL);
828 gen = AMD_CHIPSET_BEFORE_ML;
830 smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
831 PCI_DEVICE_ID_AMD_KERNCZ_SMBUS, NULL);
833 if (smbus_dev->revision < 0x51)
834 gen = AMD_CHIPSET_CZ;
836 gen = AMD_CHIPSET_NL;
838 gen = AMD_CHIPSET_UNKNOWN;
842 if ((gen == AMD_CHIPSET_BEFORE_ML) || (gen == AMD_CHIPSET_CZ)) {
843 chip->quirks2 |= SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD;
844 chip->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200;
850 static const struct sdhci_pci_fixes sdhci_amd = {
854 static const struct pci_device_id pci_ids[] = {
856 .vendor = PCI_VENDOR_ID_RICOH,
857 .device = PCI_DEVICE_ID_RICOH_R5C822,
858 .subvendor = PCI_ANY_ID,
859 .subdevice = PCI_ANY_ID,
860 .driver_data = (kernel_ulong_t)&sdhci_ricoh,
864 .vendor = PCI_VENDOR_ID_RICOH,
866 .subvendor = PCI_ANY_ID,
867 .subdevice = PCI_ANY_ID,
868 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
872 .vendor = PCI_VENDOR_ID_RICOH,
874 .subvendor = PCI_ANY_ID,
875 .subdevice = PCI_ANY_ID,
876 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
880 .vendor = PCI_VENDOR_ID_RICOH,
882 .subvendor = PCI_ANY_ID,
883 .subdevice = PCI_ANY_ID,
884 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
888 .vendor = PCI_VENDOR_ID_ENE,
889 .device = PCI_DEVICE_ID_ENE_CB712_SD,
890 .subvendor = PCI_ANY_ID,
891 .subdevice = PCI_ANY_ID,
892 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
896 .vendor = PCI_VENDOR_ID_ENE,
897 .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
898 .subvendor = PCI_ANY_ID,
899 .subdevice = PCI_ANY_ID,
900 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
904 .vendor = PCI_VENDOR_ID_ENE,
905 .device = PCI_DEVICE_ID_ENE_CB714_SD,
906 .subvendor = PCI_ANY_ID,
907 .subdevice = PCI_ANY_ID,
908 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
912 .vendor = PCI_VENDOR_ID_ENE,
913 .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
914 .subvendor = PCI_ANY_ID,
915 .subdevice = PCI_ANY_ID,
916 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
920 .vendor = PCI_VENDOR_ID_MARVELL,
921 .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
922 .subvendor = PCI_ANY_ID,
923 .subdevice = PCI_ANY_ID,
924 .driver_data = (kernel_ulong_t)&sdhci_cafe,
928 .vendor = PCI_VENDOR_ID_JMICRON,
929 .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
930 .subvendor = PCI_ANY_ID,
931 .subdevice = PCI_ANY_ID,
932 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
936 .vendor = PCI_VENDOR_ID_JMICRON,
937 .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
938 .subvendor = PCI_ANY_ID,
939 .subdevice = PCI_ANY_ID,
940 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
944 .vendor = PCI_VENDOR_ID_JMICRON,
945 .device = PCI_DEVICE_ID_JMICRON_JMB388_SD,
946 .subvendor = PCI_ANY_ID,
947 .subdevice = PCI_ANY_ID,
948 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
952 .vendor = PCI_VENDOR_ID_JMICRON,
953 .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD,
954 .subvendor = PCI_ANY_ID,
955 .subdevice = PCI_ANY_ID,
956 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
960 .vendor = PCI_VENDOR_ID_SYSKONNECT,
962 .subvendor = PCI_ANY_ID,
963 .subdevice = PCI_ANY_ID,
964 .driver_data = (kernel_ulong_t)&sdhci_syskt,
968 .vendor = PCI_VENDOR_ID_VIA,
970 .subvendor = PCI_ANY_ID,
971 .subdevice = PCI_ANY_ID,
972 .driver_data = (kernel_ulong_t)&sdhci_via,
976 .vendor = PCI_VENDOR_ID_REALTEK,
978 .subvendor = PCI_ANY_ID,
979 .subdevice = PCI_ANY_ID,
980 .driver_data = (kernel_ulong_t)&sdhci_rtsx,
984 .vendor = PCI_VENDOR_ID_INTEL,
985 .device = PCI_DEVICE_ID_INTEL_QRK_SD,
986 .subvendor = PCI_ANY_ID,
987 .subdevice = PCI_ANY_ID,
988 .driver_data = (kernel_ulong_t)&sdhci_intel_qrk,
992 .vendor = PCI_VENDOR_ID_INTEL,
993 .device = PCI_DEVICE_ID_INTEL_MRST_SD0,
994 .subvendor = PCI_ANY_ID,
995 .subdevice = PCI_ANY_ID,
996 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0,
1000 .vendor = PCI_VENDOR_ID_INTEL,
1001 .device = PCI_DEVICE_ID_INTEL_MRST_SD1,
1002 .subvendor = PCI_ANY_ID,
1003 .subdevice = PCI_ANY_ID,
1004 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
1008 .vendor = PCI_VENDOR_ID_INTEL,
1009 .device = PCI_DEVICE_ID_INTEL_MRST_SD2,
1010 .subvendor = PCI_ANY_ID,
1011 .subdevice = PCI_ANY_ID,
1012 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
1016 .vendor = PCI_VENDOR_ID_INTEL,
1017 .device = PCI_DEVICE_ID_INTEL_MFD_SD,
1018 .subvendor = PCI_ANY_ID,
1019 .subdevice = PCI_ANY_ID,
1020 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
1024 .vendor = PCI_VENDOR_ID_INTEL,
1025 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1,
1026 .subvendor = PCI_ANY_ID,
1027 .subdevice = PCI_ANY_ID,
1028 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
1032 .vendor = PCI_VENDOR_ID_INTEL,
1033 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2,
1034 .subvendor = PCI_ANY_ID,
1035 .subdevice = PCI_ANY_ID,
1036 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
1040 .vendor = PCI_VENDOR_ID_INTEL,
1041 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0,
1042 .subvendor = PCI_ANY_ID,
1043 .subdevice = PCI_ANY_ID,
1044 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
1048 .vendor = PCI_VENDOR_ID_INTEL,
1049 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1,
1050 .subvendor = PCI_ANY_ID,
1051 .subdevice = PCI_ANY_ID,
1052 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
1056 .vendor = PCI_VENDOR_ID_INTEL,
1057 .device = PCI_DEVICE_ID_INTEL_PCH_SDIO0,
1058 .subvendor = PCI_ANY_ID,
1059 .subdevice = PCI_ANY_ID,
1060 .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
1064 .vendor = PCI_VENDOR_ID_INTEL,
1065 .device = PCI_DEVICE_ID_INTEL_PCH_SDIO1,
1066 .subvendor = PCI_ANY_ID,
1067 .subdevice = PCI_ANY_ID,
1068 .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
1072 .vendor = PCI_VENDOR_ID_INTEL,
1073 .device = PCI_DEVICE_ID_INTEL_BYT_EMMC,
1074 .subvendor = PCI_ANY_ID,
1075 .subdevice = PCI_ANY_ID,
1076 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
1080 .vendor = PCI_VENDOR_ID_INTEL,
1081 .device = PCI_DEVICE_ID_INTEL_BYT_SDIO,
1082 .subvendor = PCI_ANY_ID,
1083 .subdevice = PCI_ANY_ID,
1084 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
1088 .vendor = PCI_VENDOR_ID_INTEL,
1089 .device = PCI_DEVICE_ID_INTEL_BYT_SD,
1090 .subvendor = PCI_ANY_ID,
1091 .subdevice = PCI_ANY_ID,
1092 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
1096 .vendor = PCI_VENDOR_ID_INTEL,
1097 .device = PCI_DEVICE_ID_INTEL_BYT_EMMC2,
1098 .subvendor = PCI_ANY_ID,
1099 .subdevice = PCI_ANY_ID,
1100 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
1104 .vendor = PCI_VENDOR_ID_INTEL,
1105 .device = PCI_DEVICE_ID_INTEL_BSW_EMMC,
1106 .subvendor = PCI_ANY_ID,
1107 .subdevice = PCI_ANY_ID,
1108 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
1112 .vendor = PCI_VENDOR_ID_INTEL,
1113 .device = PCI_DEVICE_ID_INTEL_BSW_SDIO,
1114 .subvendor = PCI_ANY_ID,
1115 .subdevice = PCI_ANY_ID,
1116 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
1120 .vendor = PCI_VENDOR_ID_INTEL,
1121 .device = PCI_DEVICE_ID_INTEL_BSW_SD,
1122 .subvendor = PCI_ANY_ID,
1123 .subdevice = PCI_ANY_ID,
1124 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
1128 .vendor = PCI_VENDOR_ID_INTEL,
1129 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO0,
1130 .subvendor = PCI_ANY_ID,
1131 .subdevice = PCI_ANY_ID,
1132 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
1136 .vendor = PCI_VENDOR_ID_INTEL,
1137 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO1,
1138 .subvendor = PCI_ANY_ID,
1139 .subdevice = PCI_ANY_ID,
1140 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
1144 .vendor = PCI_VENDOR_ID_INTEL,
1145 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO2,
1146 .subvendor = PCI_ANY_ID,
1147 .subdevice = PCI_ANY_ID,
1148 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
1152 .vendor = PCI_VENDOR_ID_INTEL,
1153 .device = PCI_DEVICE_ID_INTEL_CLV_EMMC0,
1154 .subvendor = PCI_ANY_ID,
1155 .subdevice = PCI_ANY_ID,
1156 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
1160 .vendor = PCI_VENDOR_ID_INTEL,
1161 .device = PCI_DEVICE_ID_INTEL_CLV_EMMC1,
1162 .subvendor = PCI_ANY_ID,
1163 .subdevice = PCI_ANY_ID,
1164 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
1168 .vendor = PCI_VENDOR_ID_INTEL,
1169 .device = PCI_DEVICE_ID_INTEL_MRFLD_MMC,
1170 .subvendor = PCI_ANY_ID,
1171 .subdevice = PCI_ANY_ID,
1172 .driver_data = (kernel_ulong_t)&sdhci_intel_mrfld_mmc,
1176 .vendor = PCI_VENDOR_ID_INTEL,
1177 .device = PCI_DEVICE_ID_INTEL_SPT_EMMC,
1178 .subvendor = PCI_ANY_ID,
1179 .subdevice = PCI_ANY_ID,
1180 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
1184 .vendor = PCI_VENDOR_ID_INTEL,
1185 .device = PCI_DEVICE_ID_INTEL_SPT_SDIO,
1186 .subvendor = PCI_ANY_ID,
1187 .subdevice = PCI_ANY_ID,
1188 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
1192 .vendor = PCI_VENDOR_ID_INTEL,
1193 .device = PCI_DEVICE_ID_INTEL_SPT_SD,
1194 .subvendor = PCI_ANY_ID,
1195 .subdevice = PCI_ANY_ID,
1196 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
1200 .vendor = PCI_VENDOR_ID_INTEL,
1201 .device = PCI_DEVICE_ID_INTEL_DNV_EMMC,
1202 .subvendor = PCI_ANY_ID,
1203 .subdevice = PCI_ANY_ID,
1204 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
1208 .vendor = PCI_VENDOR_ID_INTEL,
1209 .device = PCI_DEVICE_ID_INTEL_BXT_EMMC,
1210 .subvendor = PCI_ANY_ID,
1211 .subdevice = PCI_ANY_ID,
1212 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
1216 .vendor = PCI_VENDOR_ID_INTEL,
1217 .device = PCI_DEVICE_ID_INTEL_BXT_SDIO,
1218 .subvendor = PCI_ANY_ID,
1219 .subdevice = PCI_ANY_ID,
1220 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
1224 .vendor = PCI_VENDOR_ID_INTEL,
1225 .device = PCI_DEVICE_ID_INTEL_BXT_SD,
1226 .subvendor = PCI_ANY_ID,
1227 .subdevice = PCI_ANY_ID,
1228 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
1232 .vendor = PCI_VENDOR_ID_INTEL,
1233 .device = PCI_DEVICE_ID_INTEL_BXTM_EMMC,
1234 .subvendor = PCI_ANY_ID,
1235 .subdevice = PCI_ANY_ID,
1236 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
1240 .vendor = PCI_VENDOR_ID_INTEL,
1241 .device = PCI_DEVICE_ID_INTEL_BXTM_SDIO,
1242 .subvendor = PCI_ANY_ID,
1243 .subdevice = PCI_ANY_ID,
1244 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
1248 .vendor = PCI_VENDOR_ID_INTEL,
1249 .device = PCI_DEVICE_ID_INTEL_BXTM_SD,
1250 .subvendor = PCI_ANY_ID,
1251 .subdevice = PCI_ANY_ID,
1252 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
1256 .vendor = PCI_VENDOR_ID_INTEL,
1257 .device = PCI_DEVICE_ID_INTEL_APL_EMMC,
1258 .subvendor = PCI_ANY_ID,
1259 .subdevice = PCI_ANY_ID,
1260 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
1264 .vendor = PCI_VENDOR_ID_INTEL,
1265 .device = PCI_DEVICE_ID_INTEL_APL_SDIO,
1266 .subvendor = PCI_ANY_ID,
1267 .subdevice = PCI_ANY_ID,
1268 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
1272 .vendor = PCI_VENDOR_ID_INTEL,
1273 .device = PCI_DEVICE_ID_INTEL_APL_SD,
1274 .subvendor = PCI_ANY_ID,
1275 .subdevice = PCI_ANY_ID,
1276 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
1280 .vendor = PCI_VENDOR_ID_O2,
1281 .device = PCI_DEVICE_ID_O2_8120,
1282 .subvendor = PCI_ANY_ID,
1283 .subdevice = PCI_ANY_ID,
1284 .driver_data = (kernel_ulong_t)&sdhci_o2,
1288 .vendor = PCI_VENDOR_ID_O2,
1289 .device = PCI_DEVICE_ID_O2_8220,
1290 .subvendor = PCI_ANY_ID,
1291 .subdevice = PCI_ANY_ID,
1292 .driver_data = (kernel_ulong_t)&sdhci_o2,
1296 .vendor = PCI_VENDOR_ID_O2,
1297 .device = PCI_DEVICE_ID_O2_8221,
1298 .subvendor = PCI_ANY_ID,
1299 .subdevice = PCI_ANY_ID,
1300 .driver_data = (kernel_ulong_t)&sdhci_o2,
1304 .vendor = PCI_VENDOR_ID_O2,
1305 .device = PCI_DEVICE_ID_O2_8320,
1306 .subvendor = PCI_ANY_ID,
1307 .subdevice = PCI_ANY_ID,
1308 .driver_data = (kernel_ulong_t)&sdhci_o2,
1312 .vendor = PCI_VENDOR_ID_O2,
1313 .device = PCI_DEVICE_ID_O2_8321,
1314 .subvendor = PCI_ANY_ID,
1315 .subdevice = PCI_ANY_ID,
1316 .driver_data = (kernel_ulong_t)&sdhci_o2,
1320 .vendor = PCI_VENDOR_ID_O2,
1321 .device = PCI_DEVICE_ID_O2_FUJIN2,
1322 .subvendor = PCI_ANY_ID,
1323 .subdevice = PCI_ANY_ID,
1324 .driver_data = (kernel_ulong_t)&sdhci_o2,
1328 .vendor = PCI_VENDOR_ID_O2,
1329 .device = PCI_DEVICE_ID_O2_SDS0,
1330 .subvendor = PCI_ANY_ID,
1331 .subdevice = PCI_ANY_ID,
1332 .driver_data = (kernel_ulong_t)&sdhci_o2,
1336 .vendor = PCI_VENDOR_ID_O2,
1337 .device = PCI_DEVICE_ID_O2_SDS1,
1338 .subvendor = PCI_ANY_ID,
1339 .subdevice = PCI_ANY_ID,
1340 .driver_data = (kernel_ulong_t)&sdhci_o2,
1344 .vendor = PCI_VENDOR_ID_O2,
1345 .device = PCI_DEVICE_ID_O2_SEABIRD0,
1346 .subvendor = PCI_ANY_ID,
1347 .subdevice = PCI_ANY_ID,
1348 .driver_data = (kernel_ulong_t)&sdhci_o2,
1352 .vendor = PCI_VENDOR_ID_O2,
1353 .device = PCI_DEVICE_ID_O2_SEABIRD1,
1354 .subvendor = PCI_ANY_ID,
1355 .subdevice = PCI_ANY_ID,
1356 .driver_data = (kernel_ulong_t)&sdhci_o2,
1359 .vendor = PCI_VENDOR_ID_AMD,
1360 .device = PCI_ANY_ID,
1361 .class = PCI_CLASS_SYSTEM_SDHCI << 8,
1362 .class_mask = 0xFFFF00,
1363 .subvendor = PCI_ANY_ID,
1364 .subdevice = PCI_ANY_ID,
1365 .driver_data = (kernel_ulong_t)&sdhci_amd,
1367 { /* Generic SD host controller */
1368 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
1371 { /* end: all zeroes */ },
1374 MODULE_DEVICE_TABLE(pci, pci_ids);
1376 /*****************************************************************************\
1378 * SDHCI core callbacks *
1380 \*****************************************************************************/
1382 static int sdhci_pci_enable_dma(struct sdhci_host *host)
1384 struct sdhci_pci_slot *slot;
1385 struct pci_dev *pdev;
1387 slot = sdhci_priv(host);
1388 pdev = slot->chip->pdev;
1390 if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
1391 ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
1392 (host->flags & SDHCI_USE_SDMA)) {
1393 dev_warn(&pdev->dev, "Will use DMA mode even though HW "
1394 "doesn't fully claim to support it.\n");
1397 pci_set_master(pdev);
1402 static void sdhci_pci_set_bus_width(struct sdhci_host *host, int width)
1406 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
1409 case MMC_BUS_WIDTH_8:
1410 ctrl |= SDHCI_CTRL_8BITBUS;
1411 ctrl &= ~SDHCI_CTRL_4BITBUS;
1413 case MMC_BUS_WIDTH_4:
1414 ctrl |= SDHCI_CTRL_4BITBUS;
1415 ctrl &= ~SDHCI_CTRL_8BITBUS;
1418 ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS);
1422 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
1425 static void sdhci_pci_gpio_hw_reset(struct sdhci_host *host)
1427 struct sdhci_pci_slot *slot = sdhci_priv(host);
1428 int rst_n_gpio = slot->rst_n_gpio;
1430 if (!gpio_is_valid(rst_n_gpio))
1432 gpio_set_value_cansleep(rst_n_gpio, 0);
1433 /* For eMMC, minimum is 1us but give it 10us for good measure */
1435 gpio_set_value_cansleep(rst_n_gpio, 1);
1436 /* For eMMC, minimum is 200us but give it 300us for good measure */
1437 usleep_range(300, 1000);
1440 static void sdhci_pci_hw_reset(struct sdhci_host *host)
1442 struct sdhci_pci_slot *slot = sdhci_priv(host);
1445 slot->hw_reset(host);
1448 static int sdhci_pci_select_drive_strength(struct sdhci_host *host,
1449 struct mmc_card *card,
1450 unsigned int max_dtr, int host_drv,
1451 int card_drv, int *drv_type)
1453 struct sdhci_pci_slot *slot = sdhci_priv(host);
1455 if (!slot->select_drive_strength)
1458 return slot->select_drive_strength(host, card, max_dtr, host_drv,
1459 card_drv, drv_type);
1462 static const struct sdhci_ops sdhci_pci_ops = {
1463 .set_clock = sdhci_set_clock,
1464 .enable_dma = sdhci_pci_enable_dma,
1465 .set_bus_width = sdhci_pci_set_bus_width,
1466 .reset = sdhci_reset,
1467 .set_uhs_signaling = sdhci_set_uhs_signaling,
1468 .hw_reset = sdhci_pci_hw_reset,
1469 .select_drive_strength = sdhci_pci_select_drive_strength,
1472 /*****************************************************************************\
1476 \*****************************************************************************/
1478 #ifdef CONFIG_PM_SLEEP
1479 static int sdhci_pci_suspend(struct device *dev)
1481 struct pci_dev *pdev = to_pci_dev(dev);
1482 struct sdhci_pci_chip *chip;
1483 struct sdhci_pci_slot *slot;
1484 mmc_pm_flag_t slot_pm_flags;
1485 mmc_pm_flag_t pm_flags = 0;
1488 chip = pci_get_drvdata(pdev);
1492 for (i = 0; i < chip->num_slots; i++) {
1493 slot = chip->slots[i];
1497 ret = sdhci_suspend_host(slot->host);
1500 goto err_pci_suspend;
1502 slot_pm_flags = slot->host->mmc->pm_flags;
1503 if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
1504 sdhci_enable_irq_wakeups(slot->host);
1506 pm_flags |= slot_pm_flags;
1509 if (chip->fixes && chip->fixes->suspend) {
1510 ret = chip->fixes->suspend(chip);
1512 goto err_pci_suspend;
1515 if (pm_flags & MMC_PM_KEEP_POWER) {
1516 if (pm_flags & MMC_PM_WAKE_SDIO_IRQ)
1517 device_init_wakeup(dev, true);
1519 device_init_wakeup(dev, false);
1521 device_init_wakeup(dev, false);
1527 sdhci_resume_host(chip->slots[i]->host);
1531 static int sdhci_pci_resume(struct device *dev)
1533 struct pci_dev *pdev = to_pci_dev(dev);
1534 struct sdhci_pci_chip *chip;
1535 struct sdhci_pci_slot *slot;
1538 chip = pci_get_drvdata(pdev);
1542 if (chip->fixes && chip->fixes->resume) {
1543 ret = chip->fixes->resume(chip);
1548 for (i = 0; i < chip->num_slots; i++) {
1549 slot = chip->slots[i];
1553 ret = sdhci_resume_host(slot->host);
1563 static int sdhci_pci_runtime_suspend(struct device *dev)
1565 struct pci_dev *pdev = to_pci_dev(dev);
1566 struct sdhci_pci_chip *chip;
1567 struct sdhci_pci_slot *slot;
1570 chip = pci_get_drvdata(pdev);
1574 for (i = 0; i < chip->num_slots; i++) {
1575 slot = chip->slots[i];
1579 ret = sdhci_runtime_suspend_host(slot->host);
1582 goto err_pci_runtime_suspend;
1585 if (chip->fixes && chip->fixes->suspend) {
1586 ret = chip->fixes->suspend(chip);
1588 goto err_pci_runtime_suspend;
1593 err_pci_runtime_suspend:
1595 sdhci_runtime_resume_host(chip->slots[i]->host);
1599 static int sdhci_pci_runtime_resume(struct device *dev)
1601 struct pci_dev *pdev = to_pci_dev(dev);
1602 struct sdhci_pci_chip *chip;
1603 struct sdhci_pci_slot *slot;
1606 chip = pci_get_drvdata(pdev);
1610 if (chip->fixes && chip->fixes->resume) {
1611 ret = chip->fixes->resume(chip);
1616 for (i = 0; i < chip->num_slots; i++) {
1617 slot = chip->slots[i];
1621 ret = sdhci_runtime_resume_host(slot->host);
1630 static const struct dev_pm_ops sdhci_pci_pm_ops = {
1631 SET_SYSTEM_SLEEP_PM_OPS(sdhci_pci_suspend, sdhci_pci_resume)
1632 SET_RUNTIME_PM_OPS(sdhci_pci_runtime_suspend,
1633 sdhci_pci_runtime_resume, NULL)
1636 /*****************************************************************************\
1638 * Device probing/removal *
1640 \*****************************************************************************/
1642 static struct sdhci_pci_slot *sdhci_pci_probe_slot(
1643 struct pci_dev *pdev, struct sdhci_pci_chip *chip, int first_bar,
1646 struct sdhci_pci_slot *slot;
1647 struct sdhci_host *host;
1648 int ret, bar = first_bar + slotno;
1650 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
1651 dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
1652 return ERR_PTR(-ENODEV);
1655 if (pci_resource_len(pdev, bar) < 0x100) {
1656 dev_err(&pdev->dev, "Invalid iomem size. You may "
1657 "experience problems.\n");
1660 if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
1661 dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
1662 return ERR_PTR(-ENODEV);
1665 if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
1666 dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
1667 return ERR_PTR(-ENODEV);
1670 host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
1672 dev_err(&pdev->dev, "cannot allocate host\n");
1673 return ERR_CAST(host);
1676 slot = sdhci_priv(host);
1680 slot->rst_n_gpio = -EINVAL;
1681 slot->cd_gpio = -EINVAL;
1684 /* Retrieve platform data if there is any */
1685 if (*sdhci_pci_get_data)
1686 slot->data = sdhci_pci_get_data(pdev, slotno);
1689 if (slot->data->setup) {
1690 ret = slot->data->setup(slot->data);
1692 dev_err(&pdev->dev, "platform setup failed\n");
1696 slot->rst_n_gpio = slot->data->rst_n_gpio;
1697 slot->cd_gpio = slot->data->cd_gpio;
1700 host->hw_name = "PCI";
1701 host->ops = chip->fixes && chip->fixes->ops ?
1704 host->quirks = chip->quirks;
1705 host->quirks2 = chip->quirks2;
1707 host->irq = pdev->irq;
1709 ret = pcim_iomap_regions(pdev, BIT(bar), mmc_hostname(host->mmc));
1711 dev_err(&pdev->dev, "cannot request region\n");
1715 host->ioaddr = pcim_iomap_table(pdev)[bar];
1717 if (chip->fixes && chip->fixes->probe_slot) {
1718 ret = chip->fixes->probe_slot(slot);
1723 if (gpio_is_valid(slot->rst_n_gpio)) {
1724 if (!devm_gpio_request(&pdev->dev, slot->rst_n_gpio, "eMMC_reset")) {
1725 gpio_direction_output(slot->rst_n_gpio, 1);
1726 slot->host->mmc->caps |= MMC_CAP_HW_RESET;
1727 slot->hw_reset = sdhci_pci_gpio_hw_reset;
1729 dev_warn(&pdev->dev, "failed to request rst_n_gpio\n");
1730 slot->rst_n_gpio = -EINVAL;
1734 host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
1735 host->mmc->slotno = slotno;
1736 host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
1738 if (slot->cd_idx >= 0 &&
1739 mmc_gpiod_request_cd(host->mmc, slot->cd_con_id, slot->cd_idx,
1740 slot->cd_override_level, 0, NULL)) {
1741 dev_warn(&pdev->dev, "failed to setup card detect gpio\n");
1745 ret = sdhci_add_host(host);
1749 sdhci_pci_add_own_cd(slot);
1752 * Check if the chip needs a separate GPIO for card detect to wake up
1753 * from runtime suspend. If it is not there, don't allow runtime PM.
1754 * Note sdhci_pci_add_own_cd() sets slot->cd_gpio to -EINVAL on failure.
1756 if (chip->fixes && chip->fixes->own_cd_for_runtime_pm &&
1757 !gpio_is_valid(slot->cd_gpio) && slot->cd_idx < 0)
1758 chip->allow_runtime_pm = false;
1763 if (chip->fixes && chip->fixes->remove_slot)
1764 chip->fixes->remove_slot(slot, 0);
1767 if (slot->data && slot->data->cleanup)
1768 slot->data->cleanup(slot->data);
1771 sdhci_free_host(host);
1773 return ERR_PTR(ret);
1776 static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
1781 sdhci_pci_remove_own_cd(slot);
1784 scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
1785 if (scratch == (u32)-1)
1788 sdhci_remove_host(slot->host, dead);
1790 if (slot->chip->fixes && slot->chip->fixes->remove_slot)
1791 slot->chip->fixes->remove_slot(slot, dead);
1793 if (slot->data && slot->data->cleanup)
1794 slot->data->cleanup(slot->data);
1796 sdhci_free_host(slot->host);
1799 static void sdhci_pci_runtime_pm_allow(struct device *dev)
1801 pm_suspend_ignore_children(dev, 1);
1802 pm_runtime_set_autosuspend_delay(dev, 50);
1803 pm_runtime_use_autosuspend(dev);
1804 pm_runtime_allow(dev);
1805 /* Stay active until mmc core scans for a card */
1806 pm_runtime_put_noidle(dev);
1809 static void sdhci_pci_runtime_pm_forbid(struct device *dev)
1811 pm_runtime_forbid(dev);
1812 pm_runtime_get_noresume(dev);
1815 static int sdhci_pci_probe(struct pci_dev *pdev,
1816 const struct pci_device_id *ent)
1818 struct sdhci_pci_chip *chip;
1819 struct sdhci_pci_slot *slot;
1821 u8 slots, first_bar;
1824 BUG_ON(pdev == NULL);
1825 BUG_ON(ent == NULL);
1827 dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
1828 (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
1830 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
1834 slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
1835 dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
1839 BUG_ON(slots > MAX_SLOTS);
1841 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
1845 first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
1847 if (first_bar > 5) {
1848 dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
1852 ret = pcim_enable_device(pdev);
1856 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
1861 chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data;
1863 chip->quirks = chip->fixes->quirks;
1864 chip->quirks2 = chip->fixes->quirks2;
1865 chip->allow_runtime_pm = chip->fixes->allow_runtime_pm;
1867 chip->num_slots = slots;
1869 pci_set_drvdata(pdev, chip);
1871 if (chip->fixes && chip->fixes->probe) {
1872 ret = chip->fixes->probe(chip);
1877 slots = chip->num_slots; /* Quirk may have changed this */
1879 for (i = 0; i < slots; i++) {
1880 slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i);
1882 for (i--; i >= 0; i--)
1883 sdhci_pci_remove_slot(chip->slots[i]);
1884 return PTR_ERR(slot);
1887 chip->slots[i] = slot;
1890 if (chip->allow_runtime_pm)
1891 sdhci_pci_runtime_pm_allow(&pdev->dev);
1896 static void sdhci_pci_remove(struct pci_dev *pdev)
1899 struct sdhci_pci_chip *chip = pci_get_drvdata(pdev);
1901 if (chip->allow_runtime_pm)
1902 sdhci_pci_runtime_pm_forbid(&pdev->dev);
1904 for (i = 0; i < chip->num_slots; i++)
1905 sdhci_pci_remove_slot(chip->slots[i]);
1908 static struct pci_driver sdhci_driver = {
1909 .name = "sdhci-pci",
1910 .id_table = pci_ids,
1911 .probe = sdhci_pci_probe,
1912 .remove = sdhci_pci_remove,
1914 .pm = &sdhci_pci_pm_ops
1918 module_pci_driver(sdhci_driver);
1920 MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
1921 MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
1922 MODULE_LICENSE("GPL");