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