mmc: sdhci-pci: Fix error case in sdhci_pci_probe_slot()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / mmc / host / sdhci-pci.c
blob2fdeab52b2faf6103a904f382452c1567b9285b7
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>
20 #include <linux/mmc/host.h>
22 #include <asm/scatterlist.h>
23 #include <asm/io.h>
25 #include "sdhci.h"
28 * PCI registers
31 #define PCI_SDHCI_IFPIO 0x00
32 #define PCI_SDHCI_IFDMA 0x01
33 #define PCI_SDHCI_IFVENDOR 0x02
35 #define PCI_SLOT_INFO 0x40 /* 8 bits */
36 #define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7)
37 #define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07
39 #define MAX_SLOTS 8
41 struct sdhci_pci_chip;
42 struct sdhci_pci_slot;
44 struct sdhci_pci_fixes {
45 unsigned int quirks;
47 int (*probe)(struct sdhci_pci_chip*);
49 int (*probe_slot)(struct sdhci_pci_slot*);
50 void (*remove_slot)(struct sdhci_pci_slot*, int);
52 int (*suspend)(struct sdhci_pci_chip*,
53 pm_message_t);
54 int (*resume)(struct sdhci_pci_chip*);
57 struct sdhci_pci_slot {
58 struct sdhci_pci_chip *chip;
59 struct sdhci_host *host;
61 int pci_bar;
64 struct sdhci_pci_chip {
65 struct pci_dev *pdev;
67 unsigned int quirks;
68 const struct sdhci_pci_fixes *fixes;
70 int num_slots; /* Slots on controller */
71 struct sdhci_pci_slot *slots[MAX_SLOTS]; /* Pointers to host slots */
75 /*****************************************************************************\
76 * *
77 * Hardware specific quirk handling *
78 * *
79 \*****************************************************************************/
81 static int ricoh_probe(struct sdhci_pci_chip *chip)
83 if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
84 chip->quirks |= SDHCI_QUIRK_CLOCK_BEFORE_RESET;
86 if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
87 chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
88 chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
90 return 0;
93 static const struct sdhci_pci_fixes sdhci_ricoh = {
94 .probe = ricoh_probe,
95 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR,
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_TIMEOUT_VAL,
115 static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
117 u8 scratch;
118 int ret;
120 ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
121 if (ret)
122 return ret;
125 * Turn PMOS on [bit 0], set over current detection to 2.4 V
126 * [bit 1:2] and enable over current debouncing [bit 6].
128 if (on)
129 scratch |= 0x47;
130 else
131 scratch &= ~0x47;
133 ret = pci_write_config_byte(chip->pdev, 0xAE, scratch);
134 if (ret)
135 return ret;
137 return 0;
140 static int jmicron_probe(struct sdhci_pci_chip *chip)
142 int ret;
144 if (chip->pdev->revision == 0) {
145 chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR |
146 SDHCI_QUIRK_32BIT_DMA_SIZE |
147 SDHCI_QUIRK_32BIT_ADMA_SIZE |
148 SDHCI_QUIRK_RESET_AFTER_REQUEST |
149 SDHCI_QUIRK_BROKEN_SMALL_PIO;
153 * JMicron chips can have two interfaces to the same hardware
154 * in order to work around limitations in Microsoft's driver.
155 * We need to make sure we only bind to one of them.
157 * This code assumes two things:
159 * 1. The PCI code adds subfunctions in order.
161 * 2. The MMC interface has a lower subfunction number
162 * than the SD interface.
164 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD) {
165 struct pci_dev *sd_dev;
167 sd_dev = NULL;
168 while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON,
169 PCI_DEVICE_ID_JMICRON_JMB38X_MMC, sd_dev)) != NULL) {
170 if ((PCI_SLOT(chip->pdev->devfn) ==
171 PCI_SLOT(sd_dev->devfn)) &&
172 (chip->pdev->bus == sd_dev->bus))
173 break;
176 if (sd_dev) {
177 pci_dev_put(sd_dev);
178 dev_info(&chip->pdev->dev, "Refusing to bind to "
179 "secondary interface.\n");
180 return -ENODEV;
185 * JMicron chips need a bit of a nudge to enable the power
186 * output pins.
188 ret = jmicron_pmos(chip, 1);
189 if (ret) {
190 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
191 return ret;
194 return 0;
197 static void jmicron_enable_mmc(struct sdhci_host *host, int on)
199 u8 scratch;
201 scratch = readb(host->ioaddr + 0xC0);
203 if (on)
204 scratch |= 0x01;
205 else
206 scratch &= ~0x01;
208 writeb(scratch, host->ioaddr + 0xC0);
211 static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
213 if (slot->chip->pdev->revision == 0) {
214 u16 version;
216 version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
217 version = (version & SDHCI_VENDOR_VER_MASK) >>
218 SDHCI_VENDOR_VER_SHIFT;
221 * Older versions of the chip have lots of nasty glitches
222 * in the ADMA engine. It's best just to avoid it
223 * completely.
225 if (version < 0xAC)
226 slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
230 * The secondary interface requires a bit set to get the
231 * interrupts.
233 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC)
234 jmicron_enable_mmc(slot->host, 1);
236 return 0;
239 static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
241 if (dead)
242 return;
244 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC)
245 jmicron_enable_mmc(slot->host, 0);
248 static int jmicron_suspend(struct sdhci_pci_chip *chip, pm_message_t state)
250 int i;
252 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC) {
253 for (i = 0;i < chip->num_slots;i++)
254 jmicron_enable_mmc(chip->slots[i]->host, 0);
257 return 0;
260 static int jmicron_resume(struct sdhci_pci_chip *chip)
262 int ret, i;
264 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC) {
265 for (i = 0;i < chip->num_slots;i++)
266 jmicron_enable_mmc(chip->slots[i]->host, 1);
269 ret = jmicron_pmos(chip, 1);
270 if (ret) {
271 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
272 return ret;
275 return 0;
278 static const struct sdhci_pci_fixes sdhci_jmicron = {
279 .probe = jmicron_probe,
281 .probe_slot = jmicron_probe_slot,
282 .remove_slot = jmicron_remove_slot,
284 .suspend = jmicron_suspend,
285 .resume = jmicron_resume,
288 /* SysKonnect CardBus2SDIO extra registers */
289 #define SYSKT_CTRL 0x200
290 #define SYSKT_RDFIFO_STAT 0x204
291 #define SYSKT_WRFIFO_STAT 0x208
292 #define SYSKT_POWER_DATA 0x20c
293 #define SYSKT_POWER_330 0xef
294 #define SYSKT_POWER_300 0xf8
295 #define SYSKT_POWER_184 0xcc
296 #define SYSKT_POWER_CMD 0x20d
297 #define SYSKT_POWER_START (1 << 7)
298 #define SYSKT_POWER_STATUS 0x20e
299 #define SYSKT_POWER_STATUS_OK (1 << 0)
300 #define SYSKT_BOARD_REV 0x210
301 #define SYSKT_CHIP_REV 0x211
302 #define SYSKT_CONF_DATA 0x212
303 #define SYSKT_CONF_DATA_1V8 (1 << 2)
304 #define SYSKT_CONF_DATA_2V5 (1 << 1)
305 #define SYSKT_CONF_DATA_3V3 (1 << 0)
307 static int syskt_probe(struct sdhci_pci_chip *chip)
309 if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
310 chip->pdev->class &= ~0x0000FF;
311 chip->pdev->class |= PCI_SDHCI_IFDMA;
313 return 0;
316 static int syskt_probe_slot(struct sdhci_pci_slot *slot)
318 int tm, ps;
320 u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV);
321 u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV);
322 dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, "
323 "board rev %d.%d, chip rev %d.%d\n",
324 board_rev >> 4, board_rev & 0xf,
325 chip_rev >> 4, chip_rev & 0xf);
326 if (chip_rev >= 0x20)
327 slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA;
329 writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA);
330 writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD);
331 udelay(50);
332 tm = 10; /* Wait max 1 ms */
333 do {
334 ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS);
335 if (ps & SYSKT_POWER_STATUS_OK)
336 break;
337 udelay(100);
338 } while (--tm);
339 if (!tm) {
340 dev_err(&slot->chip->pdev->dev,
341 "power regulator never stabilized");
342 writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD);
343 return -ENODEV;
346 return 0;
349 static const struct sdhci_pci_fixes sdhci_syskt = {
350 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER,
351 .probe = syskt_probe,
352 .probe_slot = syskt_probe_slot,
355 static int via_probe(struct sdhci_pci_chip *chip)
357 if (chip->pdev->revision == 0x10)
358 chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
360 return 0;
363 static const struct sdhci_pci_fixes sdhci_via = {
364 .probe = via_probe,
367 static const struct pci_device_id pci_ids[] __devinitdata = {
369 .vendor = PCI_VENDOR_ID_RICOH,
370 .device = PCI_DEVICE_ID_RICOH_R5C822,
371 .subvendor = PCI_ANY_ID,
372 .subdevice = PCI_ANY_ID,
373 .driver_data = (kernel_ulong_t)&sdhci_ricoh,
377 .vendor = PCI_VENDOR_ID_ENE,
378 .device = PCI_DEVICE_ID_ENE_CB712_SD,
379 .subvendor = PCI_ANY_ID,
380 .subdevice = PCI_ANY_ID,
381 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
385 .vendor = PCI_VENDOR_ID_ENE,
386 .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
387 .subvendor = PCI_ANY_ID,
388 .subdevice = PCI_ANY_ID,
389 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
393 .vendor = PCI_VENDOR_ID_ENE,
394 .device = PCI_DEVICE_ID_ENE_CB714_SD,
395 .subvendor = PCI_ANY_ID,
396 .subdevice = PCI_ANY_ID,
397 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
401 .vendor = PCI_VENDOR_ID_ENE,
402 .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
403 .subvendor = PCI_ANY_ID,
404 .subdevice = PCI_ANY_ID,
405 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
409 .vendor = PCI_VENDOR_ID_MARVELL,
410 .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
411 .subvendor = PCI_ANY_ID,
412 .subdevice = PCI_ANY_ID,
413 .driver_data = (kernel_ulong_t)&sdhci_cafe,
417 .vendor = PCI_VENDOR_ID_JMICRON,
418 .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
419 .subvendor = PCI_ANY_ID,
420 .subdevice = PCI_ANY_ID,
421 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
425 .vendor = PCI_VENDOR_ID_JMICRON,
426 .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
427 .subvendor = PCI_ANY_ID,
428 .subdevice = PCI_ANY_ID,
429 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
433 .vendor = PCI_VENDOR_ID_SYSKONNECT,
434 .device = 0x8000,
435 .subvendor = PCI_ANY_ID,
436 .subdevice = PCI_ANY_ID,
437 .driver_data = (kernel_ulong_t)&sdhci_syskt,
441 .vendor = PCI_VENDOR_ID_VIA,
442 .device = 0x95d0,
443 .subvendor = PCI_ANY_ID,
444 .subdevice = PCI_ANY_ID,
445 .driver_data = (kernel_ulong_t)&sdhci_via,
448 { /* Generic SD host controller */
449 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
452 { /* end: all zeroes */ },
455 MODULE_DEVICE_TABLE(pci, pci_ids);
457 /*****************************************************************************\
459 * SDHCI core callbacks *
461 \*****************************************************************************/
463 static int sdhci_pci_enable_dma(struct sdhci_host *host)
465 struct sdhci_pci_slot *slot;
466 struct pci_dev *pdev;
467 int ret;
469 slot = sdhci_priv(host);
470 pdev = slot->chip->pdev;
472 if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
473 ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
474 (host->flags & SDHCI_USE_SDMA)) {
475 dev_warn(&pdev->dev, "Will use DMA mode even though HW "
476 "doesn't fully claim to support it.\n");
479 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
480 if (ret)
481 return ret;
483 pci_set_master(pdev);
485 return 0;
488 static struct sdhci_ops sdhci_pci_ops = {
489 .enable_dma = sdhci_pci_enable_dma,
492 /*****************************************************************************\
494 * Suspend/resume *
496 \*****************************************************************************/
498 #ifdef CONFIG_PM
500 static int sdhci_pci_suspend (struct pci_dev *pdev, pm_message_t state)
502 struct sdhci_pci_chip *chip;
503 struct sdhci_pci_slot *slot;
504 int i, ret;
506 chip = pci_get_drvdata(pdev);
507 if (!chip)
508 return 0;
510 for (i = 0;i < chip->num_slots;i++) {
511 slot = chip->slots[i];
512 if (!slot)
513 continue;
515 ret = sdhci_suspend_host(slot->host, state);
517 if (ret) {
518 for (i--;i >= 0;i--)
519 sdhci_resume_host(chip->slots[i]->host);
520 return ret;
524 if (chip->fixes && chip->fixes->suspend) {
525 ret = chip->fixes->suspend(chip, state);
526 if (ret) {
527 for (i = chip->num_slots - 1;i >= 0;i--)
528 sdhci_resume_host(chip->slots[i]->host);
529 return ret;
533 pci_save_state(pdev);
534 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
535 pci_disable_device(pdev);
536 pci_set_power_state(pdev, pci_choose_state(pdev, state));
538 return 0;
541 static int sdhci_pci_resume (struct pci_dev *pdev)
543 struct sdhci_pci_chip *chip;
544 struct sdhci_pci_slot *slot;
545 int i, ret;
547 chip = pci_get_drvdata(pdev);
548 if (!chip)
549 return 0;
551 pci_set_power_state(pdev, PCI_D0);
552 pci_restore_state(pdev);
553 ret = pci_enable_device(pdev);
554 if (ret)
555 return ret;
557 if (chip->fixes && chip->fixes->resume) {
558 ret = chip->fixes->resume(chip);
559 if (ret)
560 return ret;
563 for (i = 0;i < chip->num_slots;i++) {
564 slot = chip->slots[i];
565 if (!slot)
566 continue;
568 ret = sdhci_resume_host(slot->host);
569 if (ret)
570 return ret;
573 return 0;
576 #else /* CONFIG_PM */
578 #define sdhci_pci_suspend NULL
579 #define sdhci_pci_resume NULL
581 #endif /* CONFIG_PM */
583 /*****************************************************************************\
585 * Device probing/removal *
587 \*****************************************************************************/
589 static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
590 struct pci_dev *pdev, struct sdhci_pci_chip *chip, int bar)
592 struct sdhci_pci_slot *slot;
593 struct sdhci_host *host;
595 resource_size_t addr;
597 int ret;
599 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
600 dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
601 return ERR_PTR(-ENODEV);
604 if (pci_resource_len(pdev, bar) != 0x100) {
605 dev_err(&pdev->dev, "Invalid iomem size. You may "
606 "experience problems.\n");
609 if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
610 dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
611 return ERR_PTR(-ENODEV);
614 if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
615 dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
616 return ERR_PTR(-ENODEV);
619 host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
620 if (IS_ERR(host)) {
621 dev_err(&pdev->dev, "cannot allocate host\n");
622 return ERR_PTR(PTR_ERR(host));
625 slot = sdhci_priv(host);
627 slot->chip = chip;
628 slot->host = host;
629 slot->pci_bar = bar;
631 host->hw_name = "PCI";
632 host->ops = &sdhci_pci_ops;
633 host->quirks = chip->quirks;
635 host->irq = pdev->irq;
637 ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
638 if (ret) {
639 dev_err(&pdev->dev, "cannot request region\n");
640 goto free;
643 addr = pci_resource_start(pdev, bar);
644 host->ioaddr = pci_ioremap_bar(pdev, bar);
645 if (!host->ioaddr) {
646 dev_err(&pdev->dev, "failed to remap registers\n");
647 ret = -ENOMEM;
648 goto release;
651 if (chip->fixes && chip->fixes->probe_slot) {
652 ret = chip->fixes->probe_slot(slot);
653 if (ret)
654 goto unmap;
657 ret = sdhci_add_host(host);
658 if (ret)
659 goto remove;
661 return slot;
663 remove:
664 if (chip->fixes && chip->fixes->remove_slot)
665 chip->fixes->remove_slot(slot, 0);
667 unmap:
668 iounmap(host->ioaddr);
670 release:
671 pci_release_region(pdev, bar);
673 free:
674 sdhci_free_host(host);
676 return ERR_PTR(ret);
679 static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
681 int dead;
682 u32 scratch;
684 dead = 0;
685 scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
686 if (scratch == (u32)-1)
687 dead = 1;
689 sdhci_remove_host(slot->host, dead);
691 if (slot->chip->fixes && slot->chip->fixes->remove_slot)
692 slot->chip->fixes->remove_slot(slot, dead);
694 pci_release_region(slot->chip->pdev, slot->pci_bar);
696 sdhci_free_host(slot->host);
699 static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
700 const struct pci_device_id *ent)
702 struct sdhci_pci_chip *chip;
703 struct sdhci_pci_slot *slot;
705 u8 slots, rev, first_bar;
706 int ret, i;
708 BUG_ON(pdev == NULL);
709 BUG_ON(ent == NULL);
711 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &rev);
713 dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
714 (int)pdev->vendor, (int)pdev->device, (int)rev);
716 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
717 if (ret)
718 return ret;
720 slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
721 dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
722 if (slots == 0)
723 return -ENODEV;
725 BUG_ON(slots > MAX_SLOTS);
727 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
728 if (ret)
729 return ret;
731 first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
733 if (first_bar > 5) {
734 dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
735 return -ENODEV;
738 ret = pci_enable_device(pdev);
739 if (ret)
740 return ret;
742 chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL);
743 if (!chip) {
744 ret = -ENOMEM;
745 goto err;
748 chip->pdev = pdev;
749 chip->fixes = (const struct sdhci_pci_fixes*)ent->driver_data;
750 if (chip->fixes)
751 chip->quirks = chip->fixes->quirks;
752 chip->num_slots = slots;
754 pci_set_drvdata(pdev, chip);
756 if (chip->fixes && chip->fixes->probe) {
757 ret = chip->fixes->probe(chip);
758 if (ret)
759 goto free;
762 for (i = 0;i < slots;i++) {
763 slot = sdhci_pci_probe_slot(pdev, chip, first_bar + i);
764 if (IS_ERR(slot)) {
765 for (i--;i >= 0;i--)
766 sdhci_pci_remove_slot(chip->slots[i]);
767 ret = PTR_ERR(slot);
768 goto free;
771 chip->slots[i] = slot;
774 return 0;
776 free:
777 pci_set_drvdata(pdev, NULL);
778 kfree(chip);
780 err:
781 pci_disable_device(pdev);
782 return ret;
785 static void __devexit sdhci_pci_remove(struct pci_dev *pdev)
787 int i;
788 struct sdhci_pci_chip *chip;
790 chip = pci_get_drvdata(pdev);
792 if (chip) {
793 for (i = 0;i < chip->num_slots; i++)
794 sdhci_pci_remove_slot(chip->slots[i]);
796 pci_set_drvdata(pdev, NULL);
797 kfree(chip);
800 pci_disable_device(pdev);
803 static struct pci_driver sdhci_driver = {
804 .name = "sdhci-pci",
805 .id_table = pci_ids,
806 .probe = sdhci_pci_probe,
807 .remove = __devexit_p(sdhci_pci_remove),
808 .suspend = sdhci_pci_suspend,
809 .resume = sdhci_pci_resume,
812 /*****************************************************************************\
814 * Driver init/exit *
816 \*****************************************************************************/
818 static int __init sdhci_drv_init(void)
820 return pci_register_driver(&sdhci_driver);
823 static void __exit sdhci_drv_exit(void)
825 pci_unregister_driver(&sdhci_driver);
828 module_init(sdhci_drv_init);
829 module_exit(sdhci_drv_exit);
831 MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
832 MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
833 MODULE_LICENSE("GPL");