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/pci.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/slab.h>
20 #include <linux/device.h>
22 #include <linux/mmc/host.h>
24 #include <asm/scatterlist.h>
33 #define PCI_SDHCI_IFPIO 0x00
34 #define PCI_SDHCI_IFDMA 0x01
35 #define PCI_SDHCI_IFVENDOR 0x02
37 #define PCI_SLOT_INFO 0x40 /* 8 bits */
38 #define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7)
39 #define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07
43 struct sdhci_pci_chip;
44 struct sdhci_pci_slot;
46 struct sdhci_pci_fixes {
49 int (*probe)(struct sdhci_pci_chip*);
51 int (*probe_slot)(struct sdhci_pci_slot*);
52 void (*remove_slot)(struct sdhci_pci_slot*, int);
54 int (*suspend)(struct sdhci_pci_chip*,
56 int (*resume)(struct sdhci_pci_chip*);
59 struct sdhci_pci_slot {
60 struct sdhci_pci_chip *chip;
61 struct sdhci_host *host;
66 struct sdhci_pci_chip {
70 const struct sdhci_pci_fixes *fixes;
72 int num_slots; /* Slots on controller */
73 struct sdhci_pci_slot *slots[MAX_SLOTS]; /* Pointers to host slots */
77 /*****************************************************************************\
79 * Hardware specific quirk handling *
81 \*****************************************************************************/
83 static int ricoh_probe(struct sdhci_pci_chip *chip)
85 if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
86 chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
87 chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
91 static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot)
94 ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT)
95 & SDHCI_TIMEOUT_CLK_MASK) |
97 ((0x21 << SDHCI_CLOCK_BASE_SHIFT)
98 & SDHCI_CLOCK_BASE_MASK) |
100 SDHCI_TIMEOUT_CLK_UNIT |
106 static int ricoh_mmc_resume(struct sdhci_pci_chip *chip)
108 /* Apply a delay to allow controller to settle */
109 /* Otherwise it becomes confused if card state changed
115 static const struct sdhci_pci_fixes sdhci_ricoh = {
116 .probe = ricoh_probe,
117 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
118 SDHCI_QUIRK_FORCE_DMA |
119 SDHCI_QUIRK_CLOCK_BEFORE_RESET,
122 static const struct sdhci_pci_fixes sdhci_ricoh_mmc = {
123 .probe_slot = ricoh_mmc_probe_slot,
124 .resume = ricoh_mmc_resume,
125 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
126 SDHCI_QUIRK_CLOCK_BEFORE_RESET |
127 SDHCI_QUIRK_NO_CARD_NO_RESET |
128 SDHCI_QUIRK_MISSING_CAPS
131 static const struct sdhci_pci_fixes sdhci_ene_712 = {
132 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
133 SDHCI_QUIRK_BROKEN_DMA,
136 static const struct sdhci_pci_fixes sdhci_ene_714 = {
137 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
138 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
139 SDHCI_QUIRK_BROKEN_DMA,
142 static const struct sdhci_pci_fixes sdhci_cafe = {
143 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
144 SDHCI_QUIRK_NO_BUSY_IRQ |
145 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
148 static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
149 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
152 static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc_sdio = {
153 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
156 static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
161 ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
166 * Turn PMOS on [bit 0], set over current detection to 2.4 V
167 * [bit 1:2] and enable over current debouncing [bit 6].
174 ret = pci_write_config_byte(chip->pdev, 0xAE, scratch);
181 static int jmicron_probe(struct sdhci_pci_chip *chip)
185 if (chip->pdev->revision == 0) {
186 chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR |
187 SDHCI_QUIRK_32BIT_DMA_SIZE |
188 SDHCI_QUIRK_32BIT_ADMA_SIZE |
189 SDHCI_QUIRK_RESET_AFTER_REQUEST |
190 SDHCI_QUIRK_BROKEN_SMALL_PIO;
194 * JMicron chips can have two interfaces to the same hardware
195 * in order to work around limitations in Microsoft's driver.
196 * We need to make sure we only bind to one of them.
198 * This code assumes two things:
200 * 1. The PCI code adds subfunctions in order.
202 * 2. The MMC interface has a lower subfunction number
203 * than the SD interface.
205 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD) {
206 struct pci_dev *sd_dev;
209 while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON,
210 PCI_DEVICE_ID_JMICRON_JMB38X_MMC, sd_dev)) != NULL) {
211 if ((PCI_SLOT(chip->pdev->devfn) ==
212 PCI_SLOT(sd_dev->devfn)) &&
213 (chip->pdev->bus == sd_dev->bus))
219 dev_info(&chip->pdev->dev, "Refusing to bind to "
220 "secondary interface.\n");
226 * JMicron chips need a bit of a nudge to enable the power
229 ret = jmicron_pmos(chip, 1);
231 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
238 static void jmicron_enable_mmc(struct sdhci_host *host, int on)
242 scratch = readb(host->ioaddr + 0xC0);
249 writeb(scratch, host->ioaddr + 0xC0);
252 static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
254 if (slot->chip->pdev->revision == 0) {
257 version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
258 version = (version & SDHCI_VENDOR_VER_MASK) >>
259 SDHCI_VENDOR_VER_SHIFT;
262 * Older versions of the chip have lots of nasty glitches
263 * in the ADMA engine. It's best just to avoid it
267 slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
271 * The secondary interface requires a bit set to get the
274 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC)
275 jmicron_enable_mmc(slot->host, 1);
280 static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
285 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC)
286 jmicron_enable_mmc(slot->host, 0);
289 static int jmicron_suspend(struct sdhci_pci_chip *chip, pm_message_t state)
293 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC) {
294 for (i = 0;i < chip->num_slots;i++)
295 jmicron_enable_mmc(chip->slots[i]->host, 0);
301 static int jmicron_resume(struct sdhci_pci_chip *chip)
305 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC) {
306 for (i = 0;i < chip->num_slots;i++)
307 jmicron_enable_mmc(chip->slots[i]->host, 1);
310 ret = jmicron_pmos(chip, 1);
312 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
319 static const struct sdhci_pci_fixes sdhci_jmicron = {
320 .probe = jmicron_probe,
322 .probe_slot = jmicron_probe_slot,
323 .remove_slot = jmicron_remove_slot,
325 .suspend = jmicron_suspend,
326 .resume = jmicron_resume,
329 /* SysKonnect CardBus2SDIO extra registers */
330 #define SYSKT_CTRL 0x200
331 #define SYSKT_RDFIFO_STAT 0x204
332 #define SYSKT_WRFIFO_STAT 0x208
333 #define SYSKT_POWER_DATA 0x20c
334 #define SYSKT_POWER_330 0xef
335 #define SYSKT_POWER_300 0xf8
336 #define SYSKT_POWER_184 0xcc
337 #define SYSKT_POWER_CMD 0x20d
338 #define SYSKT_POWER_START (1 << 7)
339 #define SYSKT_POWER_STATUS 0x20e
340 #define SYSKT_POWER_STATUS_OK (1 << 0)
341 #define SYSKT_BOARD_REV 0x210
342 #define SYSKT_CHIP_REV 0x211
343 #define SYSKT_CONF_DATA 0x212
344 #define SYSKT_CONF_DATA_1V8 (1 << 2)
345 #define SYSKT_CONF_DATA_2V5 (1 << 1)
346 #define SYSKT_CONF_DATA_3V3 (1 << 0)
348 static int syskt_probe(struct sdhci_pci_chip *chip)
350 if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
351 chip->pdev->class &= ~0x0000FF;
352 chip->pdev->class |= PCI_SDHCI_IFDMA;
357 static int syskt_probe_slot(struct sdhci_pci_slot *slot)
361 u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV);
362 u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV);
363 dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, "
364 "board rev %d.%d, chip rev %d.%d\n",
365 board_rev >> 4, board_rev & 0xf,
366 chip_rev >> 4, chip_rev & 0xf);
367 if (chip_rev >= 0x20)
368 slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA;
370 writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA);
371 writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD);
373 tm = 10; /* Wait max 1 ms */
375 ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS);
376 if (ps & SYSKT_POWER_STATUS_OK)
381 dev_err(&slot->chip->pdev->dev,
382 "power regulator never stabilized");
383 writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD);
390 static const struct sdhci_pci_fixes sdhci_syskt = {
391 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER,
392 .probe = syskt_probe,
393 .probe_slot = syskt_probe_slot,
396 static int via_probe(struct sdhci_pci_chip *chip)
398 if (chip->pdev->revision == 0x10)
399 chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
404 static const struct sdhci_pci_fixes sdhci_via = {
408 static const struct pci_device_id pci_ids[] __devinitdata = {
410 .vendor = PCI_VENDOR_ID_RICOH,
411 .device = PCI_DEVICE_ID_RICOH_R5C822,
412 .subvendor = PCI_ANY_ID,
413 .subdevice = PCI_ANY_ID,
414 .driver_data = (kernel_ulong_t)&sdhci_ricoh,
418 .vendor = PCI_VENDOR_ID_RICOH,
420 .subvendor = PCI_ANY_ID,
421 .subdevice = PCI_ANY_ID,
422 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
426 .vendor = PCI_VENDOR_ID_RICOH,
428 .subvendor = PCI_ANY_ID,
429 .subdevice = PCI_ANY_ID,
430 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
434 .vendor = PCI_VENDOR_ID_ENE,
435 .device = PCI_DEVICE_ID_ENE_CB712_SD,
436 .subvendor = PCI_ANY_ID,
437 .subdevice = PCI_ANY_ID,
438 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
442 .vendor = PCI_VENDOR_ID_ENE,
443 .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
444 .subvendor = PCI_ANY_ID,
445 .subdevice = PCI_ANY_ID,
446 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
450 .vendor = PCI_VENDOR_ID_ENE,
451 .device = PCI_DEVICE_ID_ENE_CB714_SD,
452 .subvendor = PCI_ANY_ID,
453 .subdevice = PCI_ANY_ID,
454 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
458 .vendor = PCI_VENDOR_ID_ENE,
459 .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
460 .subvendor = PCI_ANY_ID,
461 .subdevice = PCI_ANY_ID,
462 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
466 .vendor = PCI_VENDOR_ID_MARVELL,
467 .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
468 .subvendor = PCI_ANY_ID,
469 .subdevice = PCI_ANY_ID,
470 .driver_data = (kernel_ulong_t)&sdhci_cafe,
474 .vendor = PCI_VENDOR_ID_JMICRON,
475 .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
476 .subvendor = PCI_ANY_ID,
477 .subdevice = PCI_ANY_ID,
478 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
482 .vendor = PCI_VENDOR_ID_JMICRON,
483 .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
484 .subvendor = PCI_ANY_ID,
485 .subdevice = PCI_ANY_ID,
486 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
490 .vendor = PCI_VENDOR_ID_SYSKONNECT,
492 .subvendor = PCI_ANY_ID,
493 .subdevice = PCI_ANY_ID,
494 .driver_data = (kernel_ulong_t)&sdhci_syskt,
498 .vendor = PCI_VENDOR_ID_VIA,
500 .subvendor = PCI_ANY_ID,
501 .subdevice = PCI_ANY_ID,
502 .driver_data = (kernel_ulong_t)&sdhci_via,
506 .vendor = PCI_VENDOR_ID_INTEL,
507 .device = PCI_DEVICE_ID_INTEL_MFD_SD,
508 .subvendor = PCI_ANY_ID,
509 .subdevice = PCI_ANY_ID,
510 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
514 .vendor = PCI_VENDOR_ID_INTEL,
515 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1,
516 .subvendor = PCI_ANY_ID,
517 .subdevice = PCI_ANY_ID,
518 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc_sdio,
522 .vendor = PCI_VENDOR_ID_INTEL,
523 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2,
524 .subvendor = PCI_ANY_ID,
525 .subdevice = PCI_ANY_ID,
526 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc_sdio,
530 .vendor = PCI_VENDOR_ID_INTEL,
531 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0,
532 .subvendor = PCI_ANY_ID,
533 .subdevice = PCI_ANY_ID,
534 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc_sdio,
538 .vendor = PCI_VENDOR_ID_INTEL,
539 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1,
540 .subvendor = PCI_ANY_ID,
541 .subdevice = PCI_ANY_ID,
542 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc_sdio,
545 { /* Generic SD host controller */
546 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
549 { /* end: all zeroes */ },
552 MODULE_DEVICE_TABLE(pci, pci_ids);
554 /*****************************************************************************\
556 * SDHCI core callbacks *
558 \*****************************************************************************/
560 static int sdhci_pci_enable_dma(struct sdhci_host *host)
562 struct sdhci_pci_slot *slot;
563 struct pci_dev *pdev;
566 slot = sdhci_priv(host);
567 pdev = slot->chip->pdev;
569 if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
570 ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
571 (host->flags & SDHCI_USE_SDMA)) {
572 dev_warn(&pdev->dev, "Will use DMA mode even though HW "
573 "doesn't fully claim to support it.\n");
576 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
580 pci_set_master(pdev);
585 static struct sdhci_ops sdhci_pci_ops = {
586 .enable_dma = sdhci_pci_enable_dma,
589 /*****************************************************************************\
593 \*****************************************************************************/
597 static int sdhci_pci_suspend (struct pci_dev *pdev, pm_message_t state)
599 struct sdhci_pci_chip *chip;
600 struct sdhci_pci_slot *slot;
601 mmc_pm_flag_t pm_flags = 0;
604 chip = pci_get_drvdata(pdev);
608 for (i = 0;i < chip->num_slots;i++) {
609 slot = chip->slots[i];
613 ret = sdhci_suspend_host(slot->host, state);
617 sdhci_resume_host(chip->slots[i]->host);
621 pm_flags |= slot->host->mmc->pm_flags;
624 if (chip->fixes && chip->fixes->suspend) {
625 ret = chip->fixes->suspend(chip, state);
627 for (i = chip->num_slots - 1;i >= 0;i--)
628 sdhci_resume_host(chip->slots[i]->host);
633 pci_save_state(pdev);
634 if (pm_flags & MMC_PM_KEEP_POWER) {
635 if (pm_flags & MMC_PM_WAKE_SDIO_IRQ)
636 pci_enable_wake(pdev, PCI_D3hot, 1);
637 pci_set_power_state(pdev, PCI_D3hot);
639 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
640 pci_disable_device(pdev);
641 pci_set_power_state(pdev, pci_choose_state(pdev, state));
647 static int sdhci_pci_resume (struct pci_dev *pdev)
649 struct sdhci_pci_chip *chip;
650 struct sdhci_pci_slot *slot;
653 chip = pci_get_drvdata(pdev);
657 pci_set_power_state(pdev, PCI_D0);
658 pci_restore_state(pdev);
659 ret = pci_enable_device(pdev);
663 if (chip->fixes && chip->fixes->resume) {
664 ret = chip->fixes->resume(chip);
669 for (i = 0;i < chip->num_slots;i++) {
670 slot = chip->slots[i];
674 ret = sdhci_resume_host(slot->host);
682 #else /* CONFIG_PM */
684 #define sdhci_pci_suspend NULL
685 #define sdhci_pci_resume NULL
687 #endif /* CONFIG_PM */
689 /*****************************************************************************\
691 * Device probing/removal *
693 \*****************************************************************************/
695 static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
696 struct pci_dev *pdev, struct sdhci_pci_chip *chip, int bar)
698 struct sdhci_pci_slot *slot;
699 struct sdhci_host *host;
701 resource_size_t addr;
705 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
706 dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
707 return ERR_PTR(-ENODEV);
710 if (pci_resource_len(pdev, bar) != 0x100) {
711 dev_err(&pdev->dev, "Invalid iomem size. You may "
712 "experience problems.\n");
715 if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
716 dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
717 return ERR_PTR(-ENODEV);
720 if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
721 dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
722 return ERR_PTR(-ENODEV);
725 host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
727 dev_err(&pdev->dev, "cannot allocate host\n");
728 return ERR_CAST(host);
731 slot = sdhci_priv(host);
737 host->hw_name = "PCI";
738 host->ops = &sdhci_pci_ops;
739 host->quirks = chip->quirks;
741 host->irq = pdev->irq;
743 ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
745 dev_err(&pdev->dev, "cannot request region\n");
749 addr = pci_resource_start(pdev, bar);
750 host->ioaddr = pci_ioremap_bar(pdev, bar);
752 dev_err(&pdev->dev, "failed to remap registers\n");
756 if (chip->fixes && chip->fixes->probe_slot) {
757 ret = chip->fixes->probe_slot(slot);
762 host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
764 ret = sdhci_add_host(host);
771 if (chip->fixes && chip->fixes->remove_slot)
772 chip->fixes->remove_slot(slot, 0);
775 iounmap(host->ioaddr);
778 pci_release_region(pdev, bar);
781 sdhci_free_host(host);
786 static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
792 scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
793 if (scratch == (u32)-1)
796 sdhci_remove_host(slot->host, dead);
798 if (slot->chip->fixes && slot->chip->fixes->remove_slot)
799 slot->chip->fixes->remove_slot(slot, dead);
801 pci_release_region(slot->chip->pdev, slot->pci_bar);
803 sdhci_free_host(slot->host);
806 static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
807 const struct pci_device_id *ent)
809 struct sdhci_pci_chip *chip;
810 struct sdhci_pci_slot *slot;
812 u8 slots, rev, first_bar;
815 BUG_ON(pdev == NULL);
818 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &rev);
820 dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
821 (int)pdev->vendor, (int)pdev->device, (int)rev);
823 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
827 slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
828 dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
832 BUG_ON(slots > MAX_SLOTS);
834 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
838 first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
841 dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
845 ret = pci_enable_device(pdev);
849 chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL);
856 chip->fixes = (const struct sdhci_pci_fixes*)ent->driver_data;
858 chip->quirks = chip->fixes->quirks;
859 chip->num_slots = slots;
861 pci_set_drvdata(pdev, chip);
863 if (chip->fixes && chip->fixes->probe) {
864 ret = chip->fixes->probe(chip);
869 slots = chip->num_slots; /* Quirk may have changed this */
871 for (i = 0;i < slots;i++) {
872 slot = sdhci_pci_probe_slot(pdev, chip, first_bar + i);
875 sdhci_pci_remove_slot(chip->slots[i]);
880 chip->slots[i] = slot;
886 pci_set_drvdata(pdev, NULL);
890 pci_disable_device(pdev);
894 static void __devexit sdhci_pci_remove(struct pci_dev *pdev)
897 struct sdhci_pci_chip *chip;
899 chip = pci_get_drvdata(pdev);
902 for (i = 0;i < chip->num_slots; i++)
903 sdhci_pci_remove_slot(chip->slots[i]);
905 pci_set_drvdata(pdev, NULL);
909 pci_disable_device(pdev);
912 static struct pci_driver sdhci_driver = {
915 .probe = sdhci_pci_probe,
916 .remove = __devexit_p(sdhci_pci_remove),
917 .suspend = sdhci_pci_suspend,
918 .resume = sdhci_pci_resume,
921 /*****************************************************************************\
925 \*****************************************************************************/
927 static int __init sdhci_drv_init(void)
929 return pci_register_driver(&sdhci_driver);
932 static void __exit sdhci_drv_exit(void)
934 pci_unregister_driver(&sdhci_driver);
937 module_init(sdhci_drv_init);
938 module_exit(sdhci_drv_exit);
940 MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
941 MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
942 MODULE_LICENSE("GPL");