1c4e05037SAdrian Hunter /* 2c4e05037SAdrian Hunter * Secure Digital Host Controller Interface ACPI driver. 3c4e05037SAdrian Hunter * 4c4e05037SAdrian Hunter * Copyright (c) 2012, Intel Corporation. 5c4e05037SAdrian Hunter * 6c4e05037SAdrian Hunter * This program is free software; you can redistribute it and/or modify it 7c4e05037SAdrian Hunter * under the terms and conditions of the GNU General Public License, 8c4e05037SAdrian Hunter * version 2, as published by the Free Software Foundation. 9c4e05037SAdrian Hunter * 10c4e05037SAdrian Hunter * This program is distributed in the hope it will be useful, but WITHOUT 11c4e05037SAdrian Hunter * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12c4e05037SAdrian Hunter * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13c4e05037SAdrian Hunter * more details. 14c4e05037SAdrian Hunter * 15c4e05037SAdrian Hunter * You should have received a copy of the GNU General Public License along with 16c4e05037SAdrian Hunter * this program; if not, write to the Free Software Foundation, Inc., 17c4e05037SAdrian Hunter * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 18c4e05037SAdrian Hunter * 19c4e05037SAdrian Hunter */ 20c4e05037SAdrian Hunter 21c4e05037SAdrian Hunter #include <linux/init.h> 22c4e05037SAdrian Hunter #include <linux/export.h> 23c4e05037SAdrian Hunter #include <linux/module.h> 24c4e05037SAdrian Hunter #include <linux/device.h> 25c4e05037SAdrian Hunter #include <linux/platform_device.h> 26c4e05037SAdrian Hunter #include <linux/ioport.h> 27c4e05037SAdrian Hunter #include <linux/io.h> 28c4e05037SAdrian Hunter #include <linux/dma-mapping.h> 29c4e05037SAdrian Hunter #include <linux/compiler.h> 30c4e05037SAdrian Hunter #include <linux/stddef.h> 31c4e05037SAdrian Hunter #include <linux/bitops.h> 32c4e05037SAdrian Hunter #include <linux/types.h> 33c4e05037SAdrian Hunter #include <linux/err.h> 34c4e05037SAdrian Hunter #include <linux/interrupt.h> 35c4e05037SAdrian Hunter #include <linux/acpi.h> 36c4e05037SAdrian Hunter #include <linux/pm.h> 37c4e05037SAdrian Hunter #include <linux/pm_runtime.h> 38b04fa064SAdrian Hunter #include <linux/delay.h> 39c4e05037SAdrian Hunter 40c4e05037SAdrian Hunter #include <linux/mmc/host.h> 41c4e05037SAdrian Hunter #include <linux/mmc/pm.h> 424fd4409cSAdrian Hunter #include <linux/mmc/slot-gpio.h> 43c4e05037SAdrian Hunter #include <linux/mmc/sdhci.h> 44c4e05037SAdrian Hunter 45c4e05037SAdrian Hunter #include "sdhci.h" 46c4e05037SAdrian Hunter 47c4e05037SAdrian Hunter enum { 48c4e05037SAdrian Hunter SDHCI_ACPI_SD_CD = BIT(0), 49c4e05037SAdrian Hunter SDHCI_ACPI_RUNTIME_PM = BIT(1), 504fd4409cSAdrian Hunter SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL = BIT(2), 51c4e05037SAdrian Hunter }; 52c4e05037SAdrian Hunter 53c4e05037SAdrian Hunter struct sdhci_acpi_chip { 54c4e05037SAdrian Hunter const struct sdhci_ops *ops; 55c4e05037SAdrian Hunter unsigned int quirks; 56c4e05037SAdrian Hunter unsigned int quirks2; 57c4e05037SAdrian Hunter unsigned long caps; 58c4e05037SAdrian Hunter unsigned int caps2; 59c4e05037SAdrian Hunter mmc_pm_flag_t pm_caps; 60c4e05037SAdrian Hunter }; 61c4e05037SAdrian Hunter 62c4e05037SAdrian Hunter struct sdhci_acpi_slot { 63c4e05037SAdrian Hunter const struct sdhci_acpi_chip *chip; 64c4e05037SAdrian Hunter unsigned int quirks; 65c4e05037SAdrian Hunter unsigned int quirks2; 66c4e05037SAdrian Hunter unsigned long caps; 67c4e05037SAdrian Hunter unsigned int caps2; 68c4e05037SAdrian Hunter mmc_pm_flag_t pm_caps; 69c4e05037SAdrian Hunter unsigned int flags; 707dafca83SAdrian Hunter int (*probe_slot)(struct platform_device *, const char *, const char *); 71578b36b6SGao, Yunpeng int (*remove_slot)(struct platform_device *); 72c4e05037SAdrian Hunter }; 73c4e05037SAdrian Hunter 74c4e05037SAdrian Hunter struct sdhci_acpi_host { 75c4e05037SAdrian Hunter struct sdhci_host *host; 76c4e05037SAdrian Hunter const struct sdhci_acpi_slot *slot; 77c4e05037SAdrian Hunter struct platform_device *pdev; 78c4e05037SAdrian Hunter bool use_runtime_pm; 794f64f843SAdrian Hunter bool dma_setup; 80c4e05037SAdrian Hunter }; 81c4e05037SAdrian Hunter 82c4e05037SAdrian Hunter static inline bool sdhci_acpi_flag(struct sdhci_acpi_host *c, unsigned int flag) 83c4e05037SAdrian Hunter { 84c4e05037SAdrian Hunter return c->slot && (c->slot->flags & flag); 85c4e05037SAdrian Hunter } 86c4e05037SAdrian Hunter 87c4e05037SAdrian Hunter static int sdhci_acpi_enable_dma(struct sdhci_host *host) 88c4e05037SAdrian Hunter { 894f64f843SAdrian Hunter struct sdhci_acpi_host *c = sdhci_priv(host); 904f64f843SAdrian Hunter struct device *dev = &c->pdev->dev; 914f64f843SAdrian Hunter int err = -1; 924f64f843SAdrian Hunter 934f64f843SAdrian Hunter if (c->dma_setup) 94c4e05037SAdrian Hunter return 0; 954f64f843SAdrian Hunter 964f64f843SAdrian Hunter if (host->flags & SDHCI_USE_64_BIT_DMA) { 974f64f843SAdrian Hunter if (host->quirks2 & SDHCI_QUIRK2_BROKEN_64_BIT_DMA) { 984f64f843SAdrian Hunter host->flags &= ~SDHCI_USE_64_BIT_DMA; 994f64f843SAdrian Hunter } else { 1004f64f843SAdrian Hunter err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); 1014f64f843SAdrian Hunter if (err) 1024f64f843SAdrian Hunter dev_warn(dev, "Failed to set 64-bit DMA mask\n"); 1034f64f843SAdrian Hunter } 1044f64f843SAdrian Hunter } 1054f64f843SAdrian Hunter 1064f64f843SAdrian Hunter if (err) 1074f64f843SAdrian Hunter err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); 1084f64f843SAdrian Hunter 1094f64f843SAdrian Hunter c->dma_setup = !err; 1104f64f843SAdrian Hunter 1114f64f843SAdrian Hunter return err; 112c4e05037SAdrian Hunter } 113c4e05037SAdrian Hunter 114b04fa064SAdrian Hunter static void sdhci_acpi_int_hw_reset(struct sdhci_host *host) 115b04fa064SAdrian Hunter { 116b04fa064SAdrian Hunter u8 reg; 117b04fa064SAdrian Hunter 118b04fa064SAdrian Hunter reg = sdhci_readb(host, SDHCI_POWER_CONTROL); 119b04fa064SAdrian Hunter reg |= 0x10; 120b04fa064SAdrian Hunter sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); 121b04fa064SAdrian Hunter /* For eMMC, minimum is 1us but give it 9us for good measure */ 122b04fa064SAdrian Hunter udelay(9); 123b04fa064SAdrian Hunter reg &= ~0x10; 124b04fa064SAdrian Hunter sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); 125b04fa064SAdrian Hunter /* For eMMC, minimum is 200us but give it 300us for good measure */ 126b04fa064SAdrian Hunter usleep_range(300, 1000); 127b04fa064SAdrian Hunter } 128b04fa064SAdrian Hunter 129c4e05037SAdrian Hunter static const struct sdhci_ops sdhci_acpi_ops_dflt = { 1301771059cSRussell King .set_clock = sdhci_set_clock, 131c4e05037SAdrian Hunter .enable_dma = sdhci_acpi_enable_dma, 1322317f56cSRussell King .set_bus_width = sdhci_set_bus_width, 13303231f9bSRussell King .reset = sdhci_reset, 13496d7b78cSRussell King .set_uhs_signaling = sdhci_set_uhs_signaling, 135c4e05037SAdrian Hunter }; 136c4e05037SAdrian Hunter 137b04fa064SAdrian Hunter static const struct sdhci_ops sdhci_acpi_ops_int = { 1381771059cSRussell King .set_clock = sdhci_set_clock, 139b04fa064SAdrian Hunter .enable_dma = sdhci_acpi_enable_dma, 1402317f56cSRussell King .set_bus_width = sdhci_set_bus_width, 14103231f9bSRussell King .reset = sdhci_reset, 14296d7b78cSRussell King .set_uhs_signaling = sdhci_set_uhs_signaling, 143b04fa064SAdrian Hunter .hw_reset = sdhci_acpi_int_hw_reset, 144b04fa064SAdrian Hunter }; 145b04fa064SAdrian Hunter 146b04fa064SAdrian Hunter static const struct sdhci_acpi_chip sdhci_acpi_chip_int = { 147b04fa064SAdrian Hunter .ops = &sdhci_acpi_ops_int, 148b04fa064SAdrian Hunter }; 149b04fa064SAdrian Hunter 1507dafca83SAdrian Hunter static int sdhci_acpi_emmc_probe_slot(struct platform_device *pdev, 1517dafca83SAdrian Hunter const char *hid, const char *uid) 152578b36b6SGao, Yunpeng { 153578b36b6SGao, Yunpeng struct sdhci_acpi_host *c = platform_get_drvdata(pdev); 154578b36b6SGao, Yunpeng struct sdhci_host *host; 155578b36b6SGao, Yunpeng 156578b36b6SGao, Yunpeng if (!c || !c->host) 157578b36b6SGao, Yunpeng return 0; 158578b36b6SGao, Yunpeng 159578b36b6SGao, Yunpeng host = c->host; 160578b36b6SGao, Yunpeng 161578b36b6SGao, Yunpeng /* Platform specific code during emmc proble slot goes here */ 162578b36b6SGao, Yunpeng 1638024379eSAdrian Hunter if (hid && uid && !strcmp(hid, "80860F14") && !strcmp(uid, "1") && 1648024379eSAdrian Hunter sdhci_readl(host, SDHCI_CAPABILITIES) == 0x446cc8b2 && 1658024379eSAdrian Hunter sdhci_readl(host, SDHCI_CAPABILITIES_1) == 0x00000807) 1668024379eSAdrian Hunter host->timeout_clk = 1000; /* 1000 kHz i.e. 1 MHz */ 1678024379eSAdrian Hunter 168578b36b6SGao, Yunpeng return 0; 169578b36b6SGao, Yunpeng } 170578b36b6SGao, Yunpeng 1717dafca83SAdrian Hunter static int sdhci_acpi_sdio_probe_slot(struct platform_device *pdev, 1727dafca83SAdrian Hunter const char *hid, const char *uid) 173578b36b6SGao, Yunpeng { 174578b36b6SGao, Yunpeng struct sdhci_acpi_host *c = platform_get_drvdata(pdev); 175578b36b6SGao, Yunpeng struct sdhci_host *host; 176578b36b6SGao, Yunpeng 177578b36b6SGao, Yunpeng if (!c || !c->host) 178578b36b6SGao, Yunpeng return 0; 179578b36b6SGao, Yunpeng 180578b36b6SGao, Yunpeng host = c->host; 181578b36b6SGao, Yunpeng 182578b36b6SGao, Yunpeng /* Platform specific code during emmc proble slot goes here */ 183578b36b6SGao, Yunpeng 184578b36b6SGao, Yunpeng return 0; 185578b36b6SGao, Yunpeng } 186578b36b6SGao, Yunpeng 1877dafca83SAdrian Hunter static int sdhci_acpi_sd_probe_slot(struct platform_device *pdev, 1887dafca83SAdrian Hunter const char *hid, const char *uid) 189578b36b6SGao, Yunpeng { 190578b36b6SGao, Yunpeng struct sdhci_acpi_host *c = platform_get_drvdata(pdev); 191578b36b6SGao, Yunpeng struct sdhci_host *host; 192578b36b6SGao, Yunpeng 193578b36b6SGao, Yunpeng if (!c || !c->host || !c->slot) 194578b36b6SGao, Yunpeng return 0; 195578b36b6SGao, Yunpeng 196578b36b6SGao, Yunpeng host = c->host; 197578b36b6SGao, Yunpeng 198578b36b6SGao, Yunpeng /* Platform specific code during emmc proble slot goes here */ 199578b36b6SGao, Yunpeng 200578b36b6SGao, Yunpeng return 0; 201578b36b6SGao, Yunpeng } 202578b36b6SGao, Yunpeng 20307a58883SAdrian Hunter static const struct sdhci_acpi_slot sdhci_acpi_slot_int_emmc = { 204b04fa064SAdrian Hunter .chip = &sdhci_acpi_chip_int, 205f25c3372SMaurice Petallo .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE | 206f25c3372SMaurice Petallo MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR, 20707a58883SAdrian Hunter .caps2 = MMC_CAP2_HC_ERASE_SZ, 20807a58883SAdrian Hunter .flags = SDHCI_ACPI_RUNTIME_PM, 209e1f5633aSAdrian Hunter .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 210934e31b9SAdrian Hunter .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | SDHCI_QUIRK2_STOP_WITH_TC, 211578b36b6SGao, Yunpeng .probe_slot = sdhci_acpi_emmc_probe_slot, 21207a58883SAdrian Hunter }; 21307a58883SAdrian Hunter 214e5571397SAdrian Hunter static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = { 215e1f5633aSAdrian Hunter .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION | 216e1f5633aSAdrian Hunter SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 217e5571397SAdrian Hunter .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON, 218e5571397SAdrian Hunter .caps = MMC_CAP_NONREMOVABLE | MMC_CAP_POWER_OFF_CARD, 219e5571397SAdrian Hunter .flags = SDHCI_ACPI_RUNTIME_PM, 220e5571397SAdrian Hunter .pm_caps = MMC_PM_KEEP_POWER, 221578b36b6SGao, Yunpeng .probe_slot = sdhci_acpi_sdio_probe_slot, 222e5571397SAdrian Hunter }; 223e5571397SAdrian Hunter 22407a58883SAdrian Hunter static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = { 2254fd4409cSAdrian Hunter .flags = SDHCI_ACPI_SD_CD | SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL | 2264fd4409cSAdrian Hunter SDHCI_ACPI_RUNTIME_PM, 227e1f5633aSAdrian Hunter .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 228934e31b9SAdrian Hunter .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON | 229934e31b9SAdrian Hunter SDHCI_QUIRK2_STOP_WITH_TC, 230578b36b6SGao, Yunpeng .probe_slot = sdhci_acpi_sd_probe_slot, 23107a58883SAdrian Hunter }; 23207a58883SAdrian Hunter 23307a58883SAdrian Hunter struct sdhci_acpi_uid_slot { 23407a58883SAdrian Hunter const char *hid; 23507a58883SAdrian Hunter const char *uid; 23607a58883SAdrian Hunter const struct sdhci_acpi_slot *slot; 23707a58883SAdrian Hunter }; 23807a58883SAdrian Hunter 23907a58883SAdrian Hunter static const struct sdhci_acpi_uid_slot sdhci_acpi_uids[] = { 24007a58883SAdrian Hunter { "80860F14" , "1" , &sdhci_acpi_slot_int_emmc }, 24107a58883SAdrian Hunter { "80860F14" , "3" , &sdhci_acpi_slot_int_sd }, 242aad95dc4SAdrian Hunter { "80860F16" , NULL, &sdhci_acpi_slot_int_sd }, 24307a58883SAdrian Hunter { "INT33BB" , "2" , &sdhci_acpi_slot_int_sdio }, 2447147eaf3SAdrian Hunter { "INT33BB" , "3" , &sdhci_acpi_slot_int_sd }, 24507a58883SAdrian Hunter { "INT33C6" , NULL, &sdhci_acpi_slot_int_sdio }, 24607c001c1SMika Westerberg { "INT3436" , NULL, &sdhci_acpi_slot_int_sdio }, 24707a58883SAdrian Hunter { "PNP0D40" }, 24807a58883SAdrian Hunter { }, 24907a58883SAdrian Hunter }; 25007a58883SAdrian Hunter 251c4e05037SAdrian Hunter static const struct acpi_device_id sdhci_acpi_ids[] = { 25207a58883SAdrian Hunter { "80860F14" }, 253aad95dc4SAdrian Hunter { "80860F16" }, 25407a58883SAdrian Hunter { "INT33BB" }, 25507a58883SAdrian Hunter { "INT33C6" }, 25607c001c1SMika Westerberg { "INT3436" }, 257c4e05037SAdrian Hunter { "PNP0D40" }, 258c4e05037SAdrian Hunter { }, 259c4e05037SAdrian Hunter }; 260c4e05037SAdrian Hunter MODULE_DEVICE_TABLE(acpi, sdhci_acpi_ids); 261c4e05037SAdrian Hunter 2623db35251SAdrian Hunter static const struct sdhci_acpi_slot *sdhci_acpi_get_slot(const char *hid, 26307a58883SAdrian Hunter const char *uid) 264c4e05037SAdrian Hunter { 26507a58883SAdrian Hunter const struct sdhci_acpi_uid_slot *u; 266c4e05037SAdrian Hunter 26707a58883SAdrian Hunter for (u = sdhci_acpi_uids; u->hid; u++) { 26807a58883SAdrian Hunter if (strcmp(u->hid, hid)) 26907a58883SAdrian Hunter continue; 27007a58883SAdrian Hunter if (!u->uid) 27107a58883SAdrian Hunter return u->slot; 27207a58883SAdrian Hunter if (uid && !strcmp(u->uid, uid)) 27307a58883SAdrian Hunter return u->slot; 27407a58883SAdrian Hunter } 275c4e05037SAdrian Hunter return NULL; 276c4e05037SAdrian Hunter } 277c4e05037SAdrian Hunter 2784e608e4eSGreg Kroah-Hartman static int sdhci_acpi_probe(struct platform_device *pdev) 279c4e05037SAdrian Hunter { 280c4e05037SAdrian Hunter struct device *dev = &pdev->dev; 281c4e05037SAdrian Hunter acpi_handle handle = ACPI_HANDLE(dev); 282c4e05037SAdrian Hunter struct acpi_device *device; 283c4e05037SAdrian Hunter struct sdhci_acpi_host *c; 284c4e05037SAdrian Hunter struct sdhci_host *host; 285c4e05037SAdrian Hunter struct resource *iomem; 286c4e05037SAdrian Hunter resource_size_t len; 287c4e05037SAdrian Hunter const char *hid; 2883db35251SAdrian Hunter const char *uid; 28987875655SMika Westerberg int err; 290c4e05037SAdrian Hunter 291c4e05037SAdrian Hunter if (acpi_bus_get_device(handle, &device)) 292c4e05037SAdrian Hunter return -ENODEV; 293c4e05037SAdrian Hunter 294c4e05037SAdrian Hunter if (acpi_bus_get_status(device) || !device->status.present) 295c4e05037SAdrian Hunter return -ENODEV; 296c4e05037SAdrian Hunter 297c4e05037SAdrian Hunter hid = acpi_device_hid(device); 2983db35251SAdrian Hunter uid = device->pnp.unique_id; 299c4e05037SAdrian Hunter 300c4e05037SAdrian Hunter iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 301c4e05037SAdrian Hunter if (!iomem) 302c4e05037SAdrian Hunter return -ENOMEM; 303c4e05037SAdrian Hunter 304c4e05037SAdrian Hunter len = resource_size(iomem); 305c4e05037SAdrian Hunter if (len < 0x100) 306c4e05037SAdrian Hunter dev_err(dev, "Invalid iomem size!\n"); 307c4e05037SAdrian Hunter 308c4e05037SAdrian Hunter if (!devm_request_mem_region(dev, iomem->start, len, dev_name(dev))) 309c4e05037SAdrian Hunter return -ENOMEM; 310c4e05037SAdrian Hunter 311c4e05037SAdrian Hunter host = sdhci_alloc_host(dev, sizeof(struct sdhci_acpi_host)); 312c4e05037SAdrian Hunter if (IS_ERR(host)) 313c4e05037SAdrian Hunter return PTR_ERR(host); 314c4e05037SAdrian Hunter 315c4e05037SAdrian Hunter c = sdhci_priv(host); 316c4e05037SAdrian Hunter c->host = host; 3173db35251SAdrian Hunter c->slot = sdhci_acpi_get_slot(hid, uid); 318c4e05037SAdrian Hunter c->pdev = pdev; 319c4e05037SAdrian Hunter c->use_runtime_pm = sdhci_acpi_flag(c, SDHCI_ACPI_RUNTIME_PM); 320c4e05037SAdrian Hunter 321c4e05037SAdrian Hunter platform_set_drvdata(pdev, c); 322c4e05037SAdrian Hunter 323c4e05037SAdrian Hunter host->hw_name = "ACPI"; 324c4e05037SAdrian Hunter host->ops = &sdhci_acpi_ops_dflt; 325c4e05037SAdrian Hunter host->irq = platform_get_irq(pdev, 0); 326c4e05037SAdrian Hunter 327c4e05037SAdrian Hunter host->ioaddr = devm_ioremap_nocache(dev, iomem->start, 328c4e05037SAdrian Hunter resource_size(iomem)); 329c4e05037SAdrian Hunter if (host->ioaddr == NULL) { 330c4e05037SAdrian Hunter err = -ENOMEM; 331c4e05037SAdrian Hunter goto err_free; 332c4e05037SAdrian Hunter } 333c4e05037SAdrian Hunter 334c4e05037SAdrian Hunter if (c->slot) { 335578b36b6SGao, Yunpeng if (c->slot->probe_slot) { 3367dafca83SAdrian Hunter err = c->slot->probe_slot(pdev, hid, uid); 337578b36b6SGao, Yunpeng if (err) 338578b36b6SGao, Yunpeng goto err_free; 339578b36b6SGao, Yunpeng } 340c4e05037SAdrian Hunter if (c->slot->chip) { 341c4e05037SAdrian Hunter host->ops = c->slot->chip->ops; 342c4e05037SAdrian Hunter host->quirks |= c->slot->chip->quirks; 343c4e05037SAdrian Hunter host->quirks2 |= c->slot->chip->quirks2; 344c4e05037SAdrian Hunter host->mmc->caps |= c->slot->chip->caps; 345c4e05037SAdrian Hunter host->mmc->caps2 |= c->slot->chip->caps2; 346c4e05037SAdrian Hunter host->mmc->pm_caps |= c->slot->chip->pm_caps; 347c4e05037SAdrian Hunter } 348c4e05037SAdrian Hunter host->quirks |= c->slot->quirks; 349c4e05037SAdrian Hunter host->quirks2 |= c->slot->quirks2; 350c4e05037SAdrian Hunter host->mmc->caps |= c->slot->caps; 351c4e05037SAdrian Hunter host->mmc->caps2 |= c->slot->caps2; 352c4e05037SAdrian Hunter host->mmc->pm_caps |= c->slot->pm_caps; 353c4e05037SAdrian Hunter } 354c4e05037SAdrian Hunter 3550d3e3350SAdrian Hunter host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP; 3560d3e3350SAdrian Hunter 3574fd4409cSAdrian Hunter if (sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD)) { 3584fd4409cSAdrian Hunter bool v = sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL); 3594fd4409cSAdrian Hunter 36089168b48SLinus Walleij if (mmc_gpiod_request_cd(host->mmc, NULL, 0, v, 0, NULL)) { 3614fd4409cSAdrian Hunter dev_warn(dev, "failed to setup card detect gpio\n"); 3624fd4409cSAdrian Hunter c->use_runtime_pm = false; 3634fd4409cSAdrian Hunter } 3644fd4409cSAdrian Hunter } 3654fd4409cSAdrian Hunter 366c4e05037SAdrian Hunter err = sdhci_add_host(host); 367c4e05037SAdrian Hunter if (err) 368c4e05037SAdrian Hunter goto err_free; 369c4e05037SAdrian Hunter 370c4e05037SAdrian Hunter if (c->use_runtime_pm) { 3711d1ff458SAdrian Hunter pm_runtime_set_active(dev); 372c4e05037SAdrian Hunter pm_suspend_ignore_children(dev, 1); 373c4e05037SAdrian Hunter pm_runtime_set_autosuspend_delay(dev, 50); 374c4e05037SAdrian Hunter pm_runtime_use_autosuspend(dev); 375c4e05037SAdrian Hunter pm_runtime_enable(dev); 376c4e05037SAdrian Hunter } 377c4e05037SAdrian Hunter 378c4e05037SAdrian Hunter return 0; 379c4e05037SAdrian Hunter 380c4e05037SAdrian Hunter err_free: 381c4e05037SAdrian Hunter sdhci_free_host(c->host); 382c4e05037SAdrian Hunter return err; 383c4e05037SAdrian Hunter } 384c4e05037SAdrian Hunter 3854e608e4eSGreg Kroah-Hartman static int sdhci_acpi_remove(struct platform_device *pdev) 386c4e05037SAdrian Hunter { 387c4e05037SAdrian Hunter struct sdhci_acpi_host *c = platform_get_drvdata(pdev); 388c4e05037SAdrian Hunter struct device *dev = &pdev->dev; 389c4e05037SAdrian Hunter int dead; 390c4e05037SAdrian Hunter 391c4e05037SAdrian Hunter if (c->use_runtime_pm) { 392c4e05037SAdrian Hunter pm_runtime_get_sync(dev); 393c4e05037SAdrian Hunter pm_runtime_disable(dev); 394c4e05037SAdrian Hunter pm_runtime_put_noidle(dev); 395c4e05037SAdrian Hunter } 396c4e05037SAdrian Hunter 397578b36b6SGao, Yunpeng if (c->slot && c->slot->remove_slot) 398578b36b6SGao, Yunpeng c->slot->remove_slot(pdev); 399578b36b6SGao, Yunpeng 400c4e05037SAdrian Hunter dead = (sdhci_readl(c->host, SDHCI_INT_STATUS) == ~0); 401c4e05037SAdrian Hunter sdhci_remove_host(c->host, dead); 402c4e05037SAdrian Hunter sdhci_free_host(c->host); 403c4e05037SAdrian Hunter 404c4e05037SAdrian Hunter return 0; 405c4e05037SAdrian Hunter } 406c4e05037SAdrian Hunter 407c4e05037SAdrian Hunter #ifdef CONFIG_PM_SLEEP 408c4e05037SAdrian Hunter 409c4e05037SAdrian Hunter static int sdhci_acpi_suspend(struct device *dev) 410c4e05037SAdrian Hunter { 411c4e05037SAdrian Hunter struct sdhci_acpi_host *c = dev_get_drvdata(dev); 412c4e05037SAdrian Hunter 413c4e05037SAdrian Hunter return sdhci_suspend_host(c->host); 414c4e05037SAdrian Hunter } 415c4e05037SAdrian Hunter 416c4e05037SAdrian Hunter static int sdhci_acpi_resume(struct device *dev) 417c4e05037SAdrian Hunter { 418c4e05037SAdrian Hunter struct sdhci_acpi_host *c = dev_get_drvdata(dev); 419c4e05037SAdrian Hunter 420c4e05037SAdrian Hunter return sdhci_resume_host(c->host); 421c4e05037SAdrian Hunter } 422c4e05037SAdrian Hunter 423c4e05037SAdrian Hunter #else 424c4e05037SAdrian Hunter 425c4e05037SAdrian Hunter #define sdhci_acpi_suspend NULL 426c4e05037SAdrian Hunter #define sdhci_acpi_resume NULL 427c4e05037SAdrian Hunter 428c4e05037SAdrian Hunter #endif 429c4e05037SAdrian Hunter 430c4e05037SAdrian Hunter #ifdef CONFIG_PM_RUNTIME 431c4e05037SAdrian Hunter 432c4e05037SAdrian Hunter static int sdhci_acpi_runtime_suspend(struct device *dev) 433c4e05037SAdrian Hunter { 434c4e05037SAdrian Hunter struct sdhci_acpi_host *c = dev_get_drvdata(dev); 435c4e05037SAdrian Hunter 436c4e05037SAdrian Hunter return sdhci_runtime_suspend_host(c->host); 437c4e05037SAdrian Hunter } 438c4e05037SAdrian Hunter 439c4e05037SAdrian Hunter static int sdhci_acpi_runtime_resume(struct device *dev) 440c4e05037SAdrian Hunter { 441c4e05037SAdrian Hunter struct sdhci_acpi_host *c = dev_get_drvdata(dev); 442c4e05037SAdrian Hunter 443c4e05037SAdrian Hunter return sdhci_runtime_resume_host(c->host); 444c4e05037SAdrian Hunter } 445c4e05037SAdrian Hunter 446c4e05037SAdrian Hunter static int sdhci_acpi_runtime_idle(struct device *dev) 447c4e05037SAdrian Hunter { 448c4e05037SAdrian Hunter return 0; 449c4e05037SAdrian Hunter } 450c4e05037SAdrian Hunter 451c4e05037SAdrian Hunter #endif 452c4e05037SAdrian Hunter 453c4e05037SAdrian Hunter static const struct dev_pm_ops sdhci_acpi_pm_ops = { 454c4e05037SAdrian Hunter .suspend = sdhci_acpi_suspend, 455c4e05037SAdrian Hunter .resume = sdhci_acpi_resume, 4561d75f74bSPeter Griffin SET_RUNTIME_PM_OPS(sdhci_acpi_runtime_suspend, 4571d75f74bSPeter Griffin sdhci_acpi_runtime_resume, sdhci_acpi_runtime_idle) 458c4e05037SAdrian Hunter }; 459c4e05037SAdrian Hunter 460c4e05037SAdrian Hunter static struct platform_driver sdhci_acpi_driver = { 461c4e05037SAdrian Hunter .driver = { 462c4e05037SAdrian Hunter .name = "sdhci-acpi", 463c4e05037SAdrian Hunter .owner = THIS_MODULE, 464c4e05037SAdrian Hunter .acpi_match_table = sdhci_acpi_ids, 465c4e05037SAdrian Hunter .pm = &sdhci_acpi_pm_ops, 466c4e05037SAdrian Hunter }, 467c4e05037SAdrian Hunter .probe = sdhci_acpi_probe, 4684e608e4eSGreg Kroah-Hartman .remove = sdhci_acpi_remove, 469c4e05037SAdrian Hunter }; 470c4e05037SAdrian Hunter 471c4e05037SAdrian Hunter module_platform_driver(sdhci_acpi_driver); 472c4e05037SAdrian Hunter 473c4e05037SAdrian Hunter MODULE_DESCRIPTION("Secure Digital Host Controller Interface ACPI driver"); 474c4e05037SAdrian Hunter MODULE_AUTHOR("Adrian Hunter"); 475c4e05037SAdrian Hunter MODULE_LICENSE("GPL v2"); 476