xref: /linux/drivers/mmc/host/sdhci-acpi.c (revision 2317f56c055fcad524bf6a873df48a754e7ebc4d)
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;
70c4e05037SAdrian Hunter };
71c4e05037SAdrian Hunter 
72c4e05037SAdrian Hunter struct sdhci_acpi_host {
73c4e05037SAdrian Hunter 	struct sdhci_host		*host;
74c4e05037SAdrian Hunter 	const struct sdhci_acpi_slot	*slot;
75c4e05037SAdrian Hunter 	struct platform_device		*pdev;
76c4e05037SAdrian Hunter 	bool				use_runtime_pm;
77c4e05037SAdrian Hunter };
78c4e05037SAdrian Hunter 
79c4e05037SAdrian Hunter static inline bool sdhci_acpi_flag(struct sdhci_acpi_host *c, unsigned int flag)
80c4e05037SAdrian Hunter {
81c4e05037SAdrian Hunter 	return c->slot && (c->slot->flags & flag);
82c4e05037SAdrian Hunter }
83c4e05037SAdrian Hunter 
84c4e05037SAdrian Hunter static int sdhci_acpi_enable_dma(struct sdhci_host *host)
85c4e05037SAdrian Hunter {
86c4e05037SAdrian Hunter 	return 0;
87c4e05037SAdrian Hunter }
88c4e05037SAdrian Hunter 
89b04fa064SAdrian Hunter static void sdhci_acpi_int_hw_reset(struct sdhci_host *host)
90b04fa064SAdrian Hunter {
91b04fa064SAdrian Hunter 	u8 reg;
92b04fa064SAdrian Hunter 
93b04fa064SAdrian Hunter 	reg = sdhci_readb(host, SDHCI_POWER_CONTROL);
94b04fa064SAdrian Hunter 	reg |= 0x10;
95b04fa064SAdrian Hunter 	sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
96b04fa064SAdrian Hunter 	/* For eMMC, minimum is 1us but give it 9us for good measure */
97b04fa064SAdrian Hunter 	udelay(9);
98b04fa064SAdrian Hunter 	reg &= ~0x10;
99b04fa064SAdrian Hunter 	sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
100b04fa064SAdrian Hunter 	/* For eMMC, minimum is 200us but give it 300us for good measure */
101b04fa064SAdrian Hunter 	usleep_range(300, 1000);
102b04fa064SAdrian Hunter }
103b04fa064SAdrian Hunter 
104c4e05037SAdrian Hunter static const struct sdhci_ops sdhci_acpi_ops_dflt = {
105c4e05037SAdrian Hunter 	.enable_dma = sdhci_acpi_enable_dma,
106*2317f56cSRussell King 	.set_bus_width = sdhci_set_bus_width,
107c4e05037SAdrian Hunter };
108c4e05037SAdrian Hunter 
109b04fa064SAdrian Hunter static const struct sdhci_ops sdhci_acpi_ops_int = {
110b04fa064SAdrian Hunter 	.enable_dma = sdhci_acpi_enable_dma,
111*2317f56cSRussell King 	.set_bus_width = sdhci_set_bus_width,
112b04fa064SAdrian Hunter 	.hw_reset   = sdhci_acpi_int_hw_reset,
113b04fa064SAdrian Hunter };
114b04fa064SAdrian Hunter 
115b04fa064SAdrian Hunter static const struct sdhci_acpi_chip sdhci_acpi_chip_int = {
116b04fa064SAdrian Hunter 	.ops = &sdhci_acpi_ops_int,
117b04fa064SAdrian Hunter };
118b04fa064SAdrian Hunter 
11907a58883SAdrian Hunter static const struct sdhci_acpi_slot sdhci_acpi_slot_int_emmc = {
120b04fa064SAdrian Hunter 	.chip    = &sdhci_acpi_chip_int,
121b04fa064SAdrian Hunter 	.caps    = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE | MMC_CAP_HW_RESET,
12207a58883SAdrian Hunter 	.caps2   = MMC_CAP2_HC_ERASE_SZ,
12307a58883SAdrian Hunter 	.flags   = SDHCI_ACPI_RUNTIME_PM,
12407a58883SAdrian Hunter };
12507a58883SAdrian Hunter 
126e5571397SAdrian Hunter static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = {
127c6748017SAdrian Hunter 	.quirks  = SDHCI_QUIRK_BROKEN_CARD_DETECTION,
128e5571397SAdrian Hunter 	.quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
129e5571397SAdrian Hunter 	.caps    = MMC_CAP_NONREMOVABLE | MMC_CAP_POWER_OFF_CARD,
130e5571397SAdrian Hunter 	.flags   = SDHCI_ACPI_RUNTIME_PM,
131e5571397SAdrian Hunter 	.pm_caps = MMC_PM_KEEP_POWER,
132e5571397SAdrian Hunter };
133e5571397SAdrian Hunter 
13407a58883SAdrian Hunter static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = {
1354fd4409cSAdrian Hunter 	.flags   = SDHCI_ACPI_SD_CD | SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL |
1364fd4409cSAdrian Hunter 		   SDHCI_ACPI_RUNTIME_PM,
137a61abe6eSAdrian Hunter 	.quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON,
13807a58883SAdrian Hunter };
13907a58883SAdrian Hunter 
14007a58883SAdrian Hunter struct sdhci_acpi_uid_slot {
14107a58883SAdrian Hunter 	const char *hid;
14207a58883SAdrian Hunter 	const char *uid;
14307a58883SAdrian Hunter 	const struct sdhci_acpi_slot *slot;
14407a58883SAdrian Hunter };
14507a58883SAdrian Hunter 
14607a58883SAdrian Hunter static const struct sdhci_acpi_uid_slot sdhci_acpi_uids[] = {
14707a58883SAdrian Hunter 	{ "80860F14" , "1" , &sdhci_acpi_slot_int_emmc },
14807a58883SAdrian Hunter 	{ "80860F14" , "3" , &sdhci_acpi_slot_int_sd   },
149aad95dc4SAdrian Hunter 	{ "80860F16" , NULL, &sdhci_acpi_slot_int_sd   },
15007a58883SAdrian Hunter 	{ "INT33BB"  , "2" , &sdhci_acpi_slot_int_sdio },
15107a58883SAdrian Hunter 	{ "INT33C6"  , NULL, &sdhci_acpi_slot_int_sdio },
15207c001c1SMika Westerberg 	{ "INT3436"  , NULL, &sdhci_acpi_slot_int_sdio },
15307a58883SAdrian Hunter 	{ "PNP0D40"  },
15407a58883SAdrian Hunter 	{ },
15507a58883SAdrian Hunter };
15607a58883SAdrian Hunter 
157c4e05037SAdrian Hunter static const struct acpi_device_id sdhci_acpi_ids[] = {
15807a58883SAdrian Hunter 	{ "80860F14" },
159aad95dc4SAdrian Hunter 	{ "80860F16" },
16007a58883SAdrian Hunter 	{ "INT33BB"  },
16107a58883SAdrian Hunter 	{ "INT33C6"  },
16207c001c1SMika Westerberg 	{ "INT3436"  },
163c4e05037SAdrian Hunter 	{ "PNP0D40"  },
164c4e05037SAdrian Hunter 	{ },
165c4e05037SAdrian Hunter };
166c4e05037SAdrian Hunter MODULE_DEVICE_TABLE(acpi, sdhci_acpi_ids);
167c4e05037SAdrian Hunter 
16807a58883SAdrian Hunter static const struct sdhci_acpi_slot *sdhci_acpi_get_slot_by_ids(const char *hid,
16907a58883SAdrian Hunter 								const char *uid)
170c4e05037SAdrian Hunter {
17107a58883SAdrian Hunter 	const struct sdhci_acpi_uid_slot *u;
172c4e05037SAdrian Hunter 
17307a58883SAdrian Hunter 	for (u = sdhci_acpi_uids; u->hid; u++) {
17407a58883SAdrian Hunter 		if (strcmp(u->hid, hid))
17507a58883SAdrian Hunter 			continue;
17607a58883SAdrian Hunter 		if (!u->uid)
17707a58883SAdrian Hunter 			return u->slot;
17807a58883SAdrian Hunter 		if (uid && !strcmp(u->uid, uid))
17907a58883SAdrian Hunter 			return u->slot;
18007a58883SAdrian Hunter 	}
181c4e05037SAdrian Hunter 	return NULL;
182c4e05037SAdrian Hunter }
183c4e05037SAdrian Hunter 
18407a58883SAdrian Hunter static const struct sdhci_acpi_slot *sdhci_acpi_get_slot(acpi_handle handle,
18507a58883SAdrian Hunter 							 const char *hid)
18607a58883SAdrian Hunter {
18707a58883SAdrian Hunter 	const struct sdhci_acpi_slot *slot;
18807a58883SAdrian Hunter 	struct acpi_device_info *info;
18907a58883SAdrian Hunter 	const char *uid = NULL;
19007a58883SAdrian Hunter 	acpi_status status;
19107a58883SAdrian Hunter 
19207a58883SAdrian Hunter 	status = acpi_get_object_info(handle, &info);
19307a58883SAdrian Hunter 	if (!ACPI_FAILURE(status) && (info->valid & ACPI_VALID_UID))
19407a58883SAdrian Hunter 		uid = info->unique_id.string;
19507a58883SAdrian Hunter 
19607a58883SAdrian Hunter 	slot = sdhci_acpi_get_slot_by_ids(hid, uid);
19707a58883SAdrian Hunter 
19807a58883SAdrian Hunter 	kfree(info);
19907a58883SAdrian Hunter 	return slot;
20007a58883SAdrian Hunter }
20107a58883SAdrian Hunter 
2024e608e4eSGreg Kroah-Hartman static int sdhci_acpi_probe(struct platform_device *pdev)
203c4e05037SAdrian Hunter {
204c4e05037SAdrian Hunter 	struct device *dev = &pdev->dev;
205c4e05037SAdrian Hunter 	acpi_handle handle = ACPI_HANDLE(dev);
206c4e05037SAdrian Hunter 	struct acpi_device *device;
207c4e05037SAdrian Hunter 	struct sdhci_acpi_host *c;
208c4e05037SAdrian Hunter 	struct sdhci_host *host;
209c4e05037SAdrian Hunter 	struct resource *iomem;
210c4e05037SAdrian Hunter 	resource_size_t len;
211c4e05037SAdrian Hunter 	const char *hid;
21287875655SMika Westerberg 	int err;
213c4e05037SAdrian Hunter 
214c4e05037SAdrian Hunter 	if (acpi_bus_get_device(handle, &device))
215c4e05037SAdrian Hunter 		return -ENODEV;
216c4e05037SAdrian Hunter 
217c4e05037SAdrian Hunter 	if (acpi_bus_get_status(device) || !device->status.present)
218c4e05037SAdrian Hunter 		return -ENODEV;
219c4e05037SAdrian Hunter 
220c4e05037SAdrian Hunter 	hid = acpi_device_hid(device);
221c4e05037SAdrian Hunter 
222c4e05037SAdrian Hunter 	iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
223c4e05037SAdrian Hunter 	if (!iomem)
224c4e05037SAdrian Hunter 		return -ENOMEM;
225c4e05037SAdrian Hunter 
226c4e05037SAdrian Hunter 	len = resource_size(iomem);
227c4e05037SAdrian Hunter 	if (len < 0x100)
228c4e05037SAdrian Hunter 		dev_err(dev, "Invalid iomem size!\n");
229c4e05037SAdrian Hunter 
230c4e05037SAdrian Hunter 	if (!devm_request_mem_region(dev, iomem->start, len, dev_name(dev)))
231c4e05037SAdrian Hunter 		return -ENOMEM;
232c4e05037SAdrian Hunter 
233c4e05037SAdrian Hunter 	host = sdhci_alloc_host(dev, sizeof(struct sdhci_acpi_host));
234c4e05037SAdrian Hunter 	if (IS_ERR(host))
235c4e05037SAdrian Hunter 		return PTR_ERR(host);
236c4e05037SAdrian Hunter 
237c4e05037SAdrian Hunter 	c = sdhci_priv(host);
238c4e05037SAdrian Hunter 	c->host = host;
23907a58883SAdrian Hunter 	c->slot = sdhci_acpi_get_slot(handle, hid);
240c4e05037SAdrian Hunter 	c->pdev = pdev;
241c4e05037SAdrian Hunter 	c->use_runtime_pm = sdhci_acpi_flag(c, SDHCI_ACPI_RUNTIME_PM);
242c4e05037SAdrian Hunter 
243c4e05037SAdrian Hunter 	platform_set_drvdata(pdev, c);
244c4e05037SAdrian Hunter 
245c4e05037SAdrian Hunter 	host->hw_name	= "ACPI";
246c4e05037SAdrian Hunter 	host->ops	= &sdhci_acpi_ops_dflt;
247c4e05037SAdrian Hunter 	host->irq	= platform_get_irq(pdev, 0);
248c4e05037SAdrian Hunter 
249c4e05037SAdrian Hunter 	host->ioaddr = devm_ioremap_nocache(dev, iomem->start,
250c4e05037SAdrian Hunter 					    resource_size(iomem));
251c4e05037SAdrian Hunter 	if (host->ioaddr == NULL) {
252c4e05037SAdrian Hunter 		err = -ENOMEM;
253c4e05037SAdrian Hunter 		goto err_free;
254c4e05037SAdrian Hunter 	}
255c4e05037SAdrian Hunter 
256c4e05037SAdrian Hunter 	if (!dev->dma_mask) {
257c4e05037SAdrian Hunter 		u64 dma_mask;
258c4e05037SAdrian Hunter 
259c4e05037SAdrian Hunter 		if (sdhci_readl(host, SDHCI_CAPABILITIES) & SDHCI_CAN_64BIT) {
260c4e05037SAdrian Hunter 			/* 64-bit DMA is not supported at present */
261c4e05037SAdrian Hunter 			dma_mask = DMA_BIT_MASK(32);
262c4e05037SAdrian Hunter 		} else {
263c4e05037SAdrian Hunter 			dma_mask = DMA_BIT_MASK(32);
264c4e05037SAdrian Hunter 		}
265c4e05037SAdrian Hunter 
26607f4450cSRussell King 		err = dma_coerce_mask_and_coherent(dev, dma_mask);
26707f4450cSRussell King 		if (err)
26807f4450cSRussell King 			goto err_free;
269c4e05037SAdrian Hunter 	}
270c4e05037SAdrian Hunter 
271c4e05037SAdrian Hunter 	if (c->slot) {
272c4e05037SAdrian Hunter 		if (c->slot->chip) {
273c4e05037SAdrian Hunter 			host->ops            = c->slot->chip->ops;
274c4e05037SAdrian Hunter 			host->quirks        |= c->slot->chip->quirks;
275c4e05037SAdrian Hunter 			host->quirks2       |= c->slot->chip->quirks2;
276c4e05037SAdrian Hunter 			host->mmc->caps     |= c->slot->chip->caps;
277c4e05037SAdrian Hunter 			host->mmc->caps2    |= c->slot->chip->caps2;
278c4e05037SAdrian Hunter 			host->mmc->pm_caps  |= c->slot->chip->pm_caps;
279c4e05037SAdrian Hunter 		}
280c4e05037SAdrian Hunter 		host->quirks        |= c->slot->quirks;
281c4e05037SAdrian Hunter 		host->quirks2       |= c->slot->quirks2;
282c4e05037SAdrian Hunter 		host->mmc->caps     |= c->slot->caps;
283c4e05037SAdrian Hunter 		host->mmc->caps2    |= c->slot->caps2;
284c4e05037SAdrian Hunter 		host->mmc->pm_caps  |= c->slot->pm_caps;
285c4e05037SAdrian Hunter 	}
286c4e05037SAdrian Hunter 
2870d3e3350SAdrian Hunter 	host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
2880d3e3350SAdrian Hunter 
2894fd4409cSAdrian Hunter 	if (sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD)) {
2904fd4409cSAdrian Hunter 		bool v = sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL);
2914fd4409cSAdrian Hunter 
2924fd4409cSAdrian Hunter 		if (mmc_gpiod_request_cd(host->mmc, NULL, 0, v, 0)) {
2934fd4409cSAdrian Hunter 			dev_warn(dev, "failed to setup card detect gpio\n");
2944fd4409cSAdrian Hunter 			c->use_runtime_pm = false;
2954fd4409cSAdrian Hunter 		}
2964fd4409cSAdrian Hunter 	}
2974fd4409cSAdrian Hunter 
298c4e05037SAdrian Hunter 	err = sdhci_add_host(host);
299c4e05037SAdrian Hunter 	if (err)
300c4e05037SAdrian Hunter 		goto err_free;
301c4e05037SAdrian Hunter 
302c4e05037SAdrian Hunter 	if (c->use_runtime_pm) {
3031d1ff458SAdrian Hunter 		pm_runtime_set_active(dev);
304c4e05037SAdrian Hunter 		pm_suspend_ignore_children(dev, 1);
305c4e05037SAdrian Hunter 		pm_runtime_set_autosuspend_delay(dev, 50);
306c4e05037SAdrian Hunter 		pm_runtime_use_autosuspend(dev);
307c4e05037SAdrian Hunter 		pm_runtime_enable(dev);
308c4e05037SAdrian Hunter 	}
309c4e05037SAdrian Hunter 
310c4e05037SAdrian Hunter 	return 0;
311c4e05037SAdrian Hunter 
312c4e05037SAdrian Hunter err_free:
313c4e05037SAdrian Hunter 	sdhci_free_host(c->host);
314c4e05037SAdrian Hunter 	return err;
315c4e05037SAdrian Hunter }
316c4e05037SAdrian Hunter 
3174e608e4eSGreg Kroah-Hartman static int sdhci_acpi_remove(struct platform_device *pdev)
318c4e05037SAdrian Hunter {
319c4e05037SAdrian Hunter 	struct sdhci_acpi_host *c = platform_get_drvdata(pdev);
320c4e05037SAdrian Hunter 	struct device *dev = &pdev->dev;
321c4e05037SAdrian Hunter 	int dead;
322c4e05037SAdrian Hunter 
323c4e05037SAdrian Hunter 	if (c->use_runtime_pm) {
324c4e05037SAdrian Hunter 		pm_runtime_get_sync(dev);
325c4e05037SAdrian Hunter 		pm_runtime_disable(dev);
326c4e05037SAdrian Hunter 		pm_runtime_put_noidle(dev);
327c4e05037SAdrian Hunter 	}
328c4e05037SAdrian Hunter 
329c4e05037SAdrian Hunter 	dead = (sdhci_readl(c->host, SDHCI_INT_STATUS) == ~0);
330c4e05037SAdrian Hunter 	sdhci_remove_host(c->host, dead);
331c4e05037SAdrian Hunter 	sdhci_free_host(c->host);
332c4e05037SAdrian Hunter 
333c4e05037SAdrian Hunter 	return 0;
334c4e05037SAdrian Hunter }
335c4e05037SAdrian Hunter 
336c4e05037SAdrian Hunter #ifdef CONFIG_PM_SLEEP
337c4e05037SAdrian Hunter 
338c4e05037SAdrian Hunter static int sdhci_acpi_suspend(struct device *dev)
339c4e05037SAdrian Hunter {
340c4e05037SAdrian Hunter 	struct sdhci_acpi_host *c = dev_get_drvdata(dev);
341c4e05037SAdrian Hunter 
342c4e05037SAdrian Hunter 	return sdhci_suspend_host(c->host);
343c4e05037SAdrian Hunter }
344c4e05037SAdrian Hunter 
345c4e05037SAdrian Hunter static int sdhci_acpi_resume(struct device *dev)
346c4e05037SAdrian Hunter {
347c4e05037SAdrian Hunter 	struct sdhci_acpi_host *c = dev_get_drvdata(dev);
348c4e05037SAdrian Hunter 
349c4e05037SAdrian Hunter 	return sdhci_resume_host(c->host);
350c4e05037SAdrian Hunter }
351c4e05037SAdrian Hunter 
352c4e05037SAdrian Hunter #else
353c4e05037SAdrian Hunter 
354c4e05037SAdrian Hunter #define sdhci_acpi_suspend	NULL
355c4e05037SAdrian Hunter #define sdhci_acpi_resume	NULL
356c4e05037SAdrian Hunter 
357c4e05037SAdrian Hunter #endif
358c4e05037SAdrian Hunter 
359c4e05037SAdrian Hunter #ifdef CONFIG_PM_RUNTIME
360c4e05037SAdrian Hunter 
361c4e05037SAdrian Hunter static int sdhci_acpi_runtime_suspend(struct device *dev)
362c4e05037SAdrian Hunter {
363c4e05037SAdrian Hunter 	struct sdhci_acpi_host *c = dev_get_drvdata(dev);
364c4e05037SAdrian Hunter 
365c4e05037SAdrian Hunter 	return sdhci_runtime_suspend_host(c->host);
366c4e05037SAdrian Hunter }
367c4e05037SAdrian Hunter 
368c4e05037SAdrian Hunter static int sdhci_acpi_runtime_resume(struct device *dev)
369c4e05037SAdrian Hunter {
370c4e05037SAdrian Hunter 	struct sdhci_acpi_host *c = dev_get_drvdata(dev);
371c4e05037SAdrian Hunter 
372c4e05037SAdrian Hunter 	return sdhci_runtime_resume_host(c->host);
373c4e05037SAdrian Hunter }
374c4e05037SAdrian Hunter 
375c4e05037SAdrian Hunter static int sdhci_acpi_runtime_idle(struct device *dev)
376c4e05037SAdrian Hunter {
377c4e05037SAdrian Hunter 	return 0;
378c4e05037SAdrian Hunter }
379c4e05037SAdrian Hunter 
380c4e05037SAdrian Hunter #else
381c4e05037SAdrian Hunter 
382c4e05037SAdrian Hunter #define sdhci_acpi_runtime_suspend	NULL
383c4e05037SAdrian Hunter #define sdhci_acpi_runtime_resume	NULL
384c4e05037SAdrian Hunter #define sdhci_acpi_runtime_idle		NULL
385c4e05037SAdrian Hunter 
386c4e05037SAdrian Hunter #endif
387c4e05037SAdrian Hunter 
388c4e05037SAdrian Hunter static const struct dev_pm_ops sdhci_acpi_pm_ops = {
389c4e05037SAdrian Hunter 	.suspend		= sdhci_acpi_suspend,
390c4e05037SAdrian Hunter 	.resume			= sdhci_acpi_resume,
391c4e05037SAdrian Hunter 	.runtime_suspend	= sdhci_acpi_runtime_suspend,
392c4e05037SAdrian Hunter 	.runtime_resume		= sdhci_acpi_runtime_resume,
393c4e05037SAdrian Hunter 	.runtime_idle		= sdhci_acpi_runtime_idle,
394c4e05037SAdrian Hunter };
395c4e05037SAdrian Hunter 
396c4e05037SAdrian Hunter static struct platform_driver sdhci_acpi_driver = {
397c4e05037SAdrian Hunter 	.driver = {
398c4e05037SAdrian Hunter 		.name			= "sdhci-acpi",
399c4e05037SAdrian Hunter 		.owner			= THIS_MODULE,
400c4e05037SAdrian Hunter 		.acpi_match_table	= sdhci_acpi_ids,
401c4e05037SAdrian Hunter 		.pm			= &sdhci_acpi_pm_ops,
402c4e05037SAdrian Hunter 	},
403c4e05037SAdrian Hunter 	.probe	= sdhci_acpi_probe,
4044e608e4eSGreg Kroah-Hartman 	.remove	= sdhci_acpi_remove,
405c4e05037SAdrian Hunter };
406c4e05037SAdrian Hunter 
407c4e05037SAdrian Hunter module_platform_driver(sdhci_acpi_driver);
408c4e05037SAdrian Hunter 
409c4e05037SAdrian Hunter MODULE_DESCRIPTION("Secure Digital Host Controller Interface ACPI driver");
410c4e05037SAdrian Hunter MODULE_AUTHOR("Adrian Hunter");
411c4e05037SAdrian Hunter MODULE_LICENSE("GPL v2");
412