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/scatterlist.h>
25 #include <linux/gpio.h>
26 #include <linux/sfi.h>
27 #include <linux/pm_runtime.h>
35 #define PCI_SDHCI_IFPIO 0x00
36 #define PCI_SDHCI_IFDMA 0x01
37 #define PCI_SDHCI_IFVENDOR 0x02
39 #define PCI_SLOT_INFO 0x40 /* 8 bits */
40 #define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7)
41 #define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07
45 struct sdhci_pci_chip;
46 struct sdhci_pci_slot;
48 struct sdhci_pci_fixes {
50 bool allow_runtime_pm;
52 int (*probe) (struct sdhci_pci_chip *);
54 int (*probe_slot) (struct sdhci_pci_slot *);
55 void (*remove_slot) (struct sdhci_pci_slot *, int);
57 int (*suspend) (struct sdhci_pci_chip *);
58 int (*resume) (struct sdhci_pci_chip *);
61 struct sdhci_pci_slot {
62 struct sdhci_pci_chip *chip;
63 struct sdhci_host *host;
71 struct sdhci_pci_chip {
75 bool allow_runtime_pm;
76 const struct sdhci_pci_fixes *fixes;
78 int num_slots; /* Slots on controller */
79 struct sdhci_pci_slot *slots[MAX_SLOTS]; /* Pointers to host slots */
83 /*****************************************************************************\
85 * Hardware specific quirk handling *
87 \*****************************************************************************/
89 static int ricoh_probe(struct sdhci_pci_chip *chip)
91 if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
92 chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
93 chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
97 static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot)
100 ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT)
101 & SDHCI_TIMEOUT_CLK_MASK) |
103 ((0x21 << SDHCI_CLOCK_BASE_SHIFT)
104 & SDHCI_CLOCK_BASE_MASK) |
106 SDHCI_TIMEOUT_CLK_UNIT |
112 static int ricoh_mmc_resume(struct sdhci_pci_chip *chip)
114 /* Apply a delay to allow controller to settle */
115 /* Otherwise it becomes confused if card state changed
121 static const struct sdhci_pci_fixes sdhci_ricoh = {
122 .probe = ricoh_probe,
123 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
124 SDHCI_QUIRK_FORCE_DMA |
125 SDHCI_QUIRK_CLOCK_BEFORE_RESET,
128 static const struct sdhci_pci_fixes sdhci_ricoh_mmc = {
129 .probe_slot = ricoh_mmc_probe_slot,
130 .resume = ricoh_mmc_resume,
131 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
132 SDHCI_QUIRK_CLOCK_BEFORE_RESET |
133 SDHCI_QUIRK_NO_CARD_NO_RESET |
134 SDHCI_QUIRK_MISSING_CAPS
137 static const struct sdhci_pci_fixes sdhci_ene_712 = {
138 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
139 SDHCI_QUIRK_BROKEN_DMA,
142 static const struct sdhci_pci_fixes sdhci_ene_714 = {
143 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
144 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
145 SDHCI_QUIRK_BROKEN_DMA,
148 static const struct sdhci_pci_fixes sdhci_cafe = {
149 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
150 SDHCI_QUIRK_NO_BUSY_IRQ |
151 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
154 static int mrst_hc_probe_slot(struct sdhci_pci_slot *slot)
156 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
161 * ADMA operation is disabled for Moorestown platform due to
164 static int mrst_hc_probe(struct sdhci_pci_chip *chip)
167 * slots number is fixed here for MRST as SDIO3/5 are never used and
168 * have hardware bugs.
174 /* Medfield eMMC hardware reset GPIOs */
175 static int mfd_emmc0_rst_gpio = -EINVAL;
176 static int mfd_emmc1_rst_gpio = -EINVAL;
178 static int mfd_emmc_gpio_parse(struct sfi_table_header *table)
180 struct sfi_table_simple *sb = (struct sfi_table_simple *)table;
181 struct sfi_gpio_table_entry *entry;
184 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
185 entry = (struct sfi_gpio_table_entry *)sb->pentry;
187 for (i = 0; i < num; i++, entry++) {
188 if (!strncmp(entry->pin_name, "emmc0_rst", SFI_NAME_LEN))
189 mfd_emmc0_rst_gpio = entry->pin_no;
190 else if (!strncmp(entry->pin_name, "emmc1_rst", SFI_NAME_LEN))
191 mfd_emmc1_rst_gpio = entry->pin_no;
197 #ifdef CONFIG_PM_RUNTIME
199 static irqreturn_t mfd_sd_cd(int irq, void *dev_id)
201 struct sdhci_pci_slot *slot = dev_id;
202 struct sdhci_host *host = slot->host;
204 mmc_detect_change(host->mmc, msecs_to_jiffies(200));
208 #define MFLD_SD_CD_PIN 69
210 static int mfd_sd_probe_slot(struct sdhci_pci_slot *slot)
212 int err, irq, gpio = MFLD_SD_CD_PIN;
214 slot->cd_gpio = -EINVAL;
215 slot->cd_irq = -EINVAL;
217 err = gpio_request(gpio, "sd_cd");
221 err = gpio_direction_input(gpio);
225 irq = gpio_to_irq(gpio);
229 err = request_irq(irq, mfd_sd_cd, IRQF_TRIGGER_RISING |
230 IRQF_TRIGGER_FALLING, "sd_cd", slot);
234 slot->cd_gpio = gpio;
236 slot->host->quirks2 |= SDHCI_QUIRK2_OWN_CARD_DETECTION;
243 dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n");
247 static void mfd_sd_remove_slot(struct sdhci_pci_slot *slot, int dead)
249 if (slot->cd_irq >= 0)
250 free_irq(slot->cd_irq, slot);
251 gpio_free(slot->cd_gpio);
256 #define mfd_sd_probe_slot NULL
257 #define mfd_sd_remove_slot NULL
261 static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot)
263 const char *name = NULL;
266 sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, mfd_emmc_gpio_parse);
268 switch (slot->chip->pdev->device) {
269 case PCI_DEVICE_ID_INTEL_MFD_EMMC0:
270 gpio = mfd_emmc0_rst_gpio;
271 name = "eMMC0_reset";
273 case PCI_DEVICE_ID_INTEL_MFD_EMMC1:
274 gpio = mfd_emmc1_rst_gpio;
275 name = "eMMC1_reset";
279 if (!gpio_request(gpio, name)) {
280 gpio_direction_output(gpio, 1);
281 slot->rst_n_gpio = gpio;
282 slot->host->mmc->caps |= MMC_CAP_HW_RESET;
285 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE;
287 slot->host->mmc->caps2 = MMC_CAP2_BOOTPART_NOACC;
292 static void mfd_emmc_remove_slot(struct sdhci_pci_slot *slot, int dead)
294 gpio_free(slot->rst_n_gpio);
297 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = {
298 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
299 .probe_slot = mrst_hc_probe_slot,
302 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = {
303 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
304 .probe = mrst_hc_probe,
307 static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
308 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
309 .allow_runtime_pm = true,
310 .probe_slot = mfd_sd_probe_slot,
311 .remove_slot = mfd_sd_remove_slot,
314 static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = {
315 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
316 .allow_runtime_pm = true,
319 static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = {
320 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
321 .allow_runtime_pm = true,
322 .probe_slot = mfd_emmc_probe_slot,
323 .remove_slot = mfd_emmc_remove_slot,
326 /* O2Micro extra registers */
327 #define O2_SD_LOCK_WP 0xD3
328 #define O2_SD_MULTI_VCC3V 0xEE
329 #define O2_SD_CLKREQ 0xEC
330 #define O2_SD_CAPS 0xE0
331 #define O2_SD_ADMA1 0xE2
332 #define O2_SD_ADMA2 0xE7
333 #define O2_SD_INF_MOD 0xF1
335 static int o2_probe(struct sdhci_pci_chip *chip)
340 switch (chip->pdev->device) {
341 case PCI_DEVICE_ID_O2_8220:
342 case PCI_DEVICE_ID_O2_8221:
343 case PCI_DEVICE_ID_O2_8320:
344 case PCI_DEVICE_ID_O2_8321:
345 /* This extra setup is required due to broken ADMA. */
346 ret = pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
350 pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
352 /* Set Multi 3 to VCC3V# */
353 pci_write_config_byte(chip->pdev, O2_SD_MULTI_VCC3V, 0x08);
355 /* Disable CLK_REQ# support after media DET */
356 ret = pci_read_config_byte(chip->pdev, O2_SD_CLKREQ, &scratch);
360 pci_write_config_byte(chip->pdev, O2_SD_CLKREQ, scratch);
362 /* Choose capabilities, enable SDMA. We have to write 0x01
363 * to the capabilities register first to unlock it.
365 ret = pci_read_config_byte(chip->pdev, O2_SD_CAPS, &scratch);
369 pci_write_config_byte(chip->pdev, O2_SD_CAPS, scratch);
370 pci_write_config_byte(chip->pdev, O2_SD_CAPS, 0x73);
372 /* Disable ADMA1/2 */
373 pci_write_config_byte(chip->pdev, O2_SD_ADMA1, 0x39);
374 pci_write_config_byte(chip->pdev, O2_SD_ADMA2, 0x08);
376 /* Disable the infinite transfer mode */
377 ret = pci_read_config_byte(chip->pdev, O2_SD_INF_MOD, &scratch);
381 pci_write_config_byte(chip->pdev, O2_SD_INF_MOD, scratch);
384 ret = pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
388 pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
394 static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
399 ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
404 * Turn PMOS on [bit 0], set over current detection to 2.4 V
405 * [bit 1:2] and enable over current debouncing [bit 6].
412 ret = pci_write_config_byte(chip->pdev, 0xAE, scratch);
419 static int jmicron_probe(struct sdhci_pci_chip *chip)
424 if (chip->pdev->revision == 0) {
425 chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR |
426 SDHCI_QUIRK_32BIT_DMA_SIZE |
427 SDHCI_QUIRK_32BIT_ADMA_SIZE |
428 SDHCI_QUIRK_RESET_AFTER_REQUEST |
429 SDHCI_QUIRK_BROKEN_SMALL_PIO;
433 * JMicron chips can have two interfaces to the same hardware
434 * in order to work around limitations in Microsoft's driver.
435 * We need to make sure we only bind to one of them.
437 * This code assumes two things:
439 * 1. The PCI code adds subfunctions in order.
441 * 2. The MMC interface has a lower subfunction number
442 * than the SD interface.
444 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD)
445 mmcdev = PCI_DEVICE_ID_JMICRON_JMB38X_MMC;
446 else if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD)
447 mmcdev = PCI_DEVICE_ID_JMICRON_JMB388_ESD;
450 struct pci_dev *sd_dev;
453 while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON,
454 mmcdev, sd_dev)) != NULL) {
455 if ((PCI_SLOT(chip->pdev->devfn) ==
456 PCI_SLOT(sd_dev->devfn)) &&
457 (chip->pdev->bus == sd_dev->bus))
463 dev_info(&chip->pdev->dev, "Refusing to bind to "
464 "secondary interface.\n");
470 * JMicron chips need a bit of a nudge to enable the power
473 ret = jmicron_pmos(chip, 1);
475 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
479 /* quirk for unsable RO-detection on JM388 chips */
480 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD ||
481 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
482 chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT;
487 static void jmicron_enable_mmc(struct sdhci_host *host, int on)
491 scratch = readb(host->ioaddr + 0xC0);
498 writeb(scratch, host->ioaddr + 0xC0);
501 static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
503 if (slot->chip->pdev->revision == 0) {
506 version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
507 version = (version & SDHCI_VENDOR_VER_MASK) >>
508 SDHCI_VENDOR_VER_SHIFT;
511 * Older versions of the chip have lots of nasty glitches
512 * in the ADMA engine. It's best just to avoid it
516 slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
519 /* JM388 MMC doesn't support 1.8V while SD supports it */
520 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
521 slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 |
522 MMC_VDD_29_30 | MMC_VDD_30_31 |
523 MMC_VDD_165_195; /* allow 1.8V */
524 slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 |
525 MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */
529 * The secondary interface requires a bit set to get the
532 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
533 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
534 jmicron_enable_mmc(slot->host, 1);
536 slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST;
541 static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
546 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
547 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
548 jmicron_enable_mmc(slot->host, 0);
551 static int jmicron_suspend(struct sdhci_pci_chip *chip)
555 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
556 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
557 for (i = 0; i < chip->num_slots; i++)
558 jmicron_enable_mmc(chip->slots[i]->host, 0);
564 static int jmicron_resume(struct sdhci_pci_chip *chip)
568 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
569 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
570 for (i = 0; i < chip->num_slots; i++)
571 jmicron_enable_mmc(chip->slots[i]->host, 1);
574 ret = jmicron_pmos(chip, 1);
576 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
583 static const struct sdhci_pci_fixes sdhci_o2 = {
587 static const struct sdhci_pci_fixes sdhci_jmicron = {
588 .probe = jmicron_probe,
590 .probe_slot = jmicron_probe_slot,
591 .remove_slot = jmicron_remove_slot,
593 .suspend = jmicron_suspend,
594 .resume = jmicron_resume,
597 /* SysKonnect CardBus2SDIO extra registers */
598 #define SYSKT_CTRL 0x200
599 #define SYSKT_RDFIFO_STAT 0x204
600 #define SYSKT_WRFIFO_STAT 0x208
601 #define SYSKT_POWER_DATA 0x20c
602 #define SYSKT_POWER_330 0xef
603 #define SYSKT_POWER_300 0xf8
604 #define SYSKT_POWER_184 0xcc
605 #define SYSKT_POWER_CMD 0x20d
606 #define SYSKT_POWER_START (1 << 7)
607 #define SYSKT_POWER_STATUS 0x20e
608 #define SYSKT_POWER_STATUS_OK (1 << 0)
609 #define SYSKT_BOARD_REV 0x210
610 #define SYSKT_CHIP_REV 0x211
611 #define SYSKT_CONF_DATA 0x212
612 #define SYSKT_CONF_DATA_1V8 (1 << 2)
613 #define SYSKT_CONF_DATA_2V5 (1 << 1)
614 #define SYSKT_CONF_DATA_3V3 (1 << 0)
616 static int syskt_probe(struct sdhci_pci_chip *chip)
618 if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
619 chip->pdev->class &= ~0x0000FF;
620 chip->pdev->class |= PCI_SDHCI_IFDMA;
625 static int syskt_probe_slot(struct sdhci_pci_slot *slot)
629 u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV);
630 u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV);
631 dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, "
632 "board rev %d.%d, chip rev %d.%d\n",
633 board_rev >> 4, board_rev & 0xf,
634 chip_rev >> 4, chip_rev & 0xf);
635 if (chip_rev >= 0x20)
636 slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA;
638 writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA);
639 writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD);
641 tm = 10; /* Wait max 1 ms */
643 ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS);
644 if (ps & SYSKT_POWER_STATUS_OK)
649 dev_err(&slot->chip->pdev->dev,
650 "power regulator never stabilized");
651 writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD);
658 static const struct sdhci_pci_fixes sdhci_syskt = {
659 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER,
660 .probe = syskt_probe,
661 .probe_slot = syskt_probe_slot,
664 static int via_probe(struct sdhci_pci_chip *chip)
666 if (chip->pdev->revision == 0x10)
667 chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
672 static const struct sdhci_pci_fixes sdhci_via = {
676 static const struct pci_device_id pci_ids[] __devinitdata = {
678 .vendor = PCI_VENDOR_ID_RICOH,
679 .device = PCI_DEVICE_ID_RICOH_R5C822,
680 .subvendor = PCI_ANY_ID,
681 .subdevice = PCI_ANY_ID,
682 .driver_data = (kernel_ulong_t)&sdhci_ricoh,
686 .vendor = PCI_VENDOR_ID_RICOH,
688 .subvendor = PCI_ANY_ID,
689 .subdevice = PCI_ANY_ID,
690 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
694 .vendor = PCI_VENDOR_ID_RICOH,
696 .subvendor = PCI_ANY_ID,
697 .subdevice = PCI_ANY_ID,
698 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
702 .vendor = PCI_VENDOR_ID_RICOH,
704 .subvendor = PCI_ANY_ID,
705 .subdevice = PCI_ANY_ID,
706 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
710 .vendor = PCI_VENDOR_ID_ENE,
711 .device = PCI_DEVICE_ID_ENE_CB712_SD,
712 .subvendor = PCI_ANY_ID,
713 .subdevice = PCI_ANY_ID,
714 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
718 .vendor = PCI_VENDOR_ID_ENE,
719 .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
720 .subvendor = PCI_ANY_ID,
721 .subdevice = PCI_ANY_ID,
722 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
726 .vendor = PCI_VENDOR_ID_ENE,
727 .device = PCI_DEVICE_ID_ENE_CB714_SD,
728 .subvendor = PCI_ANY_ID,
729 .subdevice = PCI_ANY_ID,
730 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
734 .vendor = PCI_VENDOR_ID_ENE,
735 .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
736 .subvendor = PCI_ANY_ID,
737 .subdevice = PCI_ANY_ID,
738 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
742 .vendor = PCI_VENDOR_ID_MARVELL,
743 .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
744 .subvendor = PCI_ANY_ID,
745 .subdevice = PCI_ANY_ID,
746 .driver_data = (kernel_ulong_t)&sdhci_cafe,
750 .vendor = PCI_VENDOR_ID_JMICRON,
751 .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
752 .subvendor = PCI_ANY_ID,
753 .subdevice = PCI_ANY_ID,
754 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
758 .vendor = PCI_VENDOR_ID_JMICRON,
759 .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
760 .subvendor = PCI_ANY_ID,
761 .subdevice = PCI_ANY_ID,
762 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
766 .vendor = PCI_VENDOR_ID_JMICRON,
767 .device = PCI_DEVICE_ID_JMICRON_JMB388_SD,
768 .subvendor = PCI_ANY_ID,
769 .subdevice = PCI_ANY_ID,
770 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
774 .vendor = PCI_VENDOR_ID_JMICRON,
775 .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD,
776 .subvendor = PCI_ANY_ID,
777 .subdevice = PCI_ANY_ID,
778 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
782 .vendor = PCI_VENDOR_ID_SYSKONNECT,
784 .subvendor = PCI_ANY_ID,
785 .subdevice = PCI_ANY_ID,
786 .driver_data = (kernel_ulong_t)&sdhci_syskt,
790 .vendor = PCI_VENDOR_ID_VIA,
792 .subvendor = PCI_ANY_ID,
793 .subdevice = PCI_ANY_ID,
794 .driver_data = (kernel_ulong_t)&sdhci_via,
798 .vendor = PCI_VENDOR_ID_INTEL,
799 .device = PCI_DEVICE_ID_INTEL_MRST_SD0,
800 .subvendor = PCI_ANY_ID,
801 .subdevice = PCI_ANY_ID,
802 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0,
806 .vendor = PCI_VENDOR_ID_INTEL,
807 .device = PCI_DEVICE_ID_INTEL_MRST_SD1,
808 .subvendor = PCI_ANY_ID,
809 .subdevice = PCI_ANY_ID,
810 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
814 .vendor = PCI_VENDOR_ID_INTEL,
815 .device = PCI_DEVICE_ID_INTEL_MRST_SD2,
816 .subvendor = PCI_ANY_ID,
817 .subdevice = PCI_ANY_ID,
818 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
822 .vendor = PCI_VENDOR_ID_INTEL,
823 .device = PCI_DEVICE_ID_INTEL_MFD_SD,
824 .subvendor = PCI_ANY_ID,
825 .subdevice = PCI_ANY_ID,
826 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
830 .vendor = PCI_VENDOR_ID_INTEL,
831 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1,
832 .subvendor = PCI_ANY_ID,
833 .subdevice = PCI_ANY_ID,
834 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
838 .vendor = PCI_VENDOR_ID_INTEL,
839 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2,
840 .subvendor = PCI_ANY_ID,
841 .subdevice = PCI_ANY_ID,
842 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
846 .vendor = PCI_VENDOR_ID_INTEL,
847 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0,
848 .subvendor = PCI_ANY_ID,
849 .subdevice = PCI_ANY_ID,
850 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
854 .vendor = PCI_VENDOR_ID_INTEL,
855 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1,
856 .subvendor = PCI_ANY_ID,
857 .subdevice = PCI_ANY_ID,
858 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
862 .vendor = PCI_VENDOR_ID_O2,
863 .device = PCI_DEVICE_ID_O2_8120,
864 .subvendor = PCI_ANY_ID,
865 .subdevice = PCI_ANY_ID,
866 .driver_data = (kernel_ulong_t)&sdhci_o2,
870 .vendor = PCI_VENDOR_ID_O2,
871 .device = PCI_DEVICE_ID_O2_8220,
872 .subvendor = PCI_ANY_ID,
873 .subdevice = PCI_ANY_ID,
874 .driver_data = (kernel_ulong_t)&sdhci_o2,
878 .vendor = PCI_VENDOR_ID_O2,
879 .device = PCI_DEVICE_ID_O2_8221,
880 .subvendor = PCI_ANY_ID,
881 .subdevice = PCI_ANY_ID,
882 .driver_data = (kernel_ulong_t)&sdhci_o2,
886 .vendor = PCI_VENDOR_ID_O2,
887 .device = PCI_DEVICE_ID_O2_8320,
888 .subvendor = PCI_ANY_ID,
889 .subdevice = PCI_ANY_ID,
890 .driver_data = (kernel_ulong_t)&sdhci_o2,
894 .vendor = PCI_VENDOR_ID_O2,
895 .device = PCI_DEVICE_ID_O2_8321,
896 .subvendor = PCI_ANY_ID,
897 .subdevice = PCI_ANY_ID,
898 .driver_data = (kernel_ulong_t)&sdhci_o2,
901 { /* Generic SD host controller */
902 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
905 { /* end: all zeroes */ },
908 MODULE_DEVICE_TABLE(pci, pci_ids);
910 /*****************************************************************************\
912 * SDHCI core callbacks *
914 \*****************************************************************************/
916 static int sdhci_pci_enable_dma(struct sdhci_host *host)
918 struct sdhci_pci_slot *slot;
919 struct pci_dev *pdev;
922 slot = sdhci_priv(host);
923 pdev = slot->chip->pdev;
925 if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
926 ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
927 (host->flags & SDHCI_USE_SDMA)) {
928 dev_warn(&pdev->dev, "Will use DMA mode even though HW "
929 "doesn't fully claim to support it.\n");
932 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
936 pci_set_master(pdev);
941 static int sdhci_pci_8bit_width(struct sdhci_host *host, int width)
945 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
948 case MMC_BUS_WIDTH_8:
949 ctrl |= SDHCI_CTRL_8BITBUS;
950 ctrl &= ~SDHCI_CTRL_4BITBUS;
952 case MMC_BUS_WIDTH_4:
953 ctrl |= SDHCI_CTRL_4BITBUS;
954 ctrl &= ~SDHCI_CTRL_8BITBUS;
957 ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS);
961 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
966 static void sdhci_pci_hw_reset(struct sdhci_host *host)
968 struct sdhci_pci_slot *slot = sdhci_priv(host);
969 int rst_n_gpio = slot->rst_n_gpio;
971 if (!gpio_is_valid(rst_n_gpio))
973 gpio_set_value_cansleep(rst_n_gpio, 0);
974 /* For eMMC, minimum is 1us but give it 10us for good measure */
976 gpio_set_value_cansleep(rst_n_gpio, 1);
977 /* For eMMC, minimum is 200us but give it 300us for good measure */
978 usleep_range(300, 1000);
981 static struct sdhci_ops sdhci_pci_ops = {
982 .enable_dma = sdhci_pci_enable_dma,
983 .platform_8bit_width = sdhci_pci_8bit_width,
984 .hw_reset = sdhci_pci_hw_reset,
987 /*****************************************************************************\
991 \*****************************************************************************/
995 static int sdhci_pci_suspend(struct device *dev)
997 struct pci_dev *pdev = to_pci_dev(dev);
998 struct sdhci_pci_chip *chip;
999 struct sdhci_pci_slot *slot;
1000 mmc_pm_flag_t slot_pm_flags;
1001 mmc_pm_flag_t pm_flags = 0;
1004 chip = pci_get_drvdata(pdev);
1008 for (i = 0; i < chip->num_slots; i++) {
1009 slot = chip->slots[i];
1013 ret = sdhci_suspend_host(slot->host);
1016 for (i--; i >= 0; i--)
1017 sdhci_resume_host(chip->slots[i]->host);
1021 slot_pm_flags = slot->host->mmc->pm_flags;
1022 if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
1023 sdhci_enable_irq_wakeups(slot->host);
1025 pm_flags |= slot_pm_flags;
1028 if (chip->fixes && chip->fixes->suspend) {
1029 ret = chip->fixes->suspend(chip);
1031 for (i = chip->num_slots - 1; i >= 0; i--)
1032 sdhci_resume_host(chip->slots[i]->host);
1037 pci_save_state(pdev);
1038 if (pm_flags & MMC_PM_KEEP_POWER) {
1039 if (pm_flags & MMC_PM_WAKE_SDIO_IRQ) {
1040 pci_pme_active(pdev, true);
1041 pci_enable_wake(pdev, PCI_D3hot, 1);
1043 pci_set_power_state(pdev, PCI_D3hot);
1045 pci_enable_wake(pdev, PCI_D3hot, 0);
1046 pci_disable_device(pdev);
1047 pci_set_power_state(pdev, PCI_D3hot);
1053 static int sdhci_pci_resume(struct device *dev)
1055 struct pci_dev *pdev = to_pci_dev(dev);
1056 struct sdhci_pci_chip *chip;
1057 struct sdhci_pci_slot *slot;
1060 chip = pci_get_drvdata(pdev);
1064 pci_set_power_state(pdev, PCI_D0);
1065 pci_restore_state(pdev);
1066 ret = pci_enable_device(pdev);
1070 if (chip->fixes && chip->fixes->resume) {
1071 ret = chip->fixes->resume(chip);
1076 for (i = 0; i < chip->num_slots; i++) {
1077 slot = chip->slots[i];
1081 ret = sdhci_resume_host(slot->host);
1089 #else /* CONFIG_PM */
1091 #define sdhci_pci_suspend NULL
1092 #define sdhci_pci_resume NULL
1094 #endif /* CONFIG_PM */
1096 #ifdef CONFIG_PM_RUNTIME
1098 static int sdhci_pci_runtime_suspend(struct device *dev)
1100 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1101 struct sdhci_pci_chip *chip;
1102 struct sdhci_pci_slot *slot;
1105 chip = pci_get_drvdata(pdev);
1109 for (i = 0; i < chip->num_slots; i++) {
1110 slot = chip->slots[i];
1114 ret = sdhci_runtime_suspend_host(slot->host);
1117 for (i--; i >= 0; i--)
1118 sdhci_runtime_resume_host(chip->slots[i]->host);
1123 if (chip->fixes && chip->fixes->suspend) {
1124 ret = chip->fixes->suspend(chip);
1126 for (i = chip->num_slots - 1; i >= 0; i--)
1127 sdhci_runtime_resume_host(chip->slots[i]->host);
1135 static int sdhci_pci_runtime_resume(struct device *dev)
1137 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1138 struct sdhci_pci_chip *chip;
1139 struct sdhci_pci_slot *slot;
1142 chip = pci_get_drvdata(pdev);
1146 if (chip->fixes && chip->fixes->resume) {
1147 ret = chip->fixes->resume(chip);
1152 for (i = 0; i < chip->num_slots; i++) {
1153 slot = chip->slots[i];
1157 ret = sdhci_runtime_resume_host(slot->host);
1165 static int sdhci_pci_runtime_idle(struct device *dev)
1172 #define sdhci_pci_runtime_suspend NULL
1173 #define sdhci_pci_runtime_resume NULL
1174 #define sdhci_pci_runtime_idle NULL
1178 static const struct dev_pm_ops sdhci_pci_pm_ops = {
1179 .suspend = sdhci_pci_suspend,
1180 .resume = sdhci_pci_resume,
1181 .runtime_suspend = sdhci_pci_runtime_suspend,
1182 .runtime_resume = sdhci_pci_runtime_resume,
1183 .runtime_idle = sdhci_pci_runtime_idle,
1186 /*****************************************************************************\
1188 * Device probing/removal *
1190 \*****************************************************************************/
1192 static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
1193 struct pci_dev *pdev, struct sdhci_pci_chip *chip, int bar)
1195 struct sdhci_pci_slot *slot;
1196 struct sdhci_host *host;
1199 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
1200 dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
1201 return ERR_PTR(-ENODEV);
1204 if (pci_resource_len(pdev, bar) != 0x100) {
1205 dev_err(&pdev->dev, "Invalid iomem size. You may "
1206 "experience problems.\n");
1209 if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
1210 dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
1211 return ERR_PTR(-ENODEV);
1214 if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
1215 dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
1216 return ERR_PTR(-ENODEV);
1219 host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
1221 dev_err(&pdev->dev, "cannot allocate host\n");
1222 return ERR_CAST(host);
1225 slot = sdhci_priv(host);
1229 slot->pci_bar = bar;
1230 slot->rst_n_gpio = -EINVAL;
1232 host->hw_name = "PCI";
1233 host->ops = &sdhci_pci_ops;
1234 host->quirks = chip->quirks;
1236 host->irq = pdev->irq;
1238 ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
1240 dev_err(&pdev->dev, "cannot request region\n");
1244 host->ioaddr = pci_ioremap_bar(pdev, bar);
1245 if (!host->ioaddr) {
1246 dev_err(&pdev->dev, "failed to remap registers\n");
1251 if (chip->fixes && chip->fixes->probe_slot) {
1252 ret = chip->fixes->probe_slot(slot);
1257 host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
1259 ret = sdhci_add_host(host);
1266 if (chip->fixes && chip->fixes->remove_slot)
1267 chip->fixes->remove_slot(slot, 0);
1270 iounmap(host->ioaddr);
1273 pci_release_region(pdev, bar);
1276 sdhci_free_host(host);
1278 return ERR_PTR(ret);
1281 static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
1287 scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
1288 if (scratch == (u32)-1)
1291 sdhci_remove_host(slot->host, dead);
1293 if (slot->chip->fixes && slot->chip->fixes->remove_slot)
1294 slot->chip->fixes->remove_slot(slot, dead);
1296 pci_release_region(slot->chip->pdev, slot->pci_bar);
1298 sdhci_free_host(slot->host);
1301 static void __devinit sdhci_pci_runtime_pm_allow(struct device *dev)
1303 pm_runtime_put_noidle(dev);
1304 pm_runtime_allow(dev);
1305 pm_runtime_set_autosuspend_delay(dev, 50);
1306 pm_runtime_use_autosuspend(dev);
1307 pm_suspend_ignore_children(dev, 1);
1310 static void __devexit sdhci_pci_runtime_pm_forbid(struct device *dev)
1312 pm_runtime_forbid(dev);
1313 pm_runtime_get_noresume(dev);
1316 static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
1317 const struct pci_device_id *ent)
1319 struct sdhci_pci_chip *chip;
1320 struct sdhci_pci_slot *slot;
1322 u8 slots, first_bar;
1325 BUG_ON(pdev == NULL);
1326 BUG_ON(ent == NULL);
1328 dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
1329 (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
1331 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
1335 slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
1336 dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
1340 BUG_ON(slots > MAX_SLOTS);
1342 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
1346 first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
1348 if (first_bar > 5) {
1349 dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
1353 ret = pci_enable_device(pdev);
1357 chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL);
1364 chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data;
1366 chip->quirks = chip->fixes->quirks;
1367 chip->allow_runtime_pm = chip->fixes->allow_runtime_pm;
1369 chip->num_slots = slots;
1371 pci_set_drvdata(pdev, chip);
1373 if (chip->fixes && chip->fixes->probe) {
1374 ret = chip->fixes->probe(chip);
1379 slots = chip->num_slots; /* Quirk may have changed this */
1381 for (i = 0; i < slots; i++) {
1382 slot = sdhci_pci_probe_slot(pdev, chip, first_bar + i);
1384 for (i--; i >= 0; i--)
1385 sdhci_pci_remove_slot(chip->slots[i]);
1386 ret = PTR_ERR(slot);
1390 chip->slots[i] = slot;
1393 if (chip->allow_runtime_pm)
1394 sdhci_pci_runtime_pm_allow(&pdev->dev);
1399 pci_set_drvdata(pdev, NULL);
1403 pci_disable_device(pdev);
1407 static void __devexit sdhci_pci_remove(struct pci_dev *pdev)
1410 struct sdhci_pci_chip *chip;
1412 chip = pci_get_drvdata(pdev);
1415 if (chip->allow_runtime_pm)
1416 sdhci_pci_runtime_pm_forbid(&pdev->dev);
1418 for (i = 0; i < chip->num_slots; i++)
1419 sdhci_pci_remove_slot(chip->slots[i]);
1421 pci_set_drvdata(pdev, NULL);
1425 pci_disable_device(pdev);
1428 static struct pci_driver sdhci_driver = {
1429 .name = "sdhci-pci",
1430 .id_table = pci_ids,
1431 .probe = sdhci_pci_probe,
1432 .remove = __devexit_p(sdhci_pci_remove),
1434 .pm = &sdhci_pci_pm_ops
1438 /*****************************************************************************\
1440 * Driver init/exit *
1442 \*****************************************************************************/
1444 static int __init sdhci_drv_init(void)
1446 return pci_register_driver(&sdhci_driver);
1449 static void __exit sdhci_drv_exit(void)
1451 pci_unregister_driver(&sdhci_driver);
1454 module_init(sdhci_drv_init);
1455 module_exit(sdhci_drv_exit);
1457 MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
1458 MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
1459 MODULE_LICENSE("GPL");