1 // SPDX-License-Identifier: GPL-2.0-only
3 * Secure Digital Host Controller Interface ACPI driver.
5 * Copyright (c) 2012, Intel Corporation.
8 #include <linux/init.h>
9 #include <linux/export.h>
10 #include <linux/module.h>
11 #include <linux/device.h>
12 #include <linux/platform_device.h>
13 #include <linux/ioport.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/compiler.h>
17 #include <linux/stddef.h>
18 #include <linux/bitops.h>
19 #include <linux/types.h>
20 #include <linux/err.h>
21 #include <linux/interrupt.h>
22 #include <linux/acpi.h>
24 #include <linux/pm_runtime.h>
25 #include <linux/delay.h>
27 #include <linux/mmc/host.h>
28 #include <linux/mmc/pm.h>
29 #include <linux/mmc/slot-gpio.h>
32 #include <asm/cpu_device_id.h>
33 #include <asm/intel-family.h>
34 #include <asm/iosf_mbi.h>
35 #include <linux/pci.h>
41 SDHCI_ACPI_SD_CD = BIT(0),
42 SDHCI_ACPI_RUNTIME_PM = BIT(1),
43 SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL = BIT(2),
46 struct sdhci_acpi_chip {
47 const struct sdhci_ops *ops;
52 mmc_pm_flag_t pm_caps;
55 struct sdhci_acpi_slot {
56 const struct sdhci_acpi_chip *chip;
61 mmc_pm_flag_t pm_caps;
64 int (*probe_slot)(struct platform_device *, struct acpi_device *);
65 int (*remove_slot)(struct platform_device *);
66 int (*free_slot)(struct platform_device *pdev);
67 int (*setup_host)(struct platform_device *pdev);
70 struct sdhci_acpi_host {
71 struct sdhci_host *host;
72 const struct sdhci_acpi_slot *slot;
73 struct platform_device *pdev;
75 unsigned long private[0] ____cacheline_aligned;
78 static inline void *sdhci_acpi_priv(struct sdhci_acpi_host *c)
80 return (void *)c->private;
83 static inline bool sdhci_acpi_flag(struct sdhci_acpi_host *c, unsigned int flag)
85 return c->slot && (c->slot->flags & flag);
88 #define INTEL_DSM_HS_CAPS_SDR25 BIT(0)
89 #define INTEL_DSM_HS_CAPS_DDR50 BIT(1)
90 #define INTEL_DSM_HS_CAPS_SDR50 BIT(2)
91 #define INTEL_DSM_HS_CAPS_SDR104 BIT(3)
95 INTEL_DSM_V18_SWITCH = 3,
96 INTEL_DSM_V33_SWITCH = 4,
97 INTEL_DSM_HS_CAPS = 8,
105 static const guid_t intel_dsm_guid =
106 GUID_INIT(0xF6C13EA5, 0x65CD, 0x461F,
107 0xAB, 0x7A, 0x29, 0xF7, 0xE8, 0xD5, 0xBD, 0x61);
109 static int __intel_dsm(struct intel_host *intel_host, struct device *dev,
110 unsigned int fn, u32 *result)
112 union acpi_object *obj;
115 obj = acpi_evaluate_dsm(ACPI_HANDLE(dev), &intel_dsm_guid, 0, fn, NULL);
119 if (obj->type == ACPI_TYPE_INTEGER) {
120 *result = obj->integer.value;
121 } else if (obj->type == ACPI_TYPE_BUFFER && obj->buffer.length > 0) {
122 size_t len = min_t(size_t, obj->buffer.length, 4);
125 memcpy(result, obj->buffer.pointer, len);
127 dev_err(dev, "%s DSM fn %u obj->type %d obj->buffer.length %d\n",
128 __func__, fn, obj->type, obj->buffer.length);
137 static int intel_dsm(struct intel_host *intel_host, struct device *dev,
138 unsigned int fn, u32 *result)
140 if (fn > 31 || !(intel_host->dsm_fns & (1 << fn)))
143 return __intel_dsm(intel_host, dev, fn, result);
146 static void intel_dsm_init(struct intel_host *intel_host, struct device *dev,
147 struct mmc_host *mmc)
151 intel_host->hs_caps = ~0;
153 err = __intel_dsm(intel_host, dev, INTEL_DSM_FNS, &intel_host->dsm_fns);
155 pr_debug("%s: DSM not supported, error %d\n",
156 mmc_hostname(mmc), err);
160 pr_debug("%s: DSM function mask %#x\n",
161 mmc_hostname(mmc), intel_host->dsm_fns);
163 intel_dsm(intel_host, dev, INTEL_DSM_HS_CAPS, &intel_host->hs_caps);
166 static int intel_start_signal_voltage_switch(struct mmc_host *mmc,
169 struct device *dev = mmc_dev(mmc);
170 struct sdhci_acpi_host *c = dev_get_drvdata(dev);
171 struct intel_host *intel_host = sdhci_acpi_priv(c);
176 err = sdhci_start_signal_voltage_switch(mmc, ios);
180 switch (ios->signal_voltage) {
181 case MMC_SIGNAL_VOLTAGE_330:
182 fn = INTEL_DSM_V33_SWITCH;
184 case MMC_SIGNAL_VOLTAGE_180:
185 fn = INTEL_DSM_V18_SWITCH;
191 err = intel_dsm(intel_host, dev, fn, &result);
192 pr_debug("%s: %s DSM fn %u error %d result %u\n",
193 mmc_hostname(mmc), __func__, fn, err, result);
198 static void sdhci_acpi_int_hw_reset(struct sdhci_host *host)
202 reg = sdhci_readb(host, SDHCI_POWER_CONTROL);
204 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
205 /* For eMMC, minimum is 1us but give it 9us for good measure */
208 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
209 /* For eMMC, minimum is 200us but give it 300us for good measure */
210 usleep_range(300, 1000);
213 static const struct sdhci_ops sdhci_acpi_ops_dflt = {
214 .set_clock = sdhci_set_clock,
215 .set_bus_width = sdhci_set_bus_width,
216 .reset = sdhci_reset,
217 .set_uhs_signaling = sdhci_set_uhs_signaling,
220 static const struct sdhci_ops sdhci_acpi_ops_int = {
221 .set_clock = sdhci_set_clock,
222 .set_bus_width = sdhci_set_bus_width,
223 .reset = sdhci_reset,
224 .set_uhs_signaling = sdhci_set_uhs_signaling,
225 .hw_reset = sdhci_acpi_int_hw_reset,
228 static const struct sdhci_acpi_chip sdhci_acpi_chip_int = {
229 .ops = &sdhci_acpi_ops_int,
234 static bool sdhci_acpi_byt(void)
236 static const struct x86_cpu_id byt[] = {
237 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT },
241 return x86_match_cpu(byt);
244 static bool sdhci_acpi_cht(void)
246 static const struct x86_cpu_id cht[] = {
247 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_AIRMONT },
251 return x86_match_cpu(cht);
254 #define BYT_IOSF_SCCEP 0x63
255 #define BYT_IOSF_OCP_NETCTRL0 0x1078
256 #define BYT_IOSF_OCP_TIMEOUT_BASE GENMASK(10, 8)
258 static void sdhci_acpi_byt_setting(struct device *dev)
262 if (!sdhci_acpi_byt())
265 if (iosf_mbi_read(BYT_IOSF_SCCEP, MBI_CR_READ, BYT_IOSF_OCP_NETCTRL0,
267 dev_err(dev, "%s read error\n", __func__);
271 if (!(val & BYT_IOSF_OCP_TIMEOUT_BASE))
274 val &= ~BYT_IOSF_OCP_TIMEOUT_BASE;
276 if (iosf_mbi_write(BYT_IOSF_SCCEP, MBI_CR_WRITE, BYT_IOSF_OCP_NETCTRL0,
278 dev_err(dev, "%s write error\n", __func__);
282 dev_dbg(dev, "%s completed\n", __func__);
285 static bool sdhci_acpi_byt_defer(struct device *dev)
287 if (!sdhci_acpi_byt())
290 if (!iosf_mbi_available())
293 sdhci_acpi_byt_setting(dev);
298 static bool sdhci_acpi_cht_pci_wifi(unsigned int vendor, unsigned int device,
299 unsigned int slot, unsigned int parent_slot)
301 struct pci_dev *dev, *parent, *from = NULL;
304 dev = pci_get_device(vendor, device, from);
308 parent = pci_upstream_bridge(dev);
309 if (ACPI_COMPANION(&dev->dev) && PCI_SLOT(dev->devfn) == slot &&
310 parent && PCI_SLOT(parent->devfn) == parent_slot &&
311 !pci_upstream_bridge(parent)) {
322 * GPDwin uses PCI wifi which conflicts with SDIO's use of
323 * acpi_device_fix_up_power() on child device nodes. Identifying GPDwin is
324 * problematic, but since SDIO is only used for wifi, the presence of the PCI
325 * wifi card in the expected slot with an ACPI companion node, is used to
326 * indicate that acpi_device_fix_up_power() should be avoided.
328 static inline bool sdhci_acpi_no_fixup_child_power(struct acpi_device *adev)
330 return sdhci_acpi_cht() &&
331 acpi_dev_hid_uid_match(adev, "80860F14", "2") &&
332 sdhci_acpi_cht_pci_wifi(0x14e4, 0x43ec, 0, 28);
337 static inline void sdhci_acpi_byt_setting(struct device *dev)
341 static inline bool sdhci_acpi_byt_defer(struct device *dev)
346 static inline bool sdhci_acpi_no_fixup_child_power(struct acpi_device *adev)
353 static int bxt_get_cd(struct mmc_host *mmc)
355 int gpio_cd = mmc_gpio_get_cd(mmc);
356 struct sdhci_host *host = mmc_priv(mmc);
363 spin_lock_irqsave(&host->lock, flags);
365 if (host->flags & SDHCI_DEVICE_DEAD)
368 ret = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
370 spin_unlock_irqrestore(&host->lock, flags);
375 static int intel_probe_slot(struct platform_device *pdev, struct acpi_device *adev)
377 struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
378 struct intel_host *intel_host = sdhci_acpi_priv(c);
379 struct sdhci_host *host = c->host;
381 if (acpi_dev_hid_uid_match(adev, "80860F14", "1") &&
382 sdhci_readl(host, SDHCI_CAPABILITIES) == 0x446cc8b2 &&
383 sdhci_readl(host, SDHCI_CAPABILITIES_1) == 0x00000807)
384 host->timeout_clk = 1000; /* 1000 kHz i.e. 1 MHz */
386 if (acpi_dev_hid_uid_match(adev, "80865ACA", NULL))
387 host->mmc_host_ops.get_cd = bxt_get_cd;
389 intel_dsm_init(intel_host, &pdev->dev, host->mmc);
391 host->mmc_host_ops.start_signal_voltage_switch =
392 intel_start_signal_voltage_switch;
397 static int intel_setup_host(struct platform_device *pdev)
399 struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
400 struct intel_host *intel_host = sdhci_acpi_priv(c);
402 if (!(intel_host->hs_caps & INTEL_DSM_HS_CAPS_SDR25))
403 c->host->mmc->caps &= ~MMC_CAP_UHS_SDR25;
405 if (!(intel_host->hs_caps & INTEL_DSM_HS_CAPS_SDR50))
406 c->host->mmc->caps &= ~MMC_CAP_UHS_SDR50;
408 if (!(intel_host->hs_caps & INTEL_DSM_HS_CAPS_DDR50))
409 c->host->mmc->caps &= ~MMC_CAP_UHS_DDR50;
411 if (!(intel_host->hs_caps & INTEL_DSM_HS_CAPS_SDR104))
412 c->host->mmc->caps &= ~MMC_CAP_UHS_SDR104;
417 static const struct sdhci_acpi_slot sdhci_acpi_slot_int_emmc = {
418 .chip = &sdhci_acpi_chip_int,
419 .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
420 MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR |
421 MMC_CAP_CMD_DURING_TFR | MMC_CAP_WAIT_WHILE_BUSY,
422 .flags = SDHCI_ACPI_RUNTIME_PM,
423 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC |
425 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
426 SDHCI_QUIRK2_STOP_WITH_TC |
427 SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400,
428 .probe_slot = intel_probe_slot,
429 .setup_host = intel_setup_host,
430 .priv_size = sizeof(struct intel_host),
433 static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = {
434 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
436 SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
437 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
438 .caps = MMC_CAP_NONREMOVABLE | MMC_CAP_POWER_OFF_CARD |
439 MMC_CAP_WAIT_WHILE_BUSY,
440 .flags = SDHCI_ACPI_RUNTIME_PM,
441 .pm_caps = MMC_PM_KEEP_POWER,
442 .probe_slot = intel_probe_slot,
443 .setup_host = intel_setup_host,
444 .priv_size = sizeof(struct intel_host),
447 static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = {
448 .flags = SDHCI_ACPI_SD_CD | SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL |
449 SDHCI_ACPI_RUNTIME_PM,
450 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC |
452 .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON |
453 SDHCI_QUIRK2_STOP_WITH_TC,
454 .caps = MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_AGGRESSIVE_PM,
455 .probe_slot = intel_probe_slot,
456 .setup_host = intel_setup_host,
457 .priv_size = sizeof(struct intel_host),
460 #define VENDOR_SPECIFIC_PWRCTL_CLEAR_REG 0x1a8
461 #define VENDOR_SPECIFIC_PWRCTL_CTL_REG 0x1ac
462 static irqreturn_t sdhci_acpi_qcom_handler(int irq, void *ptr)
464 struct sdhci_host *host = ptr;
466 sdhci_writel(host, 0x3, VENDOR_SPECIFIC_PWRCTL_CLEAR_REG);
467 sdhci_writel(host, 0x1, VENDOR_SPECIFIC_PWRCTL_CTL_REG);
472 static int qcom_probe_slot(struct platform_device *pdev, struct acpi_device *adev)
474 struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
475 struct sdhci_host *host = c->host;
476 int *irq = sdhci_acpi_priv(c);
480 if (!acpi_dev_hid_uid_match(adev, "QCOM8051", NULL))
483 *irq = platform_get_irq(pdev, 1);
487 return request_threaded_irq(*irq, NULL, sdhci_acpi_qcom_handler,
488 IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
492 static int qcom_free_slot(struct platform_device *pdev)
494 struct device *dev = &pdev->dev;
495 struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
496 struct sdhci_host *host = c->host;
497 struct acpi_device *adev;
498 int *irq = sdhci_acpi_priv(c);
500 adev = ACPI_COMPANION(dev);
504 if (!acpi_dev_hid_uid_match(adev, "QCOM8051", NULL))
510 free_irq(*irq, host);
514 static const struct sdhci_acpi_slot sdhci_acpi_slot_qcom_sd_3v = {
515 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION,
516 .quirks2 = SDHCI_QUIRK2_NO_1_8_V,
517 .caps = MMC_CAP_NONREMOVABLE,
518 .priv_size = sizeof(int),
519 .probe_slot = qcom_probe_slot,
520 .free_slot = qcom_free_slot,
523 static const struct sdhci_acpi_slot sdhci_acpi_slot_qcom_sd = {
524 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION,
525 .caps = MMC_CAP_NONREMOVABLE,
528 /* AMD sdhci reset dll register. */
529 #define SDHCI_AMD_RESET_DLL_REGISTER 0x908
531 static int amd_select_drive_strength(struct mmc_card *card,
532 unsigned int max_dtr, int host_drv,
533 int card_drv, int *drv_type)
535 return MMC_SET_DRIVER_TYPE_A;
538 static void sdhci_acpi_amd_hs400_dll(struct sdhci_host *host)
540 /* AMD Platform requires dll setting */
541 sdhci_writel(host, 0x40003210, SDHCI_AMD_RESET_DLL_REGISTER);
542 usleep_range(10, 20);
543 sdhci_writel(host, 0x40033210, SDHCI_AMD_RESET_DLL_REGISTER);
547 * For AMD Platform it is required to disable the tuning
548 * bit first controller to bring to HS Mode from HS200
549 * mode, later enable to tune to HS400 mode.
551 static void amd_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
553 struct sdhci_host *host = mmc_priv(mmc);
554 unsigned int old_timing = host->timing;
556 sdhci_set_ios(mmc, ios);
557 if (old_timing == MMC_TIMING_MMC_HS200 &&
558 ios->timing == MMC_TIMING_MMC_HS)
559 sdhci_writew(host, 0x9, SDHCI_HOST_CONTROL2);
560 if (old_timing != MMC_TIMING_MMC_HS400 &&
561 ios->timing == MMC_TIMING_MMC_HS400) {
562 sdhci_writew(host, 0x80, SDHCI_HOST_CONTROL2);
563 sdhci_acpi_amd_hs400_dll(host);
567 static const struct sdhci_ops sdhci_acpi_ops_amd = {
568 .set_clock = sdhci_set_clock,
569 .set_bus_width = sdhci_set_bus_width,
570 .reset = sdhci_reset,
571 .set_uhs_signaling = sdhci_set_uhs_signaling,
574 static const struct sdhci_acpi_chip sdhci_acpi_chip_amd = {
575 .ops = &sdhci_acpi_ops_amd,
578 static int sdhci_acpi_emmc_amd_probe_slot(struct platform_device *pdev,
579 struct acpi_device *adev)
581 struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
582 struct sdhci_host *host = c->host;
584 sdhci_read_caps(host);
585 if (host->caps1 & SDHCI_SUPPORT_DDR50)
586 host->mmc->caps = MMC_CAP_1_8V_DDR;
588 if ((host->caps1 & SDHCI_SUPPORT_SDR104) &&
589 (host->mmc->caps & MMC_CAP_1_8V_DDR))
590 host->mmc->caps2 = MMC_CAP2_HS400_1_8V;
592 host->mmc_host_ops.select_drive_strength = amd_select_drive_strength;
593 host->mmc_host_ops.set_ios = amd_set_ios;
597 static const struct sdhci_acpi_slot sdhci_acpi_slot_amd_emmc = {
598 .chip = &sdhci_acpi_chip_amd,
599 .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
600 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_32BIT_DMA_SIZE |
601 SDHCI_QUIRK_32BIT_ADMA_SIZE,
602 .probe_slot = sdhci_acpi_emmc_amd_probe_slot,
605 struct sdhci_acpi_uid_slot {
608 const struct sdhci_acpi_slot *slot;
611 static const struct sdhci_acpi_uid_slot sdhci_acpi_uids[] = {
612 { "80865ACA", NULL, &sdhci_acpi_slot_int_sd },
613 { "80865ACC", NULL, &sdhci_acpi_slot_int_emmc },
614 { "80865AD0", NULL, &sdhci_acpi_slot_int_sdio },
615 { "80860F14" , "1" , &sdhci_acpi_slot_int_emmc },
616 { "80860F14" , "2" , &sdhci_acpi_slot_int_sdio },
617 { "80860F14" , "3" , &sdhci_acpi_slot_int_sd },
618 { "80860F16" , NULL, &sdhci_acpi_slot_int_sd },
619 { "INT33BB" , "2" , &sdhci_acpi_slot_int_sdio },
620 { "INT33BB" , "3" , &sdhci_acpi_slot_int_sd },
621 { "INT33C6" , NULL, &sdhci_acpi_slot_int_sdio },
622 { "INT3436" , NULL, &sdhci_acpi_slot_int_sdio },
623 { "INT344D" , NULL, &sdhci_acpi_slot_int_sdio },
624 { "PNP0FFF" , "3" , &sdhci_acpi_slot_int_sd },
626 { "QCOM8051", NULL, &sdhci_acpi_slot_qcom_sd_3v },
627 { "QCOM8052", NULL, &sdhci_acpi_slot_qcom_sd },
628 { "AMDI0040", NULL, &sdhci_acpi_slot_amd_emmc },
632 static const struct acpi_device_id sdhci_acpi_ids[] = {
648 MODULE_DEVICE_TABLE(acpi, sdhci_acpi_ids);
650 static const struct sdhci_acpi_slot *sdhci_acpi_get_slot(struct acpi_device *adev)
652 const struct sdhci_acpi_uid_slot *u;
654 for (u = sdhci_acpi_uids; u->hid; u++) {
655 if (acpi_dev_hid_uid_match(adev, u->hid, u->uid))
661 static int sdhci_acpi_probe(struct platform_device *pdev)
663 struct device *dev = &pdev->dev;
664 const struct sdhci_acpi_slot *slot;
665 struct acpi_device *device, *child;
666 struct sdhci_acpi_host *c;
667 struct sdhci_host *host;
668 struct resource *iomem;
673 device = ACPI_COMPANION(dev);
677 slot = sdhci_acpi_get_slot(device);
679 /* Power on the SDHCI controller and its children */
680 acpi_device_fix_up_power(device);
681 if (!sdhci_acpi_no_fixup_child_power(device)) {
682 list_for_each_entry(child, &device->children, node)
683 if (child->status.present && child->status.enabled)
684 acpi_device_fix_up_power(child);
687 if (sdhci_acpi_byt_defer(dev))
688 return -EPROBE_DEFER;
690 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
694 len = resource_size(iomem);
696 dev_err(dev, "Invalid iomem size!\n");
698 if (!devm_request_mem_region(dev, iomem->start, len, dev_name(dev)))
701 priv_size = slot ? slot->priv_size : 0;
702 host = sdhci_alloc_host(dev, sizeof(struct sdhci_acpi_host) + priv_size);
704 return PTR_ERR(host);
706 c = sdhci_priv(host);
710 c->use_runtime_pm = sdhci_acpi_flag(c, SDHCI_ACPI_RUNTIME_PM);
712 platform_set_drvdata(pdev, c);
714 host->hw_name = "ACPI";
715 host->ops = &sdhci_acpi_ops_dflt;
716 host->irq = platform_get_irq(pdev, 0);
722 host->ioaddr = devm_ioremap(dev, iomem->start,
723 resource_size(iomem));
724 if (host->ioaddr == NULL) {
730 if (c->slot->probe_slot) {
731 err = c->slot->probe_slot(pdev, device);
736 host->ops = c->slot->chip->ops;
737 host->quirks |= c->slot->chip->quirks;
738 host->quirks2 |= c->slot->chip->quirks2;
739 host->mmc->caps |= c->slot->chip->caps;
740 host->mmc->caps2 |= c->slot->chip->caps2;
741 host->mmc->pm_caps |= c->slot->chip->pm_caps;
743 host->quirks |= c->slot->quirks;
744 host->quirks2 |= c->slot->quirks2;
745 host->mmc->caps |= c->slot->caps;
746 host->mmc->caps2 |= c->slot->caps2;
747 host->mmc->pm_caps |= c->slot->pm_caps;
750 host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
752 if (sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD)) {
753 bool v = sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL);
755 err = mmc_gpiod_request_cd(host->mmc, NULL, 0, v, 0);
757 if (err == -EPROBE_DEFER)
759 dev_warn(dev, "failed to setup card detect gpio\n");
760 c->use_runtime_pm = false;
764 err = sdhci_setup_host(host);
768 if (c->slot && c->slot->setup_host) {
769 err = c->slot->setup_host(pdev);
774 err = __sdhci_add_host(host);
778 if (c->use_runtime_pm) {
779 pm_runtime_set_active(dev);
780 pm_suspend_ignore_children(dev, 1);
781 pm_runtime_set_autosuspend_delay(dev, 50);
782 pm_runtime_use_autosuspend(dev);
783 pm_runtime_enable(dev);
786 device_enable_async_suspend(dev);
791 sdhci_cleanup_host(c->host);
793 if (c->slot && c->slot->free_slot)
794 c->slot->free_slot(pdev);
796 sdhci_free_host(c->host);
800 static int sdhci_acpi_remove(struct platform_device *pdev)
802 struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
803 struct device *dev = &pdev->dev;
806 if (c->use_runtime_pm) {
807 pm_runtime_get_sync(dev);
808 pm_runtime_disable(dev);
809 pm_runtime_put_noidle(dev);
812 if (c->slot && c->slot->remove_slot)
813 c->slot->remove_slot(pdev);
815 dead = (sdhci_readl(c->host, SDHCI_INT_STATUS) == ~0);
816 sdhci_remove_host(c->host, dead);
818 if (c->slot && c->slot->free_slot)
819 c->slot->free_slot(pdev);
821 sdhci_free_host(c->host);
826 #ifdef CONFIG_PM_SLEEP
828 static int sdhci_acpi_suspend(struct device *dev)
830 struct sdhci_acpi_host *c = dev_get_drvdata(dev);
831 struct sdhci_host *host = c->host;
833 if (host->tuning_mode != SDHCI_TUNING_MODE_3)
834 mmc_retune_needed(host->mmc);
836 return sdhci_suspend_host(host);
839 static int sdhci_acpi_resume(struct device *dev)
841 struct sdhci_acpi_host *c = dev_get_drvdata(dev);
843 sdhci_acpi_byt_setting(&c->pdev->dev);
845 return sdhci_resume_host(c->host);
852 static int sdhci_acpi_runtime_suspend(struct device *dev)
854 struct sdhci_acpi_host *c = dev_get_drvdata(dev);
855 struct sdhci_host *host = c->host;
857 if (host->tuning_mode != SDHCI_TUNING_MODE_3)
858 mmc_retune_needed(host->mmc);
860 return sdhci_runtime_suspend_host(host);
863 static int sdhci_acpi_runtime_resume(struct device *dev)
865 struct sdhci_acpi_host *c = dev_get_drvdata(dev);
867 sdhci_acpi_byt_setting(&c->pdev->dev);
869 return sdhci_runtime_resume_host(c->host, 0);
874 static const struct dev_pm_ops sdhci_acpi_pm_ops = {
875 SET_SYSTEM_SLEEP_PM_OPS(sdhci_acpi_suspend, sdhci_acpi_resume)
876 SET_RUNTIME_PM_OPS(sdhci_acpi_runtime_suspend,
877 sdhci_acpi_runtime_resume, NULL)
880 static struct platform_driver sdhci_acpi_driver = {
882 .name = "sdhci-acpi",
883 .acpi_match_table = sdhci_acpi_ids,
884 .pm = &sdhci_acpi_pm_ops,
886 .probe = sdhci_acpi_probe,
887 .remove = sdhci_acpi_remove,
890 module_platform_driver(sdhci_acpi_driver);
892 MODULE_DESCRIPTION("Secure Digital Host Controller Interface ACPI driver");
893 MODULE_AUTHOR("Adrian Hunter");
894 MODULE_LICENSE("GPL v2");