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>
21 #include <linux/mmc/host.h>
22 #include <linux/scatterlist.h>
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
41 struct sdhci_pci_chip
;
42 struct sdhci_pci_slot
;
44 struct sdhci_pci_fixes
{
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
*,
54 int (*resume
) (struct sdhci_pci_chip
*);
57 struct sdhci_pci_slot
{
58 struct sdhci_pci_chip
*chip
;
59 struct sdhci_host
*host
;
64 struct sdhci_pci_chip
{
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 /*****************************************************************************\
77 * Hardware specific quirk handling *
79 \*****************************************************************************/
81 static int ricoh_probe(struct sdhci_pci_chip
*chip
)
83 if (chip
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_SAMSUNG
||
84 chip
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_SONY
)
85 chip
->quirks
|= SDHCI_QUIRK_NO_CARD_NO_RESET
;
89 static int ricoh_mmc_probe_slot(struct sdhci_pci_slot
*slot
)
92 ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT
)
93 & SDHCI_TIMEOUT_CLK_MASK
) |
95 ((0x21 << SDHCI_CLOCK_BASE_SHIFT
)
96 & SDHCI_CLOCK_BASE_MASK
) |
98 SDHCI_TIMEOUT_CLK_UNIT
|
104 static int ricoh_mmc_resume(struct sdhci_pci_chip
*chip
)
106 /* Apply a delay to allow controller to settle */
107 /* Otherwise it becomes confused if card state changed
113 static const struct sdhci_pci_fixes sdhci_ricoh
= {
114 .probe
= ricoh_probe
,
115 .quirks
= SDHCI_QUIRK_32BIT_DMA_ADDR
|
116 SDHCI_QUIRK_FORCE_DMA
|
117 SDHCI_QUIRK_CLOCK_BEFORE_RESET
,
120 static const struct sdhci_pci_fixes sdhci_ricoh_mmc
= {
121 .probe_slot
= ricoh_mmc_probe_slot
,
122 .resume
= ricoh_mmc_resume
,
123 .quirks
= SDHCI_QUIRK_32BIT_DMA_ADDR
|
124 SDHCI_QUIRK_CLOCK_BEFORE_RESET
|
125 SDHCI_QUIRK_NO_CARD_NO_RESET
|
126 SDHCI_QUIRK_MISSING_CAPS
129 static const struct sdhci_pci_fixes sdhci_ene_712
= {
130 .quirks
= SDHCI_QUIRK_SINGLE_POWER_WRITE
|
131 SDHCI_QUIRK_BROKEN_DMA
,
134 static const struct sdhci_pci_fixes sdhci_ene_714
= {
135 .quirks
= SDHCI_QUIRK_SINGLE_POWER_WRITE
|
136 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS
|
137 SDHCI_QUIRK_BROKEN_DMA
,
140 static const struct sdhci_pci_fixes sdhci_cafe
= {
141 .quirks
= SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER
|
142 SDHCI_QUIRK_NO_BUSY_IRQ
|
143 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL
,
147 * ADMA operation is disabled for Moorestown platform due to
150 static int mrst_hc_probe(struct sdhci_pci_chip
*chip
)
153 * slots number is fixed here for MRST as SDIO3/5 are never used and
154 * have hardware bugs.
160 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0
= {
161 .quirks
= SDHCI_QUIRK_BROKEN_ADMA
| SDHCI_QUIRK_NO_HISPD_BIT
,
164 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2
= {
165 .quirks
= SDHCI_QUIRK_BROKEN_ADMA
| SDHCI_QUIRK_NO_HISPD_BIT
,
166 .probe
= mrst_hc_probe
,
169 static const struct sdhci_pci_fixes sdhci_intel_mfd_sd
= {
170 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
173 static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc_sdio
= {
174 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
177 /* O2Micro extra registers */
178 #define O2_SD_LOCK_WP 0xD3
179 #define O2_SD_MULTI_VCC3V 0xEE
180 #define O2_SD_CLKREQ 0xEC
181 #define O2_SD_CAPS 0xE0
182 #define O2_SD_ADMA1 0xE2
183 #define O2_SD_ADMA2 0xE7
184 #define O2_SD_INF_MOD 0xF1
186 static int o2_probe(struct sdhci_pci_chip
*chip
)
191 switch (chip
->pdev
->device
) {
192 case PCI_DEVICE_ID_O2_8220
:
193 case PCI_DEVICE_ID_O2_8221
:
194 case PCI_DEVICE_ID_O2_8320
:
195 case PCI_DEVICE_ID_O2_8321
:
196 /* This extra setup is required due to broken ADMA. */
197 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, &scratch
);
201 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
203 /* Set Multi 3 to VCC3V# */
204 pci_write_config_byte(chip
->pdev
, O2_SD_MULTI_VCC3V
, 0x08);
206 /* Disable CLK_REQ# support after media DET */
207 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_CLKREQ
, &scratch
);
211 pci_write_config_byte(chip
->pdev
, O2_SD_CLKREQ
, scratch
);
213 /* Choose capabilities, enable SDMA. We have to write 0x01
214 * to the capabilities register first to unlock it.
216 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_CAPS
, &scratch
);
220 pci_write_config_byte(chip
->pdev
, O2_SD_CAPS
, scratch
);
221 pci_write_config_byte(chip
->pdev
, O2_SD_CAPS
, 0x73);
223 /* Disable ADMA1/2 */
224 pci_write_config_byte(chip
->pdev
, O2_SD_ADMA1
, 0x39);
225 pci_write_config_byte(chip
->pdev
, O2_SD_ADMA2
, 0x08);
227 /* Disable the infinite transfer mode */
228 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_INF_MOD
, &scratch
);
232 pci_write_config_byte(chip
->pdev
, O2_SD_INF_MOD
, scratch
);
235 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, &scratch
);
239 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
245 static int jmicron_pmos(struct sdhci_pci_chip
*chip
, int on
)
250 ret
= pci_read_config_byte(chip
->pdev
, 0xAE, &scratch
);
255 * Turn PMOS on [bit 0], set over current detection to 2.4 V
256 * [bit 1:2] and enable over current debouncing [bit 6].
263 ret
= pci_write_config_byte(chip
->pdev
, 0xAE, scratch
);
270 static int jmicron_probe(struct sdhci_pci_chip
*chip
)
275 if (chip
->pdev
->revision
== 0) {
276 chip
->quirks
|= SDHCI_QUIRK_32BIT_DMA_ADDR
|
277 SDHCI_QUIRK_32BIT_DMA_SIZE
|
278 SDHCI_QUIRK_32BIT_ADMA_SIZE
|
279 SDHCI_QUIRK_RESET_AFTER_REQUEST
|
280 SDHCI_QUIRK_BROKEN_SMALL_PIO
;
284 * JMicron chips can have two interfaces to the same hardware
285 * in order to work around limitations in Microsoft's driver.
286 * We need to make sure we only bind to one of them.
288 * This code assumes two things:
290 * 1. The PCI code adds subfunctions in order.
292 * 2. The MMC interface has a lower subfunction number
293 * than the SD interface.
295 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_SD
)
296 mmcdev
= PCI_DEVICE_ID_JMICRON_JMB38X_MMC
;
297 else if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_SD
)
298 mmcdev
= PCI_DEVICE_ID_JMICRON_JMB388_ESD
;
301 struct pci_dev
*sd_dev
;
304 while ((sd_dev
= pci_get_device(PCI_VENDOR_ID_JMICRON
,
305 mmcdev
, sd_dev
)) != NULL
) {
306 if ((PCI_SLOT(chip
->pdev
->devfn
) ==
307 PCI_SLOT(sd_dev
->devfn
)) &&
308 (chip
->pdev
->bus
== sd_dev
->bus
))
314 dev_info(&chip
->pdev
->dev
, "Refusing to bind to "
315 "secondary interface.\n");
321 * JMicron chips need a bit of a nudge to enable the power
324 ret
= jmicron_pmos(chip
, 1);
326 dev_err(&chip
->pdev
->dev
, "Failure enabling card power\n");
330 /* quirk for unsable RO-detection on JM388 chips */
331 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_SD
||
332 chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
)
333 chip
->quirks
|= SDHCI_QUIRK_UNSTABLE_RO_DETECT
;
338 static void jmicron_enable_mmc(struct sdhci_host
*host
, int on
)
342 scratch
= readb(host
->ioaddr
+ 0xC0);
349 writeb(scratch
, host
->ioaddr
+ 0xC0);
352 static int jmicron_probe_slot(struct sdhci_pci_slot
*slot
)
354 if (slot
->chip
->pdev
->revision
== 0) {
357 version
= readl(slot
->host
->ioaddr
+ SDHCI_HOST_VERSION
);
358 version
= (version
& SDHCI_VENDOR_VER_MASK
) >>
359 SDHCI_VENDOR_VER_SHIFT
;
362 * Older versions of the chip have lots of nasty glitches
363 * in the ADMA engine. It's best just to avoid it
367 slot
->host
->quirks
|= SDHCI_QUIRK_BROKEN_ADMA
;
370 /* JM388 MMC doesn't support 1.8V while SD supports it */
371 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
) {
372 slot
->host
->ocr_avail_sd
= MMC_VDD_32_33
| MMC_VDD_33_34
|
373 MMC_VDD_29_30
| MMC_VDD_30_31
|
374 MMC_VDD_165_195
; /* allow 1.8V */
375 slot
->host
->ocr_avail_mmc
= MMC_VDD_32_33
| MMC_VDD_33_34
|
376 MMC_VDD_29_30
| MMC_VDD_30_31
; /* no 1.8V for MMC */
380 * The secondary interface requires a bit set to get the
383 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
384 slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
)
385 jmicron_enable_mmc(slot
->host
, 1);
387 slot
->host
->mmc
->caps
|= MMC_CAP_BUS_WIDTH_TEST
;
392 static void jmicron_remove_slot(struct sdhci_pci_slot
*slot
, int dead
)
397 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
398 slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
)
399 jmicron_enable_mmc(slot
->host
, 0);
402 static int jmicron_suspend(struct sdhci_pci_chip
*chip
, pm_message_t state
)
406 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
407 chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
) {
408 for (i
= 0; i
< chip
->num_slots
; i
++)
409 jmicron_enable_mmc(chip
->slots
[i
]->host
, 0);
415 static int jmicron_resume(struct sdhci_pci_chip
*chip
)
419 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
420 chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
) {
421 for (i
= 0; i
< chip
->num_slots
; i
++)
422 jmicron_enable_mmc(chip
->slots
[i
]->host
, 1);
425 ret
= jmicron_pmos(chip
, 1);
427 dev_err(&chip
->pdev
->dev
, "Failure enabling card power\n");
434 static const struct sdhci_pci_fixes sdhci_o2
= {
438 static const struct sdhci_pci_fixes sdhci_jmicron
= {
439 .probe
= jmicron_probe
,
441 .probe_slot
= jmicron_probe_slot
,
442 .remove_slot
= jmicron_remove_slot
,
444 .suspend
= jmicron_suspend
,
445 .resume
= jmicron_resume
,
448 /* SysKonnect CardBus2SDIO extra registers */
449 #define SYSKT_CTRL 0x200
450 #define SYSKT_RDFIFO_STAT 0x204
451 #define SYSKT_WRFIFO_STAT 0x208
452 #define SYSKT_POWER_DATA 0x20c
453 #define SYSKT_POWER_330 0xef
454 #define SYSKT_POWER_300 0xf8
455 #define SYSKT_POWER_184 0xcc
456 #define SYSKT_POWER_CMD 0x20d
457 #define SYSKT_POWER_START (1 << 7)
458 #define SYSKT_POWER_STATUS 0x20e
459 #define SYSKT_POWER_STATUS_OK (1 << 0)
460 #define SYSKT_BOARD_REV 0x210
461 #define SYSKT_CHIP_REV 0x211
462 #define SYSKT_CONF_DATA 0x212
463 #define SYSKT_CONF_DATA_1V8 (1 << 2)
464 #define SYSKT_CONF_DATA_2V5 (1 << 1)
465 #define SYSKT_CONF_DATA_3V3 (1 << 0)
467 static int syskt_probe(struct sdhci_pci_chip
*chip
)
469 if ((chip
->pdev
->class & 0x0000FF) == PCI_SDHCI_IFVENDOR
) {
470 chip
->pdev
->class &= ~0x0000FF;
471 chip
->pdev
->class |= PCI_SDHCI_IFDMA
;
476 static int syskt_probe_slot(struct sdhci_pci_slot
*slot
)
480 u8 board_rev
= readb(slot
->host
->ioaddr
+ SYSKT_BOARD_REV
);
481 u8 chip_rev
= readb(slot
->host
->ioaddr
+ SYSKT_CHIP_REV
);
482 dev_info(&slot
->chip
->pdev
->dev
, "SysKonnect CardBus2SDIO, "
483 "board rev %d.%d, chip rev %d.%d\n",
484 board_rev
>> 4, board_rev
& 0xf,
485 chip_rev
>> 4, chip_rev
& 0xf);
486 if (chip_rev
>= 0x20)
487 slot
->host
->quirks
|= SDHCI_QUIRK_FORCE_DMA
;
489 writeb(SYSKT_POWER_330
, slot
->host
->ioaddr
+ SYSKT_POWER_DATA
);
490 writeb(SYSKT_POWER_START
, slot
->host
->ioaddr
+ SYSKT_POWER_CMD
);
492 tm
= 10; /* Wait max 1 ms */
494 ps
= readw(slot
->host
->ioaddr
+ SYSKT_POWER_STATUS
);
495 if (ps
& SYSKT_POWER_STATUS_OK
)
500 dev_err(&slot
->chip
->pdev
->dev
,
501 "power regulator never stabilized");
502 writeb(0, slot
->host
->ioaddr
+ SYSKT_POWER_CMD
);
509 static const struct sdhci_pci_fixes sdhci_syskt
= {
510 .quirks
= SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER
,
511 .probe
= syskt_probe
,
512 .probe_slot
= syskt_probe_slot
,
515 static int via_probe(struct sdhci_pci_chip
*chip
)
517 if (chip
->pdev
->revision
== 0x10)
518 chip
->quirks
|= SDHCI_QUIRK_DELAY_AFTER_POWER
;
523 static const struct sdhci_pci_fixes sdhci_via
= {
527 static const struct pci_device_id pci_ids
[] __devinitdata
= {
529 .vendor
= PCI_VENDOR_ID_RICOH
,
530 .device
= PCI_DEVICE_ID_RICOH_R5C822
,
531 .subvendor
= PCI_ANY_ID
,
532 .subdevice
= PCI_ANY_ID
,
533 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh
,
537 .vendor
= PCI_VENDOR_ID_RICOH
,
539 .subvendor
= PCI_ANY_ID
,
540 .subdevice
= PCI_ANY_ID
,
541 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh_mmc
,
545 .vendor
= PCI_VENDOR_ID_RICOH
,
547 .subvendor
= PCI_ANY_ID
,
548 .subdevice
= PCI_ANY_ID
,
549 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh_mmc
,
553 .vendor
= PCI_VENDOR_ID_RICOH
,
555 .subvendor
= PCI_ANY_ID
,
556 .subdevice
= PCI_ANY_ID
,
557 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh_mmc
,
561 .vendor
= PCI_VENDOR_ID_ENE
,
562 .device
= PCI_DEVICE_ID_ENE_CB712_SD
,
563 .subvendor
= PCI_ANY_ID
,
564 .subdevice
= PCI_ANY_ID
,
565 .driver_data
= (kernel_ulong_t
)&sdhci_ene_712
,
569 .vendor
= PCI_VENDOR_ID_ENE
,
570 .device
= PCI_DEVICE_ID_ENE_CB712_SD_2
,
571 .subvendor
= PCI_ANY_ID
,
572 .subdevice
= PCI_ANY_ID
,
573 .driver_data
= (kernel_ulong_t
)&sdhci_ene_712
,
577 .vendor
= PCI_VENDOR_ID_ENE
,
578 .device
= PCI_DEVICE_ID_ENE_CB714_SD
,
579 .subvendor
= PCI_ANY_ID
,
580 .subdevice
= PCI_ANY_ID
,
581 .driver_data
= (kernel_ulong_t
)&sdhci_ene_714
,
585 .vendor
= PCI_VENDOR_ID_ENE
,
586 .device
= PCI_DEVICE_ID_ENE_CB714_SD_2
,
587 .subvendor
= PCI_ANY_ID
,
588 .subdevice
= PCI_ANY_ID
,
589 .driver_data
= (kernel_ulong_t
)&sdhci_ene_714
,
593 .vendor
= PCI_VENDOR_ID_MARVELL
,
594 .device
= PCI_DEVICE_ID_MARVELL_88ALP01_SD
,
595 .subvendor
= PCI_ANY_ID
,
596 .subdevice
= PCI_ANY_ID
,
597 .driver_data
= (kernel_ulong_t
)&sdhci_cafe
,
601 .vendor
= PCI_VENDOR_ID_JMICRON
,
602 .device
= PCI_DEVICE_ID_JMICRON_JMB38X_SD
,
603 .subvendor
= PCI_ANY_ID
,
604 .subdevice
= PCI_ANY_ID
,
605 .driver_data
= (kernel_ulong_t
)&sdhci_jmicron
,
609 .vendor
= PCI_VENDOR_ID_JMICRON
,
610 .device
= PCI_DEVICE_ID_JMICRON_JMB38X_MMC
,
611 .subvendor
= PCI_ANY_ID
,
612 .subdevice
= PCI_ANY_ID
,
613 .driver_data
= (kernel_ulong_t
)&sdhci_jmicron
,
617 .vendor
= PCI_VENDOR_ID_JMICRON
,
618 .device
= PCI_DEVICE_ID_JMICRON_JMB388_SD
,
619 .subvendor
= PCI_ANY_ID
,
620 .subdevice
= PCI_ANY_ID
,
621 .driver_data
= (kernel_ulong_t
)&sdhci_jmicron
,
625 .vendor
= PCI_VENDOR_ID_JMICRON
,
626 .device
= PCI_DEVICE_ID_JMICRON_JMB388_ESD
,
627 .subvendor
= PCI_ANY_ID
,
628 .subdevice
= PCI_ANY_ID
,
629 .driver_data
= (kernel_ulong_t
)&sdhci_jmicron
,
633 .vendor
= PCI_VENDOR_ID_SYSKONNECT
,
635 .subvendor
= PCI_ANY_ID
,
636 .subdevice
= PCI_ANY_ID
,
637 .driver_data
= (kernel_ulong_t
)&sdhci_syskt
,
641 .vendor
= PCI_VENDOR_ID_VIA
,
643 .subvendor
= PCI_ANY_ID
,
644 .subdevice
= PCI_ANY_ID
,
645 .driver_data
= (kernel_ulong_t
)&sdhci_via
,
649 .vendor
= PCI_VENDOR_ID_INTEL
,
650 .device
= PCI_DEVICE_ID_INTEL_MRST_SD0
,
651 .subvendor
= PCI_ANY_ID
,
652 .subdevice
= PCI_ANY_ID
,
653 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mrst_hc0
,
657 .vendor
= PCI_VENDOR_ID_INTEL
,
658 .device
= PCI_DEVICE_ID_INTEL_MRST_SD1
,
659 .subvendor
= PCI_ANY_ID
,
660 .subdevice
= PCI_ANY_ID
,
661 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mrst_hc1_hc2
,
665 .vendor
= PCI_VENDOR_ID_INTEL
,
666 .device
= PCI_DEVICE_ID_INTEL_MRST_SD2
,
667 .subvendor
= PCI_ANY_ID
,
668 .subdevice
= PCI_ANY_ID
,
669 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mrst_hc1_hc2
,
673 .vendor
= PCI_VENDOR_ID_INTEL
,
674 .device
= PCI_DEVICE_ID_INTEL_MFD_SD
,
675 .subvendor
= PCI_ANY_ID
,
676 .subdevice
= PCI_ANY_ID
,
677 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_sd
,
681 .vendor
= PCI_VENDOR_ID_INTEL
,
682 .device
= PCI_DEVICE_ID_INTEL_MFD_SDIO1
,
683 .subvendor
= PCI_ANY_ID
,
684 .subdevice
= PCI_ANY_ID
,
685 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_emmc_sdio
,
689 .vendor
= PCI_VENDOR_ID_INTEL
,
690 .device
= PCI_DEVICE_ID_INTEL_MFD_SDIO2
,
691 .subvendor
= PCI_ANY_ID
,
692 .subdevice
= PCI_ANY_ID
,
693 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_emmc_sdio
,
697 .vendor
= PCI_VENDOR_ID_INTEL
,
698 .device
= PCI_DEVICE_ID_INTEL_MFD_EMMC0
,
699 .subvendor
= PCI_ANY_ID
,
700 .subdevice
= PCI_ANY_ID
,
701 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_emmc_sdio
,
705 .vendor
= PCI_VENDOR_ID_INTEL
,
706 .device
= PCI_DEVICE_ID_INTEL_MFD_EMMC1
,
707 .subvendor
= PCI_ANY_ID
,
708 .subdevice
= PCI_ANY_ID
,
709 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_emmc_sdio
,
713 .vendor
= PCI_VENDOR_ID_O2
,
714 .device
= PCI_DEVICE_ID_O2_8120
,
715 .subvendor
= PCI_ANY_ID
,
716 .subdevice
= PCI_ANY_ID
,
717 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
721 .vendor
= PCI_VENDOR_ID_O2
,
722 .device
= PCI_DEVICE_ID_O2_8220
,
723 .subvendor
= PCI_ANY_ID
,
724 .subdevice
= PCI_ANY_ID
,
725 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
729 .vendor
= PCI_VENDOR_ID_O2
,
730 .device
= PCI_DEVICE_ID_O2_8221
,
731 .subvendor
= PCI_ANY_ID
,
732 .subdevice
= PCI_ANY_ID
,
733 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
737 .vendor
= PCI_VENDOR_ID_O2
,
738 .device
= PCI_DEVICE_ID_O2_8320
,
739 .subvendor
= PCI_ANY_ID
,
740 .subdevice
= PCI_ANY_ID
,
741 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
745 .vendor
= PCI_VENDOR_ID_O2
,
746 .device
= PCI_DEVICE_ID_O2_8321
,
747 .subvendor
= PCI_ANY_ID
,
748 .subdevice
= PCI_ANY_ID
,
749 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
752 { /* Generic SD host controller */
753 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI
<< 8), 0xFFFF00)
756 { /* end: all zeroes */ },
759 MODULE_DEVICE_TABLE(pci
, pci_ids
);
761 /*****************************************************************************\
763 * SDHCI core callbacks *
765 \*****************************************************************************/
767 static int sdhci_pci_enable_dma(struct sdhci_host
*host
)
769 struct sdhci_pci_slot
*slot
;
770 struct pci_dev
*pdev
;
773 slot
= sdhci_priv(host
);
774 pdev
= slot
->chip
->pdev
;
776 if (((pdev
->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI
<< 8)) &&
777 ((pdev
->class & 0x0000FF) != PCI_SDHCI_IFDMA
) &&
778 (host
->flags
& SDHCI_USE_SDMA
)) {
779 dev_warn(&pdev
->dev
, "Will use DMA mode even though HW "
780 "doesn't fully claim to support it.\n");
783 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
787 pci_set_master(pdev
);
792 static struct sdhci_ops sdhci_pci_ops
= {
793 .enable_dma
= sdhci_pci_enable_dma
,
796 /*****************************************************************************\
800 \*****************************************************************************/
804 static int sdhci_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
806 struct sdhci_pci_chip
*chip
;
807 struct sdhci_pci_slot
*slot
;
808 mmc_pm_flag_t slot_pm_flags
;
809 mmc_pm_flag_t pm_flags
= 0;
812 chip
= pci_get_drvdata(pdev
);
816 for (i
= 0; i
< chip
->num_slots
; i
++) {
817 slot
= chip
->slots
[i
];
821 ret
= sdhci_suspend_host(slot
->host
, state
);
824 for (i
--; i
>= 0; i
--)
825 sdhci_resume_host(chip
->slots
[i
]->host
);
829 slot_pm_flags
= slot
->host
->mmc
->pm_flags
;
830 if (slot_pm_flags
& MMC_PM_WAKE_SDIO_IRQ
)
831 sdhci_enable_irq_wakeups(slot
->host
);
833 pm_flags
|= slot_pm_flags
;
836 if (chip
->fixes
&& chip
->fixes
->suspend
) {
837 ret
= chip
->fixes
->suspend(chip
, state
);
839 for (i
= chip
->num_slots
- 1; i
>= 0; i
--)
840 sdhci_resume_host(chip
->slots
[i
]->host
);
845 pci_save_state(pdev
);
846 if (pm_flags
& MMC_PM_KEEP_POWER
) {
847 if (pm_flags
& MMC_PM_WAKE_SDIO_IRQ
) {
848 pci_pme_active(pdev
, true);
849 pci_enable_wake(pdev
, PCI_D3hot
, 1);
851 pci_set_power_state(pdev
, PCI_D3hot
);
853 pci_enable_wake(pdev
, pci_choose_state(pdev
, state
), 0);
854 pci_disable_device(pdev
);
855 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
861 static int sdhci_pci_resume(struct pci_dev
*pdev
)
863 struct sdhci_pci_chip
*chip
;
864 struct sdhci_pci_slot
*slot
;
867 chip
= pci_get_drvdata(pdev
);
871 pci_set_power_state(pdev
, PCI_D0
);
872 pci_restore_state(pdev
);
873 ret
= pci_enable_device(pdev
);
877 if (chip
->fixes
&& chip
->fixes
->resume
) {
878 ret
= chip
->fixes
->resume(chip
);
883 for (i
= 0; i
< chip
->num_slots
; i
++) {
884 slot
= chip
->slots
[i
];
888 ret
= sdhci_resume_host(slot
->host
);
896 #else /* CONFIG_PM */
898 #define sdhci_pci_suspend NULL
899 #define sdhci_pci_resume NULL
901 #endif /* CONFIG_PM */
903 /*****************************************************************************\
905 * Device probing/removal *
907 \*****************************************************************************/
909 static struct sdhci_pci_slot
* __devinit
sdhci_pci_probe_slot(
910 struct pci_dev
*pdev
, struct sdhci_pci_chip
*chip
, int bar
)
912 struct sdhci_pci_slot
*slot
;
913 struct sdhci_host
*host
;
916 if (!(pci_resource_flags(pdev
, bar
) & IORESOURCE_MEM
)) {
917 dev_err(&pdev
->dev
, "BAR %d is not iomem. Aborting.\n", bar
);
918 return ERR_PTR(-ENODEV
);
921 if (pci_resource_len(pdev
, bar
) != 0x100) {
922 dev_err(&pdev
->dev
, "Invalid iomem size. You may "
923 "experience problems.\n");
926 if ((pdev
->class & 0x0000FF) == PCI_SDHCI_IFVENDOR
) {
927 dev_err(&pdev
->dev
, "Vendor specific interface. Aborting.\n");
928 return ERR_PTR(-ENODEV
);
931 if ((pdev
->class & 0x0000FF) > PCI_SDHCI_IFVENDOR
) {
932 dev_err(&pdev
->dev
, "Unknown interface. Aborting.\n");
933 return ERR_PTR(-ENODEV
);
936 host
= sdhci_alloc_host(&pdev
->dev
, sizeof(struct sdhci_pci_slot
));
938 dev_err(&pdev
->dev
, "cannot allocate host\n");
939 return ERR_CAST(host
);
942 slot
= sdhci_priv(host
);
948 host
->hw_name
= "PCI";
949 host
->ops
= &sdhci_pci_ops
;
950 host
->quirks
= chip
->quirks
;
952 host
->irq
= pdev
->irq
;
954 ret
= pci_request_region(pdev
, bar
, mmc_hostname(host
->mmc
));
956 dev_err(&pdev
->dev
, "cannot request region\n");
960 host
->ioaddr
= pci_ioremap_bar(pdev
, bar
);
962 dev_err(&pdev
->dev
, "failed to remap registers\n");
967 if (chip
->fixes
&& chip
->fixes
->probe_slot
) {
968 ret
= chip
->fixes
->probe_slot(slot
);
973 host
->mmc
->pm_caps
= MMC_PM_KEEP_POWER
| MMC_PM_WAKE_SDIO_IRQ
;
975 ret
= sdhci_add_host(host
);
982 if (chip
->fixes
&& chip
->fixes
->remove_slot
)
983 chip
->fixes
->remove_slot(slot
, 0);
986 iounmap(host
->ioaddr
);
989 pci_release_region(pdev
, bar
);
992 sdhci_free_host(host
);
997 static void sdhci_pci_remove_slot(struct sdhci_pci_slot
*slot
)
1003 scratch
= readl(slot
->host
->ioaddr
+ SDHCI_INT_STATUS
);
1004 if (scratch
== (u32
)-1)
1007 sdhci_remove_host(slot
->host
, dead
);
1009 if (slot
->chip
->fixes
&& slot
->chip
->fixes
->remove_slot
)
1010 slot
->chip
->fixes
->remove_slot(slot
, dead
);
1012 pci_release_region(slot
->chip
->pdev
, slot
->pci_bar
);
1014 sdhci_free_host(slot
->host
);
1017 static int __devinit
sdhci_pci_probe(struct pci_dev
*pdev
,
1018 const struct pci_device_id
*ent
)
1020 struct sdhci_pci_chip
*chip
;
1021 struct sdhci_pci_slot
*slot
;
1023 u8 slots
, first_bar
;
1026 BUG_ON(pdev
== NULL
);
1027 BUG_ON(ent
== NULL
);
1029 dev_info(&pdev
->dev
, "SDHCI controller found [%04x:%04x] (rev %x)\n",
1030 (int)pdev
->vendor
, (int)pdev
->device
, (int)pdev
->revision
);
1032 ret
= pci_read_config_byte(pdev
, PCI_SLOT_INFO
, &slots
);
1036 slots
= PCI_SLOT_INFO_SLOTS(slots
) + 1;
1037 dev_dbg(&pdev
->dev
, "found %d slot(s)\n", slots
);
1041 BUG_ON(slots
> MAX_SLOTS
);
1043 ret
= pci_read_config_byte(pdev
, PCI_SLOT_INFO
, &first_bar
);
1047 first_bar
&= PCI_SLOT_INFO_FIRST_BAR_MASK
;
1049 if (first_bar
> 5) {
1050 dev_err(&pdev
->dev
, "Invalid first BAR. Aborting.\n");
1054 ret
= pci_enable_device(pdev
);
1058 chip
= kzalloc(sizeof(struct sdhci_pci_chip
), GFP_KERNEL
);
1065 chip
->fixes
= (const struct sdhci_pci_fixes
*)ent
->driver_data
;
1067 chip
->quirks
= chip
->fixes
->quirks
;
1068 chip
->num_slots
= slots
;
1070 pci_set_drvdata(pdev
, chip
);
1072 if (chip
->fixes
&& chip
->fixes
->probe
) {
1073 ret
= chip
->fixes
->probe(chip
);
1078 slots
= chip
->num_slots
; /* Quirk may have changed this */
1080 for (i
= 0; i
< slots
; i
++) {
1081 slot
= sdhci_pci_probe_slot(pdev
, chip
, first_bar
+ i
);
1083 for (i
--; i
>= 0; i
--)
1084 sdhci_pci_remove_slot(chip
->slots
[i
]);
1085 ret
= PTR_ERR(slot
);
1089 chip
->slots
[i
] = slot
;
1095 pci_set_drvdata(pdev
, NULL
);
1099 pci_disable_device(pdev
);
1103 static void __devexit
sdhci_pci_remove(struct pci_dev
*pdev
)
1106 struct sdhci_pci_chip
*chip
;
1108 chip
= pci_get_drvdata(pdev
);
1111 for (i
= 0; i
< chip
->num_slots
; i
++)
1112 sdhci_pci_remove_slot(chip
->slots
[i
]);
1114 pci_set_drvdata(pdev
, NULL
);
1118 pci_disable_device(pdev
);
1121 static struct pci_driver sdhci_driver
= {
1122 .name
= "sdhci-pci",
1123 .id_table
= pci_ids
,
1124 .probe
= sdhci_pci_probe
,
1125 .remove
= __devexit_p(sdhci_pci_remove
),
1126 .suspend
= sdhci_pci_suspend
,
1127 .resume
= sdhci_pci_resume
,
1130 /*****************************************************************************\
1132 * Driver init/exit *
1134 \*****************************************************************************/
1136 static int __init
sdhci_drv_init(void)
1138 return pci_register_driver(&sdhci_driver
);
1141 static void __exit
sdhci_drv_exit(void)
1143 pci_unregister_driver(&sdhci_driver
);
1146 module_init(sdhci_drv_init
);
1147 module_exit(sdhci_drv_exit
);
1149 MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
1150 MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
1151 MODULE_LICENSE("GPL");