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
,
149 * ADMA operation is disabled for Moorestown platform due to
152 static int mrst_hc1_probe(struct sdhci_pci_chip
*chip
)
155 * slots number is fixed here for MRST as SDIO3 is never used and has
162 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0
= {
163 .quirks
= SDHCI_QUIRK_BROKEN_ADMA
| SDHCI_QUIRK_NO_HISPD_BIT
,
166 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1
= {
167 .quirks
= SDHCI_QUIRK_BROKEN_ADMA
| SDHCI_QUIRK_NO_HISPD_BIT
,
168 .probe
= mrst_hc1_probe
,
171 static const struct sdhci_pci_fixes sdhci_intel_mfd_sd
= {
172 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
175 static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc_sdio
= {
176 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
179 static int jmicron_pmos(struct sdhci_pci_chip
*chip
, int on
)
184 ret
= pci_read_config_byte(chip
->pdev
, 0xAE, &scratch
);
189 * Turn PMOS on [bit 0], set over current detection to 2.4 V
190 * [bit 1:2] and enable over current debouncing [bit 6].
197 ret
= pci_write_config_byte(chip
->pdev
, 0xAE, scratch
);
204 static int jmicron_probe(struct sdhci_pci_chip
*chip
)
208 if (chip
->pdev
->revision
== 0) {
209 chip
->quirks
|= SDHCI_QUIRK_32BIT_DMA_ADDR
|
210 SDHCI_QUIRK_32BIT_DMA_SIZE
|
211 SDHCI_QUIRK_32BIT_ADMA_SIZE
|
212 SDHCI_QUIRK_RESET_AFTER_REQUEST
|
213 SDHCI_QUIRK_BROKEN_SMALL_PIO
;
217 * JMicron chips can have two interfaces to the same hardware
218 * in order to work around limitations in Microsoft's driver.
219 * We need to make sure we only bind to one of them.
221 * This code assumes two things:
223 * 1. The PCI code adds subfunctions in order.
225 * 2. The MMC interface has a lower subfunction number
226 * than the SD interface.
228 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_SD
) {
229 struct pci_dev
*sd_dev
;
232 while ((sd_dev
= pci_get_device(PCI_VENDOR_ID_JMICRON
,
233 PCI_DEVICE_ID_JMICRON_JMB38X_MMC
, sd_dev
)) != NULL
) {
234 if ((PCI_SLOT(chip
->pdev
->devfn
) ==
235 PCI_SLOT(sd_dev
->devfn
)) &&
236 (chip
->pdev
->bus
== sd_dev
->bus
))
242 dev_info(&chip
->pdev
->dev
, "Refusing to bind to "
243 "secondary interface.\n");
249 * JMicron chips need a bit of a nudge to enable the power
252 ret
= jmicron_pmos(chip
, 1);
254 dev_err(&chip
->pdev
->dev
, "Failure enabling card power\n");
261 static void jmicron_enable_mmc(struct sdhci_host
*host
, int on
)
265 scratch
= readb(host
->ioaddr
+ 0xC0);
272 writeb(scratch
, host
->ioaddr
+ 0xC0);
275 static int jmicron_probe_slot(struct sdhci_pci_slot
*slot
)
277 if (slot
->chip
->pdev
->revision
== 0) {
280 version
= readl(slot
->host
->ioaddr
+ SDHCI_HOST_VERSION
);
281 version
= (version
& SDHCI_VENDOR_VER_MASK
) >>
282 SDHCI_VENDOR_VER_SHIFT
;
285 * Older versions of the chip have lots of nasty glitches
286 * in the ADMA engine. It's best just to avoid it
290 slot
->host
->quirks
|= SDHCI_QUIRK_BROKEN_ADMA
;
294 * The secondary interface requires a bit set to get the
297 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
)
298 jmicron_enable_mmc(slot
->host
, 1);
303 static void jmicron_remove_slot(struct sdhci_pci_slot
*slot
, int dead
)
308 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
)
309 jmicron_enable_mmc(slot
->host
, 0);
312 static int jmicron_suspend(struct sdhci_pci_chip
*chip
, pm_message_t state
)
316 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
) {
317 for (i
= 0;i
< chip
->num_slots
;i
++)
318 jmicron_enable_mmc(chip
->slots
[i
]->host
, 0);
324 static int jmicron_resume(struct sdhci_pci_chip
*chip
)
328 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
) {
329 for (i
= 0;i
< chip
->num_slots
;i
++)
330 jmicron_enable_mmc(chip
->slots
[i
]->host
, 1);
333 ret
= jmicron_pmos(chip
, 1);
335 dev_err(&chip
->pdev
->dev
, "Failure enabling card power\n");
342 static const struct sdhci_pci_fixes sdhci_jmicron
= {
343 .probe
= jmicron_probe
,
345 .probe_slot
= jmicron_probe_slot
,
346 .remove_slot
= jmicron_remove_slot
,
348 .suspend
= jmicron_suspend
,
349 .resume
= jmicron_resume
,
352 /* SysKonnect CardBus2SDIO extra registers */
353 #define SYSKT_CTRL 0x200
354 #define SYSKT_RDFIFO_STAT 0x204
355 #define SYSKT_WRFIFO_STAT 0x208
356 #define SYSKT_POWER_DATA 0x20c
357 #define SYSKT_POWER_330 0xef
358 #define SYSKT_POWER_300 0xf8
359 #define SYSKT_POWER_184 0xcc
360 #define SYSKT_POWER_CMD 0x20d
361 #define SYSKT_POWER_START (1 << 7)
362 #define SYSKT_POWER_STATUS 0x20e
363 #define SYSKT_POWER_STATUS_OK (1 << 0)
364 #define SYSKT_BOARD_REV 0x210
365 #define SYSKT_CHIP_REV 0x211
366 #define SYSKT_CONF_DATA 0x212
367 #define SYSKT_CONF_DATA_1V8 (1 << 2)
368 #define SYSKT_CONF_DATA_2V5 (1 << 1)
369 #define SYSKT_CONF_DATA_3V3 (1 << 0)
371 static int syskt_probe(struct sdhci_pci_chip
*chip
)
373 if ((chip
->pdev
->class & 0x0000FF) == PCI_SDHCI_IFVENDOR
) {
374 chip
->pdev
->class &= ~0x0000FF;
375 chip
->pdev
->class |= PCI_SDHCI_IFDMA
;
380 static int syskt_probe_slot(struct sdhci_pci_slot
*slot
)
384 u8 board_rev
= readb(slot
->host
->ioaddr
+ SYSKT_BOARD_REV
);
385 u8 chip_rev
= readb(slot
->host
->ioaddr
+ SYSKT_CHIP_REV
);
386 dev_info(&slot
->chip
->pdev
->dev
, "SysKonnect CardBus2SDIO, "
387 "board rev %d.%d, chip rev %d.%d\n",
388 board_rev
>> 4, board_rev
& 0xf,
389 chip_rev
>> 4, chip_rev
& 0xf);
390 if (chip_rev
>= 0x20)
391 slot
->host
->quirks
|= SDHCI_QUIRK_FORCE_DMA
;
393 writeb(SYSKT_POWER_330
, slot
->host
->ioaddr
+ SYSKT_POWER_DATA
);
394 writeb(SYSKT_POWER_START
, slot
->host
->ioaddr
+ SYSKT_POWER_CMD
);
396 tm
= 10; /* Wait max 1 ms */
398 ps
= readw(slot
->host
->ioaddr
+ SYSKT_POWER_STATUS
);
399 if (ps
& SYSKT_POWER_STATUS_OK
)
404 dev_err(&slot
->chip
->pdev
->dev
,
405 "power regulator never stabilized");
406 writeb(0, slot
->host
->ioaddr
+ SYSKT_POWER_CMD
);
413 static const struct sdhci_pci_fixes sdhci_syskt
= {
414 .quirks
= SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER
,
415 .probe
= syskt_probe
,
416 .probe_slot
= syskt_probe_slot
,
419 static int via_probe(struct sdhci_pci_chip
*chip
)
421 if (chip
->pdev
->revision
== 0x10)
422 chip
->quirks
|= SDHCI_QUIRK_DELAY_AFTER_POWER
;
427 static const struct sdhci_pci_fixes sdhci_via
= {
431 static const struct pci_device_id pci_ids
[] __devinitdata
= {
433 .vendor
= PCI_VENDOR_ID_RICOH
,
434 .device
= PCI_DEVICE_ID_RICOH_R5C822
,
435 .subvendor
= PCI_ANY_ID
,
436 .subdevice
= PCI_ANY_ID
,
437 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh
,
441 .vendor
= PCI_VENDOR_ID_RICOH
,
443 .subvendor
= PCI_ANY_ID
,
444 .subdevice
= PCI_ANY_ID
,
445 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh_mmc
,
449 .vendor
= PCI_VENDOR_ID_RICOH
,
451 .subvendor
= PCI_ANY_ID
,
452 .subdevice
= PCI_ANY_ID
,
453 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh_mmc
,
457 .vendor
= PCI_VENDOR_ID_ENE
,
458 .device
= PCI_DEVICE_ID_ENE_CB712_SD
,
459 .subvendor
= PCI_ANY_ID
,
460 .subdevice
= PCI_ANY_ID
,
461 .driver_data
= (kernel_ulong_t
)&sdhci_ene_712
,
465 .vendor
= PCI_VENDOR_ID_ENE
,
466 .device
= PCI_DEVICE_ID_ENE_CB712_SD_2
,
467 .subvendor
= PCI_ANY_ID
,
468 .subdevice
= PCI_ANY_ID
,
469 .driver_data
= (kernel_ulong_t
)&sdhci_ene_712
,
473 .vendor
= PCI_VENDOR_ID_ENE
,
474 .device
= PCI_DEVICE_ID_ENE_CB714_SD
,
475 .subvendor
= PCI_ANY_ID
,
476 .subdevice
= PCI_ANY_ID
,
477 .driver_data
= (kernel_ulong_t
)&sdhci_ene_714
,
481 .vendor
= PCI_VENDOR_ID_ENE
,
482 .device
= PCI_DEVICE_ID_ENE_CB714_SD_2
,
483 .subvendor
= PCI_ANY_ID
,
484 .subdevice
= PCI_ANY_ID
,
485 .driver_data
= (kernel_ulong_t
)&sdhci_ene_714
,
489 .vendor
= PCI_VENDOR_ID_MARVELL
,
490 .device
= PCI_DEVICE_ID_MARVELL_88ALP01_SD
,
491 .subvendor
= PCI_ANY_ID
,
492 .subdevice
= PCI_ANY_ID
,
493 .driver_data
= (kernel_ulong_t
)&sdhci_cafe
,
497 .vendor
= PCI_VENDOR_ID_JMICRON
,
498 .device
= PCI_DEVICE_ID_JMICRON_JMB38X_SD
,
499 .subvendor
= PCI_ANY_ID
,
500 .subdevice
= PCI_ANY_ID
,
501 .driver_data
= (kernel_ulong_t
)&sdhci_jmicron
,
505 .vendor
= PCI_VENDOR_ID_JMICRON
,
506 .device
= PCI_DEVICE_ID_JMICRON_JMB38X_MMC
,
507 .subvendor
= PCI_ANY_ID
,
508 .subdevice
= PCI_ANY_ID
,
509 .driver_data
= (kernel_ulong_t
)&sdhci_jmicron
,
513 .vendor
= PCI_VENDOR_ID_SYSKONNECT
,
515 .subvendor
= PCI_ANY_ID
,
516 .subdevice
= PCI_ANY_ID
,
517 .driver_data
= (kernel_ulong_t
)&sdhci_syskt
,
521 .vendor
= PCI_VENDOR_ID_VIA
,
523 .subvendor
= PCI_ANY_ID
,
524 .subdevice
= PCI_ANY_ID
,
525 .driver_data
= (kernel_ulong_t
)&sdhci_via
,
529 .vendor
= PCI_VENDOR_ID_INTEL
,
530 .device
= PCI_DEVICE_ID_INTEL_MRST_SD0
,
531 .subvendor
= PCI_ANY_ID
,
532 .subdevice
= PCI_ANY_ID
,
533 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mrst_hc0
,
537 .vendor
= PCI_VENDOR_ID_INTEL
,
538 .device
= PCI_DEVICE_ID_INTEL_MRST_SD1
,
539 .subvendor
= PCI_ANY_ID
,
540 .subdevice
= PCI_ANY_ID
,
541 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mrst_hc1
,
545 .vendor
= PCI_VENDOR_ID_INTEL
,
546 .device
= PCI_DEVICE_ID_INTEL_MFD_SD
,
547 .subvendor
= PCI_ANY_ID
,
548 .subdevice
= PCI_ANY_ID
,
549 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_sd
,
553 .vendor
= PCI_VENDOR_ID_INTEL
,
554 .device
= PCI_DEVICE_ID_INTEL_MFD_SDIO1
,
555 .subvendor
= PCI_ANY_ID
,
556 .subdevice
= PCI_ANY_ID
,
557 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_emmc_sdio
,
561 .vendor
= PCI_VENDOR_ID_INTEL
,
562 .device
= PCI_DEVICE_ID_INTEL_MFD_SDIO2
,
563 .subvendor
= PCI_ANY_ID
,
564 .subdevice
= PCI_ANY_ID
,
565 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_emmc_sdio
,
569 .vendor
= PCI_VENDOR_ID_INTEL
,
570 .device
= PCI_DEVICE_ID_INTEL_MFD_EMMC0
,
571 .subvendor
= PCI_ANY_ID
,
572 .subdevice
= PCI_ANY_ID
,
573 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_emmc_sdio
,
577 .vendor
= PCI_VENDOR_ID_INTEL
,
578 .device
= PCI_DEVICE_ID_INTEL_MFD_EMMC1
,
579 .subvendor
= PCI_ANY_ID
,
580 .subdevice
= PCI_ANY_ID
,
581 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_emmc_sdio
,
584 { /* Generic SD host controller */
585 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI
<< 8), 0xFFFF00)
588 { /* end: all zeroes */ },
591 MODULE_DEVICE_TABLE(pci
, pci_ids
);
593 /*****************************************************************************\
595 * SDHCI core callbacks *
597 \*****************************************************************************/
599 static int sdhci_pci_enable_dma(struct sdhci_host
*host
)
601 struct sdhci_pci_slot
*slot
;
602 struct pci_dev
*pdev
;
605 slot
= sdhci_priv(host
);
606 pdev
= slot
->chip
->pdev
;
608 if (((pdev
->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI
<< 8)) &&
609 ((pdev
->class & 0x0000FF) != PCI_SDHCI_IFDMA
) &&
610 (host
->flags
& SDHCI_USE_SDMA
)) {
611 dev_warn(&pdev
->dev
, "Will use DMA mode even though HW "
612 "doesn't fully claim to support it.\n");
615 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
619 pci_set_master(pdev
);
624 static struct sdhci_ops sdhci_pci_ops
= {
625 .enable_dma
= sdhci_pci_enable_dma
,
628 /*****************************************************************************\
632 \*****************************************************************************/
636 static int sdhci_pci_suspend (struct pci_dev
*pdev
, pm_message_t state
)
638 struct sdhci_pci_chip
*chip
;
639 struct sdhci_pci_slot
*slot
;
640 mmc_pm_flag_t pm_flags
= 0;
643 chip
= pci_get_drvdata(pdev
);
647 for (i
= 0;i
< chip
->num_slots
;i
++) {
648 slot
= chip
->slots
[i
];
652 ret
= sdhci_suspend_host(slot
->host
, state
);
656 sdhci_resume_host(chip
->slots
[i
]->host
);
660 pm_flags
|= slot
->host
->mmc
->pm_flags
;
663 if (chip
->fixes
&& chip
->fixes
->suspend
) {
664 ret
= chip
->fixes
->suspend(chip
, state
);
666 for (i
= chip
->num_slots
- 1;i
>= 0;i
--)
667 sdhci_resume_host(chip
->slots
[i
]->host
);
672 pci_save_state(pdev
);
673 if (pm_flags
& MMC_PM_KEEP_POWER
) {
674 if (pm_flags
& MMC_PM_WAKE_SDIO_IRQ
)
675 pci_enable_wake(pdev
, PCI_D3hot
, 1);
676 pci_set_power_state(pdev
, PCI_D3hot
);
678 pci_enable_wake(pdev
, pci_choose_state(pdev
, state
), 0);
679 pci_disable_device(pdev
);
680 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
686 static int sdhci_pci_resume (struct pci_dev
*pdev
)
688 struct sdhci_pci_chip
*chip
;
689 struct sdhci_pci_slot
*slot
;
692 chip
= pci_get_drvdata(pdev
);
696 pci_set_power_state(pdev
, PCI_D0
);
697 pci_restore_state(pdev
);
698 ret
= pci_enable_device(pdev
);
702 if (chip
->fixes
&& chip
->fixes
->resume
) {
703 ret
= chip
->fixes
->resume(chip
);
708 for (i
= 0;i
< chip
->num_slots
;i
++) {
709 slot
= chip
->slots
[i
];
713 ret
= sdhci_resume_host(slot
->host
);
721 #else /* CONFIG_PM */
723 #define sdhci_pci_suspend NULL
724 #define sdhci_pci_resume NULL
726 #endif /* CONFIG_PM */
728 /*****************************************************************************\
730 * Device probing/removal *
732 \*****************************************************************************/
734 static struct sdhci_pci_slot
* __devinit
sdhci_pci_probe_slot(
735 struct pci_dev
*pdev
, struct sdhci_pci_chip
*chip
, int bar
)
737 struct sdhci_pci_slot
*slot
;
738 struct sdhci_host
*host
;
740 resource_size_t addr
;
744 if (!(pci_resource_flags(pdev
, bar
) & IORESOURCE_MEM
)) {
745 dev_err(&pdev
->dev
, "BAR %d is not iomem. Aborting.\n", bar
);
746 return ERR_PTR(-ENODEV
);
749 if (pci_resource_len(pdev
, bar
) != 0x100) {
750 dev_err(&pdev
->dev
, "Invalid iomem size. You may "
751 "experience problems.\n");
754 if ((pdev
->class & 0x0000FF) == PCI_SDHCI_IFVENDOR
) {
755 dev_err(&pdev
->dev
, "Vendor specific interface. Aborting.\n");
756 return ERR_PTR(-ENODEV
);
759 if ((pdev
->class & 0x0000FF) > PCI_SDHCI_IFVENDOR
) {
760 dev_err(&pdev
->dev
, "Unknown interface. Aborting.\n");
761 return ERR_PTR(-ENODEV
);
764 host
= sdhci_alloc_host(&pdev
->dev
, sizeof(struct sdhci_pci_slot
));
766 dev_err(&pdev
->dev
, "cannot allocate host\n");
767 return ERR_CAST(host
);
770 slot
= sdhci_priv(host
);
776 host
->hw_name
= "PCI";
777 host
->ops
= &sdhci_pci_ops
;
778 host
->quirks
= chip
->quirks
;
780 host
->irq
= pdev
->irq
;
782 ret
= pci_request_region(pdev
, bar
, mmc_hostname(host
->mmc
));
784 dev_err(&pdev
->dev
, "cannot request region\n");
788 addr
= pci_resource_start(pdev
, bar
);
789 host
->ioaddr
= pci_ioremap_bar(pdev
, bar
);
791 dev_err(&pdev
->dev
, "failed to remap registers\n");
795 if (chip
->fixes
&& chip
->fixes
->probe_slot
) {
796 ret
= chip
->fixes
->probe_slot(slot
);
801 host
->mmc
->pm_caps
= MMC_PM_KEEP_POWER
| MMC_PM_WAKE_SDIO_IRQ
;
803 ret
= sdhci_add_host(host
);
810 if (chip
->fixes
&& chip
->fixes
->remove_slot
)
811 chip
->fixes
->remove_slot(slot
, 0);
814 iounmap(host
->ioaddr
);
817 pci_release_region(pdev
, bar
);
820 sdhci_free_host(host
);
825 static void sdhci_pci_remove_slot(struct sdhci_pci_slot
*slot
)
831 scratch
= readl(slot
->host
->ioaddr
+ SDHCI_INT_STATUS
);
832 if (scratch
== (u32
)-1)
835 sdhci_remove_host(slot
->host
, dead
);
837 if (slot
->chip
->fixes
&& slot
->chip
->fixes
->remove_slot
)
838 slot
->chip
->fixes
->remove_slot(slot
, dead
);
840 pci_release_region(slot
->chip
->pdev
, slot
->pci_bar
);
842 sdhci_free_host(slot
->host
);
845 static int __devinit
sdhci_pci_probe(struct pci_dev
*pdev
,
846 const struct pci_device_id
*ent
)
848 struct sdhci_pci_chip
*chip
;
849 struct sdhci_pci_slot
*slot
;
851 u8 slots
, rev
, first_bar
;
854 BUG_ON(pdev
== NULL
);
857 pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &rev
);
859 dev_info(&pdev
->dev
, "SDHCI controller found [%04x:%04x] (rev %x)\n",
860 (int)pdev
->vendor
, (int)pdev
->device
, (int)rev
);
862 ret
= pci_read_config_byte(pdev
, PCI_SLOT_INFO
, &slots
);
866 slots
= PCI_SLOT_INFO_SLOTS(slots
) + 1;
867 dev_dbg(&pdev
->dev
, "found %d slot(s)\n", slots
);
871 BUG_ON(slots
> MAX_SLOTS
);
873 ret
= pci_read_config_byte(pdev
, PCI_SLOT_INFO
, &first_bar
);
877 first_bar
&= PCI_SLOT_INFO_FIRST_BAR_MASK
;
880 dev_err(&pdev
->dev
, "Invalid first BAR. Aborting.\n");
884 ret
= pci_enable_device(pdev
);
888 chip
= kzalloc(sizeof(struct sdhci_pci_chip
), GFP_KERNEL
);
895 chip
->fixes
= (const struct sdhci_pci_fixes
*)ent
->driver_data
;
897 chip
->quirks
= chip
->fixes
->quirks
;
898 chip
->num_slots
= slots
;
900 pci_set_drvdata(pdev
, chip
);
902 if (chip
->fixes
&& chip
->fixes
->probe
) {
903 ret
= chip
->fixes
->probe(chip
);
908 slots
= chip
->num_slots
; /* Quirk may have changed this */
910 for (i
= 0;i
< slots
;i
++) {
911 slot
= sdhci_pci_probe_slot(pdev
, chip
, first_bar
+ i
);
914 sdhci_pci_remove_slot(chip
->slots
[i
]);
919 chip
->slots
[i
] = slot
;
925 pci_set_drvdata(pdev
, NULL
);
929 pci_disable_device(pdev
);
933 static void __devexit
sdhci_pci_remove(struct pci_dev
*pdev
)
936 struct sdhci_pci_chip
*chip
;
938 chip
= pci_get_drvdata(pdev
);
941 for (i
= 0;i
< chip
->num_slots
; i
++)
942 sdhci_pci_remove_slot(chip
->slots
[i
]);
944 pci_set_drvdata(pdev
, NULL
);
948 pci_disable_device(pdev
);
951 static struct pci_driver sdhci_driver
= {
954 .probe
= sdhci_pci_probe
,
955 .remove
= __devexit_p(sdhci_pci_remove
),
956 .suspend
= sdhci_pci_suspend
,
957 .resume
= sdhci_pci_resume
,
960 /*****************************************************************************\
964 \*****************************************************************************/
966 static int __init
sdhci_drv_init(void)
968 return pci_register_driver(&sdhci_driver
);
971 static void __exit
sdhci_drv_exit(void)
973 pci_unregister_driver(&sdhci_driver
);
976 module_init(sdhci_drv_init
);
977 module_exit(sdhci_drv_exit
);
979 MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
980 MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
981 MODULE_LICENSE("GPL");