Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 1 | /* |
| 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 Hunter | b04fa06 | 2013-06-13 11:50:27 +0300 | [diff] [blame] | 38 | #include <linux/delay.h> |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 39 | |
| 40 | #include <linux/mmc/host.h> |
| 41 | #include <linux/mmc/pm.h> |
Adrian Hunter | 4fd4409 | 2014-03-10 15:02:42 +0200 | [diff] [blame] | 42 | #include <linux/mmc/slot-gpio.h> |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 43 | #include <linux/mmc/sdhci.h> |
| 44 | |
| 45 | #include "sdhci.h" |
| 46 | |
| 47 | enum { |
Adrian Hunter | 4fd4409 | 2014-03-10 15:02:42 +0200 | [diff] [blame] | 48 | SDHCI_ACPI_SD_CD = BIT(0), |
| 49 | SDHCI_ACPI_RUNTIME_PM = BIT(1), |
| 50 | SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL = BIT(2), |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | struct sdhci_acpi_chip { |
| 54 | const struct sdhci_ops *ops; |
| 55 | unsigned int quirks; |
| 56 | unsigned int quirks2; |
| 57 | unsigned long caps; |
| 58 | unsigned int caps2; |
| 59 | mmc_pm_flag_t pm_caps; |
| 60 | }; |
| 61 | |
| 62 | struct sdhci_acpi_slot { |
| 63 | const struct sdhci_acpi_chip *chip; |
| 64 | unsigned int quirks; |
| 65 | unsigned int quirks2; |
| 66 | unsigned long caps; |
| 67 | unsigned int caps2; |
| 68 | mmc_pm_flag_t pm_caps; |
| 69 | unsigned int flags; |
Adrian Hunter | 7dafca8 | 2014-10-06 15:23:06 +0300 | [diff] [blame] | 70 | int (*probe_slot)(struct platform_device *, const char *, const char *); |
Gao, Yunpeng | 578b36b | 2014-09-01 11:35:40 +0800 | [diff] [blame] | 71 | int (*remove_slot)(struct platform_device *); |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | struct sdhci_acpi_host { |
| 75 | struct sdhci_host *host; |
| 76 | const struct sdhci_acpi_slot *slot; |
| 77 | struct platform_device *pdev; |
| 78 | bool use_runtime_pm; |
| 79 | }; |
| 80 | |
| 81 | static inline bool sdhci_acpi_flag(struct sdhci_acpi_host *c, unsigned int flag) |
| 82 | { |
| 83 | return c->slot && (c->slot->flags & flag); |
| 84 | } |
| 85 | |
| 86 | static int sdhci_acpi_enable_dma(struct sdhci_host *host) |
| 87 | { |
| 88 | return 0; |
| 89 | } |
| 90 | |
Adrian Hunter | b04fa06 | 2013-06-13 11:50:27 +0300 | [diff] [blame] | 91 | static void sdhci_acpi_int_hw_reset(struct sdhci_host *host) |
| 92 | { |
| 93 | u8 reg; |
| 94 | |
| 95 | reg = sdhci_readb(host, SDHCI_POWER_CONTROL); |
| 96 | reg |= 0x10; |
| 97 | sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); |
| 98 | /* For eMMC, minimum is 1us but give it 9us for good measure */ |
| 99 | udelay(9); |
| 100 | reg &= ~0x10; |
| 101 | sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); |
| 102 | /* For eMMC, minimum is 200us but give it 300us for good measure */ |
| 103 | usleep_range(300, 1000); |
| 104 | } |
| 105 | |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 106 | static const struct sdhci_ops sdhci_acpi_ops_dflt = { |
Russell King | 1771059 | 2014-04-25 12:58:55 +0100 | [diff] [blame] | 107 | .set_clock = sdhci_set_clock, |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 108 | .enable_dma = sdhci_acpi_enable_dma, |
Russell King | 2317f56 | 2014-04-25 12:57:07 +0100 | [diff] [blame] | 109 | .set_bus_width = sdhci_set_bus_width, |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 110 | .reset = sdhci_reset, |
Russell King | 96d7b78 | 2014-04-25 12:59:26 +0100 | [diff] [blame] | 111 | .set_uhs_signaling = sdhci_set_uhs_signaling, |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 112 | }; |
| 113 | |
Adrian Hunter | b04fa06 | 2013-06-13 11:50:27 +0300 | [diff] [blame] | 114 | static const struct sdhci_ops sdhci_acpi_ops_int = { |
Russell King | 1771059 | 2014-04-25 12:58:55 +0100 | [diff] [blame] | 115 | .set_clock = sdhci_set_clock, |
Adrian Hunter | b04fa06 | 2013-06-13 11:50:27 +0300 | [diff] [blame] | 116 | .enable_dma = sdhci_acpi_enable_dma, |
Russell King | 2317f56 | 2014-04-25 12:57:07 +0100 | [diff] [blame] | 117 | .set_bus_width = sdhci_set_bus_width, |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 118 | .reset = sdhci_reset, |
Russell King | 96d7b78 | 2014-04-25 12:59:26 +0100 | [diff] [blame] | 119 | .set_uhs_signaling = sdhci_set_uhs_signaling, |
Adrian Hunter | b04fa06 | 2013-06-13 11:50:27 +0300 | [diff] [blame] | 120 | .hw_reset = sdhci_acpi_int_hw_reset, |
| 121 | }; |
| 122 | |
| 123 | static const struct sdhci_acpi_chip sdhci_acpi_chip_int = { |
| 124 | .ops = &sdhci_acpi_ops_int, |
| 125 | }; |
| 126 | |
Adrian Hunter | 7dafca8 | 2014-10-06 15:23:06 +0300 | [diff] [blame] | 127 | static int sdhci_acpi_emmc_probe_slot(struct platform_device *pdev, |
| 128 | const char *hid, const char *uid) |
Gao, Yunpeng | 578b36b | 2014-09-01 11:35:40 +0800 | [diff] [blame] | 129 | { |
| 130 | struct sdhci_acpi_host *c = platform_get_drvdata(pdev); |
| 131 | struct sdhci_host *host; |
| 132 | |
| 133 | if (!c || !c->host) |
| 134 | return 0; |
| 135 | |
| 136 | host = c->host; |
| 137 | |
| 138 | /* Platform specific code during emmc proble slot goes here */ |
| 139 | |
Adrian Hunter | 8024379 | 2014-10-06 15:23:07 +0300 | [diff] [blame^] | 140 | if (hid && uid && !strcmp(hid, "80860F14") && !strcmp(uid, "1") && |
| 141 | sdhci_readl(host, SDHCI_CAPABILITIES) == 0x446cc8b2 && |
| 142 | sdhci_readl(host, SDHCI_CAPABILITIES_1) == 0x00000807) |
| 143 | host->timeout_clk = 1000; /* 1000 kHz i.e. 1 MHz */ |
| 144 | |
Gao, Yunpeng | 578b36b | 2014-09-01 11:35:40 +0800 | [diff] [blame] | 145 | return 0; |
| 146 | } |
| 147 | |
Adrian Hunter | 7dafca8 | 2014-10-06 15:23:06 +0300 | [diff] [blame] | 148 | static int sdhci_acpi_sdio_probe_slot(struct platform_device *pdev, |
| 149 | const char *hid, const char *uid) |
Gao, Yunpeng | 578b36b | 2014-09-01 11:35:40 +0800 | [diff] [blame] | 150 | { |
| 151 | struct sdhci_acpi_host *c = platform_get_drvdata(pdev); |
| 152 | struct sdhci_host *host; |
| 153 | |
| 154 | if (!c || !c->host) |
| 155 | return 0; |
| 156 | |
| 157 | host = c->host; |
| 158 | |
| 159 | /* Platform specific code during emmc proble slot goes here */ |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
Adrian Hunter | 7dafca8 | 2014-10-06 15:23:06 +0300 | [diff] [blame] | 164 | static int sdhci_acpi_sd_probe_slot(struct platform_device *pdev, |
| 165 | const char *hid, const char *uid) |
Gao, Yunpeng | 578b36b | 2014-09-01 11:35:40 +0800 | [diff] [blame] | 166 | { |
| 167 | struct sdhci_acpi_host *c = platform_get_drvdata(pdev); |
| 168 | struct sdhci_host *host; |
| 169 | |
| 170 | if (!c || !c->host || !c->slot) |
| 171 | return 0; |
| 172 | |
| 173 | host = c->host; |
| 174 | |
| 175 | /* Platform specific code during emmc proble slot goes here */ |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
Adrian Hunter | 07a5888 | 2013-04-26 11:27:22 +0300 | [diff] [blame] | 180 | static const struct sdhci_acpi_slot sdhci_acpi_slot_int_emmc = { |
Adrian Hunter | b04fa06 | 2013-06-13 11:50:27 +0300 | [diff] [blame] | 181 | .chip = &sdhci_acpi_chip_int, |
Maurice Petallo | f25c337 | 2014-07-08 19:11:01 +0800 | [diff] [blame] | 182 | .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE | |
| 183 | MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR, |
Adrian Hunter | 07a5888 | 2013-04-26 11:27:22 +0300 | [diff] [blame] | 184 | .caps2 = MMC_CAP2_HC_ERASE_SZ, |
| 185 | .flags = SDHCI_ACPI_RUNTIME_PM, |
Adrian Hunter | 934e31b | 2014-09-24 10:27:28 +0300 | [diff] [blame] | 186 | .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | SDHCI_QUIRK2_STOP_WITH_TC, |
Gao, Yunpeng | 578b36b | 2014-09-01 11:35:40 +0800 | [diff] [blame] | 187 | .probe_slot = sdhci_acpi_emmc_probe_slot, |
Adrian Hunter | 07a5888 | 2013-04-26 11:27:22 +0300 | [diff] [blame] | 188 | }; |
| 189 | |
Adrian Hunter | e557139 | 2012-12-10 21:18:48 +0100 | [diff] [blame] | 190 | static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = { |
Adrian Hunter | c674801 | 2014-04-03 14:58:39 +0300 | [diff] [blame] | 191 | .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION, |
Adrian Hunter | e557139 | 2012-12-10 21:18:48 +0100 | [diff] [blame] | 192 | .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON, |
| 193 | .caps = MMC_CAP_NONREMOVABLE | MMC_CAP_POWER_OFF_CARD, |
| 194 | .flags = SDHCI_ACPI_RUNTIME_PM, |
| 195 | .pm_caps = MMC_PM_KEEP_POWER, |
Gao, Yunpeng | 578b36b | 2014-09-01 11:35:40 +0800 | [diff] [blame] | 196 | .probe_slot = sdhci_acpi_sdio_probe_slot, |
Adrian Hunter | e557139 | 2012-12-10 21:18:48 +0100 | [diff] [blame] | 197 | }; |
| 198 | |
Adrian Hunter | 07a5888 | 2013-04-26 11:27:22 +0300 | [diff] [blame] | 199 | static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = { |
Adrian Hunter | 4fd4409 | 2014-03-10 15:02:42 +0200 | [diff] [blame] | 200 | .flags = SDHCI_ACPI_SD_CD | SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL | |
| 201 | SDHCI_ACPI_RUNTIME_PM, |
Adrian Hunter | 934e31b | 2014-09-24 10:27:28 +0300 | [diff] [blame] | 202 | .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON | |
| 203 | SDHCI_QUIRK2_STOP_WITH_TC, |
Gao, Yunpeng | 578b36b | 2014-09-01 11:35:40 +0800 | [diff] [blame] | 204 | .probe_slot = sdhci_acpi_sd_probe_slot, |
Adrian Hunter | 07a5888 | 2013-04-26 11:27:22 +0300 | [diff] [blame] | 205 | }; |
| 206 | |
| 207 | struct sdhci_acpi_uid_slot { |
| 208 | const char *hid; |
| 209 | const char *uid; |
| 210 | const struct sdhci_acpi_slot *slot; |
| 211 | }; |
| 212 | |
| 213 | static const struct sdhci_acpi_uid_slot sdhci_acpi_uids[] = { |
| 214 | { "80860F14" , "1" , &sdhci_acpi_slot_int_emmc }, |
| 215 | { "80860F14" , "3" , &sdhci_acpi_slot_int_sd }, |
Adrian Hunter | aad95dc | 2014-03-10 15:02:43 +0200 | [diff] [blame] | 216 | { "80860F16" , NULL, &sdhci_acpi_slot_int_sd }, |
Adrian Hunter | 07a5888 | 2013-04-26 11:27:22 +0300 | [diff] [blame] | 217 | { "INT33BB" , "2" , &sdhci_acpi_slot_int_sdio }, |
Adrian Hunter | 7147eaf | 2014-09-24 10:27:29 +0300 | [diff] [blame] | 218 | { "INT33BB" , "3" , &sdhci_acpi_slot_int_sd }, |
Adrian Hunter | 07a5888 | 2013-04-26 11:27:22 +0300 | [diff] [blame] | 219 | { "INT33C6" , NULL, &sdhci_acpi_slot_int_sdio }, |
Mika Westerberg | 07c001c | 2013-11-12 12:01:33 +0200 | [diff] [blame] | 220 | { "INT3436" , NULL, &sdhci_acpi_slot_int_sdio }, |
Adrian Hunter | 07a5888 | 2013-04-26 11:27:22 +0300 | [diff] [blame] | 221 | { "PNP0D40" }, |
| 222 | { }, |
| 223 | }; |
| 224 | |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 225 | static const struct acpi_device_id sdhci_acpi_ids[] = { |
Adrian Hunter | 07a5888 | 2013-04-26 11:27:22 +0300 | [diff] [blame] | 226 | { "80860F14" }, |
Adrian Hunter | aad95dc | 2014-03-10 15:02:43 +0200 | [diff] [blame] | 227 | { "80860F16" }, |
Adrian Hunter | 07a5888 | 2013-04-26 11:27:22 +0300 | [diff] [blame] | 228 | { "INT33BB" }, |
| 229 | { "INT33C6" }, |
Mika Westerberg | 07c001c | 2013-11-12 12:01:33 +0200 | [diff] [blame] | 230 | { "INT3436" }, |
Adrian Hunter | 07a5888 | 2013-04-26 11:27:22 +0300 | [diff] [blame] | 231 | { "PNP0D40" }, |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 232 | { }, |
| 233 | }; |
| 234 | MODULE_DEVICE_TABLE(acpi, sdhci_acpi_ids); |
| 235 | |
Adrian Hunter | 3db3525 | 2014-10-06 15:23:05 +0300 | [diff] [blame] | 236 | static const struct sdhci_acpi_slot *sdhci_acpi_get_slot(const char *hid, |
| 237 | const char *uid) |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 238 | { |
Adrian Hunter | 07a5888 | 2013-04-26 11:27:22 +0300 | [diff] [blame] | 239 | const struct sdhci_acpi_uid_slot *u; |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 240 | |
Adrian Hunter | 07a5888 | 2013-04-26 11:27:22 +0300 | [diff] [blame] | 241 | for (u = sdhci_acpi_uids; u->hid; u++) { |
| 242 | if (strcmp(u->hid, hid)) |
| 243 | continue; |
| 244 | if (!u->uid) |
| 245 | return u->slot; |
| 246 | if (uid && !strcmp(u->uid, uid)) |
| 247 | return u->slot; |
| 248 | } |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 249 | return NULL; |
| 250 | } |
| 251 | |
Greg Kroah-Hartman | 4e608e4 | 2012-12-21 15:05:47 -0800 | [diff] [blame] | 252 | static int sdhci_acpi_probe(struct platform_device *pdev) |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 253 | { |
| 254 | struct device *dev = &pdev->dev; |
| 255 | acpi_handle handle = ACPI_HANDLE(dev); |
| 256 | struct acpi_device *device; |
| 257 | struct sdhci_acpi_host *c; |
| 258 | struct sdhci_host *host; |
| 259 | struct resource *iomem; |
| 260 | resource_size_t len; |
| 261 | const char *hid; |
Adrian Hunter | 3db3525 | 2014-10-06 15:23:05 +0300 | [diff] [blame] | 262 | const char *uid; |
Mika Westerberg | 8787565 | 2014-01-08 12:40:55 +0200 | [diff] [blame] | 263 | int err; |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 264 | |
| 265 | if (acpi_bus_get_device(handle, &device)) |
| 266 | return -ENODEV; |
| 267 | |
| 268 | if (acpi_bus_get_status(device) || !device->status.present) |
| 269 | return -ENODEV; |
| 270 | |
| 271 | hid = acpi_device_hid(device); |
Adrian Hunter | 3db3525 | 2014-10-06 15:23:05 +0300 | [diff] [blame] | 272 | uid = device->pnp.unique_id; |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 273 | |
| 274 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 275 | if (!iomem) |
| 276 | return -ENOMEM; |
| 277 | |
| 278 | len = resource_size(iomem); |
| 279 | if (len < 0x100) |
| 280 | dev_err(dev, "Invalid iomem size!\n"); |
| 281 | |
| 282 | if (!devm_request_mem_region(dev, iomem->start, len, dev_name(dev))) |
| 283 | return -ENOMEM; |
| 284 | |
| 285 | host = sdhci_alloc_host(dev, sizeof(struct sdhci_acpi_host)); |
| 286 | if (IS_ERR(host)) |
| 287 | return PTR_ERR(host); |
| 288 | |
| 289 | c = sdhci_priv(host); |
| 290 | c->host = host; |
Adrian Hunter | 3db3525 | 2014-10-06 15:23:05 +0300 | [diff] [blame] | 291 | c->slot = sdhci_acpi_get_slot(hid, uid); |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 292 | c->pdev = pdev; |
| 293 | c->use_runtime_pm = sdhci_acpi_flag(c, SDHCI_ACPI_RUNTIME_PM); |
| 294 | |
| 295 | platform_set_drvdata(pdev, c); |
| 296 | |
| 297 | host->hw_name = "ACPI"; |
| 298 | host->ops = &sdhci_acpi_ops_dflt; |
| 299 | host->irq = platform_get_irq(pdev, 0); |
| 300 | |
| 301 | host->ioaddr = devm_ioremap_nocache(dev, iomem->start, |
| 302 | resource_size(iomem)); |
| 303 | if (host->ioaddr == NULL) { |
| 304 | err = -ENOMEM; |
| 305 | goto err_free; |
| 306 | } |
| 307 | |
| 308 | if (!dev->dma_mask) { |
| 309 | u64 dma_mask; |
| 310 | |
| 311 | if (sdhci_readl(host, SDHCI_CAPABILITIES) & SDHCI_CAN_64BIT) { |
| 312 | /* 64-bit DMA is not supported at present */ |
| 313 | dma_mask = DMA_BIT_MASK(32); |
| 314 | } else { |
| 315 | dma_mask = DMA_BIT_MASK(32); |
| 316 | } |
| 317 | |
Russell King | 07f4450 | 2013-06-27 14:06:28 +0100 | [diff] [blame] | 318 | err = dma_coerce_mask_and_coherent(dev, dma_mask); |
| 319 | if (err) |
| 320 | goto err_free; |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | if (c->slot) { |
Gao, Yunpeng | 578b36b | 2014-09-01 11:35:40 +0800 | [diff] [blame] | 324 | if (c->slot->probe_slot) { |
Adrian Hunter | 7dafca8 | 2014-10-06 15:23:06 +0300 | [diff] [blame] | 325 | err = c->slot->probe_slot(pdev, hid, uid); |
Gao, Yunpeng | 578b36b | 2014-09-01 11:35:40 +0800 | [diff] [blame] | 326 | if (err) |
| 327 | goto err_free; |
| 328 | } |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 329 | if (c->slot->chip) { |
| 330 | host->ops = c->slot->chip->ops; |
| 331 | host->quirks |= c->slot->chip->quirks; |
| 332 | host->quirks2 |= c->slot->chip->quirks2; |
| 333 | host->mmc->caps |= c->slot->chip->caps; |
| 334 | host->mmc->caps2 |= c->slot->chip->caps2; |
| 335 | host->mmc->pm_caps |= c->slot->chip->pm_caps; |
| 336 | } |
| 337 | host->quirks |= c->slot->quirks; |
| 338 | host->quirks2 |= c->slot->quirks2; |
| 339 | host->mmc->caps |= c->slot->caps; |
| 340 | host->mmc->caps2 |= c->slot->caps2; |
| 341 | host->mmc->pm_caps |= c->slot->pm_caps; |
| 342 | } |
| 343 | |
Adrian Hunter | 0d3e335 | 2013-04-04 16:41:06 +0300 | [diff] [blame] | 344 | host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP; |
| 345 | |
Adrian Hunter | 4fd4409 | 2014-03-10 15:02:42 +0200 | [diff] [blame] | 346 | if (sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD)) { |
| 347 | bool v = sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL); |
| 348 | |
Linus Walleij | 89168b4 | 2014-10-02 09:08:46 +0200 | [diff] [blame] | 349 | if (mmc_gpiod_request_cd(host->mmc, NULL, 0, v, 0, NULL)) { |
Adrian Hunter | 4fd4409 | 2014-03-10 15:02:42 +0200 | [diff] [blame] | 350 | dev_warn(dev, "failed to setup card detect gpio\n"); |
| 351 | c->use_runtime_pm = false; |
| 352 | } |
| 353 | } |
| 354 | |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 355 | err = sdhci_add_host(host); |
| 356 | if (err) |
| 357 | goto err_free; |
| 358 | |
| 359 | if (c->use_runtime_pm) { |
Adrian Hunter | 1d1ff45 | 2013-04-26 11:27:21 +0300 | [diff] [blame] | 360 | pm_runtime_set_active(dev); |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 361 | pm_suspend_ignore_children(dev, 1); |
| 362 | pm_runtime_set_autosuspend_delay(dev, 50); |
| 363 | pm_runtime_use_autosuspend(dev); |
| 364 | pm_runtime_enable(dev); |
| 365 | } |
| 366 | |
| 367 | return 0; |
| 368 | |
| 369 | err_free: |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 370 | sdhci_free_host(c->host); |
| 371 | return err; |
| 372 | } |
| 373 | |
Greg Kroah-Hartman | 4e608e4 | 2012-12-21 15:05:47 -0800 | [diff] [blame] | 374 | static int sdhci_acpi_remove(struct platform_device *pdev) |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 375 | { |
| 376 | struct sdhci_acpi_host *c = platform_get_drvdata(pdev); |
| 377 | struct device *dev = &pdev->dev; |
| 378 | int dead; |
| 379 | |
| 380 | if (c->use_runtime_pm) { |
| 381 | pm_runtime_get_sync(dev); |
| 382 | pm_runtime_disable(dev); |
| 383 | pm_runtime_put_noidle(dev); |
| 384 | } |
| 385 | |
Gao, Yunpeng | 578b36b | 2014-09-01 11:35:40 +0800 | [diff] [blame] | 386 | if (c->slot && c->slot->remove_slot) |
| 387 | c->slot->remove_slot(pdev); |
| 388 | |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 389 | dead = (sdhci_readl(c->host, SDHCI_INT_STATUS) == ~0); |
| 390 | sdhci_remove_host(c->host, dead); |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 391 | sdhci_free_host(c->host); |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | #ifdef CONFIG_PM_SLEEP |
| 397 | |
| 398 | static int sdhci_acpi_suspend(struct device *dev) |
| 399 | { |
| 400 | struct sdhci_acpi_host *c = dev_get_drvdata(dev); |
| 401 | |
| 402 | return sdhci_suspend_host(c->host); |
| 403 | } |
| 404 | |
| 405 | static int sdhci_acpi_resume(struct device *dev) |
| 406 | { |
| 407 | struct sdhci_acpi_host *c = dev_get_drvdata(dev); |
| 408 | |
| 409 | return sdhci_resume_host(c->host); |
| 410 | } |
| 411 | |
| 412 | #else |
| 413 | |
| 414 | #define sdhci_acpi_suspend NULL |
| 415 | #define sdhci_acpi_resume NULL |
| 416 | |
| 417 | #endif |
| 418 | |
| 419 | #ifdef CONFIG_PM_RUNTIME |
| 420 | |
| 421 | static int sdhci_acpi_runtime_suspend(struct device *dev) |
| 422 | { |
| 423 | struct sdhci_acpi_host *c = dev_get_drvdata(dev); |
| 424 | |
| 425 | return sdhci_runtime_suspend_host(c->host); |
| 426 | } |
| 427 | |
| 428 | static int sdhci_acpi_runtime_resume(struct device *dev) |
| 429 | { |
| 430 | struct sdhci_acpi_host *c = dev_get_drvdata(dev); |
| 431 | |
| 432 | return sdhci_runtime_resume_host(c->host); |
| 433 | } |
| 434 | |
| 435 | static int sdhci_acpi_runtime_idle(struct device *dev) |
| 436 | { |
| 437 | return 0; |
| 438 | } |
| 439 | |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 440 | #endif |
| 441 | |
| 442 | static const struct dev_pm_ops sdhci_acpi_pm_ops = { |
| 443 | .suspend = sdhci_acpi_suspend, |
| 444 | .resume = sdhci_acpi_resume, |
Peter Griffin | 1d75f74 | 2014-08-12 17:14:29 +0100 | [diff] [blame] | 445 | SET_RUNTIME_PM_OPS(sdhci_acpi_runtime_suspend, |
| 446 | sdhci_acpi_runtime_resume, sdhci_acpi_runtime_idle) |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 447 | }; |
| 448 | |
| 449 | static struct platform_driver sdhci_acpi_driver = { |
| 450 | .driver = { |
| 451 | .name = "sdhci-acpi", |
| 452 | .owner = THIS_MODULE, |
| 453 | .acpi_match_table = sdhci_acpi_ids, |
| 454 | .pm = &sdhci_acpi_pm_ops, |
| 455 | }, |
| 456 | .probe = sdhci_acpi_probe, |
Greg Kroah-Hartman | 4e608e4 | 2012-12-21 15:05:47 -0800 | [diff] [blame] | 457 | .remove = sdhci_acpi_remove, |
Adrian Hunter | c4e0503 | 2012-11-23 21:17:34 +0100 | [diff] [blame] | 458 | }; |
| 459 | |
| 460 | module_platform_driver(sdhci_acpi_driver); |
| 461 | |
| 462 | MODULE_DESCRIPTION("Secure Digital Host Controller Interface ACPI driver"); |
| 463 | MODULE_AUTHOR("Adrian Hunter"); |
| 464 | MODULE_LICENSE("GPL v2"); |