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; 79c4e05037SAdrian Hunter }; 80c4e05037SAdrian Hunter 81c4e05037SAdrian Hunter static inline bool sdhci_acpi_flag(struct sdhci_acpi_host *c, unsigned int flag) 82c4e05037SAdrian Hunter { 83c4e05037SAdrian Hunter return c->slot && (c->slot->flags & flag); 84c4e05037SAdrian Hunter } 85c4e05037SAdrian Hunter 86c4e05037SAdrian Hunter static int sdhci_acpi_enable_dma(struct sdhci_host *host) 87c4e05037SAdrian Hunter { 88c4e05037SAdrian Hunter return 0; 89c4e05037SAdrian Hunter } 90c4e05037SAdrian Hunter 91b04fa064SAdrian Hunter static void sdhci_acpi_int_hw_reset(struct sdhci_host *host) 92b04fa064SAdrian Hunter { 93b04fa064SAdrian Hunter u8 reg; 94b04fa064SAdrian Hunter 95b04fa064SAdrian Hunter reg = sdhci_readb(host, SDHCI_POWER_CONTROL); 96b04fa064SAdrian Hunter reg |= 0x10; 97b04fa064SAdrian Hunter sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); 98b04fa064SAdrian Hunter /* For eMMC, minimum is 1us but give it 9us for good measure */ 99b04fa064SAdrian Hunter udelay(9); 100b04fa064SAdrian Hunter reg &= ~0x10; 101b04fa064SAdrian Hunter sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); 102b04fa064SAdrian Hunter /* For eMMC, minimum is 200us but give it 300us for good measure */ 103b04fa064SAdrian Hunter usleep_range(300, 1000); 104b04fa064SAdrian Hunter } 105b04fa064SAdrian Hunter 106c4e05037SAdrian Hunter static const struct sdhci_ops sdhci_acpi_ops_dflt = { 1071771059cSRussell King .set_clock = sdhci_set_clock, 108c4e05037SAdrian Hunter .enable_dma = sdhci_acpi_enable_dma, 1092317f56cSRussell King .set_bus_width = sdhci_set_bus_width, 11003231f9bSRussell King .reset = sdhci_reset, 11196d7b78cSRussell King .set_uhs_signaling = sdhci_set_uhs_signaling, 112c4e05037SAdrian Hunter }; 113c4e05037SAdrian Hunter 114b04fa064SAdrian Hunter static const struct sdhci_ops sdhci_acpi_ops_int = { 1151771059cSRussell King .set_clock = sdhci_set_clock, 116b04fa064SAdrian Hunter .enable_dma = sdhci_acpi_enable_dma, 1172317f56cSRussell King .set_bus_width = sdhci_set_bus_width, 11803231f9bSRussell King .reset = sdhci_reset, 11996d7b78cSRussell King .set_uhs_signaling = sdhci_set_uhs_signaling, 120b04fa064SAdrian Hunter .hw_reset = sdhci_acpi_int_hw_reset, 121b04fa064SAdrian Hunter }; 122b04fa064SAdrian Hunter 123b04fa064SAdrian Hunter static const struct sdhci_acpi_chip sdhci_acpi_chip_int = { 124b04fa064SAdrian Hunter .ops = &sdhci_acpi_ops_int, 125b04fa064SAdrian Hunter }; 126b04fa064SAdrian Hunter 1277dafca83SAdrian Hunter static int sdhci_acpi_emmc_probe_slot(struct platform_device *pdev, 1287dafca83SAdrian Hunter const char *hid, const char *uid) 129578b36b6SGao, Yunpeng { 130578b36b6SGao, Yunpeng struct sdhci_acpi_host *c = platform_get_drvdata(pdev); 131578b36b6SGao, Yunpeng struct sdhci_host *host; 132578b36b6SGao, Yunpeng 133578b36b6SGao, Yunpeng if (!c || !c->host) 134578b36b6SGao, Yunpeng return 0; 135578b36b6SGao, Yunpeng 136578b36b6SGao, Yunpeng host = c->host; 137578b36b6SGao, Yunpeng 138578b36b6SGao, Yunpeng /* Platform specific code during emmc proble slot goes here */ 139578b36b6SGao, Yunpeng 140*8024379eSAdrian Hunter if (hid && uid && !strcmp(hid, "80860F14") && !strcmp(uid, "1") && 141*8024379eSAdrian Hunter sdhci_readl(host, SDHCI_CAPABILITIES) == 0x446cc8b2 && 142*8024379eSAdrian Hunter sdhci_readl(host, SDHCI_CAPABILITIES_1) == 0x00000807) 143*8024379eSAdrian Hunter host->timeout_clk = 1000; /* 1000 kHz i.e. 1 MHz */ 144*8024379eSAdrian Hunter 145578b36b6SGao, Yunpeng return 0; 146578b36b6SGao, Yunpeng } 147578b36b6SGao, Yunpeng 1487dafca83SAdrian Hunter static int sdhci_acpi_sdio_probe_slot(struct platform_device *pdev, 1497dafca83SAdrian Hunter const char *hid, const char *uid) 150578b36b6SGao, Yunpeng { 151578b36b6SGao, Yunpeng struct sdhci_acpi_host *c = platform_get_drvdata(pdev); 152578b36b6SGao, Yunpeng struct sdhci_host *host; 153578b36b6SGao, Yunpeng 154578b36b6SGao, Yunpeng if (!c || !c->host) 155578b36b6SGao, Yunpeng return 0; 156578b36b6SGao, Yunpeng 157578b36b6SGao, Yunpeng host = c->host; 158578b36b6SGao, Yunpeng 159578b36b6SGao, Yunpeng /* Platform specific code during emmc proble slot goes here */ 160578b36b6SGao, Yunpeng 161578b36b6SGao, Yunpeng return 0; 162578b36b6SGao, Yunpeng } 163578b36b6SGao, Yunpeng 1647dafca83SAdrian Hunter static int sdhci_acpi_sd_probe_slot(struct platform_device *pdev, 1657dafca83SAdrian Hunter const char *hid, const char *uid) 166578b36b6SGao, Yunpeng { 167578b36b6SGao, Yunpeng struct sdhci_acpi_host *c = platform_get_drvdata(pdev); 168578b36b6SGao, Yunpeng struct sdhci_host *host; 169578b36b6SGao, Yunpeng 170578b36b6SGao, Yunpeng if (!c || !c->host || !c->slot) 171578b36b6SGao, Yunpeng return 0; 172578b36b6SGao, Yunpeng 173578b36b6SGao, Yunpeng host = c->host; 174578b36b6SGao, Yunpeng 175578b36b6SGao, Yunpeng /* Platform specific code during emmc proble slot goes here */ 176578b36b6SGao, Yunpeng 177578b36b6SGao, Yunpeng return 0; 178578b36b6SGao, Yunpeng } 179578b36b6SGao, Yunpeng 18007a58883SAdrian Hunter static const struct sdhci_acpi_slot sdhci_acpi_slot_int_emmc = { 181b04fa064SAdrian Hunter .chip = &sdhci_acpi_chip_int, 182f25c3372SMaurice Petallo .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE | 183f25c3372SMaurice Petallo MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR, 18407a58883SAdrian Hunter .caps2 = MMC_CAP2_HC_ERASE_SZ, 18507a58883SAdrian Hunter .flags = SDHCI_ACPI_RUNTIME_PM, 186934e31b9SAdrian Hunter .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | SDHCI_QUIRK2_STOP_WITH_TC, 187578b36b6SGao, Yunpeng .probe_slot = sdhci_acpi_emmc_probe_slot, 18807a58883SAdrian Hunter }; 18907a58883SAdrian Hunter 190e5571397SAdrian Hunter static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = { 191c6748017SAdrian Hunter .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION, 192e5571397SAdrian Hunter .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON, 193e5571397SAdrian Hunter .caps = MMC_CAP_NONREMOVABLE | MMC_CAP_POWER_OFF_CARD, 194e5571397SAdrian Hunter .flags = SDHCI_ACPI_RUNTIME_PM, 195e5571397SAdrian Hunter .pm_caps = MMC_PM_KEEP_POWER, 196578b36b6SGao, Yunpeng .probe_slot = sdhci_acpi_sdio_probe_slot, 197e5571397SAdrian Hunter }; 198e5571397SAdrian Hunter 19907a58883SAdrian Hunter static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = { 2004fd4409cSAdrian Hunter .flags = SDHCI_ACPI_SD_CD | SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL | 2014fd4409cSAdrian Hunter SDHCI_ACPI_RUNTIME_PM, 202934e31b9SAdrian Hunter .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON | 203934e31b9SAdrian Hunter SDHCI_QUIRK2_STOP_WITH_TC, 204578b36b6SGao, Yunpeng .probe_slot = sdhci_acpi_sd_probe_slot, 20507a58883SAdrian Hunter }; 20607a58883SAdrian Hunter 20707a58883SAdrian Hunter struct sdhci_acpi_uid_slot { 20807a58883SAdrian Hunter const char *hid; 20907a58883SAdrian Hunter const char *uid; 21007a58883SAdrian Hunter const struct sdhci_acpi_slot *slot; 21107a58883SAdrian Hunter }; 21207a58883SAdrian Hunter 21307a58883SAdrian Hunter static const struct sdhci_acpi_uid_slot sdhci_acpi_uids[] = { 21407a58883SAdrian Hunter { "80860F14" , "1" , &sdhci_acpi_slot_int_emmc }, 21507a58883SAdrian Hunter { "80860F14" , "3" , &sdhci_acpi_slot_int_sd }, 216aad95dc4SAdrian Hunter { "80860F16" , NULL, &sdhci_acpi_slot_int_sd }, 21707a58883SAdrian Hunter { "INT33BB" , "2" , &sdhci_acpi_slot_int_sdio }, 2187147eaf3SAdrian Hunter { "INT33BB" , "3" , &sdhci_acpi_slot_int_sd }, 21907a58883SAdrian Hunter { "INT33C6" , NULL, &sdhci_acpi_slot_int_sdio }, 22007c001c1SMika Westerberg { "INT3436" , NULL, &sdhci_acpi_slot_int_sdio }, 22107a58883SAdrian Hunter { "PNP0D40" }, 22207a58883SAdrian Hunter { }, 22307a58883SAdrian Hunter }; 22407a58883SAdrian Hunter 225c4e05037SAdrian Hunter static const struct acpi_device_id sdhci_acpi_ids[] = { 22607a58883SAdrian Hunter { "80860F14" }, 227aad95dc4SAdrian Hunter { "80860F16" }, 22807a58883SAdrian Hunter { "INT33BB" }, 22907a58883SAdrian Hunter { "INT33C6" }, 23007c001c1SMika Westerberg { "INT3436" }, 231c4e05037SAdrian Hunter { "PNP0D40" }, 232c4e05037SAdrian Hunter { }, 233c4e05037SAdrian Hunter }; 234c4e05037SAdrian Hunter MODULE_DEVICE_TABLE(acpi, sdhci_acpi_ids); 235c4e05037SAdrian Hunter 2363db35251SAdrian Hunter static const struct sdhci_acpi_slot *sdhci_acpi_get_slot(const char *hid, 23707a58883SAdrian Hunter const char *uid) 238c4e05037SAdrian Hunter { 23907a58883SAdrian Hunter const struct sdhci_acpi_uid_slot *u; 240c4e05037SAdrian Hunter 24107a58883SAdrian Hunter for (u = sdhci_acpi_uids; u->hid; u++) { 24207a58883SAdrian Hunter if (strcmp(u->hid, hid)) 24307a58883SAdrian Hunter continue; 24407a58883SAdrian Hunter if (!u->uid) 24507a58883SAdrian Hunter return u->slot; 24607a58883SAdrian Hunter if (uid && !strcmp(u->uid, uid)) 24707a58883SAdrian Hunter return u->slot; 24807a58883SAdrian Hunter } 249c4e05037SAdrian Hunter return NULL; 250c4e05037SAdrian Hunter } 251c4e05037SAdrian Hunter 2524e608e4eSGreg Kroah-Hartman static int sdhci_acpi_probe(struct platform_device *pdev) 253c4e05037SAdrian Hunter { 254c4e05037SAdrian Hunter struct device *dev = &pdev->dev; 255c4e05037SAdrian Hunter acpi_handle handle = ACPI_HANDLE(dev); 256c4e05037SAdrian Hunter struct acpi_device *device; 257c4e05037SAdrian Hunter struct sdhci_acpi_host *c; 258c4e05037SAdrian Hunter struct sdhci_host *host; 259c4e05037SAdrian Hunter struct resource *iomem; 260c4e05037SAdrian Hunter resource_size_t len; 261c4e05037SAdrian Hunter const char *hid; 2623db35251SAdrian Hunter const char *uid; 26387875655SMika Westerberg int err; 264c4e05037SAdrian Hunter 265c4e05037SAdrian Hunter if (acpi_bus_get_device(handle, &device)) 266c4e05037SAdrian Hunter return -ENODEV; 267c4e05037SAdrian Hunter 268c4e05037SAdrian Hunter if (acpi_bus_get_status(device) || !device->status.present) 269c4e05037SAdrian Hunter return -ENODEV; 270c4e05037SAdrian Hunter 271c4e05037SAdrian Hunter hid = acpi_device_hid(device); 2723db35251SAdrian Hunter uid = device->pnp.unique_id; 273c4e05037SAdrian Hunter 274c4e05037SAdrian Hunter iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 275c4e05037SAdrian Hunter if (!iomem) 276c4e05037SAdrian Hunter return -ENOMEM; 277c4e05037SAdrian Hunter 278c4e05037SAdrian Hunter len = resource_size(iomem); 279c4e05037SAdrian Hunter if (len < 0x100) 280c4e05037SAdrian Hunter dev_err(dev, "Invalid iomem size!\n"); 281c4e05037SAdrian Hunter 282c4e05037SAdrian Hunter if (!devm_request_mem_region(dev, iomem->start, len, dev_name(dev))) 283c4e05037SAdrian Hunter return -ENOMEM; 284c4e05037SAdrian Hunter 285c4e05037SAdrian Hunter host = sdhci_alloc_host(dev, sizeof(struct sdhci_acpi_host)); 286c4e05037SAdrian Hunter if (IS_ERR(host)) 287c4e05037SAdrian Hunter return PTR_ERR(host); 288c4e05037SAdrian Hunter 289c4e05037SAdrian Hunter c = sdhci_priv(host); 290c4e05037SAdrian Hunter c->host = host; 2913db35251SAdrian Hunter c->slot = sdhci_acpi_get_slot(hid, uid); 292c4e05037SAdrian Hunter c->pdev = pdev; 293c4e05037SAdrian Hunter c->use_runtime_pm = sdhci_acpi_flag(c, SDHCI_ACPI_RUNTIME_PM); 294c4e05037SAdrian Hunter 295c4e05037SAdrian Hunter platform_set_drvdata(pdev, c); 296c4e05037SAdrian Hunter 297c4e05037SAdrian Hunter host->hw_name = "ACPI"; 298c4e05037SAdrian Hunter host->ops = &sdhci_acpi_ops_dflt; 299c4e05037SAdrian Hunter host->irq = platform_get_irq(pdev, 0); 300c4e05037SAdrian Hunter 301c4e05037SAdrian Hunter host->ioaddr = devm_ioremap_nocache(dev, iomem->start, 302c4e05037SAdrian Hunter resource_size(iomem)); 303c4e05037SAdrian Hunter if (host->ioaddr == NULL) { 304c4e05037SAdrian Hunter err = -ENOMEM; 305c4e05037SAdrian Hunter goto err_free; 306c4e05037SAdrian Hunter } 307c4e05037SAdrian Hunter 308c4e05037SAdrian Hunter if (!dev->dma_mask) { 309c4e05037SAdrian Hunter u64 dma_mask; 310c4e05037SAdrian Hunter 311c4e05037SAdrian Hunter if (sdhci_readl(host, SDHCI_CAPABILITIES) & SDHCI_CAN_64BIT) { 312c4e05037SAdrian Hunter /* 64-bit DMA is not supported at present */ 313c4e05037SAdrian Hunter dma_mask = DMA_BIT_MASK(32); 314c4e05037SAdrian Hunter } else { 315c4e05037SAdrian Hunter dma_mask = DMA_BIT_MASK(32); 316c4e05037SAdrian Hunter } 317c4e05037SAdrian Hunter 31807f4450cSRussell King err = dma_coerce_mask_and_coherent(dev, dma_mask); 31907f4450cSRussell King if (err) 32007f4450cSRussell King goto err_free; 321c4e05037SAdrian Hunter } 322c4e05037SAdrian Hunter 323c4e05037SAdrian Hunter if (c->slot) { 324578b36b6SGao, Yunpeng if (c->slot->probe_slot) { 3257dafca83SAdrian Hunter err = c->slot->probe_slot(pdev, hid, uid); 326578b36b6SGao, Yunpeng if (err) 327578b36b6SGao, Yunpeng goto err_free; 328578b36b6SGao, Yunpeng } 329c4e05037SAdrian Hunter if (c->slot->chip) { 330c4e05037SAdrian Hunter host->ops = c->slot->chip->ops; 331c4e05037SAdrian Hunter host->quirks |= c->slot->chip->quirks; 332c4e05037SAdrian Hunter host->quirks2 |= c->slot->chip->quirks2; 333c4e05037SAdrian Hunter host->mmc->caps |= c->slot->chip->caps; 334c4e05037SAdrian Hunter host->mmc->caps2 |= c->slot->chip->caps2; 335c4e05037SAdrian Hunter host->mmc->pm_caps |= c->slot->chip->pm_caps; 336c4e05037SAdrian Hunter } 337c4e05037SAdrian Hunter host->quirks |= c->slot->quirks; 338c4e05037SAdrian Hunter host->quirks2 |= c->slot->quirks2; 339c4e05037SAdrian Hunter host->mmc->caps |= c->slot->caps; 340c4e05037SAdrian Hunter host->mmc->caps2 |= c->slot->caps2; 341c4e05037SAdrian Hunter host->mmc->pm_caps |= c->slot->pm_caps; 342c4e05037SAdrian Hunter } 343c4e05037SAdrian Hunter 3440d3e3350SAdrian Hunter host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP; 3450d3e3350SAdrian Hunter 3464fd4409cSAdrian Hunter if (sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD)) { 3474fd4409cSAdrian Hunter bool v = sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL); 3484fd4409cSAdrian Hunter 34989168b48SLinus Walleij if (mmc_gpiod_request_cd(host->mmc, NULL, 0, v, 0, NULL)) { 3504fd4409cSAdrian Hunter dev_warn(dev, "failed to setup card detect gpio\n"); 3514fd4409cSAdrian Hunter c->use_runtime_pm = false; 3524fd4409cSAdrian Hunter } 3534fd4409cSAdrian Hunter } 3544fd4409cSAdrian Hunter 355c4e05037SAdrian Hunter err = sdhci_add_host(host); 356c4e05037SAdrian Hunter if (err) 357c4e05037SAdrian Hunter goto err_free; 358c4e05037SAdrian Hunter 359c4e05037SAdrian Hunter if (c->use_runtime_pm) { 3601d1ff458SAdrian Hunter pm_runtime_set_active(dev); 361c4e05037SAdrian Hunter pm_suspend_ignore_children(dev, 1); 362c4e05037SAdrian Hunter pm_runtime_set_autosuspend_delay(dev, 50); 363c4e05037SAdrian Hunter pm_runtime_use_autosuspend(dev); 364c4e05037SAdrian Hunter pm_runtime_enable(dev); 365c4e05037SAdrian Hunter } 366c4e05037SAdrian Hunter 367c4e05037SAdrian Hunter return 0; 368c4e05037SAdrian Hunter 369c4e05037SAdrian Hunter err_free: 370c4e05037SAdrian Hunter sdhci_free_host(c->host); 371c4e05037SAdrian Hunter return err; 372c4e05037SAdrian Hunter } 373c4e05037SAdrian Hunter 3744e608e4eSGreg Kroah-Hartman static int sdhci_acpi_remove(struct platform_device *pdev) 375c4e05037SAdrian Hunter { 376c4e05037SAdrian Hunter struct sdhci_acpi_host *c = platform_get_drvdata(pdev); 377c4e05037SAdrian Hunter struct device *dev = &pdev->dev; 378c4e05037SAdrian Hunter int dead; 379c4e05037SAdrian Hunter 380c4e05037SAdrian Hunter if (c->use_runtime_pm) { 381c4e05037SAdrian Hunter pm_runtime_get_sync(dev); 382c4e05037SAdrian Hunter pm_runtime_disable(dev); 383c4e05037SAdrian Hunter pm_runtime_put_noidle(dev); 384c4e05037SAdrian Hunter } 385c4e05037SAdrian Hunter 386578b36b6SGao, Yunpeng if (c->slot && c->slot->remove_slot) 387578b36b6SGao, Yunpeng c->slot->remove_slot(pdev); 388578b36b6SGao, Yunpeng 389c4e05037SAdrian Hunter dead = (sdhci_readl(c->host, SDHCI_INT_STATUS) == ~0); 390c4e05037SAdrian Hunter sdhci_remove_host(c->host, dead); 391c4e05037SAdrian Hunter sdhci_free_host(c->host); 392c4e05037SAdrian Hunter 393c4e05037SAdrian Hunter return 0; 394c4e05037SAdrian Hunter } 395c4e05037SAdrian Hunter 396c4e05037SAdrian Hunter #ifdef CONFIG_PM_SLEEP 397c4e05037SAdrian Hunter 398c4e05037SAdrian Hunter static int sdhci_acpi_suspend(struct device *dev) 399c4e05037SAdrian Hunter { 400c4e05037SAdrian Hunter struct sdhci_acpi_host *c = dev_get_drvdata(dev); 401c4e05037SAdrian Hunter 402c4e05037SAdrian Hunter return sdhci_suspend_host(c->host); 403c4e05037SAdrian Hunter } 404c4e05037SAdrian Hunter 405c4e05037SAdrian Hunter static int sdhci_acpi_resume(struct device *dev) 406c4e05037SAdrian Hunter { 407c4e05037SAdrian Hunter struct sdhci_acpi_host *c = dev_get_drvdata(dev); 408c4e05037SAdrian Hunter 409c4e05037SAdrian Hunter return sdhci_resume_host(c->host); 410c4e05037SAdrian Hunter } 411c4e05037SAdrian Hunter 412c4e05037SAdrian Hunter #else 413c4e05037SAdrian Hunter 414c4e05037SAdrian Hunter #define sdhci_acpi_suspend NULL 415c4e05037SAdrian Hunter #define sdhci_acpi_resume NULL 416c4e05037SAdrian Hunter 417c4e05037SAdrian Hunter #endif 418c4e05037SAdrian Hunter 419c4e05037SAdrian Hunter #ifdef CONFIG_PM_RUNTIME 420c4e05037SAdrian Hunter 421c4e05037SAdrian Hunter static int sdhci_acpi_runtime_suspend(struct device *dev) 422c4e05037SAdrian Hunter { 423c4e05037SAdrian Hunter struct sdhci_acpi_host *c = dev_get_drvdata(dev); 424c4e05037SAdrian Hunter 425c4e05037SAdrian Hunter return sdhci_runtime_suspend_host(c->host); 426c4e05037SAdrian Hunter } 427c4e05037SAdrian Hunter 428c4e05037SAdrian Hunter static int sdhci_acpi_runtime_resume(struct device *dev) 429c4e05037SAdrian Hunter { 430c4e05037SAdrian Hunter struct sdhci_acpi_host *c = dev_get_drvdata(dev); 431c4e05037SAdrian Hunter 432c4e05037SAdrian Hunter return sdhci_runtime_resume_host(c->host); 433c4e05037SAdrian Hunter } 434c4e05037SAdrian Hunter 435c4e05037SAdrian Hunter static int sdhci_acpi_runtime_idle(struct device *dev) 436c4e05037SAdrian Hunter { 437c4e05037SAdrian Hunter return 0; 438c4e05037SAdrian Hunter } 439c4e05037SAdrian Hunter 440c4e05037SAdrian Hunter #endif 441c4e05037SAdrian Hunter 442c4e05037SAdrian Hunter static const struct dev_pm_ops sdhci_acpi_pm_ops = { 443c4e05037SAdrian Hunter .suspend = sdhci_acpi_suspend, 444c4e05037SAdrian Hunter .resume = sdhci_acpi_resume, 4451d75f74bSPeter Griffin SET_RUNTIME_PM_OPS(sdhci_acpi_runtime_suspend, 4461d75f74bSPeter Griffin sdhci_acpi_runtime_resume, sdhci_acpi_runtime_idle) 447c4e05037SAdrian Hunter }; 448c4e05037SAdrian Hunter 449c4e05037SAdrian Hunter static struct platform_driver sdhci_acpi_driver = { 450c4e05037SAdrian Hunter .driver = { 451c4e05037SAdrian Hunter .name = "sdhci-acpi", 452c4e05037SAdrian Hunter .owner = THIS_MODULE, 453c4e05037SAdrian Hunter .acpi_match_table = sdhci_acpi_ids, 454c4e05037SAdrian Hunter .pm = &sdhci_acpi_pm_ops, 455c4e05037SAdrian Hunter }, 456c4e05037SAdrian Hunter .probe = sdhci_acpi_probe, 4574e608e4eSGreg Kroah-Hartman .remove = sdhci_acpi_remove, 458c4e05037SAdrian Hunter }; 459c4e05037SAdrian Hunter 460c4e05037SAdrian Hunter module_platform_driver(sdhci_acpi_driver); 461c4e05037SAdrian Hunter 462c4e05037SAdrian Hunter MODULE_DESCRIPTION("Secure Digital Host Controller Interface ACPI driver"); 463c4e05037SAdrian Hunter MODULE_AUTHOR("Adrian Hunter"); 464c4e05037SAdrian Hunter MODULE_LICENSE("GPL v2"); 465