blob: 4e94684ab6ce047a9f3d46590e9b2b68d0eb6799 [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;
Adrian Hunter4f64f842014-11-04 12:42:47 +020078 bool dma_setup;
Adrian Hunterc4e05032012-11-23 21:17:34 +010079};
80
81static inline bool sdhci_acpi_flag(struct sdhci_acpi_host *c, unsigned int flag)
82{
83 return c->slot && (c->slot->flags & flag);
84}
85
86static int sdhci_acpi_enable_dma(struct sdhci_host *host)
87{
Adrian Hunter4f64f842014-11-04 12:42:47 +020088 struct sdhci_acpi_host *c = sdhci_priv(host);
89 struct device *dev = &c->pdev->dev;
90 int err = -1;
91
92 if (c->dma_setup)
93 return 0;
94
95 if (host->flags & SDHCI_USE_64_BIT_DMA) {
96 if (host->quirks2 & SDHCI_QUIRK2_BROKEN_64_BIT_DMA) {
97 host->flags &= ~SDHCI_USE_64_BIT_DMA;
98 } else {
99 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
100 if (err)
101 dev_warn(dev, "Failed to set 64-bit DMA mask\n");
102 }
103 }
104
105 if (err)
106 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
107
108 c->dma_setup = !err;
109
110 return err;
Adrian Hunterc4e05032012-11-23 21:17:34 +0100111}
112
Adrian Hunterb04fa062013-06-13 11:50:27 +0300113static void sdhci_acpi_int_hw_reset(struct sdhci_host *host)
114{
115 u8 reg;
116
117 reg = sdhci_readb(host, SDHCI_POWER_CONTROL);
118 reg |= 0x10;
119 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
120 /* For eMMC, minimum is 1us but give it 9us for good measure */
121 udelay(9);
122 reg &= ~0x10;
123 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
124 /* For eMMC, minimum is 200us but give it 300us for good measure */
125 usleep_range(300, 1000);
126}
127
Adrian Hunterc4e05032012-11-23 21:17:34 +0100128static const struct sdhci_ops sdhci_acpi_ops_dflt = {
Russell King17710592014-04-25 12:58:55 +0100129 .set_clock = sdhci_set_clock,
Adrian Hunterc4e05032012-11-23 21:17:34 +0100130 .enable_dma = sdhci_acpi_enable_dma,
Russell King2317f562014-04-25 12:57:07 +0100131 .set_bus_width = sdhci_set_bus_width,
Russell King03231f92014-04-25 12:57:12 +0100132 .reset = sdhci_reset,
Russell King96d7b782014-04-25 12:59:26 +0100133 .set_uhs_signaling = sdhci_set_uhs_signaling,
Adrian Hunterc4e05032012-11-23 21:17:34 +0100134};
135
Adrian Hunterb04fa062013-06-13 11:50:27 +0300136static const struct sdhci_ops sdhci_acpi_ops_int = {
Russell King17710592014-04-25 12:58:55 +0100137 .set_clock = sdhci_set_clock,
Adrian Hunterb04fa062013-06-13 11:50:27 +0300138 .enable_dma = sdhci_acpi_enable_dma,
Russell King2317f562014-04-25 12:57:07 +0100139 .set_bus_width = sdhci_set_bus_width,
Russell King03231f92014-04-25 12:57:12 +0100140 .reset = sdhci_reset,
Russell King96d7b782014-04-25 12:59:26 +0100141 .set_uhs_signaling = sdhci_set_uhs_signaling,
Adrian Hunterb04fa062013-06-13 11:50:27 +0300142 .hw_reset = sdhci_acpi_int_hw_reset,
143};
144
145static const struct sdhci_acpi_chip sdhci_acpi_chip_int = {
146 .ops = &sdhci_acpi_ops_int,
147};
148
Adrian Hunter6a645dd2016-02-09 16:12:38 +0200149static int bxt_get_cd(struct mmc_host *mmc)
150{
151 int gpio_cd = mmc_gpio_get_cd(mmc);
152 struct sdhci_host *host = mmc_priv(mmc);
153 unsigned long flags;
154 int ret = 0;
155
156 if (!gpio_cd)
157 return 0;
158
159 pm_runtime_get_sync(mmc->parent);
160
161 spin_lock_irqsave(&host->lock, flags);
162
163 if (host->flags & SDHCI_DEVICE_DEAD)
164 goto out;
165
166 ret = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
167out:
168 spin_unlock_irqrestore(&host->lock, flags);
169
170 pm_runtime_mark_last_busy(mmc->parent);
171 pm_runtime_put_autosuspend(mmc->parent);
172
173 return ret;
174}
175
Adrian Hunter7dafca82014-10-06 15:23:06 +0300176static int sdhci_acpi_emmc_probe_slot(struct platform_device *pdev,
177 const char *hid, const char *uid)
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800178{
179 struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
180 struct sdhci_host *host;
181
182 if (!c || !c->host)
183 return 0;
184
185 host = c->host;
186
Andy Shevchenko94203042015-01-12 19:37:25 +0200187 /* Platform specific code during emmc probe slot goes here */
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800188
Adrian Hunter80243792014-10-06 15:23:07 +0300189 if (hid && uid && !strcmp(hid, "80860F14") && !strcmp(uid, "1") &&
190 sdhci_readl(host, SDHCI_CAPABILITIES) == 0x446cc8b2 &&
191 sdhci_readl(host, SDHCI_CAPABILITIES_1) == 0x00000807)
192 host->timeout_clk = 1000; /* 1000 kHz i.e. 1 MHz */
193
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800194 return 0;
195}
196
Adrian Hunter7dafca82014-10-06 15:23:06 +0300197static int sdhci_acpi_sdio_probe_slot(struct platform_device *pdev,
198 const char *hid, const char *uid)
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800199{
200 struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
201 struct sdhci_host *host;
202
203 if (!c || !c->host)
204 return 0;
205
206 host = c->host;
207
Andy Shevchenko94203042015-01-12 19:37:25 +0200208 /* Platform specific code during sdio probe slot goes here */
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800209
210 return 0;
211}
212
Adrian Hunter7dafca82014-10-06 15:23:06 +0300213static int sdhci_acpi_sd_probe_slot(struct platform_device *pdev,
214 const char *hid, const char *uid)
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800215{
216 struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
217 struct sdhci_host *host;
218
219 if (!c || !c->host || !c->slot)
220 return 0;
221
222 host = c->host;
223
Andy Shevchenko94203042015-01-12 19:37:25 +0200224 /* Platform specific code during sd probe slot goes here */
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800225
Adrian Hunter6a645dd2016-02-09 16:12:38 +0200226 if (hid && !strcmp(hid, "80865ACA"))
227 host->mmc_host_ops.get_cd = bxt_get_cd;
228
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800229 return 0;
230}
231
Adrian Hunter07a58882013-04-26 11:27:22 +0300232static const struct sdhci_acpi_slot sdhci_acpi_slot_int_emmc = {
Adrian Hunterb04fa062013-06-13 11:50:27 +0300233 .chip = &sdhci_acpi_chip_int,
Maurice Petallof25c3372014-07-08 19:11:01 +0800234 .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
Adrian Hunter9d65cb82014-12-01 15:51:19 +0200235 MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR |
236 MMC_CAP_BUS_WIDTH_TEST | MMC_CAP_WAIT_WHILE_BUSY,
Adrian Hunter07a58882013-04-26 11:27:22 +0300237 .caps2 = MMC_CAP2_HC_ERASE_SZ,
238 .flags = SDHCI_ACPI_RUNTIME_PM,
Adrian Huntere1f56332014-12-01 15:51:17 +0200239 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Huntere839b132015-10-21 11:15:46 +0300240 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
241 SDHCI_QUIRK2_STOP_WITH_TC |
242 SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400,
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800243 .probe_slot = sdhci_acpi_emmc_probe_slot,
Adrian Hunter07a58882013-04-26 11:27:22 +0300244};
245
Adrian Huntere5571392012-12-10 21:18:48 +0100246static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = {
Adrian Huntere1f56332014-12-01 15:51:17 +0200247 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
248 SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Huntere5571392012-12-10 21:18:48 +0100249 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
Adrian Hunter9d65cb82014-12-01 15:51:19 +0200250 .caps = MMC_CAP_NONREMOVABLE | MMC_CAP_POWER_OFF_CARD |
251 MMC_CAP_BUS_WIDTH_TEST | MMC_CAP_WAIT_WHILE_BUSY,
Adrian Huntere5571392012-12-10 21:18:48 +0100252 .flags = SDHCI_ACPI_RUNTIME_PM,
253 .pm_caps = MMC_PM_KEEP_POWER,
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800254 .probe_slot = sdhci_acpi_sdio_probe_slot,
Adrian Huntere5571392012-12-10 21:18:48 +0100255};
256
Adrian Hunter07a58882013-04-26 11:27:22 +0300257static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = {
Adrian Hunter4fd44092014-03-10 15:02:42 +0200258 .flags = SDHCI_ACPI_SD_CD | SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL |
259 SDHCI_ACPI_RUNTIME_PM,
Adrian Huntere1f56332014-12-01 15:51:17 +0200260 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunter934e31b2014-09-24 10:27:28 +0300261 .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON |
262 SDHCI_QUIRK2_STOP_WITH_TC,
Adrian Hunter9d65cb82014-12-01 15:51:19 +0200263 .caps = MMC_CAP_BUS_WIDTH_TEST | MMC_CAP_WAIT_WHILE_BUSY,
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800264 .probe_slot = sdhci_acpi_sd_probe_slot,
Adrian Hunter07a58882013-04-26 11:27:22 +0300265};
266
Philip Elcan70cce2a2016-03-03 11:38:46 -0500267static const struct sdhci_acpi_slot sdhci_acpi_slot_qcom_sd_3v = {
268 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION,
269 .quirks2 = SDHCI_QUIRK2_NO_1_8_V,
270 .caps = MMC_CAP_NONREMOVABLE,
271};
272
273static const struct sdhci_acpi_slot sdhci_acpi_slot_qcom_sd = {
274 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION,
275 .caps = MMC_CAP_NONREMOVABLE,
276};
277
Adrian Hunter07a58882013-04-26 11:27:22 +0300278struct sdhci_acpi_uid_slot {
279 const char *hid;
280 const char *uid;
281 const struct sdhci_acpi_slot *slot;
282};
283
284static const struct sdhci_acpi_uid_slot sdhci_acpi_uids[] = {
Adrian Huntere839b132015-10-21 11:15:46 +0300285 { "80865ACA", NULL, &sdhci_acpi_slot_int_sd },
286 { "80865ACC", NULL, &sdhci_acpi_slot_int_emmc },
287 { "80865AD0", NULL, &sdhci_acpi_slot_int_sdio },
Adrian Hunter07a58882013-04-26 11:27:22 +0300288 { "80860F14" , "1" , &sdhci_acpi_slot_int_emmc },
289 { "80860F14" , "3" , &sdhci_acpi_slot_int_sd },
Adrian Hunteraad95dc2014-03-10 15:02:43 +0200290 { "80860F16" , NULL, &sdhci_acpi_slot_int_sd },
Adrian Hunter07a58882013-04-26 11:27:22 +0300291 { "INT33BB" , "2" , &sdhci_acpi_slot_int_sdio },
Adrian Hunter7147eaf2014-09-24 10:27:29 +0300292 { "INT33BB" , "3" , &sdhci_acpi_slot_int_sd },
Adrian Hunter07a58882013-04-26 11:27:22 +0300293 { "INT33C6" , NULL, &sdhci_acpi_slot_int_sdio },
Mika Westerberg07c001c2013-11-12 12:01:33 +0200294 { "INT3436" , NULL, &sdhci_acpi_slot_int_sdio },
Adrian Hunterd0ed8e62015-01-05 14:47:57 +0200295 { "INT344D" , NULL, &sdhci_acpi_slot_int_sdio },
Michele Curti0cd2f042015-09-05 08:49:52 +0200296 { "PNP0FFF" , "3" , &sdhci_acpi_slot_int_sd },
Adrian Hunter07a58882013-04-26 11:27:22 +0300297 { "PNP0D40" },
Philip Elcan70cce2a2016-03-03 11:38:46 -0500298 { "QCOM8051", NULL, &sdhci_acpi_slot_qcom_sd_3v },
299 { "QCOM8052", NULL, &sdhci_acpi_slot_qcom_sd },
Adrian Hunter07a58882013-04-26 11:27:22 +0300300 { },
301};
302
Adrian Hunterc4e05032012-11-23 21:17:34 +0100303static const struct acpi_device_id sdhci_acpi_ids[] = {
Adrian Huntere839b132015-10-21 11:15:46 +0300304 { "80865ACA" },
305 { "80865ACC" },
306 { "80865AD0" },
Adrian Hunter07a58882013-04-26 11:27:22 +0300307 { "80860F14" },
Adrian Hunteraad95dc2014-03-10 15:02:43 +0200308 { "80860F16" },
Adrian Hunter07a58882013-04-26 11:27:22 +0300309 { "INT33BB" },
310 { "INT33C6" },
Mika Westerberg07c001c2013-11-12 12:01:33 +0200311 { "INT3436" },
Adrian Hunterd0ed8e62015-01-05 14:47:57 +0200312 { "INT344D" },
Adrian Hunter07a58882013-04-26 11:27:22 +0300313 { "PNP0D40" },
Philip Elcan70cce2a2016-03-03 11:38:46 -0500314 { "QCOM8051" },
315 { "QCOM8052" },
Adrian Hunterc4e05032012-11-23 21:17:34 +0100316 { },
317};
318MODULE_DEVICE_TABLE(acpi, sdhci_acpi_ids);
319
Adrian Hunter3db35252014-10-06 15:23:05 +0300320static const struct sdhci_acpi_slot *sdhci_acpi_get_slot(const char *hid,
321 const char *uid)
Adrian Hunterc4e05032012-11-23 21:17:34 +0100322{
Adrian Hunter07a58882013-04-26 11:27:22 +0300323 const struct sdhci_acpi_uid_slot *u;
Adrian Hunterc4e05032012-11-23 21:17:34 +0100324
Adrian Hunter07a58882013-04-26 11:27:22 +0300325 for (u = sdhci_acpi_uids; u->hid; u++) {
326 if (strcmp(u->hid, hid))
327 continue;
328 if (!u->uid)
329 return u->slot;
330 if (uid && !strcmp(u->uid, uid))
331 return u->slot;
332 }
Adrian Hunterc4e05032012-11-23 21:17:34 +0100333 return NULL;
334}
335
Greg Kroah-Hartman4e608e42012-12-21 15:05:47 -0800336static int sdhci_acpi_probe(struct platform_device *pdev)
Adrian Hunterc4e05032012-11-23 21:17:34 +0100337{
338 struct device *dev = &pdev->dev;
339 acpi_handle handle = ACPI_HANDLE(dev);
340 struct acpi_device *device;
341 struct sdhci_acpi_host *c;
342 struct sdhci_host *host;
343 struct resource *iomem;
344 resource_size_t len;
345 const char *hid;
Adrian Hunter3db35252014-10-06 15:23:05 +0300346 const char *uid;
Mika Westerberg87875652014-01-08 12:40:55 +0200347 int err;
Adrian Hunterc4e05032012-11-23 21:17:34 +0100348
349 if (acpi_bus_get_device(handle, &device))
350 return -ENODEV;
351
352 if (acpi_bus_get_status(device) || !device->status.present)
353 return -ENODEV;
354
355 hid = acpi_device_hid(device);
Adrian Hunter3db35252014-10-06 15:23:05 +0300356 uid = device->pnp.unique_id;
Adrian Hunterc4e05032012-11-23 21:17:34 +0100357
358 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
359 if (!iomem)
360 return -ENOMEM;
361
362 len = resource_size(iomem);
363 if (len < 0x100)
364 dev_err(dev, "Invalid iomem size!\n");
365
366 if (!devm_request_mem_region(dev, iomem->start, len, dev_name(dev)))
367 return -ENOMEM;
368
369 host = sdhci_alloc_host(dev, sizeof(struct sdhci_acpi_host));
370 if (IS_ERR(host))
371 return PTR_ERR(host);
372
373 c = sdhci_priv(host);
374 c->host = host;
Adrian Hunter3db35252014-10-06 15:23:05 +0300375 c->slot = sdhci_acpi_get_slot(hid, uid);
Adrian Hunterc4e05032012-11-23 21:17:34 +0100376 c->pdev = pdev;
377 c->use_runtime_pm = sdhci_acpi_flag(c, SDHCI_ACPI_RUNTIME_PM);
378
379 platform_set_drvdata(pdev, c);
380
381 host->hw_name = "ACPI";
382 host->ops = &sdhci_acpi_ops_dflt;
383 host->irq = platform_get_irq(pdev, 0);
384
385 host->ioaddr = devm_ioremap_nocache(dev, iomem->start,
386 resource_size(iomem));
387 if (host->ioaddr == NULL) {
388 err = -ENOMEM;
389 goto err_free;
390 }
391
Adrian Hunterc4e05032012-11-23 21:17:34 +0100392 if (c->slot) {
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800393 if (c->slot->probe_slot) {
Adrian Hunter7dafca82014-10-06 15:23:06 +0300394 err = c->slot->probe_slot(pdev, hid, uid);
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800395 if (err)
396 goto err_free;
397 }
Adrian Hunterc4e05032012-11-23 21:17:34 +0100398 if (c->slot->chip) {
399 host->ops = c->slot->chip->ops;
400 host->quirks |= c->slot->chip->quirks;
401 host->quirks2 |= c->slot->chip->quirks2;
402 host->mmc->caps |= c->slot->chip->caps;
403 host->mmc->caps2 |= c->slot->chip->caps2;
404 host->mmc->pm_caps |= c->slot->chip->pm_caps;
405 }
406 host->quirks |= c->slot->quirks;
407 host->quirks2 |= c->slot->quirks2;
408 host->mmc->caps |= c->slot->caps;
409 host->mmc->caps2 |= c->slot->caps2;
410 host->mmc->pm_caps |= c->slot->pm_caps;
411 }
412
Adrian Hunter0d3e3352013-04-04 16:41:06 +0300413 host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
414
Adrian Hunter4fd44092014-03-10 15:02:42 +0200415 if (sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD)) {
416 bool v = sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL);
417
Linus Walleij89168b42014-10-02 09:08:46 +0200418 if (mmc_gpiod_request_cd(host->mmc, NULL, 0, v, 0, NULL)) {
Adrian Hunter4fd44092014-03-10 15:02:42 +0200419 dev_warn(dev, "failed to setup card detect gpio\n");
420 c->use_runtime_pm = false;
421 }
422 }
423
Adrian Hunterc4e05032012-11-23 21:17:34 +0100424 err = sdhci_add_host(host);
425 if (err)
426 goto err_free;
427
428 if (c->use_runtime_pm) {
Adrian Hunter1d1ff452013-04-26 11:27:21 +0300429 pm_runtime_set_active(dev);
Adrian Hunterc4e05032012-11-23 21:17:34 +0100430 pm_suspend_ignore_children(dev, 1);
431 pm_runtime_set_autosuspend_delay(dev, 50);
432 pm_runtime_use_autosuspend(dev);
433 pm_runtime_enable(dev);
434 }
435
Fu, Zhonghui4e6a2ef2016-01-22 12:35:26 +0800436 device_enable_async_suspend(dev);
437
Adrian Hunterc4e05032012-11-23 21:17:34 +0100438 return 0;
439
440err_free:
Adrian Hunterc4e05032012-11-23 21:17:34 +0100441 sdhci_free_host(c->host);
442 return err;
443}
444
Greg Kroah-Hartman4e608e42012-12-21 15:05:47 -0800445static int sdhci_acpi_remove(struct platform_device *pdev)
Adrian Hunterc4e05032012-11-23 21:17:34 +0100446{
447 struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
448 struct device *dev = &pdev->dev;
449 int dead;
450
451 if (c->use_runtime_pm) {
452 pm_runtime_get_sync(dev);
453 pm_runtime_disable(dev);
454 pm_runtime_put_noidle(dev);
455 }
456
Gao, Yunpeng578b36b2014-09-01 11:35:40 +0800457 if (c->slot && c->slot->remove_slot)
458 c->slot->remove_slot(pdev);
459
Adrian Hunterc4e05032012-11-23 21:17:34 +0100460 dead = (sdhci_readl(c->host, SDHCI_INT_STATUS) == ~0);
461 sdhci_remove_host(c->host, dead);
Adrian Hunterc4e05032012-11-23 21:17:34 +0100462 sdhci_free_host(c->host);
463
464 return 0;
465}
466
467#ifdef CONFIG_PM_SLEEP
468
469static int sdhci_acpi_suspend(struct device *dev)
470{
471 struct sdhci_acpi_host *c = dev_get_drvdata(dev);
472
473 return sdhci_suspend_host(c->host);
474}
475
476static int sdhci_acpi_resume(struct device *dev)
477{
478 struct sdhci_acpi_host *c = dev_get_drvdata(dev);
479
480 return sdhci_resume_host(c->host);
481}
482
483#else
484
485#define sdhci_acpi_suspend NULL
486#define sdhci_acpi_resume NULL
487
488#endif
489
Rafael J. Wysocki162d6f92014-12-05 03:05:33 +0100490#ifdef CONFIG_PM
Adrian Hunterc4e05032012-11-23 21:17:34 +0100491
492static int sdhci_acpi_runtime_suspend(struct device *dev)
493{
494 struct sdhci_acpi_host *c = dev_get_drvdata(dev);
495
496 return sdhci_runtime_suspend_host(c->host);
497}
498
499static int sdhci_acpi_runtime_resume(struct device *dev)
500{
501 struct sdhci_acpi_host *c = dev_get_drvdata(dev);
502
503 return sdhci_runtime_resume_host(c->host);
504}
505
Adrian Hunterc4e05032012-11-23 21:17:34 +0100506#endif
507
508static const struct dev_pm_ops sdhci_acpi_pm_ops = {
509 .suspend = sdhci_acpi_suspend,
510 .resume = sdhci_acpi_resume,
Peter Griffin1d75f742014-08-12 17:14:29 +0100511 SET_RUNTIME_PM_OPS(sdhci_acpi_runtime_suspend,
Ulf Hansson9b449e92015-01-02 14:47:00 +0100512 sdhci_acpi_runtime_resume, NULL)
Adrian Hunterc4e05032012-11-23 21:17:34 +0100513};
514
515static struct platform_driver sdhci_acpi_driver = {
516 .driver = {
517 .name = "sdhci-acpi",
Adrian Hunterc4e05032012-11-23 21:17:34 +0100518 .acpi_match_table = sdhci_acpi_ids,
519 .pm = &sdhci_acpi_pm_ops,
520 },
521 .probe = sdhci_acpi_probe,
Greg Kroah-Hartman4e608e42012-12-21 15:05:47 -0800522 .remove = sdhci_acpi_remove,
Adrian Hunterc4e05032012-11-23 21:17:34 +0100523};
524
525module_platform_driver(sdhci_acpi_driver);
526
527MODULE_DESCRIPTION("Secure Digital Host Controller Interface ACPI driver");
528MODULE_AUTHOR("Adrian Hunter");
529MODULE_LICENSE("GPL v2");