2 * Secure Digital Host Controller Interface ACPI driver.
4 * Copyright (c) 2012, Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <linux/init.h>
22 #include <linux/export.h>
23 #include <linux/module.h>
24 #include <linux/device.h>
25 #include <linux/platform_device.h>
26 #include <linux/ioport.h>
28 #include <linux/dma-mapping.h>
29 #include <linux/compiler.h>
30 #include <linux/stddef.h>
31 #include <linux/bitops.h>
32 #include <linux/types.h>
33 #include <linux/err.h>
34 #include <linux/interrupt.h>
35 #include <linux/acpi.h>
37 #include <linux/pm_runtime.h>
38 #include <linux/delay.h>
40 #include <linux/mmc/host.h>
41 #include <linux/mmc/pm.h>
42 #include <linux/mmc/slot-gpio.h>
45 #include <asm/cpu_device_id.h>
46 #include <asm/intel-family.h>
47 #include <asm/iosf_mbi.h>
48 #include <linux/pci.h>
54 SDHCI_ACPI_SD_CD
= BIT(0),
55 SDHCI_ACPI_RUNTIME_PM
= BIT(1),
56 SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL
= BIT(2),
59 struct sdhci_acpi_chip
{
60 const struct sdhci_ops
*ops
;
65 mmc_pm_flag_t pm_caps
;
68 struct sdhci_acpi_slot
{
69 const struct sdhci_acpi_chip
*chip
;
74 mmc_pm_flag_t pm_caps
;
77 int (*probe_slot
)(struct platform_device
*, const char *, const char *);
78 int (*remove_slot
)(struct platform_device
*);
79 int (*setup_host
)(struct platform_device
*pdev
);
82 struct sdhci_acpi_host
{
83 struct sdhci_host
*host
;
84 const struct sdhci_acpi_slot
*slot
;
85 struct platform_device
*pdev
;
87 unsigned long private[0] ____cacheline_aligned
;
90 static inline void *sdhci_acpi_priv(struct sdhci_acpi_host
*c
)
92 return (void *)c
->private;
95 static inline bool sdhci_acpi_flag(struct sdhci_acpi_host
*c
, unsigned int flag
)
97 return c
->slot
&& (c
->slot
->flags
& flag
);
100 #define INTEL_DSM_HS_CAPS_SDR25 BIT(0)
101 #define INTEL_DSM_HS_CAPS_DDR50 BIT(1)
102 #define INTEL_DSM_HS_CAPS_SDR50 BIT(2)
103 #define INTEL_DSM_HS_CAPS_SDR104 BIT(3)
107 INTEL_DSM_V18_SWITCH
= 3,
108 INTEL_DSM_V33_SWITCH
= 4,
109 INTEL_DSM_HS_CAPS
= 8,
117 static const guid_t intel_dsm_guid
=
118 GUID_INIT(0xF6C13EA5, 0x65CD, 0x461F,
119 0xAB, 0x7A, 0x29, 0xF7, 0xE8, 0xD5, 0xBD, 0x61);
121 static int __intel_dsm(struct intel_host
*intel_host
, struct device
*dev
,
122 unsigned int fn
, u32
*result
)
124 union acpi_object
*obj
;
127 obj
= acpi_evaluate_dsm(ACPI_HANDLE(dev
), &intel_dsm_guid
, 0, fn
, NULL
);
131 if (obj
->type
== ACPI_TYPE_INTEGER
) {
132 *result
= obj
->integer
.value
;
133 } else if (obj
->type
== ACPI_TYPE_BUFFER
&& obj
->buffer
.length
> 0) {
134 size_t len
= min_t(size_t, obj
->buffer
.length
, 4);
137 memcpy(result
, obj
->buffer
.pointer
, len
);
139 dev_err(dev
, "%s DSM fn %u obj->type %d obj->buffer.length %d\n",
140 __func__
, fn
, obj
->type
, obj
->buffer
.length
);
149 static int intel_dsm(struct intel_host
*intel_host
, struct device
*dev
,
150 unsigned int fn
, u32
*result
)
152 if (fn
> 31 || !(intel_host
->dsm_fns
& (1 << fn
)))
155 return __intel_dsm(intel_host
, dev
, fn
, result
);
158 static void intel_dsm_init(struct intel_host
*intel_host
, struct device
*dev
,
159 struct mmc_host
*mmc
)
163 intel_host
->hs_caps
= ~0;
165 err
= __intel_dsm(intel_host
, dev
, INTEL_DSM_FNS
, &intel_host
->dsm_fns
);
167 pr_debug("%s: DSM not supported, error %d\n",
168 mmc_hostname(mmc
), err
);
172 pr_debug("%s: DSM function mask %#x\n",
173 mmc_hostname(mmc
), intel_host
->dsm_fns
);
175 intel_dsm(intel_host
, dev
, INTEL_DSM_HS_CAPS
, &intel_host
->hs_caps
);
178 static int intel_start_signal_voltage_switch(struct mmc_host
*mmc
,
181 struct device
*dev
= mmc_dev(mmc
);
182 struct sdhci_acpi_host
*c
= dev_get_drvdata(dev
);
183 struct intel_host
*intel_host
= sdhci_acpi_priv(c
);
188 err
= sdhci_start_signal_voltage_switch(mmc
, ios
);
192 switch (ios
->signal_voltage
) {
193 case MMC_SIGNAL_VOLTAGE_330
:
194 fn
= INTEL_DSM_V33_SWITCH
;
196 case MMC_SIGNAL_VOLTAGE_180
:
197 fn
= INTEL_DSM_V18_SWITCH
;
203 err
= intel_dsm(intel_host
, dev
, fn
, &result
);
204 pr_debug("%s: %s DSM fn %u error %d result %u\n",
205 mmc_hostname(mmc
), __func__
, fn
, err
, result
);
210 static void sdhci_acpi_int_hw_reset(struct sdhci_host
*host
)
214 reg
= sdhci_readb(host
, SDHCI_POWER_CONTROL
);
216 sdhci_writeb(host
, reg
, SDHCI_POWER_CONTROL
);
217 /* For eMMC, minimum is 1us but give it 9us for good measure */
220 sdhci_writeb(host
, reg
, SDHCI_POWER_CONTROL
);
221 /* For eMMC, minimum is 200us but give it 300us for good measure */
222 usleep_range(300, 1000);
225 static const struct sdhci_ops sdhci_acpi_ops_dflt
= {
226 .set_clock
= sdhci_set_clock
,
227 .set_bus_width
= sdhci_set_bus_width
,
228 .reset
= sdhci_reset
,
229 .set_uhs_signaling
= sdhci_set_uhs_signaling
,
232 static const struct sdhci_ops sdhci_acpi_ops_int
= {
233 .set_clock
= sdhci_set_clock
,
234 .set_bus_width
= sdhci_set_bus_width
,
235 .reset
= sdhci_reset
,
236 .set_uhs_signaling
= sdhci_set_uhs_signaling
,
237 .hw_reset
= sdhci_acpi_int_hw_reset
,
240 static const struct sdhci_acpi_chip sdhci_acpi_chip_int
= {
241 .ops
= &sdhci_acpi_ops_int
,
246 static bool sdhci_acpi_byt(void)
248 static const struct x86_cpu_id byt
[] = {
249 { X86_VENDOR_INTEL
, 6, INTEL_FAM6_ATOM_SILVERMONT1
},
253 return x86_match_cpu(byt
);
256 static bool sdhci_acpi_cht(void)
258 static const struct x86_cpu_id cht
[] = {
259 { X86_VENDOR_INTEL
, 6, INTEL_FAM6_ATOM_AIRMONT
},
263 return x86_match_cpu(cht
);
266 #define BYT_IOSF_SCCEP 0x63
267 #define BYT_IOSF_OCP_NETCTRL0 0x1078
268 #define BYT_IOSF_OCP_TIMEOUT_BASE GENMASK(10, 8)
270 static void sdhci_acpi_byt_setting(struct device
*dev
)
274 if (!sdhci_acpi_byt())
277 if (iosf_mbi_read(BYT_IOSF_SCCEP
, MBI_CR_READ
, BYT_IOSF_OCP_NETCTRL0
,
279 dev_err(dev
, "%s read error\n", __func__
);
283 if (!(val
& BYT_IOSF_OCP_TIMEOUT_BASE
))
286 val
&= ~BYT_IOSF_OCP_TIMEOUT_BASE
;
288 if (iosf_mbi_write(BYT_IOSF_SCCEP
, MBI_CR_WRITE
, BYT_IOSF_OCP_NETCTRL0
,
290 dev_err(dev
, "%s write error\n", __func__
);
294 dev_dbg(dev
, "%s completed\n", __func__
);
297 static bool sdhci_acpi_byt_defer(struct device
*dev
)
299 if (!sdhci_acpi_byt())
302 if (!iosf_mbi_available())
305 sdhci_acpi_byt_setting(dev
);
310 static bool sdhci_acpi_cht_pci_wifi(unsigned int vendor
, unsigned int device
,
311 unsigned int slot
, unsigned int parent_slot
)
313 struct pci_dev
*dev
, *parent
, *from
= NULL
;
316 dev
= pci_get_device(vendor
, device
, from
);
320 parent
= pci_upstream_bridge(dev
);
321 if (ACPI_COMPANION(&dev
->dev
) && PCI_SLOT(dev
->devfn
) == slot
&&
322 parent
&& PCI_SLOT(parent
->devfn
) == parent_slot
&&
323 !pci_upstream_bridge(parent
)) {
334 * GPDwin uses PCI wifi which conflicts with SDIO's use of
335 * acpi_device_fix_up_power() on child device nodes. Identifying GPDwin is
336 * problematic, but since SDIO is only used for wifi, the presence of the PCI
337 * wifi card in the expected slot with an ACPI companion node, is used to
338 * indicate that acpi_device_fix_up_power() should be avoided.
340 static inline bool sdhci_acpi_no_fixup_child_power(const char *hid
,
343 return sdhci_acpi_cht() &&
344 !strcmp(hid
, "80860F14") &&
346 sdhci_acpi_cht_pci_wifi(0x14e4, 0x43ec, 0, 28);
351 static inline void sdhci_acpi_byt_setting(struct device
*dev
)
355 static inline bool sdhci_acpi_byt_defer(struct device
*dev
)
360 static inline bool sdhci_acpi_no_fixup_child_power(const char *hid
,
368 static int bxt_get_cd(struct mmc_host
*mmc
)
370 int gpio_cd
= mmc_gpio_get_cd(mmc
);
371 struct sdhci_host
*host
= mmc_priv(mmc
);
378 spin_lock_irqsave(&host
->lock
, flags
);
380 if (host
->flags
& SDHCI_DEVICE_DEAD
)
383 ret
= !!(sdhci_readl(host
, SDHCI_PRESENT_STATE
) & SDHCI_CARD_PRESENT
);
385 spin_unlock_irqrestore(&host
->lock
, flags
);
390 static int intel_probe_slot(struct platform_device
*pdev
, const char *hid
,
393 struct sdhci_acpi_host
*c
= platform_get_drvdata(pdev
);
394 struct intel_host
*intel_host
= sdhci_acpi_priv(c
);
395 struct sdhci_host
*host
= c
->host
;
397 if (hid
&& uid
&& !strcmp(hid
, "80860F14") && !strcmp(uid
, "1") &&
398 sdhci_readl(host
, SDHCI_CAPABILITIES
) == 0x446cc8b2 &&
399 sdhci_readl(host
, SDHCI_CAPABILITIES_1
) == 0x00000807)
400 host
->timeout_clk
= 1000; /* 1000 kHz i.e. 1 MHz */
402 if (hid
&& !strcmp(hid
, "80865ACA"))
403 host
->mmc_host_ops
.get_cd
= bxt_get_cd
;
405 intel_dsm_init(intel_host
, &pdev
->dev
, host
->mmc
);
407 host
->mmc_host_ops
.start_signal_voltage_switch
=
408 intel_start_signal_voltage_switch
;
413 static int intel_setup_host(struct platform_device
*pdev
)
415 struct sdhci_acpi_host
*c
= platform_get_drvdata(pdev
);
416 struct intel_host
*intel_host
= sdhci_acpi_priv(c
);
418 if (!(intel_host
->hs_caps
& INTEL_DSM_HS_CAPS_SDR25
))
419 c
->host
->mmc
->caps
&= ~MMC_CAP_UHS_SDR25
;
421 if (!(intel_host
->hs_caps
& INTEL_DSM_HS_CAPS_SDR50
))
422 c
->host
->mmc
->caps
&= ~MMC_CAP_UHS_SDR50
;
424 if (!(intel_host
->hs_caps
& INTEL_DSM_HS_CAPS_DDR50
))
425 c
->host
->mmc
->caps
&= ~MMC_CAP_UHS_DDR50
;
427 if (!(intel_host
->hs_caps
& INTEL_DSM_HS_CAPS_SDR104
))
428 c
->host
->mmc
->caps
&= ~MMC_CAP_UHS_SDR104
;
433 static const struct sdhci_acpi_slot sdhci_acpi_slot_int_emmc
= {
434 .chip
= &sdhci_acpi_chip_int
,
435 .caps
= MMC_CAP_8_BIT_DATA
| MMC_CAP_NONREMOVABLE
|
436 MMC_CAP_HW_RESET
| MMC_CAP_1_8V_DDR
|
437 MMC_CAP_CMD_DURING_TFR
| MMC_CAP_WAIT_WHILE_BUSY
,
438 .flags
= SDHCI_ACPI_RUNTIME_PM
,
439 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
440 .quirks2
= SDHCI_QUIRK2_PRESET_VALUE_BROKEN
|
441 SDHCI_QUIRK2_STOP_WITH_TC
|
442 SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400
,
443 .probe_slot
= intel_probe_slot
,
444 .setup_host
= intel_setup_host
,
445 .priv_size
= sizeof(struct intel_host
),
448 static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio
= {
449 .quirks
= SDHCI_QUIRK_BROKEN_CARD_DETECTION
|
450 SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
451 .quirks2
= SDHCI_QUIRK2_HOST_OFF_CARD_ON
,
452 .caps
= MMC_CAP_NONREMOVABLE
| MMC_CAP_POWER_OFF_CARD
|
453 MMC_CAP_WAIT_WHILE_BUSY
,
454 .flags
= SDHCI_ACPI_RUNTIME_PM
,
455 .pm_caps
= MMC_PM_KEEP_POWER
,
456 .probe_slot
= intel_probe_slot
,
457 .setup_host
= intel_setup_host
,
458 .priv_size
= sizeof(struct intel_host
),
461 static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd
= {
462 .flags
= SDHCI_ACPI_SD_CD
| SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL
|
463 SDHCI_ACPI_RUNTIME_PM
,
464 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
465 .quirks2
= SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON
|
466 SDHCI_QUIRK2_STOP_WITH_TC
,
467 .caps
= MMC_CAP_WAIT_WHILE_BUSY
| MMC_CAP_AGGRESSIVE_PM
,
468 .probe_slot
= intel_probe_slot
,
469 .setup_host
= intel_setup_host
,
470 .priv_size
= sizeof(struct intel_host
),
473 static const struct sdhci_acpi_slot sdhci_acpi_slot_qcom_sd_3v
= {
474 .quirks
= SDHCI_QUIRK_BROKEN_CARD_DETECTION
,
475 .quirks2
= SDHCI_QUIRK2_NO_1_8_V
,
476 .caps
= MMC_CAP_NONREMOVABLE
,
479 static const struct sdhci_acpi_slot sdhci_acpi_slot_qcom_sd
= {
480 .quirks
= SDHCI_QUIRK_BROKEN_CARD_DETECTION
,
481 .caps
= MMC_CAP_NONREMOVABLE
,
484 /* AMD sdhci reset dll register. */
485 #define SDHCI_AMD_RESET_DLL_REGISTER 0x908
487 static int amd_select_drive_strength(struct mmc_card
*card
,
488 unsigned int max_dtr
, int host_drv
,
489 int card_drv
, int *drv_type
)
491 return MMC_SET_DRIVER_TYPE_A
;
494 static void sdhci_acpi_amd_hs400_dll(struct sdhci_host
*host
)
496 /* AMD Platform requires dll setting */
497 sdhci_writel(host
, 0x40003210, SDHCI_AMD_RESET_DLL_REGISTER
);
498 usleep_range(10, 20);
499 sdhci_writel(host
, 0x40033210, SDHCI_AMD_RESET_DLL_REGISTER
);
503 * For AMD Platform it is required to disable the tuning
504 * bit first controller to bring to HS Mode from HS200
505 * mode, later enable to tune to HS400 mode.
507 static void amd_set_ios(struct mmc_host
*mmc
, struct mmc_ios
*ios
)
509 struct sdhci_host
*host
= mmc_priv(mmc
);
510 unsigned int old_timing
= host
->timing
;
512 sdhci_set_ios(mmc
, ios
);
513 if (old_timing
== MMC_TIMING_MMC_HS200
&&
514 ios
->timing
== MMC_TIMING_MMC_HS
)
515 sdhci_writew(host
, 0x9, SDHCI_HOST_CONTROL2
);
516 if (old_timing
!= MMC_TIMING_MMC_HS400
&&
517 ios
->timing
== MMC_TIMING_MMC_HS400
) {
518 sdhci_writew(host
, 0x80, SDHCI_HOST_CONTROL2
);
519 sdhci_acpi_amd_hs400_dll(host
);
523 static const struct sdhci_ops sdhci_acpi_ops_amd
= {
524 .set_clock
= sdhci_set_clock
,
525 .set_bus_width
= sdhci_set_bus_width
,
526 .reset
= sdhci_reset
,
527 .set_uhs_signaling
= sdhci_set_uhs_signaling
,
530 static const struct sdhci_acpi_chip sdhci_acpi_chip_amd
= {
531 .ops
= &sdhci_acpi_ops_amd
,
534 static int sdhci_acpi_emmc_amd_probe_slot(struct platform_device
*pdev
,
535 const char *hid
, const char *uid
)
537 struct sdhci_acpi_host
*c
= platform_get_drvdata(pdev
);
538 struct sdhci_host
*host
= c
->host
;
540 sdhci_read_caps(host
);
541 if (host
->caps1
& SDHCI_SUPPORT_DDR50
)
542 host
->mmc
->caps
= MMC_CAP_1_8V_DDR
;
544 if ((host
->caps1
& SDHCI_SUPPORT_SDR104
) &&
545 (host
->mmc
->caps
& MMC_CAP_1_8V_DDR
))
546 host
->mmc
->caps2
= MMC_CAP2_HS400_1_8V
;
548 host
->mmc_host_ops
.select_drive_strength
= amd_select_drive_strength
;
549 host
->mmc_host_ops
.set_ios
= amd_set_ios
;
553 static const struct sdhci_acpi_slot sdhci_acpi_slot_amd_emmc
= {
554 .chip
= &sdhci_acpi_chip_amd
,
555 .caps
= MMC_CAP_8_BIT_DATA
| MMC_CAP_NONREMOVABLE
,
556 .quirks
= SDHCI_QUIRK_32BIT_DMA_ADDR
| SDHCI_QUIRK_32BIT_DMA_SIZE
|
557 SDHCI_QUIRK_32BIT_ADMA_SIZE
,
558 .probe_slot
= sdhci_acpi_emmc_amd_probe_slot
,
561 struct sdhci_acpi_uid_slot
{
564 const struct sdhci_acpi_slot
*slot
;
567 static const struct sdhci_acpi_uid_slot sdhci_acpi_uids
[] = {
568 { "80865ACA", NULL
, &sdhci_acpi_slot_int_sd
},
569 { "80865ACC", NULL
, &sdhci_acpi_slot_int_emmc
},
570 { "80865AD0", NULL
, &sdhci_acpi_slot_int_sdio
},
571 { "80860F14" , "1" , &sdhci_acpi_slot_int_emmc
},
572 { "80860F14" , "2" , &sdhci_acpi_slot_int_sdio
},
573 { "80860F14" , "3" , &sdhci_acpi_slot_int_sd
},
574 { "80860F16" , NULL
, &sdhci_acpi_slot_int_sd
},
575 { "INT33BB" , "2" , &sdhci_acpi_slot_int_sdio
},
576 { "INT33BB" , "3" , &sdhci_acpi_slot_int_sd
},
577 { "INT33C6" , NULL
, &sdhci_acpi_slot_int_sdio
},
578 { "INT3436" , NULL
, &sdhci_acpi_slot_int_sdio
},
579 { "INT344D" , NULL
, &sdhci_acpi_slot_int_sdio
},
580 { "PNP0FFF" , "3" , &sdhci_acpi_slot_int_sd
},
582 { "QCOM8051", NULL
, &sdhci_acpi_slot_qcom_sd_3v
},
583 { "QCOM8052", NULL
, &sdhci_acpi_slot_qcom_sd
},
584 { "AMDI0040", NULL
, &sdhci_acpi_slot_amd_emmc
},
588 static const struct acpi_device_id sdhci_acpi_ids
[] = {
604 MODULE_DEVICE_TABLE(acpi
, sdhci_acpi_ids
);
606 static const struct sdhci_acpi_slot
*sdhci_acpi_get_slot(const char *hid
,
609 const struct sdhci_acpi_uid_slot
*u
;
611 for (u
= sdhci_acpi_uids
; u
->hid
; u
++) {
612 if (strcmp(u
->hid
, hid
))
616 if (uid
&& !strcmp(u
->uid
, uid
))
622 static int sdhci_acpi_probe(struct platform_device
*pdev
)
624 struct device
*dev
= &pdev
->dev
;
625 const struct sdhci_acpi_slot
*slot
;
626 struct acpi_device
*device
, *child
;
627 struct sdhci_acpi_host
*c
;
628 struct sdhci_host
*host
;
629 struct resource
*iomem
;
636 device
= ACPI_COMPANION(dev
);
640 hid
= acpi_device_hid(device
);
641 uid
= acpi_device_uid(device
);
643 slot
= sdhci_acpi_get_slot(hid
, uid
);
645 /* Power on the SDHCI controller and its children */
646 acpi_device_fix_up_power(device
);
647 if (!sdhci_acpi_no_fixup_child_power(hid
, uid
)) {
648 list_for_each_entry(child
, &device
->children
, node
)
649 if (child
->status
.present
&& child
->status
.enabled
)
650 acpi_device_fix_up_power(child
);
653 if (sdhci_acpi_byt_defer(dev
))
654 return -EPROBE_DEFER
;
656 iomem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
660 len
= resource_size(iomem
);
662 dev_err(dev
, "Invalid iomem size!\n");
664 if (!devm_request_mem_region(dev
, iomem
->start
, len
, dev_name(dev
)))
667 priv_size
= slot
? slot
->priv_size
: 0;
668 host
= sdhci_alloc_host(dev
, sizeof(struct sdhci_acpi_host
) + priv_size
);
670 return PTR_ERR(host
);
672 c
= sdhci_priv(host
);
676 c
->use_runtime_pm
= sdhci_acpi_flag(c
, SDHCI_ACPI_RUNTIME_PM
);
678 platform_set_drvdata(pdev
, c
);
680 host
->hw_name
= "ACPI";
681 host
->ops
= &sdhci_acpi_ops_dflt
;
682 host
->irq
= platform_get_irq(pdev
, 0);
688 host
->ioaddr
= devm_ioremap_nocache(dev
, iomem
->start
,
689 resource_size(iomem
));
690 if (host
->ioaddr
== NULL
) {
696 if (c
->slot
->probe_slot
) {
697 err
= c
->slot
->probe_slot(pdev
, hid
, uid
);
702 host
->ops
= c
->slot
->chip
->ops
;
703 host
->quirks
|= c
->slot
->chip
->quirks
;
704 host
->quirks2
|= c
->slot
->chip
->quirks2
;
705 host
->mmc
->caps
|= c
->slot
->chip
->caps
;
706 host
->mmc
->caps2
|= c
->slot
->chip
->caps2
;
707 host
->mmc
->pm_caps
|= c
->slot
->chip
->pm_caps
;
709 host
->quirks
|= c
->slot
->quirks
;
710 host
->quirks2
|= c
->slot
->quirks2
;
711 host
->mmc
->caps
|= c
->slot
->caps
;
712 host
->mmc
->caps2
|= c
->slot
->caps2
;
713 host
->mmc
->pm_caps
|= c
->slot
->pm_caps
;
716 host
->mmc
->caps2
|= MMC_CAP2_NO_PRESCAN_POWERUP
;
718 if (sdhci_acpi_flag(c
, SDHCI_ACPI_SD_CD
)) {
719 bool v
= sdhci_acpi_flag(c
, SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL
);
721 err
= mmc_gpiod_request_cd(host
->mmc
, NULL
, 0, v
, 0, NULL
);
723 if (err
== -EPROBE_DEFER
)
725 dev_warn(dev
, "failed to setup card detect gpio\n");
726 c
->use_runtime_pm
= false;
730 err
= sdhci_setup_host(host
);
734 if (c
->slot
&& c
->slot
->setup_host
) {
735 err
= c
->slot
->setup_host(pdev
);
740 err
= __sdhci_add_host(host
);
744 if (c
->use_runtime_pm
) {
745 pm_runtime_set_active(dev
);
746 pm_suspend_ignore_children(dev
, 1);
747 pm_runtime_set_autosuspend_delay(dev
, 50);
748 pm_runtime_use_autosuspend(dev
);
749 pm_runtime_enable(dev
);
752 device_enable_async_suspend(dev
);
757 sdhci_cleanup_host(c
->host
);
759 sdhci_free_host(c
->host
);
763 static int sdhci_acpi_remove(struct platform_device
*pdev
)
765 struct sdhci_acpi_host
*c
= platform_get_drvdata(pdev
);
766 struct device
*dev
= &pdev
->dev
;
769 if (c
->use_runtime_pm
) {
770 pm_runtime_get_sync(dev
);
771 pm_runtime_disable(dev
);
772 pm_runtime_put_noidle(dev
);
775 if (c
->slot
&& c
->slot
->remove_slot
)
776 c
->slot
->remove_slot(pdev
);
778 dead
= (sdhci_readl(c
->host
, SDHCI_INT_STATUS
) == ~0);
779 sdhci_remove_host(c
->host
, dead
);
780 sdhci_free_host(c
->host
);
785 #ifdef CONFIG_PM_SLEEP
787 static int sdhci_acpi_suspend(struct device
*dev
)
789 struct sdhci_acpi_host
*c
= dev_get_drvdata(dev
);
790 struct sdhci_host
*host
= c
->host
;
792 if (host
->tuning_mode
!= SDHCI_TUNING_MODE_3
)
793 mmc_retune_needed(host
->mmc
);
795 return sdhci_suspend_host(host
);
798 static int sdhci_acpi_resume(struct device
*dev
)
800 struct sdhci_acpi_host
*c
= dev_get_drvdata(dev
);
802 sdhci_acpi_byt_setting(&c
->pdev
->dev
);
804 return sdhci_resume_host(c
->host
);
811 static int sdhci_acpi_runtime_suspend(struct device
*dev
)
813 struct sdhci_acpi_host
*c
= dev_get_drvdata(dev
);
814 struct sdhci_host
*host
= c
->host
;
816 if (host
->tuning_mode
!= SDHCI_TUNING_MODE_3
)
817 mmc_retune_needed(host
->mmc
);
819 return sdhci_runtime_suspend_host(host
);
822 static int sdhci_acpi_runtime_resume(struct device
*dev
)
824 struct sdhci_acpi_host
*c
= dev_get_drvdata(dev
);
826 sdhci_acpi_byt_setting(&c
->pdev
->dev
);
828 return sdhci_runtime_resume_host(c
->host
);
833 static const struct dev_pm_ops sdhci_acpi_pm_ops
= {
834 SET_SYSTEM_SLEEP_PM_OPS(sdhci_acpi_suspend
, sdhci_acpi_resume
)
835 SET_RUNTIME_PM_OPS(sdhci_acpi_runtime_suspend
,
836 sdhci_acpi_runtime_resume
, NULL
)
839 static struct platform_driver sdhci_acpi_driver
= {
841 .name
= "sdhci-acpi",
842 .acpi_match_table
= sdhci_acpi_ids
,
843 .pm
= &sdhci_acpi_pm_ops
,
845 .probe
= sdhci_acpi_probe
,
846 .remove
= sdhci_acpi_remove
,
849 module_platform_driver(sdhci_acpi_driver
);
851 MODULE_DESCRIPTION("Secure Digital Host Controller Interface ACPI driver");
852 MODULE_AUTHOR("Adrian Hunter");
853 MODULE_LICENSE("GPL v2");