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> 3487875655SMika Westerberg #include <linux/gpio/consumer.h> 35c4e05037SAdrian Hunter #include <linux/interrupt.h> 36c4e05037SAdrian Hunter #include <linux/acpi.h> 37c4e05037SAdrian Hunter #include <linux/pm.h> 38c4e05037SAdrian Hunter #include <linux/pm_runtime.h> 39b04fa064SAdrian Hunter #include <linux/delay.h> 40c4e05037SAdrian Hunter 41c4e05037SAdrian Hunter #include <linux/mmc/host.h> 42c4e05037SAdrian Hunter #include <linux/mmc/pm.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), 50c4e05037SAdrian Hunter }; 51c4e05037SAdrian Hunter 52c4e05037SAdrian Hunter struct sdhci_acpi_chip { 53c4e05037SAdrian Hunter const struct sdhci_ops *ops; 54c4e05037SAdrian Hunter unsigned int quirks; 55c4e05037SAdrian Hunter unsigned int quirks2; 56c4e05037SAdrian Hunter unsigned long caps; 57c4e05037SAdrian Hunter unsigned int caps2; 58c4e05037SAdrian Hunter mmc_pm_flag_t pm_caps; 59c4e05037SAdrian Hunter }; 60c4e05037SAdrian Hunter 61c4e05037SAdrian Hunter struct sdhci_acpi_slot { 62c4e05037SAdrian Hunter const struct sdhci_acpi_chip *chip; 63c4e05037SAdrian Hunter unsigned int quirks; 64c4e05037SAdrian Hunter unsigned int quirks2; 65c4e05037SAdrian Hunter unsigned long caps; 66c4e05037SAdrian Hunter unsigned int caps2; 67c4e05037SAdrian Hunter mmc_pm_flag_t pm_caps; 68c4e05037SAdrian Hunter unsigned int flags; 69c4e05037SAdrian Hunter }; 70c4e05037SAdrian Hunter 71c4e05037SAdrian Hunter struct sdhci_acpi_host { 72c4e05037SAdrian Hunter struct sdhci_host *host; 73c4e05037SAdrian Hunter const struct sdhci_acpi_slot *slot; 74c4e05037SAdrian Hunter struct platform_device *pdev; 75c4e05037SAdrian Hunter bool use_runtime_pm; 76c4e05037SAdrian Hunter }; 77c4e05037SAdrian Hunter 78c4e05037SAdrian Hunter static inline bool sdhci_acpi_flag(struct sdhci_acpi_host *c, unsigned int flag) 79c4e05037SAdrian Hunter { 80c4e05037SAdrian Hunter return c->slot && (c->slot->flags & flag); 81c4e05037SAdrian Hunter } 82c4e05037SAdrian Hunter 83c4e05037SAdrian Hunter static int sdhci_acpi_enable_dma(struct sdhci_host *host) 84c4e05037SAdrian Hunter { 85c4e05037SAdrian Hunter return 0; 86c4e05037SAdrian Hunter } 87c4e05037SAdrian Hunter 88b04fa064SAdrian Hunter static void sdhci_acpi_int_hw_reset(struct sdhci_host *host) 89b04fa064SAdrian Hunter { 90b04fa064SAdrian Hunter u8 reg; 91b04fa064SAdrian Hunter 92b04fa064SAdrian Hunter reg = sdhci_readb(host, SDHCI_POWER_CONTROL); 93b04fa064SAdrian Hunter reg |= 0x10; 94b04fa064SAdrian Hunter sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); 95b04fa064SAdrian Hunter /* For eMMC, minimum is 1us but give it 9us for good measure */ 96b04fa064SAdrian Hunter udelay(9); 97b04fa064SAdrian Hunter reg &= ~0x10; 98b04fa064SAdrian Hunter sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); 99b04fa064SAdrian Hunter /* For eMMC, minimum is 200us but give it 300us for good measure */ 100b04fa064SAdrian Hunter usleep_range(300, 1000); 101b04fa064SAdrian Hunter } 102b04fa064SAdrian Hunter 103c4e05037SAdrian Hunter static const struct sdhci_ops sdhci_acpi_ops_dflt = { 104c4e05037SAdrian Hunter .enable_dma = sdhci_acpi_enable_dma, 105c4e05037SAdrian Hunter }; 106c4e05037SAdrian Hunter 107b04fa064SAdrian Hunter static const struct sdhci_ops sdhci_acpi_ops_int = { 108b04fa064SAdrian Hunter .enable_dma = sdhci_acpi_enable_dma, 109b04fa064SAdrian Hunter .hw_reset = sdhci_acpi_int_hw_reset, 110b04fa064SAdrian Hunter }; 111b04fa064SAdrian Hunter 112b04fa064SAdrian Hunter static const struct sdhci_acpi_chip sdhci_acpi_chip_int = { 113b04fa064SAdrian Hunter .ops = &sdhci_acpi_ops_int, 114b04fa064SAdrian Hunter }; 115b04fa064SAdrian Hunter 11607a58883SAdrian Hunter static const struct sdhci_acpi_slot sdhci_acpi_slot_int_emmc = { 117b04fa064SAdrian Hunter .chip = &sdhci_acpi_chip_int, 118b04fa064SAdrian Hunter .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE | MMC_CAP_HW_RESET, 11907a58883SAdrian Hunter .caps2 = MMC_CAP2_HC_ERASE_SZ, 12007a58883SAdrian Hunter .flags = SDHCI_ACPI_RUNTIME_PM, 12107a58883SAdrian Hunter }; 12207a58883SAdrian Hunter 123e5571397SAdrian Hunter static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = { 124e5571397SAdrian Hunter .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON, 125e5571397SAdrian Hunter .caps = MMC_CAP_NONREMOVABLE | MMC_CAP_POWER_OFF_CARD, 126e5571397SAdrian Hunter .flags = SDHCI_ACPI_RUNTIME_PM, 127e5571397SAdrian Hunter .pm_caps = MMC_PM_KEEP_POWER, 128e5571397SAdrian Hunter }; 129e5571397SAdrian Hunter 13007a58883SAdrian Hunter static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = { 131a61abe6eSAdrian Hunter .flags = SDHCI_ACPI_SD_CD | SDHCI_ACPI_RUNTIME_PM, 132a61abe6eSAdrian Hunter .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON, 13307a58883SAdrian Hunter }; 13407a58883SAdrian Hunter 13507a58883SAdrian Hunter struct sdhci_acpi_uid_slot { 13607a58883SAdrian Hunter const char *hid; 13707a58883SAdrian Hunter const char *uid; 13807a58883SAdrian Hunter const struct sdhci_acpi_slot *slot; 13907a58883SAdrian Hunter }; 14007a58883SAdrian Hunter 14107a58883SAdrian Hunter static const struct sdhci_acpi_uid_slot sdhci_acpi_uids[] = { 14207a58883SAdrian Hunter { "80860F14" , "1" , &sdhci_acpi_slot_int_emmc }, 14307a58883SAdrian Hunter { "80860F14" , "3" , &sdhci_acpi_slot_int_sd }, 14407a58883SAdrian Hunter { "INT33BB" , "2" , &sdhci_acpi_slot_int_sdio }, 14507a58883SAdrian Hunter { "INT33C6" , NULL, &sdhci_acpi_slot_int_sdio }, 14607a58883SAdrian Hunter { "PNP0D40" }, 14707a58883SAdrian Hunter { }, 14807a58883SAdrian Hunter }; 14907a58883SAdrian Hunter 150c4e05037SAdrian Hunter static const struct acpi_device_id sdhci_acpi_ids[] = { 15107a58883SAdrian Hunter { "80860F14" }, 15207a58883SAdrian Hunter { "INT33BB" }, 15307a58883SAdrian Hunter { "INT33C6" }, 154c4e05037SAdrian Hunter { "PNP0D40" }, 155c4e05037SAdrian Hunter { }, 156c4e05037SAdrian Hunter }; 157c4e05037SAdrian Hunter MODULE_DEVICE_TABLE(acpi, sdhci_acpi_ids); 158c4e05037SAdrian Hunter 15907a58883SAdrian Hunter static const struct sdhci_acpi_slot *sdhci_acpi_get_slot_by_ids(const char *hid, 16007a58883SAdrian Hunter const char *uid) 161c4e05037SAdrian Hunter { 16207a58883SAdrian Hunter const struct sdhci_acpi_uid_slot *u; 163c4e05037SAdrian Hunter 16407a58883SAdrian Hunter for (u = sdhci_acpi_uids; u->hid; u++) { 16507a58883SAdrian Hunter if (strcmp(u->hid, hid)) 16607a58883SAdrian Hunter continue; 16707a58883SAdrian Hunter if (!u->uid) 16807a58883SAdrian Hunter return u->slot; 16907a58883SAdrian Hunter if (uid && !strcmp(u->uid, uid)) 17007a58883SAdrian Hunter return u->slot; 17107a58883SAdrian Hunter } 172c4e05037SAdrian Hunter return NULL; 173c4e05037SAdrian Hunter } 174c4e05037SAdrian Hunter 17507a58883SAdrian Hunter static const struct sdhci_acpi_slot *sdhci_acpi_get_slot(acpi_handle handle, 17607a58883SAdrian Hunter const char *hid) 17707a58883SAdrian Hunter { 17807a58883SAdrian Hunter const struct sdhci_acpi_slot *slot; 17907a58883SAdrian Hunter struct acpi_device_info *info; 18007a58883SAdrian Hunter const char *uid = NULL; 18107a58883SAdrian Hunter acpi_status status; 18207a58883SAdrian Hunter 18307a58883SAdrian Hunter status = acpi_get_object_info(handle, &info); 18407a58883SAdrian Hunter if (!ACPI_FAILURE(status) && (info->valid & ACPI_VALID_UID)) 18507a58883SAdrian Hunter uid = info->unique_id.string; 18607a58883SAdrian Hunter 18707a58883SAdrian Hunter slot = sdhci_acpi_get_slot_by_ids(hid, uid); 18807a58883SAdrian Hunter 18907a58883SAdrian Hunter kfree(info); 19007a58883SAdrian Hunter return slot; 19107a58883SAdrian Hunter } 19207a58883SAdrian Hunter 193a61abe6eSAdrian Hunter #ifdef CONFIG_PM_RUNTIME 194a61abe6eSAdrian Hunter 195a61abe6eSAdrian Hunter static irqreturn_t sdhci_acpi_sd_cd(int irq, void *dev_id) 196a61abe6eSAdrian Hunter { 197a61abe6eSAdrian Hunter mmc_detect_change(dev_id, msecs_to_jiffies(200)); 198a61abe6eSAdrian Hunter return IRQ_HANDLED; 199a61abe6eSAdrian Hunter } 200a61abe6eSAdrian Hunter 20187875655SMika Westerberg static int sdhci_acpi_add_own_cd(struct device *dev, struct mmc_host *mmc) 202a61abe6eSAdrian Hunter { 20387875655SMika Westerberg struct gpio_desc *desc; 204a61abe6eSAdrian Hunter unsigned long flags; 205a61abe6eSAdrian Hunter int err, irq; 206a61abe6eSAdrian Hunter 20787875655SMika Westerberg desc = devm_gpiod_get_index(dev, "sd_cd", 0); 20887875655SMika Westerberg if (IS_ERR(desc)) { 20987875655SMika Westerberg err = PTR_ERR(desc); 210a61abe6eSAdrian Hunter goto out; 211a61abe6eSAdrian Hunter } 212a61abe6eSAdrian Hunter 21387875655SMika Westerberg err = gpiod_direction_input(desc); 214a61abe6eSAdrian Hunter if (err) 21587875655SMika Westerberg goto out_free; 216a61abe6eSAdrian Hunter 21787875655SMika Westerberg irq = gpiod_to_irq(desc); 2185a0e8074SWei Yongjun if (irq < 0) { 2195a0e8074SWei Yongjun err = irq; 220a61abe6eSAdrian Hunter goto out_free; 2215a0e8074SWei Yongjun } 222a61abe6eSAdrian Hunter 223a61abe6eSAdrian Hunter flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING; 224a61abe6eSAdrian Hunter err = devm_request_irq(dev, irq, sdhci_acpi_sd_cd, flags, "sd_cd", mmc); 225a61abe6eSAdrian Hunter if (err) 226a61abe6eSAdrian Hunter goto out_free; 227a61abe6eSAdrian Hunter 228a61abe6eSAdrian Hunter return 0; 229a61abe6eSAdrian Hunter 230a61abe6eSAdrian Hunter out_free: 23187875655SMika Westerberg devm_gpiod_put(dev, desc); 232a61abe6eSAdrian Hunter out: 233a61abe6eSAdrian Hunter dev_warn(dev, "failed to setup card detect wake up\n"); 234a61abe6eSAdrian Hunter return err; 235a61abe6eSAdrian Hunter } 236a61abe6eSAdrian Hunter 237a61abe6eSAdrian Hunter #else 238a61abe6eSAdrian Hunter 23987875655SMika Westerberg static int sdhci_acpi_add_own_cd(struct device *dev, struct mmc_host *mmc) 240a61abe6eSAdrian Hunter { 241a61abe6eSAdrian Hunter return 0; 242a61abe6eSAdrian Hunter } 243a61abe6eSAdrian Hunter 244a61abe6eSAdrian Hunter #endif 245a61abe6eSAdrian Hunter 2464e608e4eSGreg Kroah-Hartman static int sdhci_acpi_probe(struct platform_device *pdev) 247c4e05037SAdrian Hunter { 248c4e05037SAdrian Hunter struct device *dev = &pdev->dev; 249c4e05037SAdrian Hunter acpi_handle handle = ACPI_HANDLE(dev); 250c4e05037SAdrian Hunter struct acpi_device *device; 251c4e05037SAdrian Hunter struct sdhci_acpi_host *c; 252c4e05037SAdrian Hunter struct sdhci_host *host; 253c4e05037SAdrian Hunter struct resource *iomem; 254c4e05037SAdrian Hunter resource_size_t len; 255c4e05037SAdrian Hunter const char *hid; 25687875655SMika Westerberg int err; 257c4e05037SAdrian Hunter 258c4e05037SAdrian Hunter if (acpi_bus_get_device(handle, &device)) 259c4e05037SAdrian Hunter return -ENODEV; 260c4e05037SAdrian Hunter 261c4e05037SAdrian Hunter if (acpi_bus_get_status(device) || !device->status.present) 262c4e05037SAdrian Hunter return -ENODEV; 263c4e05037SAdrian Hunter 264c4e05037SAdrian Hunter hid = acpi_device_hid(device); 265c4e05037SAdrian Hunter 266c4e05037SAdrian Hunter iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 267c4e05037SAdrian Hunter if (!iomem) 268c4e05037SAdrian Hunter return -ENOMEM; 269c4e05037SAdrian Hunter 270c4e05037SAdrian Hunter len = resource_size(iomem); 271c4e05037SAdrian Hunter if (len < 0x100) 272c4e05037SAdrian Hunter dev_err(dev, "Invalid iomem size!\n"); 273c4e05037SAdrian Hunter 274c4e05037SAdrian Hunter if (!devm_request_mem_region(dev, iomem->start, len, dev_name(dev))) 275c4e05037SAdrian Hunter return -ENOMEM; 276c4e05037SAdrian Hunter 277c4e05037SAdrian Hunter host = sdhci_alloc_host(dev, sizeof(struct sdhci_acpi_host)); 278c4e05037SAdrian Hunter if (IS_ERR(host)) 279c4e05037SAdrian Hunter return PTR_ERR(host); 280c4e05037SAdrian Hunter 281c4e05037SAdrian Hunter c = sdhci_priv(host); 282c4e05037SAdrian Hunter c->host = host; 28307a58883SAdrian Hunter c->slot = sdhci_acpi_get_slot(handle, hid); 284c4e05037SAdrian Hunter c->pdev = pdev; 285c4e05037SAdrian Hunter c->use_runtime_pm = sdhci_acpi_flag(c, SDHCI_ACPI_RUNTIME_PM); 286c4e05037SAdrian Hunter 287c4e05037SAdrian Hunter platform_set_drvdata(pdev, c); 288c4e05037SAdrian Hunter 289c4e05037SAdrian Hunter host->hw_name = "ACPI"; 290c4e05037SAdrian Hunter host->ops = &sdhci_acpi_ops_dflt; 291c4e05037SAdrian Hunter host->irq = platform_get_irq(pdev, 0); 292c4e05037SAdrian Hunter 293c4e05037SAdrian Hunter host->ioaddr = devm_ioremap_nocache(dev, iomem->start, 294c4e05037SAdrian Hunter resource_size(iomem)); 295c4e05037SAdrian Hunter if (host->ioaddr == NULL) { 296c4e05037SAdrian Hunter err = -ENOMEM; 297c4e05037SAdrian Hunter goto err_free; 298c4e05037SAdrian Hunter } 299c4e05037SAdrian Hunter 300c4e05037SAdrian Hunter if (!dev->dma_mask) { 301c4e05037SAdrian Hunter u64 dma_mask; 302c4e05037SAdrian Hunter 303c4e05037SAdrian Hunter if (sdhci_readl(host, SDHCI_CAPABILITIES) & SDHCI_CAN_64BIT) { 304c4e05037SAdrian Hunter /* 64-bit DMA is not supported at present */ 305c4e05037SAdrian Hunter dma_mask = DMA_BIT_MASK(32); 306c4e05037SAdrian Hunter } else { 307c4e05037SAdrian Hunter dma_mask = DMA_BIT_MASK(32); 308c4e05037SAdrian Hunter } 309c4e05037SAdrian Hunter 31007f4450cSRussell King err = dma_coerce_mask_and_coherent(dev, dma_mask); 31107f4450cSRussell King if (err) 31207f4450cSRussell King goto err_free; 313c4e05037SAdrian Hunter } 314c4e05037SAdrian Hunter 315c4e05037SAdrian Hunter if (c->slot) { 316c4e05037SAdrian Hunter if (c->slot->chip) { 317c4e05037SAdrian Hunter host->ops = c->slot->chip->ops; 318c4e05037SAdrian Hunter host->quirks |= c->slot->chip->quirks; 319c4e05037SAdrian Hunter host->quirks2 |= c->slot->chip->quirks2; 320c4e05037SAdrian Hunter host->mmc->caps |= c->slot->chip->caps; 321c4e05037SAdrian Hunter host->mmc->caps2 |= c->slot->chip->caps2; 322c4e05037SAdrian Hunter host->mmc->pm_caps |= c->slot->chip->pm_caps; 323c4e05037SAdrian Hunter } 324c4e05037SAdrian Hunter host->quirks |= c->slot->quirks; 325c4e05037SAdrian Hunter host->quirks2 |= c->slot->quirks2; 326c4e05037SAdrian Hunter host->mmc->caps |= c->slot->caps; 327c4e05037SAdrian Hunter host->mmc->caps2 |= c->slot->caps2; 328c4e05037SAdrian Hunter host->mmc->pm_caps |= c->slot->pm_caps; 329c4e05037SAdrian Hunter } 330c4e05037SAdrian Hunter 3310d3e3350SAdrian Hunter host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP; 3320d3e3350SAdrian Hunter 333c4e05037SAdrian Hunter err = sdhci_add_host(host); 334c4e05037SAdrian Hunter if (err) 335c4e05037SAdrian Hunter goto err_free; 336c4e05037SAdrian Hunter 337a61abe6eSAdrian Hunter if (sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD)) { 33887875655SMika Westerberg if (sdhci_acpi_add_own_cd(dev, host->mmc)) 339a61abe6eSAdrian Hunter c->use_runtime_pm = false; 340a61abe6eSAdrian Hunter } 341a61abe6eSAdrian Hunter 342c4e05037SAdrian Hunter if (c->use_runtime_pm) { 3431d1ff458SAdrian Hunter pm_runtime_set_active(dev); 344c4e05037SAdrian Hunter pm_suspend_ignore_children(dev, 1); 345c4e05037SAdrian Hunter pm_runtime_set_autosuspend_delay(dev, 50); 346c4e05037SAdrian Hunter pm_runtime_use_autosuspend(dev); 347c4e05037SAdrian Hunter pm_runtime_enable(dev); 348c4e05037SAdrian Hunter } 349c4e05037SAdrian Hunter 350c4e05037SAdrian Hunter return 0; 351c4e05037SAdrian Hunter 352c4e05037SAdrian Hunter err_free: 353c4e05037SAdrian Hunter sdhci_free_host(c->host); 354c4e05037SAdrian Hunter return err; 355c4e05037SAdrian Hunter } 356c4e05037SAdrian Hunter 3574e608e4eSGreg Kroah-Hartman static int sdhci_acpi_remove(struct platform_device *pdev) 358c4e05037SAdrian Hunter { 359c4e05037SAdrian Hunter struct sdhci_acpi_host *c = platform_get_drvdata(pdev); 360c4e05037SAdrian Hunter struct device *dev = &pdev->dev; 361c4e05037SAdrian Hunter int dead; 362c4e05037SAdrian Hunter 363c4e05037SAdrian Hunter if (c->use_runtime_pm) { 364c4e05037SAdrian Hunter pm_runtime_get_sync(dev); 365c4e05037SAdrian Hunter pm_runtime_disable(dev); 366c4e05037SAdrian Hunter pm_runtime_put_noidle(dev); 367c4e05037SAdrian Hunter } 368c4e05037SAdrian Hunter 369c4e05037SAdrian Hunter dead = (sdhci_readl(c->host, SDHCI_INT_STATUS) == ~0); 370c4e05037SAdrian Hunter sdhci_remove_host(c->host, dead); 371c4e05037SAdrian Hunter sdhci_free_host(c->host); 372c4e05037SAdrian Hunter 373c4e05037SAdrian Hunter return 0; 374c4e05037SAdrian Hunter } 375c4e05037SAdrian Hunter 376c4e05037SAdrian Hunter #ifdef CONFIG_PM_SLEEP 377c4e05037SAdrian Hunter 378c4e05037SAdrian Hunter static int sdhci_acpi_suspend(struct device *dev) 379c4e05037SAdrian Hunter { 380c4e05037SAdrian Hunter struct sdhci_acpi_host *c = dev_get_drvdata(dev); 381c4e05037SAdrian Hunter 382c4e05037SAdrian Hunter return sdhci_suspend_host(c->host); 383c4e05037SAdrian Hunter } 384c4e05037SAdrian Hunter 385c4e05037SAdrian Hunter static int sdhci_acpi_resume(struct device *dev) 386c4e05037SAdrian Hunter { 387c4e05037SAdrian Hunter struct sdhci_acpi_host *c = dev_get_drvdata(dev); 388c4e05037SAdrian Hunter 389c4e05037SAdrian Hunter return sdhci_resume_host(c->host); 390c4e05037SAdrian Hunter } 391c4e05037SAdrian Hunter 392c4e05037SAdrian Hunter #else 393c4e05037SAdrian Hunter 394c4e05037SAdrian Hunter #define sdhci_acpi_suspend NULL 395c4e05037SAdrian Hunter #define sdhci_acpi_resume NULL 396c4e05037SAdrian Hunter 397c4e05037SAdrian Hunter #endif 398c4e05037SAdrian Hunter 399c4e05037SAdrian Hunter #ifdef CONFIG_PM_RUNTIME 400c4e05037SAdrian Hunter 401c4e05037SAdrian Hunter static int sdhci_acpi_runtime_suspend(struct device *dev) 402c4e05037SAdrian Hunter { 403c4e05037SAdrian Hunter struct sdhci_acpi_host *c = dev_get_drvdata(dev); 404c4e05037SAdrian Hunter 405c4e05037SAdrian Hunter return sdhci_runtime_suspend_host(c->host); 406c4e05037SAdrian Hunter } 407c4e05037SAdrian Hunter 408c4e05037SAdrian Hunter static int sdhci_acpi_runtime_resume(struct device *dev) 409c4e05037SAdrian Hunter { 410c4e05037SAdrian Hunter struct sdhci_acpi_host *c = dev_get_drvdata(dev); 411c4e05037SAdrian Hunter 412c4e05037SAdrian Hunter return sdhci_runtime_resume_host(c->host); 413c4e05037SAdrian Hunter } 414c4e05037SAdrian Hunter 415c4e05037SAdrian Hunter static int sdhci_acpi_runtime_idle(struct device *dev) 416c4e05037SAdrian Hunter { 417c4e05037SAdrian Hunter return 0; 418c4e05037SAdrian Hunter } 419c4e05037SAdrian Hunter 420c4e05037SAdrian Hunter #else 421c4e05037SAdrian Hunter 422c4e05037SAdrian Hunter #define sdhci_acpi_runtime_suspend NULL 423c4e05037SAdrian Hunter #define sdhci_acpi_runtime_resume NULL 424c4e05037SAdrian Hunter #define sdhci_acpi_runtime_idle NULL 425c4e05037SAdrian Hunter 426c4e05037SAdrian Hunter #endif 427c4e05037SAdrian Hunter 428c4e05037SAdrian Hunter static const struct dev_pm_ops sdhci_acpi_pm_ops = { 429c4e05037SAdrian Hunter .suspend = sdhci_acpi_suspend, 430c4e05037SAdrian Hunter .resume = sdhci_acpi_resume, 431c4e05037SAdrian Hunter .runtime_suspend = sdhci_acpi_runtime_suspend, 432c4e05037SAdrian Hunter .runtime_resume = sdhci_acpi_runtime_resume, 433c4e05037SAdrian Hunter .runtime_idle = sdhci_acpi_runtime_idle, 434c4e05037SAdrian Hunter }; 435c4e05037SAdrian Hunter 436c4e05037SAdrian Hunter static struct platform_driver sdhci_acpi_driver = { 437c4e05037SAdrian Hunter .driver = { 438c4e05037SAdrian Hunter .name = "sdhci-acpi", 439c4e05037SAdrian Hunter .owner = THIS_MODULE, 440c4e05037SAdrian Hunter .acpi_match_table = sdhci_acpi_ids, 441c4e05037SAdrian Hunter .pm = &sdhci_acpi_pm_ops, 442c4e05037SAdrian Hunter }, 443c4e05037SAdrian Hunter .probe = sdhci_acpi_probe, 4444e608e4eSGreg Kroah-Hartman .remove = sdhci_acpi_remove, 445c4e05037SAdrian Hunter }; 446c4e05037SAdrian Hunter 447c4e05037SAdrian Hunter module_platform_driver(sdhci_acpi_driver); 448c4e05037SAdrian Hunter 449c4e05037SAdrian Hunter MODULE_DESCRIPTION("Secure Digital Host Controller Interface ACPI driver"); 450c4e05037SAdrian Hunter MODULE_AUTHOR("Adrian Hunter"); 451c4e05037SAdrian Hunter MODULE_LICENSE("GPL v2"); 452