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/pm_runtime.h>
27 #include <linux/mmc/sdhci-pci-data.h>
30 #include "sdhci-pci.h"
32 /*****************************************************************************\
34 * Hardware specific quirk handling *
36 \*****************************************************************************/
38 static int ricoh_probe(struct sdhci_pci_chip
*chip
)
40 if (chip
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_SAMSUNG
||
41 chip
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_SONY
)
42 chip
->quirks
|= SDHCI_QUIRK_NO_CARD_NO_RESET
;
46 static int ricoh_mmc_probe_slot(struct sdhci_pci_slot
*slot
)
49 ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT
)
50 & SDHCI_TIMEOUT_CLK_MASK
) |
52 ((0x21 << SDHCI_CLOCK_BASE_SHIFT
)
53 & SDHCI_CLOCK_BASE_MASK
) |
55 SDHCI_TIMEOUT_CLK_UNIT
|
62 static int ricoh_mmc_resume(struct sdhci_pci_chip
*chip
)
64 /* Apply a delay to allow controller to settle */
65 /* Otherwise it becomes confused if card state changed
71 static const struct sdhci_pci_fixes sdhci_ricoh
= {
73 .quirks
= SDHCI_QUIRK_32BIT_DMA_ADDR
|
74 SDHCI_QUIRK_FORCE_DMA
|
75 SDHCI_QUIRK_CLOCK_BEFORE_RESET
,
78 static const struct sdhci_pci_fixes sdhci_ricoh_mmc
= {
79 .probe_slot
= ricoh_mmc_probe_slot
,
80 .resume
= ricoh_mmc_resume
,
81 .quirks
= SDHCI_QUIRK_32BIT_DMA_ADDR
|
82 SDHCI_QUIRK_CLOCK_BEFORE_RESET
|
83 SDHCI_QUIRK_NO_CARD_NO_RESET
|
84 SDHCI_QUIRK_MISSING_CAPS
87 static const struct sdhci_pci_fixes sdhci_ene_712
= {
88 .quirks
= SDHCI_QUIRK_SINGLE_POWER_WRITE
|
89 SDHCI_QUIRK_BROKEN_DMA
,
92 static const struct sdhci_pci_fixes sdhci_ene_714
= {
93 .quirks
= SDHCI_QUIRK_SINGLE_POWER_WRITE
|
94 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS
|
95 SDHCI_QUIRK_BROKEN_DMA
,
98 static const struct sdhci_pci_fixes sdhci_cafe
= {
99 .quirks
= SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER
|
100 SDHCI_QUIRK_NO_BUSY_IRQ
|
101 SDHCI_QUIRK_BROKEN_CARD_DETECTION
|
102 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL
,
105 static const struct sdhci_pci_fixes sdhci_intel_qrk
= {
106 .quirks
= SDHCI_QUIRK_NO_HISPD_BIT
,
109 static int mrst_hc_probe_slot(struct sdhci_pci_slot
*slot
)
111 slot
->host
->mmc
->caps
|= MMC_CAP_8_BIT_DATA
;
116 * ADMA operation is disabled for Moorestown platform due to
119 static int mrst_hc_probe(struct sdhci_pci_chip
*chip
)
122 * slots number is fixed here for MRST as SDIO3/5 are never used and
123 * have hardware bugs.
129 static int pch_hc_probe_slot(struct sdhci_pci_slot
*slot
)
131 slot
->host
->mmc
->caps
|= MMC_CAP_8_BIT_DATA
;
135 #ifdef CONFIG_PM_RUNTIME
137 static irqreturn_t
sdhci_pci_sd_cd(int irq
, void *dev_id
)
139 struct sdhci_pci_slot
*slot
= dev_id
;
140 struct sdhci_host
*host
= slot
->host
;
142 mmc_detect_change(host
->mmc
, msecs_to_jiffies(200));
146 static void sdhci_pci_add_own_cd(struct sdhci_pci_slot
*slot
)
148 int err
, irq
, gpio
= slot
->cd_gpio
;
150 slot
->cd_gpio
= -EINVAL
;
151 slot
->cd_irq
= -EINVAL
;
153 if (!gpio_is_valid(gpio
))
156 err
= gpio_request(gpio
, "sd_cd");
160 err
= gpio_direction_input(gpio
);
164 irq
= gpio_to_irq(gpio
);
168 err
= request_irq(irq
, sdhci_pci_sd_cd
, IRQF_TRIGGER_RISING
|
169 IRQF_TRIGGER_FALLING
, "sd_cd", slot
);
173 slot
->cd_gpio
= gpio
;
181 dev_warn(&slot
->chip
->pdev
->dev
, "failed to setup card detect wake up\n");
184 static void sdhci_pci_remove_own_cd(struct sdhci_pci_slot
*slot
)
186 if (slot
->cd_irq
>= 0)
187 free_irq(slot
->cd_irq
, slot
);
188 if (gpio_is_valid(slot
->cd_gpio
))
189 gpio_free(slot
->cd_gpio
);
194 static inline void sdhci_pci_add_own_cd(struct sdhci_pci_slot
*slot
)
198 static inline void sdhci_pci_remove_own_cd(struct sdhci_pci_slot
*slot
)
204 static int mfd_emmc_probe_slot(struct sdhci_pci_slot
*slot
)
206 slot
->host
->mmc
->caps
|= MMC_CAP_8_BIT_DATA
| MMC_CAP_NONREMOVABLE
;
207 slot
->host
->mmc
->caps2
|= MMC_CAP2_BOOTPART_NOACC
|
208 MMC_CAP2_HC_ERASE_SZ
;
212 static int mfd_sdio_probe_slot(struct sdhci_pci_slot
*slot
)
214 slot
->host
->mmc
->caps
|= MMC_CAP_POWER_OFF_CARD
| MMC_CAP_NONREMOVABLE
;
218 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0
= {
219 .quirks
= SDHCI_QUIRK_BROKEN_ADMA
| SDHCI_QUIRK_NO_HISPD_BIT
,
220 .probe_slot
= mrst_hc_probe_slot
,
223 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2
= {
224 .quirks
= SDHCI_QUIRK_BROKEN_ADMA
| SDHCI_QUIRK_NO_HISPD_BIT
,
225 .probe
= mrst_hc_probe
,
228 static const struct sdhci_pci_fixes sdhci_intel_mfd_sd
= {
229 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
230 .allow_runtime_pm
= true,
231 .own_cd_for_runtime_pm
= true,
234 static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio
= {
235 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
236 .quirks2
= SDHCI_QUIRK2_HOST_OFF_CARD_ON
,
237 .allow_runtime_pm
= true,
238 .probe_slot
= mfd_sdio_probe_slot
,
241 static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc
= {
242 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
243 .allow_runtime_pm
= true,
244 .probe_slot
= mfd_emmc_probe_slot
,
247 static const struct sdhci_pci_fixes sdhci_intel_pch_sdio
= {
248 .quirks
= SDHCI_QUIRK_BROKEN_ADMA
,
249 .probe_slot
= pch_hc_probe_slot
,
252 static void sdhci_pci_int_hw_reset(struct sdhci_host
*host
)
256 reg
= sdhci_readb(host
, SDHCI_POWER_CONTROL
);
258 sdhci_writeb(host
, reg
, SDHCI_POWER_CONTROL
);
259 /* For eMMC, minimum is 1us but give it 9us for good measure */
262 sdhci_writeb(host
, reg
, SDHCI_POWER_CONTROL
);
263 /* For eMMC, minimum is 200us but give it 300us for good measure */
264 usleep_range(300, 1000);
267 static int byt_emmc_probe_slot(struct sdhci_pci_slot
*slot
)
269 slot
->host
->mmc
->caps
|= MMC_CAP_8_BIT_DATA
| MMC_CAP_NONREMOVABLE
|
271 slot
->host
->mmc
->caps2
|= MMC_CAP2_HC_ERASE_SZ
;
272 slot
->hw_reset
= sdhci_pci_int_hw_reset
;
273 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_INTEL_BSW_EMMC
)
274 slot
->host
->timeout_clk
= 1000; /* 1000 kHz i.e. 1 MHz */
278 static int byt_sdio_probe_slot(struct sdhci_pci_slot
*slot
)
280 slot
->host
->mmc
->caps
|= MMC_CAP_POWER_OFF_CARD
| MMC_CAP_NONREMOVABLE
;
284 static const struct sdhci_pci_fixes sdhci_intel_byt_emmc
= {
285 .allow_runtime_pm
= true,
286 .probe_slot
= byt_emmc_probe_slot
,
287 .quirks2
= SDHCI_QUIRK2_PRESET_VALUE_BROKEN
,
290 static const struct sdhci_pci_fixes sdhci_intel_byt_sdio
= {
291 .quirks2
= SDHCI_QUIRK2_HOST_OFF_CARD_ON
,
292 .allow_runtime_pm
= true,
293 .probe_slot
= byt_sdio_probe_slot
,
296 static const struct sdhci_pci_fixes sdhci_intel_byt_sd
= {
297 .quirks2
= SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON
,
298 .allow_runtime_pm
= true,
299 .own_cd_for_runtime_pm
= true,
302 /* Define Host controllers for Intel Merrifield platform */
303 #define INTEL_MRFL_EMMC_0 0
304 #define INTEL_MRFL_EMMC_1 1
306 static int intel_mrfl_mmc_probe_slot(struct sdhci_pci_slot
*slot
)
308 if ((PCI_FUNC(slot
->chip
->pdev
->devfn
) != INTEL_MRFL_EMMC_0
) &&
309 (PCI_FUNC(slot
->chip
->pdev
->devfn
) != INTEL_MRFL_EMMC_1
))
310 /* SD support is not ready yet */
313 slot
->host
->mmc
->caps
|= MMC_CAP_8_BIT_DATA
| MMC_CAP_NONREMOVABLE
|
319 static const struct sdhci_pci_fixes sdhci_intel_mrfl_mmc
= {
320 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
321 .quirks2
= SDHCI_QUIRK2_BROKEN_HS200
,
322 .probe_slot
= intel_mrfl_mmc_probe_slot
,
325 /* O2Micro extra registers */
326 #define O2_SD_LOCK_WP 0xD3
327 #define O2_SD_MULTI_VCC3V 0xEE
328 #define O2_SD_CLKREQ 0xEC
329 #define O2_SD_CAPS 0xE0
330 #define O2_SD_ADMA1 0xE2
331 #define O2_SD_ADMA2 0xE7
332 #define O2_SD_INF_MOD 0xF1
334 static int o2_probe(struct sdhci_pci_chip
*chip
)
339 switch (chip
->pdev
->device
) {
340 case PCI_DEVICE_ID_O2_8220
:
341 case PCI_DEVICE_ID_O2_8221
:
342 case PCI_DEVICE_ID_O2_8320
:
343 case PCI_DEVICE_ID_O2_8321
:
344 /* This extra setup is required due to broken ADMA. */
345 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, &scratch
);
349 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
351 /* Set Multi 3 to VCC3V# */
352 pci_write_config_byte(chip
->pdev
, O2_SD_MULTI_VCC3V
, 0x08);
354 /* Disable CLK_REQ# support after media DET */
355 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_CLKREQ
, &scratch
);
359 pci_write_config_byte(chip
->pdev
, O2_SD_CLKREQ
, scratch
);
361 /* Choose capabilities, enable SDMA. We have to write 0x01
362 * to the capabilities register first to unlock it.
364 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_CAPS
, &scratch
);
368 pci_write_config_byte(chip
->pdev
, O2_SD_CAPS
, scratch
);
369 pci_write_config_byte(chip
->pdev
, O2_SD_CAPS
, 0x73);
371 /* Disable ADMA1/2 */
372 pci_write_config_byte(chip
->pdev
, O2_SD_ADMA1
, 0x39);
373 pci_write_config_byte(chip
->pdev
, O2_SD_ADMA2
, 0x08);
375 /* Disable the infinite transfer mode */
376 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_INF_MOD
, &scratch
);
380 pci_write_config_byte(chip
->pdev
, O2_SD_INF_MOD
, scratch
);
383 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, &scratch
);
387 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
393 static int jmicron_pmos(struct sdhci_pci_chip
*chip
, int on
)
398 ret
= pci_read_config_byte(chip
->pdev
, 0xAE, &scratch
);
403 * Turn PMOS on [bit 0], set over current detection to 2.4 V
404 * [bit 1:2] and enable over current debouncing [bit 6].
411 ret
= pci_write_config_byte(chip
->pdev
, 0xAE, scratch
);
418 static int jmicron_probe(struct sdhci_pci_chip
*chip
)
423 if (chip
->pdev
->revision
== 0) {
424 chip
->quirks
|= SDHCI_QUIRK_32BIT_DMA_ADDR
|
425 SDHCI_QUIRK_32BIT_DMA_SIZE
|
426 SDHCI_QUIRK_32BIT_ADMA_SIZE
|
427 SDHCI_QUIRK_RESET_AFTER_REQUEST
|
428 SDHCI_QUIRK_BROKEN_SMALL_PIO
;
432 * JMicron chips can have two interfaces to the same hardware
433 * in order to work around limitations in Microsoft's driver.
434 * We need to make sure we only bind to one of them.
436 * This code assumes two things:
438 * 1. The PCI code adds subfunctions in order.
440 * 2. The MMC interface has a lower subfunction number
441 * than the SD interface.
443 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_SD
)
444 mmcdev
= PCI_DEVICE_ID_JMICRON_JMB38X_MMC
;
445 else if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_SD
)
446 mmcdev
= PCI_DEVICE_ID_JMICRON_JMB388_ESD
;
449 struct pci_dev
*sd_dev
;
452 while ((sd_dev
= pci_get_device(PCI_VENDOR_ID_JMICRON
,
453 mmcdev
, sd_dev
)) != NULL
) {
454 if ((PCI_SLOT(chip
->pdev
->devfn
) ==
455 PCI_SLOT(sd_dev
->devfn
)) &&
456 (chip
->pdev
->bus
== sd_dev
->bus
))
462 dev_info(&chip
->pdev
->dev
, "Refusing to bind to "
463 "secondary interface.\n");
469 * JMicron chips need a bit of a nudge to enable the power
472 ret
= jmicron_pmos(chip
, 1);
474 dev_err(&chip
->pdev
->dev
, "Failure enabling card power\n");
478 /* quirk for unsable RO-detection on JM388 chips */
479 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_SD
||
480 chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
)
481 chip
->quirks
|= SDHCI_QUIRK_UNSTABLE_RO_DETECT
;
486 static void jmicron_enable_mmc(struct sdhci_host
*host
, int on
)
490 scratch
= readb(host
->ioaddr
+ 0xC0);
497 writeb(scratch
, host
->ioaddr
+ 0xC0);
500 static int jmicron_probe_slot(struct sdhci_pci_slot
*slot
)
502 if (slot
->chip
->pdev
->revision
== 0) {
505 version
= readl(slot
->host
->ioaddr
+ SDHCI_HOST_VERSION
);
506 version
= (version
& SDHCI_VENDOR_VER_MASK
) >>
507 SDHCI_VENDOR_VER_SHIFT
;
510 * Older versions of the chip have lots of nasty glitches
511 * in the ADMA engine. It's best just to avoid it
515 slot
->host
->quirks
|= SDHCI_QUIRK_BROKEN_ADMA
;
518 /* JM388 MMC doesn't support 1.8V while SD supports it */
519 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
) {
520 slot
->host
->ocr_avail_sd
= MMC_VDD_32_33
| MMC_VDD_33_34
|
521 MMC_VDD_29_30
| MMC_VDD_30_31
|
522 MMC_VDD_165_195
; /* allow 1.8V */
523 slot
->host
->ocr_avail_mmc
= MMC_VDD_32_33
| MMC_VDD_33_34
|
524 MMC_VDD_29_30
| MMC_VDD_30_31
; /* no 1.8V for MMC */
528 * The secondary interface requires a bit set to get the
531 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
532 slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
)
533 jmicron_enable_mmc(slot
->host
, 1);
535 slot
->host
->mmc
->caps
|= MMC_CAP_BUS_WIDTH_TEST
;
540 static void jmicron_remove_slot(struct sdhci_pci_slot
*slot
, int dead
)
545 if (slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
546 slot
->chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
)
547 jmicron_enable_mmc(slot
->host
, 0);
550 static int jmicron_suspend(struct sdhci_pci_chip
*chip
)
554 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
555 chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
) {
556 for (i
= 0; i
< chip
->num_slots
; i
++)
557 jmicron_enable_mmc(chip
->slots
[i
]->host
, 0);
563 static int jmicron_resume(struct sdhci_pci_chip
*chip
)
567 if (chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB38X_MMC
||
568 chip
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMB388_ESD
) {
569 for (i
= 0; i
< chip
->num_slots
; i
++)
570 jmicron_enable_mmc(chip
->slots
[i
]->host
, 1);
573 ret
= jmicron_pmos(chip
, 1);
575 dev_err(&chip
->pdev
->dev
, "Failure enabling card power\n");
582 static const struct sdhci_pci_fixes sdhci_o2
= {
586 static const struct sdhci_pci_fixes sdhci_jmicron
= {
587 .probe
= jmicron_probe
,
589 .probe_slot
= jmicron_probe_slot
,
590 .remove_slot
= jmicron_remove_slot
,
592 .suspend
= jmicron_suspend
,
593 .resume
= jmicron_resume
,
596 /* SysKonnect CardBus2SDIO extra registers */
597 #define SYSKT_CTRL 0x200
598 #define SYSKT_RDFIFO_STAT 0x204
599 #define SYSKT_WRFIFO_STAT 0x208
600 #define SYSKT_POWER_DATA 0x20c
601 #define SYSKT_POWER_330 0xef
602 #define SYSKT_POWER_300 0xf8
603 #define SYSKT_POWER_184 0xcc
604 #define SYSKT_POWER_CMD 0x20d
605 #define SYSKT_POWER_START (1 << 7)
606 #define SYSKT_POWER_STATUS 0x20e
607 #define SYSKT_POWER_STATUS_OK (1 << 0)
608 #define SYSKT_BOARD_REV 0x210
609 #define SYSKT_CHIP_REV 0x211
610 #define SYSKT_CONF_DATA 0x212
611 #define SYSKT_CONF_DATA_1V8 (1 << 2)
612 #define SYSKT_CONF_DATA_2V5 (1 << 1)
613 #define SYSKT_CONF_DATA_3V3 (1 << 0)
615 static int syskt_probe(struct sdhci_pci_chip
*chip
)
617 if ((chip
->pdev
->class & 0x0000FF) == PCI_SDHCI_IFVENDOR
) {
618 chip
->pdev
->class &= ~0x0000FF;
619 chip
->pdev
->class |= PCI_SDHCI_IFDMA
;
624 static int syskt_probe_slot(struct sdhci_pci_slot
*slot
)
628 u8 board_rev
= readb(slot
->host
->ioaddr
+ SYSKT_BOARD_REV
);
629 u8 chip_rev
= readb(slot
->host
->ioaddr
+ SYSKT_CHIP_REV
);
630 dev_info(&slot
->chip
->pdev
->dev
, "SysKonnect CardBus2SDIO, "
631 "board rev %d.%d, chip rev %d.%d\n",
632 board_rev
>> 4, board_rev
& 0xf,
633 chip_rev
>> 4, chip_rev
& 0xf);
634 if (chip_rev
>= 0x20)
635 slot
->host
->quirks
|= SDHCI_QUIRK_FORCE_DMA
;
637 writeb(SYSKT_POWER_330
, slot
->host
->ioaddr
+ SYSKT_POWER_DATA
);
638 writeb(SYSKT_POWER_START
, slot
->host
->ioaddr
+ SYSKT_POWER_CMD
);
640 tm
= 10; /* Wait max 1 ms */
642 ps
= readw(slot
->host
->ioaddr
+ SYSKT_POWER_STATUS
);
643 if (ps
& SYSKT_POWER_STATUS_OK
)
648 dev_err(&slot
->chip
->pdev
->dev
,
649 "power regulator never stabilized");
650 writeb(0, slot
->host
->ioaddr
+ SYSKT_POWER_CMD
);
657 static const struct sdhci_pci_fixes sdhci_syskt
= {
658 .quirks
= SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER
,
659 .probe
= syskt_probe
,
660 .probe_slot
= syskt_probe_slot
,
663 static int via_probe(struct sdhci_pci_chip
*chip
)
665 if (chip
->pdev
->revision
== 0x10)
666 chip
->quirks
|= SDHCI_QUIRK_DELAY_AFTER_POWER
;
671 static const struct sdhci_pci_fixes sdhci_via
= {
675 static int rtsx_probe_slot(struct sdhci_pci_slot
*slot
)
677 slot
->host
->mmc
->caps2
|= MMC_CAP2_HS200
;
681 static const struct sdhci_pci_fixes sdhci_rtsx
= {
682 .quirks2
= SDHCI_QUIRK2_PRESET_VALUE_BROKEN
|
683 SDHCI_QUIRK2_BROKEN_DDR50
,
684 .probe_slot
= rtsx_probe_slot
,
687 static const struct pci_device_id pci_ids
[] = {
689 .vendor
= PCI_VENDOR_ID_RICOH
,
690 .device
= PCI_DEVICE_ID_RICOH_R5C822
,
691 .subvendor
= PCI_ANY_ID
,
692 .subdevice
= PCI_ANY_ID
,
693 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh
,
697 .vendor
= PCI_VENDOR_ID_RICOH
,
699 .subvendor
= PCI_ANY_ID
,
700 .subdevice
= PCI_ANY_ID
,
701 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh_mmc
,
705 .vendor
= PCI_VENDOR_ID_RICOH
,
707 .subvendor
= PCI_ANY_ID
,
708 .subdevice
= PCI_ANY_ID
,
709 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh_mmc
,
713 .vendor
= PCI_VENDOR_ID_RICOH
,
715 .subvendor
= PCI_ANY_ID
,
716 .subdevice
= PCI_ANY_ID
,
717 .driver_data
= (kernel_ulong_t
)&sdhci_ricoh_mmc
,
721 .vendor
= PCI_VENDOR_ID_ENE
,
722 .device
= PCI_DEVICE_ID_ENE_CB712_SD
,
723 .subvendor
= PCI_ANY_ID
,
724 .subdevice
= PCI_ANY_ID
,
725 .driver_data
= (kernel_ulong_t
)&sdhci_ene_712
,
729 .vendor
= PCI_VENDOR_ID_ENE
,
730 .device
= PCI_DEVICE_ID_ENE_CB712_SD_2
,
731 .subvendor
= PCI_ANY_ID
,
732 .subdevice
= PCI_ANY_ID
,
733 .driver_data
= (kernel_ulong_t
)&sdhci_ene_712
,
737 .vendor
= PCI_VENDOR_ID_ENE
,
738 .device
= PCI_DEVICE_ID_ENE_CB714_SD
,
739 .subvendor
= PCI_ANY_ID
,
740 .subdevice
= PCI_ANY_ID
,
741 .driver_data
= (kernel_ulong_t
)&sdhci_ene_714
,
745 .vendor
= PCI_VENDOR_ID_ENE
,
746 .device
= PCI_DEVICE_ID_ENE_CB714_SD_2
,
747 .subvendor
= PCI_ANY_ID
,
748 .subdevice
= PCI_ANY_ID
,
749 .driver_data
= (kernel_ulong_t
)&sdhci_ene_714
,
753 .vendor
= PCI_VENDOR_ID_MARVELL
,
754 .device
= PCI_DEVICE_ID_MARVELL_88ALP01_SD
,
755 .subvendor
= PCI_ANY_ID
,
756 .subdevice
= PCI_ANY_ID
,
757 .driver_data
= (kernel_ulong_t
)&sdhci_cafe
,
761 .vendor
= PCI_VENDOR_ID_JMICRON
,
762 .device
= PCI_DEVICE_ID_JMICRON_JMB38X_SD
,
763 .subvendor
= PCI_ANY_ID
,
764 .subdevice
= PCI_ANY_ID
,
765 .driver_data
= (kernel_ulong_t
)&sdhci_jmicron
,
769 .vendor
= PCI_VENDOR_ID_JMICRON
,
770 .device
= PCI_DEVICE_ID_JMICRON_JMB38X_MMC
,
771 .subvendor
= PCI_ANY_ID
,
772 .subdevice
= PCI_ANY_ID
,
773 .driver_data
= (kernel_ulong_t
)&sdhci_jmicron
,
777 .vendor
= PCI_VENDOR_ID_JMICRON
,
778 .device
= PCI_DEVICE_ID_JMICRON_JMB388_SD
,
779 .subvendor
= PCI_ANY_ID
,
780 .subdevice
= PCI_ANY_ID
,
781 .driver_data
= (kernel_ulong_t
)&sdhci_jmicron
,
785 .vendor
= PCI_VENDOR_ID_JMICRON
,
786 .device
= PCI_DEVICE_ID_JMICRON_JMB388_ESD
,
787 .subvendor
= PCI_ANY_ID
,
788 .subdevice
= PCI_ANY_ID
,
789 .driver_data
= (kernel_ulong_t
)&sdhci_jmicron
,
793 .vendor
= PCI_VENDOR_ID_SYSKONNECT
,
795 .subvendor
= PCI_ANY_ID
,
796 .subdevice
= PCI_ANY_ID
,
797 .driver_data
= (kernel_ulong_t
)&sdhci_syskt
,
801 .vendor
= PCI_VENDOR_ID_VIA
,
803 .subvendor
= PCI_ANY_ID
,
804 .subdevice
= PCI_ANY_ID
,
805 .driver_data
= (kernel_ulong_t
)&sdhci_via
,
809 .vendor
= PCI_VENDOR_ID_REALTEK
,
811 .subvendor
= PCI_ANY_ID
,
812 .subdevice
= PCI_ANY_ID
,
813 .driver_data
= (kernel_ulong_t
)&sdhci_rtsx
,
817 .vendor
= PCI_VENDOR_ID_INTEL
,
818 .device
= PCI_DEVICE_ID_INTEL_QRK_SD
,
819 .subvendor
= PCI_ANY_ID
,
820 .subdevice
= PCI_ANY_ID
,
821 .driver_data
= (kernel_ulong_t
)&sdhci_intel_qrk
,
825 .vendor
= PCI_VENDOR_ID_INTEL
,
826 .device
= PCI_DEVICE_ID_INTEL_MRST_SD0
,
827 .subvendor
= PCI_ANY_ID
,
828 .subdevice
= PCI_ANY_ID
,
829 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mrst_hc0
,
833 .vendor
= PCI_VENDOR_ID_INTEL
,
834 .device
= PCI_DEVICE_ID_INTEL_MRST_SD1
,
835 .subvendor
= PCI_ANY_ID
,
836 .subdevice
= PCI_ANY_ID
,
837 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mrst_hc1_hc2
,
841 .vendor
= PCI_VENDOR_ID_INTEL
,
842 .device
= PCI_DEVICE_ID_INTEL_MRST_SD2
,
843 .subvendor
= PCI_ANY_ID
,
844 .subdevice
= PCI_ANY_ID
,
845 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mrst_hc1_hc2
,
849 .vendor
= PCI_VENDOR_ID_INTEL
,
850 .device
= PCI_DEVICE_ID_INTEL_MFD_SD
,
851 .subvendor
= PCI_ANY_ID
,
852 .subdevice
= PCI_ANY_ID
,
853 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_sd
,
857 .vendor
= PCI_VENDOR_ID_INTEL
,
858 .device
= PCI_DEVICE_ID_INTEL_MFD_SDIO1
,
859 .subvendor
= PCI_ANY_ID
,
860 .subdevice
= PCI_ANY_ID
,
861 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_sdio
,
865 .vendor
= PCI_VENDOR_ID_INTEL
,
866 .device
= PCI_DEVICE_ID_INTEL_MFD_SDIO2
,
867 .subvendor
= PCI_ANY_ID
,
868 .subdevice
= PCI_ANY_ID
,
869 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_sdio
,
873 .vendor
= PCI_VENDOR_ID_INTEL
,
874 .device
= PCI_DEVICE_ID_INTEL_MFD_EMMC0
,
875 .subvendor
= PCI_ANY_ID
,
876 .subdevice
= PCI_ANY_ID
,
877 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_emmc
,
881 .vendor
= PCI_VENDOR_ID_INTEL
,
882 .device
= PCI_DEVICE_ID_INTEL_MFD_EMMC1
,
883 .subvendor
= PCI_ANY_ID
,
884 .subdevice
= PCI_ANY_ID
,
885 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_emmc
,
889 .vendor
= PCI_VENDOR_ID_INTEL
,
890 .device
= PCI_DEVICE_ID_INTEL_PCH_SDIO0
,
891 .subvendor
= PCI_ANY_ID
,
892 .subdevice
= PCI_ANY_ID
,
893 .driver_data
= (kernel_ulong_t
)&sdhci_intel_pch_sdio
,
897 .vendor
= PCI_VENDOR_ID_INTEL
,
898 .device
= PCI_DEVICE_ID_INTEL_PCH_SDIO1
,
899 .subvendor
= PCI_ANY_ID
,
900 .subdevice
= PCI_ANY_ID
,
901 .driver_data
= (kernel_ulong_t
)&sdhci_intel_pch_sdio
,
905 .vendor
= PCI_VENDOR_ID_INTEL
,
906 .device
= PCI_DEVICE_ID_INTEL_BYT_EMMC
,
907 .subvendor
= PCI_ANY_ID
,
908 .subdevice
= PCI_ANY_ID
,
909 .driver_data
= (kernel_ulong_t
)&sdhci_intel_byt_emmc
,
913 .vendor
= PCI_VENDOR_ID_INTEL
,
914 .device
= PCI_DEVICE_ID_INTEL_BYT_SDIO
,
915 .subvendor
= PCI_ANY_ID
,
916 .subdevice
= PCI_ANY_ID
,
917 .driver_data
= (kernel_ulong_t
)&sdhci_intel_byt_sdio
,
921 .vendor
= PCI_VENDOR_ID_INTEL
,
922 .device
= PCI_DEVICE_ID_INTEL_BYT_SD
,
923 .subvendor
= PCI_ANY_ID
,
924 .subdevice
= PCI_ANY_ID
,
925 .driver_data
= (kernel_ulong_t
)&sdhci_intel_byt_sd
,
929 .vendor
= PCI_VENDOR_ID_INTEL
,
930 .device
= PCI_DEVICE_ID_INTEL_BYT_EMMC2
,
931 .subvendor
= PCI_ANY_ID
,
932 .subdevice
= PCI_ANY_ID
,
933 .driver_data
= (kernel_ulong_t
)&sdhci_intel_byt_emmc
,
937 .vendor
= PCI_VENDOR_ID_INTEL
,
938 .device
= PCI_DEVICE_ID_INTEL_BSW_EMMC
,
939 .subvendor
= PCI_ANY_ID
,
940 .subdevice
= PCI_ANY_ID
,
941 .driver_data
= (kernel_ulong_t
)&sdhci_intel_byt_emmc
,
945 .vendor
= PCI_VENDOR_ID_INTEL
,
946 .device
= PCI_DEVICE_ID_INTEL_BSW_SDIO
,
947 .subvendor
= PCI_ANY_ID
,
948 .subdevice
= PCI_ANY_ID
,
949 .driver_data
= (kernel_ulong_t
)&sdhci_intel_byt_sdio
,
953 .vendor
= PCI_VENDOR_ID_INTEL
,
954 .device
= PCI_DEVICE_ID_INTEL_BSW_SD
,
955 .subvendor
= PCI_ANY_ID
,
956 .subdevice
= PCI_ANY_ID
,
957 .driver_data
= (kernel_ulong_t
)&sdhci_intel_byt_sd
,
961 .vendor
= PCI_VENDOR_ID_INTEL
,
962 .device
= PCI_DEVICE_ID_INTEL_CLV_SDIO0
,
963 .subvendor
= PCI_ANY_ID
,
964 .subdevice
= PCI_ANY_ID
,
965 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_sd
,
969 .vendor
= PCI_VENDOR_ID_INTEL
,
970 .device
= PCI_DEVICE_ID_INTEL_CLV_SDIO1
,
971 .subvendor
= PCI_ANY_ID
,
972 .subdevice
= PCI_ANY_ID
,
973 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_sdio
,
977 .vendor
= PCI_VENDOR_ID_INTEL
,
978 .device
= PCI_DEVICE_ID_INTEL_CLV_SDIO2
,
979 .subvendor
= PCI_ANY_ID
,
980 .subdevice
= PCI_ANY_ID
,
981 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_sdio
,
985 .vendor
= PCI_VENDOR_ID_INTEL
,
986 .device
= PCI_DEVICE_ID_INTEL_CLV_EMMC0
,
987 .subvendor
= PCI_ANY_ID
,
988 .subdevice
= PCI_ANY_ID
,
989 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_emmc
,
993 .vendor
= PCI_VENDOR_ID_INTEL
,
994 .device
= PCI_DEVICE_ID_INTEL_CLV_EMMC1
,
995 .subvendor
= PCI_ANY_ID
,
996 .subdevice
= PCI_ANY_ID
,
997 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mfd_emmc
,
1001 .vendor
= PCI_VENDOR_ID_INTEL
,
1002 .device
= PCI_DEVICE_ID_INTEL_MRFL_MMC
,
1003 .subvendor
= PCI_ANY_ID
,
1004 .subdevice
= PCI_ANY_ID
,
1005 .driver_data
= (kernel_ulong_t
)&sdhci_intel_mrfl_mmc
,
1009 .vendor
= PCI_VENDOR_ID_INTEL
,
1010 .device
= PCI_DEVICE_ID_INTEL_SPT_EMMC
,
1011 .subvendor
= PCI_ANY_ID
,
1012 .subdevice
= PCI_ANY_ID
,
1013 .driver_data
= (kernel_ulong_t
)&sdhci_intel_byt_emmc
,
1017 .vendor
= PCI_VENDOR_ID_INTEL
,
1018 .device
= PCI_DEVICE_ID_INTEL_SPT_SDIO
,
1019 .subvendor
= PCI_ANY_ID
,
1020 .subdevice
= PCI_ANY_ID
,
1021 .driver_data
= (kernel_ulong_t
)&sdhci_intel_byt_sdio
,
1025 .vendor
= PCI_VENDOR_ID_INTEL
,
1026 .device
= PCI_DEVICE_ID_INTEL_SPT_SD
,
1027 .subvendor
= PCI_ANY_ID
,
1028 .subdevice
= PCI_ANY_ID
,
1029 .driver_data
= (kernel_ulong_t
)&sdhci_intel_byt_sd
,
1033 .vendor
= PCI_VENDOR_ID_O2
,
1034 .device
= PCI_DEVICE_ID_O2_8120
,
1035 .subvendor
= PCI_ANY_ID
,
1036 .subdevice
= PCI_ANY_ID
,
1037 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
1041 .vendor
= PCI_VENDOR_ID_O2
,
1042 .device
= PCI_DEVICE_ID_O2_8220
,
1043 .subvendor
= PCI_ANY_ID
,
1044 .subdevice
= PCI_ANY_ID
,
1045 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
1049 .vendor
= PCI_VENDOR_ID_O2
,
1050 .device
= PCI_DEVICE_ID_O2_8221
,
1051 .subvendor
= PCI_ANY_ID
,
1052 .subdevice
= PCI_ANY_ID
,
1053 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
1057 .vendor
= PCI_VENDOR_ID_O2
,
1058 .device
= PCI_DEVICE_ID_O2_8320
,
1059 .subvendor
= PCI_ANY_ID
,
1060 .subdevice
= PCI_ANY_ID
,
1061 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
1065 .vendor
= PCI_VENDOR_ID_O2
,
1066 .device
= PCI_DEVICE_ID_O2_8321
,
1067 .subvendor
= PCI_ANY_ID
,
1068 .subdevice
= PCI_ANY_ID
,
1069 .driver_data
= (kernel_ulong_t
)&sdhci_o2
,
1072 { /* Generic SD host controller */
1073 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI
<< 8), 0xFFFF00)
1076 { /* end: all zeroes */ },
1079 MODULE_DEVICE_TABLE(pci
, pci_ids
);
1081 /*****************************************************************************\
1083 * SDHCI core callbacks *
1085 \*****************************************************************************/
1087 static int sdhci_pci_enable_dma(struct sdhci_host
*host
)
1089 struct sdhci_pci_slot
*slot
;
1090 struct pci_dev
*pdev
;
1093 slot
= sdhci_priv(host
);
1094 pdev
= slot
->chip
->pdev
;
1096 if (((pdev
->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI
<< 8)) &&
1097 ((pdev
->class & 0x0000FF) != PCI_SDHCI_IFDMA
) &&
1098 (host
->flags
& SDHCI_USE_SDMA
)) {
1099 dev_warn(&pdev
->dev
, "Will use DMA mode even though HW "
1100 "doesn't fully claim to support it.\n");
1103 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
1107 pci_set_master(pdev
);
1112 static int sdhci_pci_bus_width(struct sdhci_host
*host
, int width
)
1116 ctrl
= sdhci_readb(host
, SDHCI_HOST_CONTROL
);
1119 case MMC_BUS_WIDTH_8
:
1120 ctrl
|= SDHCI_CTRL_8BITBUS
;
1121 ctrl
&= ~SDHCI_CTRL_4BITBUS
;
1123 case MMC_BUS_WIDTH_4
:
1124 ctrl
|= SDHCI_CTRL_4BITBUS
;
1125 ctrl
&= ~SDHCI_CTRL_8BITBUS
;
1128 ctrl
&= ~(SDHCI_CTRL_8BITBUS
| SDHCI_CTRL_4BITBUS
);
1132 sdhci_writeb(host
, ctrl
, SDHCI_HOST_CONTROL
);
1137 static void sdhci_pci_gpio_hw_reset(struct sdhci_host
*host
)
1139 struct sdhci_pci_slot
*slot
= sdhci_priv(host
);
1140 int rst_n_gpio
= slot
->rst_n_gpio
;
1142 if (!gpio_is_valid(rst_n_gpio
))
1144 gpio_set_value_cansleep(rst_n_gpio
, 0);
1145 /* For eMMC, minimum is 1us but give it 10us for good measure */
1147 gpio_set_value_cansleep(rst_n_gpio
, 1);
1148 /* For eMMC, minimum is 200us but give it 300us for good measure */
1149 usleep_range(300, 1000);
1152 static void sdhci_pci_hw_reset(struct sdhci_host
*host
)
1154 struct sdhci_pci_slot
*slot
= sdhci_priv(host
);
1157 slot
->hw_reset(host
);
1160 static const struct sdhci_ops sdhci_pci_ops
= {
1161 .enable_dma
= sdhci_pci_enable_dma
,
1162 .platform_bus_width
= sdhci_pci_bus_width
,
1163 .hw_reset
= sdhci_pci_hw_reset
,
1166 /*****************************************************************************\
1170 \*****************************************************************************/
1174 static int sdhci_pci_suspend(struct device
*dev
)
1176 struct pci_dev
*pdev
= to_pci_dev(dev
);
1177 struct sdhci_pci_chip
*chip
;
1178 struct sdhci_pci_slot
*slot
;
1179 mmc_pm_flag_t slot_pm_flags
;
1180 mmc_pm_flag_t pm_flags
= 0;
1183 chip
= pci_get_drvdata(pdev
);
1187 for (i
= 0; i
< chip
->num_slots
; i
++) {
1188 slot
= chip
->slots
[i
];
1192 ret
= sdhci_suspend_host(slot
->host
);
1195 goto err_pci_suspend
;
1197 slot_pm_flags
= slot
->host
->mmc
->pm_flags
;
1198 if (slot_pm_flags
& MMC_PM_WAKE_SDIO_IRQ
)
1199 sdhci_enable_irq_wakeups(slot
->host
);
1201 pm_flags
|= slot_pm_flags
;
1204 if (chip
->fixes
&& chip
->fixes
->suspend
) {
1205 ret
= chip
->fixes
->suspend(chip
);
1207 goto err_pci_suspend
;
1210 pci_save_state(pdev
);
1211 if (pm_flags
& MMC_PM_KEEP_POWER
) {
1212 if (pm_flags
& MMC_PM_WAKE_SDIO_IRQ
) {
1213 pci_pme_active(pdev
, true);
1214 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1216 pci_set_power_state(pdev
, PCI_D3hot
);
1218 pci_enable_wake(pdev
, PCI_D3hot
, 0);
1219 pci_disable_device(pdev
);
1220 pci_set_power_state(pdev
, PCI_D3hot
);
1227 sdhci_resume_host(chip
->slots
[i
]->host
);
1231 static int sdhci_pci_resume(struct device
*dev
)
1233 struct pci_dev
*pdev
= to_pci_dev(dev
);
1234 struct sdhci_pci_chip
*chip
;
1235 struct sdhci_pci_slot
*slot
;
1238 chip
= pci_get_drvdata(pdev
);
1242 pci_set_power_state(pdev
, PCI_D0
);
1243 pci_restore_state(pdev
);
1244 ret
= pci_enable_device(pdev
);
1248 if (chip
->fixes
&& chip
->fixes
->resume
) {
1249 ret
= chip
->fixes
->resume(chip
);
1254 for (i
= 0; i
< chip
->num_slots
; i
++) {
1255 slot
= chip
->slots
[i
];
1259 ret
= sdhci_resume_host(slot
->host
);
1267 #else /* CONFIG_PM */
1269 #define sdhci_pci_suspend NULL
1270 #define sdhci_pci_resume NULL
1272 #endif /* CONFIG_PM */
1274 #ifdef CONFIG_PM_RUNTIME
1276 static int sdhci_pci_runtime_suspend(struct device
*dev
)
1278 struct pci_dev
*pdev
= container_of(dev
, struct pci_dev
, dev
);
1279 struct sdhci_pci_chip
*chip
;
1280 struct sdhci_pci_slot
*slot
;
1283 chip
= pci_get_drvdata(pdev
);
1287 for (i
= 0; i
< chip
->num_slots
; i
++) {
1288 slot
= chip
->slots
[i
];
1292 ret
= sdhci_runtime_suspend_host(slot
->host
);
1295 goto err_pci_runtime_suspend
;
1298 if (chip
->fixes
&& chip
->fixes
->suspend
) {
1299 ret
= chip
->fixes
->suspend(chip
);
1301 goto err_pci_runtime_suspend
;
1306 err_pci_runtime_suspend
:
1308 sdhci_runtime_resume_host(chip
->slots
[i
]->host
);
1312 static int sdhci_pci_runtime_resume(struct device
*dev
)
1314 struct pci_dev
*pdev
= container_of(dev
, struct pci_dev
, dev
);
1315 struct sdhci_pci_chip
*chip
;
1316 struct sdhci_pci_slot
*slot
;
1319 chip
= pci_get_drvdata(pdev
);
1323 if (chip
->fixes
&& chip
->fixes
->resume
) {
1324 ret
= chip
->fixes
->resume(chip
);
1329 for (i
= 0; i
< chip
->num_slots
; i
++) {
1330 slot
= chip
->slots
[i
];
1334 ret
= sdhci_runtime_resume_host(slot
->host
);
1342 static int sdhci_pci_runtime_idle(struct device
*dev
)
1349 #define sdhci_pci_runtime_suspend NULL
1350 #define sdhci_pci_runtime_resume NULL
1351 #define sdhci_pci_runtime_idle NULL
1355 static const struct dev_pm_ops sdhci_pci_pm_ops
= {
1356 .suspend
= sdhci_pci_suspend
,
1357 .resume
= sdhci_pci_resume
,
1358 .runtime_suspend
= sdhci_pci_runtime_suspend
,
1359 .runtime_resume
= sdhci_pci_runtime_resume
,
1360 .runtime_idle
= sdhci_pci_runtime_idle
,
1363 /*****************************************************************************\
1365 * Device probing/removal *
1367 \*****************************************************************************/
1369 static struct sdhci_pci_slot
*sdhci_pci_probe_slot(
1370 struct pci_dev
*pdev
, struct sdhci_pci_chip
*chip
, int first_bar
,
1373 struct sdhci_pci_slot
*slot
;
1374 struct sdhci_host
*host
;
1375 int ret
, bar
= first_bar
+ slotno
;
1377 if (!(pci_resource_flags(pdev
, bar
) & IORESOURCE_MEM
)) {
1378 dev_err(&pdev
->dev
, "BAR %d is not iomem. Aborting.\n", bar
);
1379 return ERR_PTR(-ENODEV
);
1382 if (pci_resource_len(pdev
, bar
) < 0x100) {
1383 dev_err(&pdev
->dev
, "Invalid iomem size. You may "
1384 "experience problems.\n");
1387 if ((pdev
->class & 0x0000FF) == PCI_SDHCI_IFVENDOR
) {
1388 dev_err(&pdev
->dev
, "Vendor specific interface. Aborting.\n");
1389 return ERR_PTR(-ENODEV
);
1392 if ((pdev
->class & 0x0000FF) > PCI_SDHCI_IFVENDOR
) {
1393 dev_err(&pdev
->dev
, "Unknown interface. Aborting.\n");
1394 return ERR_PTR(-ENODEV
);
1397 host
= sdhci_alloc_host(&pdev
->dev
, sizeof(struct sdhci_pci_slot
));
1399 dev_err(&pdev
->dev
, "cannot allocate host\n");
1400 return ERR_CAST(host
);
1403 slot
= sdhci_priv(host
);
1407 slot
->pci_bar
= bar
;
1408 slot
->rst_n_gpio
= -EINVAL
;
1409 slot
->cd_gpio
= -EINVAL
;
1411 /* Retrieve platform data if there is any */
1412 if (*sdhci_pci_get_data
)
1413 slot
->data
= sdhci_pci_get_data(pdev
, slotno
);
1416 if (slot
->data
->setup
) {
1417 ret
= slot
->data
->setup(slot
->data
);
1419 dev_err(&pdev
->dev
, "platform setup failed\n");
1423 slot
->rst_n_gpio
= slot
->data
->rst_n_gpio
;
1424 slot
->cd_gpio
= slot
->data
->cd_gpio
;
1427 host
->hw_name
= "PCI";
1428 host
->ops
= &sdhci_pci_ops
;
1429 host
->quirks
= chip
->quirks
;
1430 host
->quirks2
= chip
->quirks2
;
1432 host
->irq
= pdev
->irq
;
1434 ret
= pci_request_region(pdev
, bar
, mmc_hostname(host
->mmc
));
1436 dev_err(&pdev
->dev
, "cannot request region\n");
1440 host
->ioaddr
= pci_ioremap_bar(pdev
, bar
);
1441 if (!host
->ioaddr
) {
1442 dev_err(&pdev
->dev
, "failed to remap registers\n");
1447 if (chip
->fixes
&& chip
->fixes
->probe_slot
) {
1448 ret
= chip
->fixes
->probe_slot(slot
);
1453 if (gpio_is_valid(slot
->rst_n_gpio
)) {
1454 if (!gpio_request(slot
->rst_n_gpio
, "eMMC_reset")) {
1455 gpio_direction_output(slot
->rst_n_gpio
, 1);
1456 slot
->host
->mmc
->caps
|= MMC_CAP_HW_RESET
;
1457 slot
->hw_reset
= sdhci_pci_gpio_hw_reset
;
1459 dev_warn(&pdev
->dev
, "failed to request rst_n_gpio\n");
1460 slot
->rst_n_gpio
= -EINVAL
;
1464 host
->mmc
->pm_caps
= MMC_PM_KEEP_POWER
| MMC_PM_WAKE_SDIO_IRQ
;
1465 host
->mmc
->slotno
= slotno
;
1466 host
->mmc
->caps2
|= MMC_CAP2_NO_PRESCAN_POWERUP
;
1468 ret
= sdhci_add_host(host
);
1472 sdhci_pci_add_own_cd(slot
);
1475 * Check if the chip needs a separate GPIO for card detect to wake up
1476 * from runtime suspend. If it is not there, don't allow runtime PM.
1477 * Note sdhci_pci_add_own_cd() sets slot->cd_gpio to -EINVAL on failure.
1479 if (chip
->fixes
&& chip
->fixes
->own_cd_for_runtime_pm
&&
1480 !gpio_is_valid(slot
->cd_gpio
))
1481 chip
->allow_runtime_pm
= false;
1486 if (gpio_is_valid(slot
->rst_n_gpio
))
1487 gpio_free(slot
->rst_n_gpio
);
1489 if (chip
->fixes
&& chip
->fixes
->remove_slot
)
1490 chip
->fixes
->remove_slot(slot
, 0);
1493 iounmap(host
->ioaddr
);
1496 pci_release_region(pdev
, bar
);
1499 if (slot
->data
&& slot
->data
->cleanup
)
1500 slot
->data
->cleanup(slot
->data
);
1503 sdhci_free_host(host
);
1505 return ERR_PTR(ret
);
1508 static void sdhci_pci_remove_slot(struct sdhci_pci_slot
*slot
)
1513 sdhci_pci_remove_own_cd(slot
);
1516 scratch
= readl(slot
->host
->ioaddr
+ SDHCI_INT_STATUS
);
1517 if (scratch
== (u32
)-1)
1520 sdhci_remove_host(slot
->host
, dead
);
1522 if (gpio_is_valid(slot
->rst_n_gpio
))
1523 gpio_free(slot
->rst_n_gpio
);
1525 if (slot
->chip
->fixes
&& slot
->chip
->fixes
->remove_slot
)
1526 slot
->chip
->fixes
->remove_slot(slot
, dead
);
1528 if (slot
->data
&& slot
->data
->cleanup
)
1529 slot
->data
->cleanup(slot
->data
);
1531 pci_release_region(slot
->chip
->pdev
, slot
->pci_bar
);
1533 sdhci_free_host(slot
->host
);
1536 static void sdhci_pci_runtime_pm_allow(struct device
*dev
)
1538 pm_runtime_put_noidle(dev
);
1539 pm_runtime_allow(dev
);
1540 pm_runtime_set_autosuspend_delay(dev
, 50);
1541 pm_runtime_use_autosuspend(dev
);
1542 pm_suspend_ignore_children(dev
, 1);
1545 static void sdhci_pci_runtime_pm_forbid(struct device
*dev
)
1547 pm_runtime_forbid(dev
);
1548 pm_runtime_get_noresume(dev
);
1551 static int sdhci_pci_probe(struct pci_dev
*pdev
,
1552 const struct pci_device_id
*ent
)
1554 struct sdhci_pci_chip
*chip
;
1555 struct sdhci_pci_slot
*slot
;
1557 u8 slots
, first_bar
;
1560 BUG_ON(pdev
== NULL
);
1561 BUG_ON(ent
== NULL
);
1563 dev_info(&pdev
->dev
, "SDHCI controller found [%04x:%04x] (rev %x)\n",
1564 (int)pdev
->vendor
, (int)pdev
->device
, (int)pdev
->revision
);
1566 ret
= pci_read_config_byte(pdev
, PCI_SLOT_INFO
, &slots
);
1570 slots
= PCI_SLOT_INFO_SLOTS(slots
) + 1;
1571 dev_dbg(&pdev
->dev
, "found %d slot(s)\n", slots
);
1575 BUG_ON(slots
> MAX_SLOTS
);
1577 ret
= pci_read_config_byte(pdev
, PCI_SLOT_INFO
, &first_bar
);
1581 first_bar
&= PCI_SLOT_INFO_FIRST_BAR_MASK
;
1583 if (first_bar
> 5) {
1584 dev_err(&pdev
->dev
, "Invalid first BAR. Aborting.\n");
1588 ret
= pci_enable_device(pdev
);
1592 chip
= kzalloc(sizeof(struct sdhci_pci_chip
), GFP_KERNEL
);
1599 chip
->fixes
= (const struct sdhci_pci_fixes
*)ent
->driver_data
;
1601 chip
->quirks
= chip
->fixes
->quirks
;
1602 chip
->quirks2
= chip
->fixes
->quirks2
;
1603 chip
->allow_runtime_pm
= chip
->fixes
->allow_runtime_pm
;
1605 chip
->num_slots
= slots
;
1607 pci_set_drvdata(pdev
, chip
);
1609 if (chip
->fixes
&& chip
->fixes
->probe
) {
1610 ret
= chip
->fixes
->probe(chip
);
1615 slots
= chip
->num_slots
; /* Quirk may have changed this */
1617 for (i
= 0; i
< slots
; i
++) {
1618 slot
= sdhci_pci_probe_slot(pdev
, chip
, first_bar
, i
);
1620 for (i
--; i
>= 0; i
--)
1621 sdhci_pci_remove_slot(chip
->slots
[i
]);
1622 ret
= PTR_ERR(slot
);
1626 chip
->slots
[i
] = slot
;
1629 if (chip
->allow_runtime_pm
)
1630 sdhci_pci_runtime_pm_allow(&pdev
->dev
);
1635 pci_set_drvdata(pdev
, NULL
);
1639 pci_disable_device(pdev
);
1643 static void sdhci_pci_remove(struct pci_dev
*pdev
)
1646 struct sdhci_pci_chip
*chip
;
1648 chip
= pci_get_drvdata(pdev
);
1651 if (chip
->allow_runtime_pm
)
1652 sdhci_pci_runtime_pm_forbid(&pdev
->dev
);
1654 for (i
= 0; i
< chip
->num_slots
; i
++)
1655 sdhci_pci_remove_slot(chip
->slots
[i
]);
1657 pci_set_drvdata(pdev
, NULL
);
1661 pci_disable_device(pdev
);
1664 static struct pci_driver sdhci_driver
= {
1665 .name
= "sdhci-pci",
1666 .id_table
= pci_ids
,
1667 .probe
= sdhci_pci_probe
,
1668 .remove
= sdhci_pci_remove
,
1670 .pm
= &sdhci_pci_pm_ops
1674 module_pci_driver(sdhci_driver
);
1676 MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
1677 MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
1678 MODULE_LICENSE("GPL");