blob: 6839e41c6d585294bc75ab01a69f73e1f433b9b1 [file] [log] [blame]
Adrian Hunterc4e05032012-11-23 21:17:34 +01001/*
2 * Secure Digital Host Controller Interface ACPI driver.
3 *
4 * Copyright (c) 2012, Intel Corporation.
5 *
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.
9 *
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
13 * more details.
14 *
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.
18 *
19 */
20
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>
27#include <linux/io.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>
36#include <linux/pm.h>
37#include <linux/pm_runtime.h>
Adrian Hunterb04fa062013-06-13 11:50:27 +030038#include <linux/delay.h>
Adrian Hunterc4e05032012-11-23 21:17:34 +010039
40#include <linux/mmc/host.h>
41#include <linux/mmc/pm.h>
Adrian Hunter4fd44092014-03-10 15:02:42 +020042#include <linux/mmc/slot-gpio.h>
Adrian Hunterc4e05032012-11-23 21:17:34 +010043
44#include "sdhci.h"
45
46enum {
Adrian Hunter4fd44092014-03-10 15:02:42 +020047 SDHCI_ACPI_SD_CD = BIT(0),
48 SDHCI_ACPI_RUNTIME_PM = BIT(1),
49 SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL = BIT(2),
Adrian Hunterc4e05032012-11-23 21:17:34 +010050};
51
52struct sdhci_acpi_chip {
53 const struct sdhci_ops *ops;
54 unsigned int quirks;
55 unsigned int quirks2;
56 unsigned long caps;
57 unsigned int caps2;
58 mmc_pm_flag_t pm_caps;
59};
60
61struct sdhci_acpi_slot {
62 const struct sdhci_acpi_chip *chip;
63 unsigned int quirks;
64 unsigned int quirks2;
65 unsigned long caps;
66 unsigned int caps2;
67 mmc_pm_flag_t pm_caps;
68 unsigned int flags;
Adrian Hunter7dafca82014-10-06 15:23:06 +030069 int (*probe_slot)(struct platform_device *, const char *, const char *);
Gao, Yunpeng578b36b2014-09-01 11:35:40 +080070 int (*remove_slot)(struct platform_device *);
Adrian Hunterc4e05032012-11-23 21:17:34 +010071};
72
73struct sdhci_acpi_host {
74 struct sdhci_host *host;
75 const struct sdhci_acpi_slot *slot;
76 struct platform_device *pdev;
77 bool use_runtime_pm;
78};
79
80static inline bool sdhci_acpi_flag(struct sdhci_acpi_host *c, unsigned int flag)
81{
82 return c->slot && (c->slot->flags & flag);
83}
84
Adrian Hunterb04fa062013-06-13 11:50:27 +030085static void sdhci_acpi_int_hw_reset(struct sdhci_host *host)
86{
87 u8 reg;
88
89 reg = sdhci_readb(host, SDHCI_POWER_CONTROL);
90 reg |= 0x10;
91 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
92 /* For eMMC, minimum is 1us but give it 9us for good measure */
93 udelay(9);
94 reg &= ~0x10;
95 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
96 /* For eMMC, minimum is 200us but give it 300us for good measure */
97 usleep_range(300, 1000);
98}
99
Adrian Hunterc4e05032012-11-23 21:17:34 +0100100static const struct sdhci_ops sdhci_acpi_ops_dflt = {
Russell King17710592014-04-25 12:58:55 +0100101 .set_clock = sdhci_set_clock,
Russell King2317f562014-04-25 12:57:07 +0100102 .set_bus_width = sdhci_set_bus_width,
Russell King03231f92014-04-25 12:57:12 +0100103 .reset = sdhci_reset,
Russell King96d7b782014-04-25 12:59:26 +0100104 .set_uhs_signaling = sdhci_set_uhs_signaling,
Adrian Hunterc4e05032012-11-23 21:17:34 +0100105};
106
Adrian Hunterb04fa062013-06-13 11:50:27 +0300107static const struct sdhci_ops sdhci_acpi_ops_int = {
Russell King17710592014-04-25 12:58:55 +0100108 .set_clock = sdhci_set_clock,
Russell King2317f562014-04-25 12:57:07 +0100109 .set_bus_width = sdhci_set_bus_width,
Russell King03231f92014-04-25 12:57:12 +0100110 .reset = sdhci_reset,
Russell King96d7b782014-04-25 12:59:26 +0100111 .set_uhs_signaling = sdhci_set_uhs_signaling,
Adrian Hunterb04fa062013-06-13 11:50:27 +0300112 .hw_reset = sdhci_acpi_int_hw_reset,
113};
114
115static const struct sdhci_acpi_chip sdhci_acpi_chip_int = {
116 .ops = &sdhci_acpi_ops_int,
117};
118
Adrian Hunter6a645dd2016-02-09 16:12:38 +0200119static int bxt_get_cd(struct mmc_host *mmc)
120{
121 int gpio_cd = mmc_gpio_get_cd(mmc);
122 struct sdhci_host *host = mmc_priv(mmc);
123 unsigned long flags;
124 int ret = 0;
125
126 if (!gpio_cd)
127 return 0;
128
129 pm_runtime_get_sync(mmc->parent);
130
131 spin_lock_irqsave(&host->lock, flags);
132
133 if (host->flags & SDHCI_DEVICE_DEAD)
134 goto out;
135
136 ret = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
137out:
138 spin_unlock_irqrestore(&host->lock, flags);
139
140 pm_runtime_mark_last_busy(mmc->parent);
141 pm_runtime_put_autosuspend(mmc->parent);
142
143 return ret;
144}
145
Adrian Hunter7dafca82014-10-06 15:23:06 +0300146static int sdhci_acpi_emmc_probe_slot(struct platform_device *pdev,
147 const char *hid, const char *uid)
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800148{
149 struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
150 struct sdhci_host *host;
151
152 if (!c || !c->host)
153 return 0;
154
155 host = c->host;
156
Andy Shevchenko94203042015-01-12 19:37:25 +0200157 /* Platform specific code during emmc probe slot goes here */
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800158
Adrian Hunter80243792014-10-06 15:23:07 +0300159 if (hid && uid && !strcmp(hid, "80860F14") && !strcmp(uid, "1") &&
160 sdhci_readl(host, SDHCI_CAPABILITIES) == 0x446cc8b2 &&
161 sdhci_readl(host, SDHCI_CAPABILITIES_1) == 0x00000807)
162 host->timeout_clk = 1000; /* 1000 kHz i.e. 1 MHz */
163
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800164 return 0;
165}
166
Adrian Hunter7dafca82014-10-06 15:23:06 +0300167static int sdhci_acpi_sdio_probe_slot(struct platform_device *pdev,
168 const char *hid, const char *uid)
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800169{
170 struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
171 struct sdhci_host *host;
172
173 if (!c || !c->host)
174 return 0;
175
176 host = c->host;
177
Andy Shevchenko94203042015-01-12 19:37:25 +0200178 /* Platform specific code during sdio probe slot goes here */
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800179
180 return 0;
181}
182
Adrian Hunter7dafca82014-10-06 15:23:06 +0300183static int sdhci_acpi_sd_probe_slot(struct platform_device *pdev,
184 const char *hid, const char *uid)
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800185{
186 struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
187 struct sdhci_host *host;
188
189 if (!c || !c->host || !c->slot)
190 return 0;
191
192 host = c->host;
193
Andy Shevchenko94203042015-01-12 19:37:25 +0200194 /* Platform specific code during sd probe slot goes here */
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800195
Adrian Hunter6a645dd2016-02-09 16:12:38 +0200196 if (hid && !strcmp(hid, "80865ACA"))
197 host->mmc_host_ops.get_cd = bxt_get_cd;
198
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800199 return 0;
200}
201
Adrian Hunter07a58882013-04-26 11:27:22 +0300202static const struct sdhci_acpi_slot sdhci_acpi_slot_int_emmc = {
Adrian Hunterb04fa062013-06-13 11:50:27 +0300203 .chip = &sdhci_acpi_chip_int,
Maurice Petallof25c3372014-07-08 19:11:01 +0800204 .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
Adrian Hunter9d65cb82014-12-01 15:51:19 +0200205 MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR |
206 MMC_CAP_BUS_WIDTH_TEST | MMC_CAP_WAIT_WHILE_BUSY,
Adrian Hunter07a58882013-04-26 11:27:22 +0300207 .caps2 = MMC_CAP2_HC_ERASE_SZ,
208 .flags = SDHCI_ACPI_RUNTIME_PM,
Adrian Huntere1f56332014-12-01 15:51:17 +0200209 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Huntere839b132015-10-21 11:15:46 +0300210 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
211 SDHCI_QUIRK2_STOP_WITH_TC |
212 SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400,
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800213 .probe_slot = sdhci_acpi_emmc_probe_slot,
Adrian Hunter07a58882013-04-26 11:27:22 +0300214};
215
Adrian Huntere5571392012-12-10 21:18:48 +0100216static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = {
Adrian Huntere1f56332014-12-01 15:51:17 +0200217 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
218 SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Huntere5571392012-12-10 21:18:48 +0100219 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
Adrian Hunter9d65cb82014-12-01 15:51:19 +0200220 .caps = MMC_CAP_NONREMOVABLE | MMC_CAP_POWER_OFF_CARD |
221 MMC_CAP_BUS_WIDTH_TEST | MMC_CAP_WAIT_WHILE_BUSY,
Adrian Huntere5571392012-12-10 21:18:48 +0100222 .flags = SDHCI_ACPI_RUNTIME_PM,
223 .pm_caps = MMC_PM_KEEP_POWER,
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800224 .probe_slot = sdhci_acpi_sdio_probe_slot,
Adrian Huntere5571392012-12-10 21:18:48 +0100225};
226
Adrian Hunter07a58882013-04-26 11:27:22 +0300227static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = {
Adrian Hunter4fd44092014-03-10 15:02:42 +0200228 .flags = SDHCI_ACPI_SD_CD | SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL |
229 SDHCI_ACPI_RUNTIME_PM,
Adrian Huntere1f56332014-12-01 15:51:17 +0200230 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunter934e31b2014-09-24 10:27:28 +0300231 .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON |
232 SDHCI_QUIRK2_STOP_WITH_TC,
Adrian Hunter9d65cb82014-12-01 15:51:19 +0200233 .caps = MMC_CAP_BUS_WIDTH_TEST | MMC_CAP_WAIT_WHILE_BUSY,
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800234 .probe_slot = sdhci_acpi_sd_probe_slot,
Adrian Hunter07a58882013-04-26 11:27:22 +0300235};
236
Philip Elcan70cce2a2016-03-03 11:38:46 -0500237static const struct sdhci_acpi_slot sdhci_acpi_slot_qcom_sd_3v = {
238 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION,
239 .quirks2 = SDHCI_QUIRK2_NO_1_8_V,
240 .caps = MMC_CAP_NONREMOVABLE,
241};
242
243static const struct sdhci_acpi_slot sdhci_acpi_slot_qcom_sd = {
244 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION,
245 .caps = MMC_CAP_NONREMOVABLE,
246};
247
Adrian Hunter07a58882013-04-26 11:27:22 +0300248struct sdhci_acpi_uid_slot {
249 const char *hid;
250 const char *uid;
251 const struct sdhci_acpi_slot *slot;
252};
253
254static const struct sdhci_acpi_uid_slot sdhci_acpi_uids[] = {
Adrian Huntere839b132015-10-21 11:15:46 +0300255 { "80865ACA", NULL, &sdhci_acpi_slot_int_sd },
256 { "80865ACC", NULL, &sdhci_acpi_slot_int_emmc },
257 { "80865AD0", NULL, &sdhci_acpi_slot_int_sdio },
Adrian Hunter07a58882013-04-26 11:27:22 +0300258 { "80860F14" , "1" , &sdhci_acpi_slot_int_emmc },
259 { "80860F14" , "3" , &sdhci_acpi_slot_int_sd },
Adrian Hunteraad95dc2014-03-10 15:02:43 +0200260 { "80860F16" , NULL, &sdhci_acpi_slot_int_sd },
Adrian Hunter07a58882013-04-26 11:27:22 +0300261 { "INT33BB" , "2" , &sdhci_acpi_slot_int_sdio },
Adrian Hunter7147eaf2014-09-24 10:27:29 +0300262 { "INT33BB" , "3" , &sdhci_acpi_slot_int_sd },
Adrian Hunter07a58882013-04-26 11:27:22 +0300263 { "INT33C6" , NULL, &sdhci_acpi_slot_int_sdio },
Mika Westerberg07c001c2013-11-12 12:01:33 +0200264 { "INT3436" , NULL, &sdhci_acpi_slot_int_sdio },
Adrian Hunterd0ed8e62015-01-05 14:47:57 +0200265 { "INT344D" , NULL, &sdhci_acpi_slot_int_sdio },
Michele Curti0cd2f042015-09-05 08:49:52 +0200266 { "PNP0FFF" , "3" , &sdhci_acpi_slot_int_sd },
Adrian Hunter07a58882013-04-26 11:27:22 +0300267 { "PNP0D40" },
Philip Elcan70cce2a2016-03-03 11:38:46 -0500268 { "QCOM8051", NULL, &sdhci_acpi_slot_qcom_sd_3v },
269 { "QCOM8052", NULL, &sdhci_acpi_slot_qcom_sd },
Adrian Hunter07a58882013-04-26 11:27:22 +0300270 { },
271};
272
Adrian Hunterc4e05032012-11-23 21:17:34 +0100273static const struct acpi_device_id sdhci_acpi_ids[] = {
Adrian Huntere839b132015-10-21 11:15:46 +0300274 { "80865ACA" },
275 { "80865ACC" },
276 { "80865AD0" },
Adrian Hunter07a58882013-04-26 11:27:22 +0300277 { "80860F14" },
Adrian Hunteraad95dc2014-03-10 15:02:43 +0200278 { "80860F16" },
Adrian Hunter07a58882013-04-26 11:27:22 +0300279 { "INT33BB" },
280 { "INT33C6" },
Mika Westerberg07c001c2013-11-12 12:01:33 +0200281 { "INT3436" },
Adrian Hunterd0ed8e62015-01-05 14:47:57 +0200282 { "INT344D" },
Adrian Hunter07a58882013-04-26 11:27:22 +0300283 { "PNP0D40" },
Philip Elcan70cce2a2016-03-03 11:38:46 -0500284 { "QCOM8051" },
285 { "QCOM8052" },
Adrian Hunterc4e05032012-11-23 21:17:34 +0100286 { },
287};
288MODULE_DEVICE_TABLE(acpi, sdhci_acpi_ids);
289
Adrian Hunter3db35252014-10-06 15:23:05 +0300290static const struct sdhci_acpi_slot *sdhci_acpi_get_slot(const char *hid,
291 const char *uid)
Adrian Hunterc4e05032012-11-23 21:17:34 +0100292{
Adrian Hunter07a58882013-04-26 11:27:22 +0300293 const struct sdhci_acpi_uid_slot *u;
Adrian Hunterc4e05032012-11-23 21:17:34 +0100294
Adrian Hunter07a58882013-04-26 11:27:22 +0300295 for (u = sdhci_acpi_uids; u->hid; u++) {
296 if (strcmp(u->hid, hid))
297 continue;
298 if (!u->uid)
299 return u->slot;
300 if (uid && !strcmp(u->uid, uid))
301 return u->slot;
302 }
Adrian Hunterc4e05032012-11-23 21:17:34 +0100303 return NULL;
304}
305
Greg Kroah-Hartman4e608e42012-12-21 15:05:47 -0800306static int sdhci_acpi_probe(struct platform_device *pdev)
Adrian Hunterc4e05032012-11-23 21:17:34 +0100307{
308 struct device *dev = &pdev->dev;
309 acpi_handle handle = ACPI_HANDLE(dev);
310 struct acpi_device *device;
311 struct sdhci_acpi_host *c;
312 struct sdhci_host *host;
313 struct resource *iomem;
314 resource_size_t len;
315 const char *hid;
Adrian Hunter3db35252014-10-06 15:23:05 +0300316 const char *uid;
Mika Westerberg87875652014-01-08 12:40:55 +0200317 int err;
Adrian Hunterc4e05032012-11-23 21:17:34 +0100318
319 if (acpi_bus_get_device(handle, &device))
320 return -ENODEV;
321
322 if (acpi_bus_get_status(device) || !device->status.present)
323 return -ENODEV;
324
325 hid = acpi_device_hid(device);
Adrian Hunter3db35252014-10-06 15:23:05 +0300326 uid = device->pnp.unique_id;
Adrian Hunterc4e05032012-11-23 21:17:34 +0100327
328 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
329 if (!iomem)
330 return -ENOMEM;
331
332 len = resource_size(iomem);
333 if (len < 0x100)
334 dev_err(dev, "Invalid iomem size!\n");
335
336 if (!devm_request_mem_region(dev, iomem->start, len, dev_name(dev)))
337 return -ENOMEM;
338
339 host = sdhci_alloc_host(dev, sizeof(struct sdhci_acpi_host));
340 if (IS_ERR(host))
341 return PTR_ERR(host);
342
343 c = sdhci_priv(host);
344 c->host = host;
Adrian Hunter3db35252014-10-06 15:23:05 +0300345 c->slot = sdhci_acpi_get_slot(hid, uid);
Adrian Hunterc4e05032012-11-23 21:17:34 +0100346 c->pdev = pdev;
347 c->use_runtime_pm = sdhci_acpi_flag(c, SDHCI_ACPI_RUNTIME_PM);
348
349 platform_set_drvdata(pdev, c);
350
351 host->hw_name = "ACPI";
352 host->ops = &sdhci_acpi_ops_dflt;
353 host->irq = platform_get_irq(pdev, 0);
354
355 host->ioaddr = devm_ioremap_nocache(dev, iomem->start,
356 resource_size(iomem));
357 if (host->ioaddr == NULL) {
358 err = -ENOMEM;
359 goto err_free;
360 }
361
Adrian Hunterc4e05032012-11-23 21:17:34 +0100362 if (c->slot) {
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800363 if (c->slot->probe_slot) {
Adrian Hunter7dafca82014-10-06 15:23:06 +0300364 err = c->slot->probe_slot(pdev, hid, uid);
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800365 if (err)
366 goto err_free;
367 }
Adrian Hunterc4e05032012-11-23 21:17:34 +0100368 if (c->slot->chip) {
369 host->ops = c->slot->chip->ops;
370 host->quirks |= c->slot->chip->quirks;
371 host->quirks2 |= c->slot->chip->quirks2;
372 host->mmc->caps |= c->slot->chip->caps;
373 host->mmc->caps2 |= c->slot->chip->caps2;
374 host->mmc->pm_caps |= c->slot->chip->pm_caps;
375 }
376 host->quirks |= c->slot->quirks;
377 host->quirks2 |= c->slot->quirks2;
378 host->mmc->caps |= c->slot->caps;
379 host->mmc->caps2 |= c->slot->caps2;
380 host->mmc->pm_caps |= c->slot->pm_caps;
381 }
382
Adrian Hunter0d3e3352013-04-04 16:41:06 +0300383 host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
384
Adrian Hunter4fd44092014-03-10 15:02:42 +0200385 if (sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD)) {
386 bool v = sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL);
387
Linus Walleij89168b42014-10-02 09:08:46 +0200388 if (mmc_gpiod_request_cd(host->mmc, NULL, 0, v, 0, NULL)) {
Adrian Hunter4fd44092014-03-10 15:02:42 +0200389 dev_warn(dev, "failed to setup card detect gpio\n");
390 c->use_runtime_pm = false;
391 }
392 }
393
Adrian Hunterc4e05032012-11-23 21:17:34 +0100394 err = sdhci_add_host(host);
395 if (err)
396 goto err_free;
397
398 if (c->use_runtime_pm) {
Adrian Hunter1d1ff452013-04-26 11:27:21 +0300399 pm_runtime_set_active(dev);
Adrian Hunterc4e05032012-11-23 21:17:34 +0100400 pm_suspend_ignore_children(dev, 1);
401 pm_runtime_set_autosuspend_delay(dev, 50);
402 pm_runtime_use_autosuspend(dev);
403 pm_runtime_enable(dev);
404 }
405
Fu, Zhonghui4e6a2ef2016-01-22 12:35:26 +0800406 device_enable_async_suspend(dev);
407
Adrian Hunterc4e05032012-11-23 21:17:34 +0100408 return 0;
409
410err_free:
Adrian Hunterc4e05032012-11-23 21:17:34 +0100411 sdhci_free_host(c->host);
412 return err;
413}
414
Greg Kroah-Hartman4e608e42012-12-21 15:05:47 -0800415static int sdhci_acpi_remove(struct platform_device *pdev)
Adrian Hunterc4e05032012-11-23 21:17:34 +0100416{
417 struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
418 struct device *dev = &pdev->dev;
419 int dead;
420
421 if (c->use_runtime_pm) {
422 pm_runtime_get_sync(dev);
423 pm_runtime_disable(dev);
424 pm_runtime_put_noidle(dev);
425 }
426
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800427 if (c->slot && c->slot->remove_slot)
428 c->slot->remove_slot(pdev);
429
Adrian Hunterc4e05032012-11-23 21:17:34 +0100430 dead = (sdhci_readl(c->host, SDHCI_INT_STATUS) == ~0);
431 sdhci_remove_host(c->host, dead);
Adrian Hunterc4e05032012-11-23 21:17:34 +0100432 sdhci_free_host(c->host);
433
434 return 0;
435}
436
437#ifdef CONFIG_PM_SLEEP
438
439static int sdhci_acpi_suspend(struct device *dev)
440{
441 struct sdhci_acpi_host *c = dev_get_drvdata(dev);
442
443 return sdhci_suspend_host(c->host);
444}
445
446static int sdhci_acpi_resume(struct device *dev)
447{
448 struct sdhci_acpi_host *c = dev_get_drvdata(dev);
449
450 return sdhci_resume_host(c->host);
451}
452
453#else
454
455#define sdhci_acpi_suspend NULL
456#define sdhci_acpi_resume NULL
457
458#endif
459
Rafael J. Wysocki162d6f92014-12-05 03:05:33 +0100460#ifdef CONFIG_PM
Adrian Hunterc4e05032012-11-23 21:17:34 +0100461
462static int sdhci_acpi_runtime_suspend(struct device *dev)
463{
464 struct sdhci_acpi_host *c = dev_get_drvdata(dev);
465
466 return sdhci_runtime_suspend_host(c->host);
467}
468
469static int sdhci_acpi_runtime_resume(struct device *dev)
470{
471 struct sdhci_acpi_host *c = dev_get_drvdata(dev);
472
473 return sdhci_runtime_resume_host(c->host);
474}
475
Adrian Hunterc4e05032012-11-23 21:17:34 +0100476#endif
477
478static const struct dev_pm_ops sdhci_acpi_pm_ops = {
479 .suspend = sdhci_acpi_suspend,
480 .resume = sdhci_acpi_resume,
Peter Griffin1d75f742014-08-12 17:14:29 +0100481 SET_RUNTIME_PM_OPS(sdhci_acpi_runtime_suspend,
Ulf Hansson9b449e92015-01-02 14:47:00 +0100482 sdhci_acpi_runtime_resume, NULL)
Adrian Hunterc4e05032012-11-23 21:17:34 +0100483};
484
485static struct platform_driver sdhci_acpi_driver = {
486 .driver = {
487 .name = "sdhci-acpi",
Adrian Hunterc4e05032012-11-23 21:17:34 +0100488 .acpi_match_table = sdhci_acpi_ids,
489 .pm = &sdhci_acpi_pm_ops,
490 },
491 .probe = sdhci_acpi_probe,
Greg Kroah-Hartman4e608e42012-12-21 15:05:47 -0800492 .remove = sdhci_acpi_remove,
Adrian Hunterc4e05032012-11-23 21:17:34 +0100493};
494
495module_platform_driver(sdhci_acpi_driver);
496
497MODULE_DESCRIPTION("Secure Digital Host Controller Interface ACPI driver");
498MODULE_AUTHOR("Adrian Hunter");
499MODULE_LICENSE("GPL v2");