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_CARD_DETECTION
|
152 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL
,
155 static int mrst_hc_probe_slot(struct sdhci_pci_slot
*slot
)
157 slot
->host
->mmc
->caps
|= MMC_CAP_8_BIT_DATA
;
162 * ADMA operation is disabled for Moorestown platform due to
165 static int mrst_hc_probe(struct sdhci_pci_chip
*chip
)
168 * slots number is fixed here for MRST as SDIO3/5 are never used and
169 * have hardware bugs.
175 /* Medfield eMMC hardware reset GPIOs */
176 static int mfd_emmc0_rst_gpio
= -EINVAL
;
177 static int mfd_emmc1_rst_gpio
= -EINVAL
;
179 static int mfd_emmc_gpio_parse(struct sfi_table_header
*table
)
181 struct sfi_table_simple
*sb
= (struct sfi_table_simple
*)table
;
182 struct sfi_gpio_table_entry
*entry
;
185 num
= SFI_GET_NUM_ENTRIES(sb
, struct sfi_gpio_table_entry
);
186 entry
= (struct sfi_gpio_table_entry
*)sb
->pentry
;
188 for (i
= 0; i
< num
; i
++, entry
++) {
189 if (!strncmp(entry
->pin_name
, "emmc0_rst", SFI_NAME_LEN
))
190 mfd_emmc0_rst_gpio
= entry
->pin_no
;
191 else if (!strncmp(entry
->pin_name
, "emmc1_rst", SFI_NAME_LEN
))
192 mfd_emmc1_rst_gpio
= entry
->pin_no
;
198 #ifdef CONFIG_PM_RUNTIME
200 static irqreturn_t
mfd_sd_cd(int irq
, void *dev_id
)
202 struct sdhci_pci_slot
*slot
= dev_id
;
203 struct sdhci_host
*host
= slot
->host
;
205 mmc_detect_change(host
->mmc
, msecs_to_jiffies(200));
209 #define MFLD_SD_CD_PIN 69
211 static int mfd_sd_probe_slot(struct sdhci_pci_slot
*slot
)
213 int err
, irq
, gpio
= MFLD_SD_CD_PIN
;
215 slot
->cd_gpio
= -EINVAL
;
216 slot
->cd_irq
= -EINVAL
;
218 err
= gpio_request(gpio
, "sd_cd");
222 err
= gpio_direction_input(gpio
);
226 irq
= gpio_to_irq(gpio
);
230 err
= request_irq(irq
, mfd_sd_cd
, IRQF_TRIGGER_RISING
|
231 IRQF_TRIGGER_FALLING
, "sd_cd", slot
);
235 slot
->cd_gpio
= gpio
;
237 slot
->host
->quirks2
|= SDHCI_QUIRK2_OWN_CARD_DETECTION
;
244 dev_warn(&slot
->chip
->pdev
->dev
, "failed to setup card detect wake up\n");
248 static void mfd_sd_remove_slot(struct sdhci_pci_slot
*slot
, int dead
)
250 if (slot
->cd_irq
>= 0)
251 free_irq(slot
->cd_irq
, slot
);
252 gpio_free(slot
->cd_gpio
);
257 #define mfd_sd_probe_slot NULL
258 #define mfd_sd_remove_slot NULL
262 static int mfd_emmc_probe_slot(struct sdhci_pci_slot
*slot
)
264 const char *name
= NULL
;
267 sfi_table_parse(SFI_SIG_GPIO
, NULL
, NULL
, mfd_emmc_gpio_parse
);
269 switch (slot
->chip
->pdev
->device
) {
270 case PCI_DEVICE_ID_INTEL_MFD_EMMC0
:
271 gpio
= mfd_emmc0_rst_gpio
;
272 name
= "eMMC0_reset";
274 case PCI_DEVICE_ID_INTEL_MFD_EMMC1
:
275 gpio
= mfd_emmc1_rst_gpio
;
276 name
= "eMMC1_reset";
280 if (!gpio_request(gpio
, name
)) {
281 gpio_direction_output(gpio
, 1);
282 slot
->rst_n_gpio
= gpio
;
283 slot
->host
->mmc
->caps
|= MMC_CAP_HW_RESET
;
286 slot
->host
->mmc
->caps
|= MMC_CAP_8_BIT_DATA
| MMC_CAP_NONREMOVABLE
;
288 slot
->host
->mmc
->caps2
= MMC_CAP2_BOOTPART_NOACC
;
293 static void mfd_emmc_remove_slot(struct sdhci_pci_slot
*slot
, int dead
)
295 gpio_free(slot
->rst_n_gpio
);
298 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0
= {
299 .quirks
= SDHCI_QUIRK_BROKEN_ADMA
| SDHCI_QUIRK_NO_HISPD_BIT
,
300 .probe_slot
= mrst_hc_probe_slot
,
303 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2
= {
304 .quirks
= SDHCI_QUIRK_BROKEN_ADMA
| SDHCI_QUIRK_NO_HISPD_BIT
,
305 .probe
= mrst_hc_probe
,
308 static const struct sdhci_pci_fixes sdhci_intel_mfd_sd
= {
309 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
310 .allow_runtime_pm
= true,
311 .probe_slot
= mfd_sd_probe_slot
,
312 .remove_slot
= mfd_sd_remove_slot
,
315 static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio
= {
316 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
317 .allow_runtime_pm
= true,
320 static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc
= {
321 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
322 .allow_runtime_pm
= true,
323 .probe_slot
= mfd_emmc_probe_slot
,
324 .remove_slot
= mfd_emmc_remove_slot
,
327 /* O2Micro extra registers */
328 #define O2_SD_LOCK_WP 0xD3
329 #define O2_SD_MULTI_VCC3V 0xEE
330 #define O2_SD_CLKREQ 0xEC
331 #define O2_SD_CAPS 0xE0
332 #define O2_SD_ADMA1 0xE2
333 #define O2_SD_ADMA2 0xE7
334 #define O2_SD_INF_MOD 0xF1
336 static int o2_probe(struct sdhci_pci_chip
*chip
)
341 switch (chip
->pdev
->device
) {
342 case PCI_DEVICE_ID_O2_8220
:
343 case PCI_DEVICE_ID_O2_8221
:
344 case PCI_DEVICE_ID_O2_8320
:
345 case PCI_DEVICE_ID_O2_8321
:
346 /* This extra setup is required due to broken ADMA. */
347 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, &scratch
);
351 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
353 /* Set Multi 3 to VCC3V# */
354 pci_write_config_byte(chip
->pdev
, O2_SD_MULTI_VCC3V
, 0x08);
356 /* Disable CLK_REQ# support after media DET */
357 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_CLKREQ
, &scratch
);
361 pci_write_config_byte(chip
->pdev
, O2_SD_CLKREQ
, scratch
);
363 /* Choose capabilities, enable SDMA. We have to write 0x01
364 * to the capabilities register first to unlock it.
366 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_CAPS
, &scratch
);
370 pci_write_config_byte(chip
->pdev
, O2_SD_CAPS
, scratch
);
371 pci_write_config_byte(chip
->pdev
, O2_SD_CAPS
, 0x73);
373 /* Disable ADMA1/2 */
374 pci_write_config_byte(chip
->pdev
, O2_SD_ADMA1
, 0x39);
375 pci_write_config_byte(chip
->pdev
, O2_SD_ADMA2
, 0x08);
377 /* Disable the infinite transfer mode */
378 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_INF_MOD
, &scratch
);
382 pci_write_config_byte(chip
->pdev
, O2_SD_INF_MOD
, scratch
);
385 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, &scratch
);
389 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
395 static int jmicron_pmos(struct sdhci_pci_chip
*chip
, int on
)
400 ret
= pci_read_config_byte(chip
->pdev
, 0xAE, &scratch
);
405 * Turn PMOS on [bit 0], set over current detection to 2.4 V
406 * [bit 1:2] and enable over current debouncing [bit 6].
413 ret
= pci_write_config_byte(chip
->pdev
, 0xAE, scratch
);
420 static int jmicron_probe(struct sdhci_pci_chip
*chip
)
425 if (chip
->pdev
->revision
== 0) {
426 chip
->quirks
|= SDHCI_QUIRK_32BIT_DMA_ADDR
|
427 SDHCI_QUIRK_32BIT_DMA_SIZE
|
428 SDHCI_QUIRK_32BIT_ADMA_SIZE
|
429 SDHCI_QUIRK_RESET_AFTER_REQUEST
|
430 SDHCI_QUIRK_BROKEN_SMALL_PIO
;
434 * JMicron chips can have two interfaces to the same hardware
435 * in order to work around limitations in Microsoft's driver.
436 * We need to make sure we only bind to one of them.
438 * This code assumes two things:
440 * 1. The PCI code adds subfunctions in order.
442 * 2. The MMC interface has a lower subfunction number
443 * than the SD interface.
445 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_SD
)
446 mmcdev
= PCI_DEVICE_ID_JMICRON_JMB38X_MMC
;
447 else if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_SD
)
448 mmcdev
= PCI_DEVICE_ID_JMICRON_JMB388_ESD
;
451 struct pci_dev
*sd_dev
;
454 while ((sd_dev
= pci_get_device(PCI_VENDOR_ID_JMICRON
,
455 mmcdev
, sd_dev
)) != NULL
) {
456 if ((PCI_SLOT(chip
->pdev
->devfn
) ==
457 PCI_SLOT(sd_dev
->devfn
)) &&
458 (chip
->pdev
->bus
== sd_dev
->bus
))
464 dev_info(&chip
->pdev
->dev
, "Refusing to bind to "
465 "secondary interface.\n");
471 * JMicron chips need a bit of a nudge to enable the power
474 ret
= jmicron_pmos(chip
, 1);
476 dev_err(&chip
->pdev
->dev
, "Failure enabling card power\n");
480 /* quirk for unsable RO-detection on JM388 chips */
481 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_SD
||
482 chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
)
483 chip
->quirks
|= SDHCI_QUIRK_UNSTABLE_RO_DETECT
;
488 static void jmicron_enable_mmc(struct sdhci_host
*host
, int on
)
492 scratch
= readb(host
->ioaddr
+ 0xC0);
499 writeb(scratch
, host
->ioaddr
+ 0xC0);
502 static int jmicron_probe_slot(struct sdhci_pci_slot
*slot
)
504 if (slot
->chip
->pdev
->revision
== 0) {
507 version
= readl(slot
->host
->ioaddr
+ SDHCI_HOST_VERSION
);
508 version
= (version
& SDHCI_VENDOR_VER_MASK
) >>
509 SDHCI_VENDOR_VER_SHIFT
;
512 * Older versions of the chip have lots of nasty glitches
513 * in the ADMA engine. It's best just to avoid it
517 slot
->host
->quirks
|= SDHCI_QUIRK_BROKEN_ADMA
;
520 /* JM388 MMC doesn't support 1.8V while SD supports it */
521 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
) {
522 slot
->host
->ocr_avail_sd
= MMC_VDD_32_33
| MMC_VDD_33_34
|
523 MMC_VDD_29_30
| MMC_VDD_30_31
|
524 MMC_VDD_165_195
; /* allow 1.8V */
525 slot
->host
->ocr_avail_mmc
= MMC_VDD_32_33
| MMC_VDD_33_34
|
526 MMC_VDD_29_30
| MMC_VDD_30_31
; /* no 1.8V for MMC */
530 * The secondary interface requires a bit set to get the
533 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
534 slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
)
535 jmicron_enable_mmc(slot
->host
, 1);
537 slot
->host
->mmc
->caps
|= MMC_CAP_BUS_WIDTH_TEST
;
542 static void jmicron_remove_slot(struct sdhci_pci_slot
*slot
, int dead
)
547 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
548 slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
)
549 jmicron_enable_mmc(slot
->host
, 0);
552 static int jmicron_suspend(struct sdhci_pci_chip
*chip
)
556 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
557 chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
) {
558 for (i
= 0; i
< chip
->num_slots
; i
++)
559 jmicron_enable_mmc(chip
->slots
[i
]->host
, 0);
565 static int jmicron_resume(struct sdhci_pci_chip
*chip
)
569 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
570 chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
) {
571 for (i
= 0; i
< chip
->num_slots
; i
++)
572 jmicron_enable_mmc(chip
->slots
[i
]->host
, 1);
575 ret
= jmicron_pmos(chip
, 1);
577 dev_err(&chip
->pdev
->dev
, "Failure enabling card power\n");
584 static const struct sdhci_pci_fixes sdhci_o2
= {
588 static const struct sdhci_pci_fixes sdhci_jmicron
= {
589 .probe
= jmicron_probe
,
591 .probe_slot
= jmicron_probe_slot
,
592 .remove_slot
= jmicron_remove_slot
,
594 .suspend
= jmicron_suspend
,
595 .resume
= jmicron_resume
,
598 /* SysKonnect CardBus2SDIO extra registers */
599 #define SYSKT_CTRL 0x200
600 #define SYSKT_RDFIFO_STAT 0x204
601 #define SYSKT_WRFIFO_STAT 0x208
602 #define SYSKT_POWER_DATA 0x20c
603 #define SYSKT_POWER_330 0xef
604 #define SYSKT_POWER_300 0xf8
605 #define SYSKT_POWER_184 0xcc
606 #define SYSKT_POWER_CMD 0x20d
607 #define SYSKT_POWER_START (1 << 7)
608 #define SYSKT_POWER_STATUS 0x20e
609 #define SYSKT_POWER_STATUS_OK (1 << 0)
610 #define SYSKT_BOARD_REV 0x210
611 #define SYSKT_CHIP_REV 0x211
612 #define SYSKT_CONF_DATA 0x212
613 #define SYSKT_CONF_DATA_1V8 (1 << 2)
614 #define SYSKT_CONF_DATA_2V5 (1 << 1)
615 #define SYSKT_CONF_DATA_3V3 (1 << 0)
617 static int syskt_probe(struct sdhci_pci_chip
*chip
)
619 if ((chip
->pdev
->class & 0x0000FF) == PCI_SDHCI_IFVENDOR
) {
620 chip
->pdev
->class &= ~0x0000FF;
621 chip
->pdev
->class |= PCI_SDHCI_IFDMA
;
626 static int syskt_probe_slot(struct sdhci_pci_slot
*slot
)
630 u8 board_rev
= readb(slot
->host
->ioaddr
+ SYSKT_BOARD_REV
);
631 u8 chip_rev
= readb(slot
->host
->ioaddr
+ SYSKT_CHIP_REV
);
632 dev_info(&slot
->chip
->pdev
->dev
, "SysKonnect CardBus2SDIO, "
633 "board rev %d.%d, chip rev %d.%d\n",
634 board_rev
>> 4, board_rev
& 0xf,
635 chip_rev
>> 4, chip_rev
& 0xf);
636 if (chip_rev
>= 0x20)
637 slot
->host
->quirks
|= SDHCI_QUIRK_FORCE_DMA
;
639 writeb(SYSKT_POWER_330
, slot
->host
->ioaddr
+ SYSKT_POWER_DATA
);
640 writeb(SYSKT_POWER_START
, slot
->host
->ioaddr
+ SYSKT_POWER_CMD
);
642 tm
= 10; /* Wait max 1 ms */
644 ps
= readw(slot
->host
->ioaddr
+ SYSKT_POWER_STATUS
);
645 if (ps
& SYSKT_POWER_STATUS_OK
)
650 dev_err(&slot
->chip
->pdev
->dev
,
651 "power regulator never stabilized");
652 writeb(0, slot
->host
->ioaddr
+ SYSKT_POWER_CMD
);
659 static const struct sdhci_pci_fixes sdhci_syskt
= {
660 .quirks
= SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER
,
661 .probe
= syskt_probe
,
662 .probe_slot
= syskt_probe_slot
,
665 static int via_probe(struct sdhci_pci_chip
*chip
)
667 if (chip
->pdev
->revision
== 0x10)
668 chip
->quirks
|= SDHCI_QUIRK_DELAY_AFTER_POWER
;
673 static const struct sdhci_pci_fixes sdhci_via
= {
677 static const struct pci_device_id pci_ids
[] __devinitdata
= {
679 .vendor
= PCI_VENDOR_ID_RICOH
,
680 .device
= PCI_DEVICE_ID_RICOH_R5C822
,
681 .subvendor
= PCI_ANY_ID
,
682 .subdevice
= PCI_ANY_ID
,
683 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh
,
687 .vendor
= PCI_VENDOR_ID_RICOH
,
689 .subvendor
= PCI_ANY_ID
,
690 .subdevice
= PCI_ANY_ID
,
691 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh_mmc
,
695 .vendor
= PCI_VENDOR_ID_RICOH
,
697 .subvendor
= PCI_ANY_ID
,
698 .subdevice
= PCI_ANY_ID
,
699 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh_mmc
,
703 .vendor
= PCI_VENDOR_ID_RICOH
,
705 .subvendor
= PCI_ANY_ID
,
706 .subdevice
= PCI_ANY_ID
,
707 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh_mmc
,
711 .vendor
= PCI_VENDOR_ID_ENE
,
712 .device
= PCI_DEVICE_ID_ENE_CB712_SD
,
713 .subvendor
= PCI_ANY_ID
,
714 .subdevice
= PCI_ANY_ID
,
715 .driver_data
= (kernel_ulong_t
)&sdhci_ene_712
,
719 .vendor
= PCI_VENDOR_ID_ENE
,
720 .device
= PCI_DEVICE_ID_ENE_CB712_SD_2
,
721 .subvendor
= PCI_ANY_ID
,
722 .subdevice
= PCI_ANY_ID
,
723 .driver_data
= (kernel_ulong_t
)&sdhci_ene_712
,
727 .vendor
= PCI_VENDOR_ID_ENE
,
728 .device
= PCI_DEVICE_ID_ENE_CB714_SD
,
729 .subvendor
= PCI_ANY_ID
,
730 .subdevice
= PCI_ANY_ID
,
731 .driver_data
= (kernel_ulong_t
)&sdhci_ene_714
,
735 .vendor
= PCI_VENDOR_ID_ENE
,
736 .device
= PCI_DEVICE_ID_ENE_CB714_SD_2
,
737 .subvendor
= PCI_ANY_ID
,
738 .subdevice
= PCI_ANY_ID
,
739 .driver_data
= (kernel_ulong_t
)&sdhci_ene_714
,
743 .vendor
= PCI_VENDOR_ID_MARVELL
,
744 .device
= PCI_DEVICE_ID_MARVELL_88ALP01_SD
,
745 .subvendor
= PCI_ANY_ID
,
746 .subdevice
= PCI_ANY_ID
,
747 .driver_data
= (kernel_ulong_t
)&sdhci_cafe
,
751 .vendor
= PCI_VENDOR_ID_JMICRON
,
752 .device
= PCI_DEVICE_ID_JMICRON_JMB38X_SD
,
753 .subvendor
= PCI_ANY_ID
,
754 .subdevice
= PCI_ANY_ID
,
755 .driver_data
= (kernel_ulong_t
)&sdhci_jmicron
,
759 .vendor
= PCI_VENDOR_ID_JMICRON
,
760 .device
= PCI_DEVICE_ID_JMICRON_JMB38X_MMC
,
761 .subvendor
= PCI_ANY_ID
,
762 .subdevice
= PCI_ANY_ID
,
763 .driver_data
= (kernel_ulong_t
)&sdhci_jmicron
,
767 .vendor
= PCI_VENDOR_ID_JMICRON
,
768 .device
= PCI_DEVICE_ID_JMICRON_JMB388_SD
,
769 .subvendor
= PCI_ANY_ID
,
770 .subdevice
= PCI_ANY_ID
,
771 .driver_data
= (kernel_ulong_t
)&sdhci_jmicron
,
775 .vendor
= PCI_VENDOR_ID_JMICRON
,
776 .device
= PCI_DEVICE_ID_JMICRON_JMB388_ESD
,
777 .subvendor
= PCI_ANY_ID
,
778 .subdevice
= PCI_ANY_ID
,
779 .driver_data
= (kernel_ulong_t
)&sdhci_jmicron
,
783 .vendor
= PCI_VENDOR_ID_SYSKONNECT
,
785 .subvendor
= PCI_ANY_ID
,
786 .subdevice
= PCI_ANY_ID
,
787 .driver_data
= (kernel_ulong_t
)&sdhci_syskt
,
791 .vendor
= PCI_VENDOR_ID_VIA
,
793 .subvendor
= PCI_ANY_ID
,
794 .subdevice
= PCI_ANY_ID
,
795 .driver_data
= (kernel_ulong_t
)&sdhci_via
,
799 .vendor
= PCI_VENDOR_ID_INTEL
,
800 .device
= PCI_DEVICE_ID_INTEL_MRST_SD0
,
801 .subvendor
= PCI_ANY_ID
,
802 .subdevice
= PCI_ANY_ID
,
803 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mrst_hc0
,
807 .vendor
= PCI_VENDOR_ID_INTEL
,
808 .device
= PCI_DEVICE_ID_INTEL_MRST_SD1
,
809 .subvendor
= PCI_ANY_ID
,
810 .subdevice
= PCI_ANY_ID
,
811 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mrst_hc1_hc2
,
815 .vendor
= PCI_VENDOR_ID_INTEL
,
816 .device
= PCI_DEVICE_ID_INTEL_MRST_SD2
,
817 .subvendor
= PCI_ANY_ID
,
818 .subdevice
= PCI_ANY_ID
,
819 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mrst_hc1_hc2
,
823 .vendor
= PCI_VENDOR_ID_INTEL
,
824 .device
= PCI_DEVICE_ID_INTEL_MFD_SD
,
825 .subvendor
= PCI_ANY_ID
,
826 .subdevice
= PCI_ANY_ID
,
827 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_sd
,
831 .vendor
= PCI_VENDOR_ID_INTEL
,
832 .device
= PCI_DEVICE_ID_INTEL_MFD_SDIO1
,
833 .subvendor
= PCI_ANY_ID
,
834 .subdevice
= PCI_ANY_ID
,
835 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_sdio
,
839 .vendor
= PCI_VENDOR_ID_INTEL
,
840 .device
= PCI_DEVICE_ID_INTEL_MFD_SDIO2
,
841 .subvendor
= PCI_ANY_ID
,
842 .subdevice
= PCI_ANY_ID
,
843 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_sdio
,
847 .vendor
= PCI_VENDOR_ID_INTEL
,
848 .device
= PCI_DEVICE_ID_INTEL_MFD_EMMC0
,
849 .subvendor
= PCI_ANY_ID
,
850 .subdevice
= PCI_ANY_ID
,
851 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_emmc
,
855 .vendor
= PCI_VENDOR_ID_INTEL
,
856 .device
= PCI_DEVICE_ID_INTEL_MFD_EMMC1
,
857 .subvendor
= PCI_ANY_ID
,
858 .subdevice
= PCI_ANY_ID
,
859 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_emmc
,
863 .vendor
= PCI_VENDOR_ID_O2
,
864 .device
= PCI_DEVICE_ID_O2_8120
,
865 .subvendor
= PCI_ANY_ID
,
866 .subdevice
= PCI_ANY_ID
,
867 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
871 .vendor
= PCI_VENDOR_ID_O2
,
872 .device
= PCI_DEVICE_ID_O2_8220
,
873 .subvendor
= PCI_ANY_ID
,
874 .subdevice
= PCI_ANY_ID
,
875 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
879 .vendor
= PCI_VENDOR_ID_O2
,
880 .device
= PCI_DEVICE_ID_O2_8221
,
881 .subvendor
= PCI_ANY_ID
,
882 .subdevice
= PCI_ANY_ID
,
883 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
887 .vendor
= PCI_VENDOR_ID_O2
,
888 .device
= PCI_DEVICE_ID_O2_8320
,
889 .subvendor
= PCI_ANY_ID
,
890 .subdevice
= PCI_ANY_ID
,
891 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
895 .vendor
= PCI_VENDOR_ID_O2
,
896 .device
= PCI_DEVICE_ID_O2_8321
,
897 .subvendor
= PCI_ANY_ID
,
898 .subdevice
= PCI_ANY_ID
,
899 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
902 { /* Generic SD host controller */
903 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI
<< 8), 0xFFFF00)
906 { /* end: all zeroes */ },
909 MODULE_DEVICE_TABLE(pci
, pci_ids
);
911 /*****************************************************************************\
913 * SDHCI core callbacks *
915 \*****************************************************************************/
917 static int sdhci_pci_enable_dma(struct sdhci_host
*host
)
919 struct sdhci_pci_slot
*slot
;
920 struct pci_dev
*pdev
;
923 slot
= sdhci_priv(host
);
924 pdev
= slot
->chip
->pdev
;
926 if (((pdev
->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI
<< 8)) &&
927 ((pdev
->class & 0x0000FF) != PCI_SDHCI_IFDMA
) &&
928 (host
->flags
& SDHCI_USE_SDMA
)) {
929 dev_warn(&pdev
->dev
, "Will use DMA mode even though HW "
930 "doesn't fully claim to support it.\n");
933 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
937 pci_set_master(pdev
);
942 static int sdhci_pci_8bit_width(struct sdhci_host
*host
, int width
)
946 ctrl
= sdhci_readb(host
, SDHCI_HOST_CONTROL
);
949 case MMC_BUS_WIDTH_8
:
950 ctrl
|= SDHCI_CTRL_8BITBUS
;
951 ctrl
&= ~SDHCI_CTRL_4BITBUS
;
953 case MMC_BUS_WIDTH_4
:
954 ctrl
|= SDHCI_CTRL_4BITBUS
;
955 ctrl
&= ~SDHCI_CTRL_8BITBUS
;
958 ctrl
&= ~(SDHCI_CTRL_8BITBUS
| SDHCI_CTRL_4BITBUS
);
962 sdhci_writeb(host
, ctrl
, SDHCI_HOST_CONTROL
);
967 static void sdhci_pci_hw_reset(struct sdhci_host
*host
)
969 struct sdhci_pci_slot
*slot
= sdhci_priv(host
);
970 int rst_n_gpio
= slot
->rst_n_gpio
;
972 if (!gpio_is_valid(rst_n_gpio
))
974 gpio_set_value_cansleep(rst_n_gpio
, 0);
975 /* For eMMC, minimum is 1us but give it 10us for good measure */
977 gpio_set_value_cansleep(rst_n_gpio
, 1);
978 /* For eMMC, minimum is 200us but give it 300us for good measure */
979 usleep_range(300, 1000);
982 static struct sdhci_ops sdhci_pci_ops
= {
983 .enable_dma
= sdhci_pci_enable_dma
,
984 .platform_8bit_width
= sdhci_pci_8bit_width
,
985 .hw_reset
= sdhci_pci_hw_reset
,
988 /*****************************************************************************\
992 \*****************************************************************************/
996 static int sdhci_pci_suspend(struct device
*dev
)
998 struct pci_dev
*pdev
= to_pci_dev(dev
);
999 struct sdhci_pci_chip
*chip
;
1000 struct sdhci_pci_slot
*slot
;
1001 mmc_pm_flag_t slot_pm_flags
;
1002 mmc_pm_flag_t pm_flags
= 0;
1005 chip
= pci_get_drvdata(pdev
);
1009 for (i
= 0; i
< chip
->num_slots
; i
++) {
1010 slot
= chip
->slots
[i
];
1014 ret
= sdhci_suspend_host(slot
->host
);
1017 for (i
--; i
>= 0; i
--)
1018 sdhci_resume_host(chip
->slots
[i
]->host
);
1022 slot_pm_flags
= slot
->host
->mmc
->pm_flags
;
1023 if (slot_pm_flags
& MMC_PM_WAKE_SDIO_IRQ
)
1024 sdhci_enable_irq_wakeups(slot
->host
);
1026 pm_flags
|= slot_pm_flags
;
1029 if (chip
->fixes
&& chip
->fixes
->suspend
) {
1030 ret
= chip
->fixes
->suspend(chip
);
1032 for (i
= chip
->num_slots
- 1; i
>= 0; i
--)
1033 sdhci_resume_host(chip
->slots
[i
]->host
);
1038 pci_save_state(pdev
);
1039 if (pm_flags
& MMC_PM_KEEP_POWER
) {
1040 if (pm_flags
& MMC_PM_WAKE_SDIO_IRQ
) {
1041 pci_pme_active(pdev
, true);
1042 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1044 pci_set_power_state(pdev
, PCI_D3hot
);
1046 pci_enable_wake(pdev
, PCI_D3hot
, 0);
1047 pci_disable_device(pdev
);
1048 pci_set_power_state(pdev
, PCI_D3hot
);
1054 static int sdhci_pci_resume(struct device
*dev
)
1056 struct pci_dev
*pdev
= to_pci_dev(dev
);
1057 struct sdhci_pci_chip
*chip
;
1058 struct sdhci_pci_slot
*slot
;
1061 chip
= pci_get_drvdata(pdev
);
1065 pci_set_power_state(pdev
, PCI_D0
);
1066 pci_restore_state(pdev
);
1067 ret
= pci_enable_device(pdev
);
1071 if (chip
->fixes
&& chip
->fixes
->resume
) {
1072 ret
= chip
->fixes
->resume(chip
);
1077 for (i
= 0; i
< chip
->num_slots
; i
++) {
1078 slot
= chip
->slots
[i
];
1082 ret
= sdhci_resume_host(slot
->host
);
1090 #else /* CONFIG_PM */
1092 #define sdhci_pci_suspend NULL
1093 #define sdhci_pci_resume NULL
1095 #endif /* CONFIG_PM */
1097 #ifdef CONFIG_PM_RUNTIME
1099 static int sdhci_pci_runtime_suspend(struct device
*dev
)
1101 struct pci_dev
*pdev
= container_of(dev
, struct pci_dev
, dev
);
1102 struct sdhci_pci_chip
*chip
;
1103 struct sdhci_pci_slot
*slot
;
1106 chip
= pci_get_drvdata(pdev
);
1110 for (i
= 0; i
< chip
->num_slots
; i
++) {
1111 slot
= chip
->slots
[i
];
1115 ret
= sdhci_runtime_suspend_host(slot
->host
);
1118 for (i
--; i
>= 0; i
--)
1119 sdhci_runtime_resume_host(chip
->slots
[i
]->host
);
1124 if (chip
->fixes
&& chip
->fixes
->suspend
) {
1125 ret
= chip
->fixes
->suspend(chip
);
1127 for (i
= chip
->num_slots
- 1; i
>= 0; i
--)
1128 sdhci_runtime_resume_host(chip
->slots
[i
]->host
);
1136 static int sdhci_pci_runtime_resume(struct device
*dev
)
1138 struct pci_dev
*pdev
= container_of(dev
, struct pci_dev
, dev
);
1139 struct sdhci_pci_chip
*chip
;
1140 struct sdhci_pci_slot
*slot
;
1143 chip
= pci_get_drvdata(pdev
);
1147 if (chip
->fixes
&& chip
->fixes
->resume
) {
1148 ret
= chip
->fixes
->resume(chip
);
1153 for (i
= 0; i
< chip
->num_slots
; i
++) {
1154 slot
= chip
->slots
[i
];
1158 ret
= sdhci_runtime_resume_host(slot
->host
);
1166 static int sdhci_pci_runtime_idle(struct device
*dev
)
1173 #define sdhci_pci_runtime_suspend NULL
1174 #define sdhci_pci_runtime_resume NULL
1175 #define sdhci_pci_runtime_idle NULL
1179 static const struct dev_pm_ops sdhci_pci_pm_ops
= {
1180 .suspend
= sdhci_pci_suspend
,
1181 .resume
= sdhci_pci_resume
,
1182 .runtime_suspend
= sdhci_pci_runtime_suspend
,
1183 .runtime_resume
= sdhci_pci_runtime_resume
,
1184 .runtime_idle
= sdhci_pci_runtime_idle
,
1187 /*****************************************************************************\
1189 * Device probing/removal *
1191 \*****************************************************************************/
1193 static struct sdhci_pci_slot
* __devinit
sdhci_pci_probe_slot(
1194 struct pci_dev
*pdev
, struct sdhci_pci_chip
*chip
, int bar
)
1196 struct sdhci_pci_slot
*slot
;
1197 struct sdhci_host
*host
;
1200 if (!(pci_resource_flags(pdev
, bar
) & IORESOURCE_MEM
)) {
1201 dev_err(&pdev
->dev
, "BAR %d is not iomem. Aborting.\n", bar
);
1202 return ERR_PTR(-ENODEV
);
1205 if (pci_resource_len(pdev
, bar
) != 0x100) {
1206 dev_err(&pdev
->dev
, "Invalid iomem size. You may "
1207 "experience problems.\n");
1210 if ((pdev
->class & 0x0000FF) == PCI_SDHCI_IFVENDOR
) {
1211 dev_err(&pdev
->dev
, "Vendor specific interface. Aborting.\n");
1212 return ERR_PTR(-ENODEV
);
1215 if ((pdev
->class & 0x0000FF) > PCI_SDHCI_IFVENDOR
) {
1216 dev_err(&pdev
->dev
, "Unknown interface. Aborting.\n");
1217 return ERR_PTR(-ENODEV
);
1220 host
= sdhci_alloc_host(&pdev
->dev
, sizeof(struct sdhci_pci_slot
));
1222 dev_err(&pdev
->dev
, "cannot allocate host\n");
1223 return ERR_CAST(host
);
1226 slot
= sdhci_priv(host
);
1230 slot
->pci_bar
= bar
;
1231 slot
->rst_n_gpio
= -EINVAL
;
1233 host
->hw_name
= "PCI";
1234 host
->ops
= &sdhci_pci_ops
;
1235 host
->quirks
= chip
->quirks
;
1237 host
->irq
= pdev
->irq
;
1239 ret
= pci_request_region(pdev
, bar
, mmc_hostname(host
->mmc
));
1241 dev_err(&pdev
->dev
, "cannot request region\n");
1245 host
->ioaddr
= pci_ioremap_bar(pdev
, bar
);
1246 if (!host
->ioaddr
) {
1247 dev_err(&pdev
->dev
, "failed to remap registers\n");
1252 if (chip
->fixes
&& chip
->fixes
->probe_slot
) {
1253 ret
= chip
->fixes
->probe_slot(slot
);
1258 host
->mmc
->pm_caps
= MMC_PM_KEEP_POWER
| MMC_PM_WAKE_SDIO_IRQ
;
1260 ret
= sdhci_add_host(host
);
1267 if (chip
->fixes
&& chip
->fixes
->remove_slot
)
1268 chip
->fixes
->remove_slot(slot
, 0);
1271 iounmap(host
->ioaddr
);
1274 pci_release_region(pdev
, bar
);
1277 sdhci_free_host(host
);
1279 return ERR_PTR(ret
);
1282 static void sdhci_pci_remove_slot(struct sdhci_pci_slot
*slot
)
1288 scratch
= readl(slot
->host
->ioaddr
+ SDHCI_INT_STATUS
);
1289 if (scratch
== (u32
)-1)
1292 sdhci_remove_host(slot
->host
, dead
);
1294 if (slot
->chip
->fixes
&& slot
->chip
->fixes
->remove_slot
)
1295 slot
->chip
->fixes
->remove_slot(slot
, dead
);
1297 pci_release_region(slot
->chip
->pdev
, slot
->pci_bar
);
1299 sdhci_free_host(slot
->host
);
1302 static void __devinit
sdhci_pci_runtime_pm_allow(struct device
*dev
)
1304 pm_runtime_put_noidle(dev
);
1305 pm_runtime_allow(dev
);
1306 pm_runtime_set_autosuspend_delay(dev
, 50);
1307 pm_runtime_use_autosuspend(dev
);
1308 pm_suspend_ignore_children(dev
, 1);
1311 static void __devexit
sdhci_pci_runtime_pm_forbid(struct device
*dev
)
1313 pm_runtime_forbid(dev
);
1314 pm_runtime_get_noresume(dev
);
1317 static int __devinit
sdhci_pci_probe(struct pci_dev
*pdev
,
1318 const struct pci_device_id
*ent
)
1320 struct sdhci_pci_chip
*chip
;
1321 struct sdhci_pci_slot
*slot
;
1323 u8 slots
, first_bar
;
1326 BUG_ON(pdev
== NULL
);
1327 BUG_ON(ent
== NULL
);
1329 dev_info(&pdev
->dev
, "SDHCI controller found [%04x:%04x] (rev %x)\n",
1330 (int)pdev
->vendor
, (int)pdev
->device
, (int)pdev
->revision
);
1332 ret
= pci_read_config_byte(pdev
, PCI_SLOT_INFO
, &slots
);
1336 slots
= PCI_SLOT_INFO_SLOTS(slots
) + 1;
1337 dev_dbg(&pdev
->dev
, "found %d slot(s)\n", slots
);
1341 BUG_ON(slots
> MAX_SLOTS
);
1343 ret
= pci_read_config_byte(pdev
, PCI_SLOT_INFO
, &first_bar
);
1347 first_bar
&= PCI_SLOT_INFO_FIRST_BAR_MASK
;
1349 if (first_bar
> 5) {
1350 dev_err(&pdev
->dev
, "Invalid first BAR. Aborting.\n");
1354 ret
= pci_enable_device(pdev
);
1358 chip
= kzalloc(sizeof(struct sdhci_pci_chip
), GFP_KERNEL
);
1365 chip
->fixes
= (const struct sdhci_pci_fixes
*)ent
->driver_data
;
1367 chip
->quirks
= chip
->fixes
->quirks
;
1368 chip
->allow_runtime_pm
= chip
->fixes
->allow_runtime_pm
;
1370 chip
->num_slots
= slots
;
1372 pci_set_drvdata(pdev
, chip
);
1374 if (chip
->fixes
&& chip
->fixes
->probe
) {
1375 ret
= chip
->fixes
->probe(chip
);
1380 slots
= chip
->num_slots
; /* Quirk may have changed this */
1382 for (i
= 0; i
< slots
; i
++) {
1383 slot
= sdhci_pci_probe_slot(pdev
, chip
, first_bar
+ i
);
1385 for (i
--; i
>= 0; i
--)
1386 sdhci_pci_remove_slot(chip
->slots
[i
]);
1387 ret
= PTR_ERR(slot
);
1391 chip
->slots
[i
] = slot
;
1394 if (chip
->allow_runtime_pm
)
1395 sdhci_pci_runtime_pm_allow(&pdev
->dev
);
1400 pci_set_drvdata(pdev
, NULL
);
1404 pci_disable_device(pdev
);
1408 static void __devexit
sdhci_pci_remove(struct pci_dev
*pdev
)
1411 struct sdhci_pci_chip
*chip
;
1413 chip
= pci_get_drvdata(pdev
);
1416 if (chip
->allow_runtime_pm
)
1417 sdhci_pci_runtime_pm_forbid(&pdev
->dev
);
1419 for (i
= 0; i
< chip
->num_slots
; i
++)
1420 sdhci_pci_remove_slot(chip
->slots
[i
]);
1422 pci_set_drvdata(pdev
, NULL
);
1426 pci_disable_device(pdev
);
1429 static struct pci_driver sdhci_driver
= {
1430 .name
= "sdhci-pci",
1431 .id_table
= pci_ids
,
1432 .probe
= sdhci_pci_probe
,
1433 .remove
= __devexit_p(sdhci_pci_remove
),
1435 .pm
= &sdhci_pci_pm_ops
1439 /*****************************************************************************\
1441 * Driver init/exit *
1443 \*****************************************************************************/
1445 static int __init
sdhci_drv_init(void)
1447 return pci_register_driver(&sdhci_driver
);
1450 static void __exit
sdhci_drv_exit(void)
1452 pci_unregister_driver(&sdhci_driver
);
1455 module_init(sdhci_drv_init
);
1456 module_exit(sdhci_drv_exit
);
1458 MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
1459 MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
1460 MODULE_LICENSE("GPL");