]>
Commit | Line | Data |
---|---|---|
c4e05037 AH |
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> | |
b04fa064 | 38 | #include <linux/delay.h> |
c4e05037 AH |
39 | |
40 | #include <linux/mmc/host.h> | |
41 | #include <linux/mmc/pm.h> | |
4fd4409c | 42 | #include <linux/mmc/slot-gpio.h> |
c4e05037 | 43 | |
6e1c7d61 AH |
44 | #ifdef CONFIG_X86 |
45 | #include <asm/cpu_device_id.h> | |
8ba4cb53 | 46 | #include <asm/intel-family.h> |
6e1c7d61 | 47 | #include <asm/iosf_mbi.h> |
17753d16 | 48 | #include <linux/pci.h> |
6e1c7d61 AH |
49 | #endif |
50 | ||
c4e05037 AH |
51 | #include "sdhci.h" |
52 | ||
53 | enum { | |
4fd4409c AH |
54 | SDHCI_ACPI_SD_CD = BIT(0), |
55 | SDHCI_ACPI_RUNTIME_PM = BIT(1), | |
56 | SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL = BIT(2), | |
c4e05037 AH |
57 | }; |
58 | ||
59 | struct sdhci_acpi_chip { | |
60 | const struct sdhci_ops *ops; | |
61 | unsigned int quirks; | |
62 | unsigned int quirks2; | |
63 | unsigned long caps; | |
64 | unsigned int caps2; | |
65 | mmc_pm_flag_t pm_caps; | |
66 | }; | |
67 | ||
68 | struct sdhci_acpi_slot { | |
69 | const struct sdhci_acpi_chip *chip; | |
70 | unsigned int quirks; | |
71 | unsigned int quirks2; | |
72 | unsigned long caps; | |
73 | unsigned int caps2; | |
74 | mmc_pm_flag_t pm_caps; | |
75 | unsigned int flags; | |
f07b7952 | 76 | size_t priv_size; |
7dafca83 | 77 | int (*probe_slot)(struct platform_device *, const char *, const char *); |
578b36b6 | 78 | int (*remove_slot)(struct platform_device *); |
0406157f | 79 | int (*free_slot)(struct platform_device *pdev); |
c4e05037 AH |
80 | }; |
81 | ||
82 | struct sdhci_acpi_host { | |
83 | struct sdhci_host *host; | |
84 | const struct sdhci_acpi_slot *slot; | |
85 | struct platform_device *pdev; | |
86 | bool use_runtime_pm; | |
f07b7952 | 87 | unsigned long private[0] ____cacheline_aligned; |
c4e05037 AH |
88 | }; |
89 | ||
f07b7952 AH |
90 | static inline void *sdhci_acpi_priv(struct sdhci_acpi_host *c) |
91 | { | |
92 | return (void *)c->private; | |
93 | } | |
94 | ||
c4e05037 AH |
95 | static inline bool sdhci_acpi_flag(struct sdhci_acpi_host *c, unsigned int flag) |
96 | { | |
97 | return c->slot && (c->slot->flags & flag); | |
98 | } | |
99 | ||
1c451c13 AH |
100 | enum { |
101 | INTEL_DSM_FNS = 0, | |
102 | INTEL_DSM_V18_SWITCH = 3, | |
103 | INTEL_DSM_V33_SWITCH = 4, | |
104 | }; | |
105 | ||
106 | struct intel_host { | |
107 | u32 dsm_fns; | |
108 | }; | |
109 | ||
110 | static const guid_t intel_dsm_guid = | |
111 | GUID_INIT(0xF6C13EA5, 0x65CD, 0x461F, | |
112 | 0xAB, 0x7A, 0x29, 0xF7, 0xE8, 0xD5, 0xBD, 0x61); | |
113 | ||
114 | static int __intel_dsm(struct intel_host *intel_host, struct device *dev, | |
115 | unsigned int fn, u32 *result) | |
116 | { | |
117 | union acpi_object *obj; | |
118 | int err = 0; | |
119 | ||
120 | obj = acpi_evaluate_dsm(ACPI_HANDLE(dev), &intel_dsm_guid, 0, fn, NULL); | |
121 | if (!obj) | |
122 | return -EOPNOTSUPP; | |
123 | ||
124 | if (obj->type == ACPI_TYPE_INTEGER) { | |
125 | *result = obj->integer.value; | |
126 | } else if (obj->type == ACPI_TYPE_BUFFER && obj->buffer.length > 0) { | |
127 | size_t len = min_t(size_t, obj->buffer.length, 4); | |
128 | ||
129 | *result = 0; | |
130 | memcpy(result, obj->buffer.pointer, len); | |
131 | } else { | |
132 | dev_err(dev, "%s DSM fn %u obj->type %d obj->buffer.length %d\n", | |
133 | __func__, fn, obj->type, obj->buffer.length); | |
134 | err = -EINVAL; | |
135 | } | |
136 | ||
137 | ACPI_FREE(obj); | |
138 | ||
139 | return err; | |
140 | } | |
141 | ||
142 | static int intel_dsm(struct intel_host *intel_host, struct device *dev, | |
143 | unsigned int fn, u32 *result) | |
144 | { | |
145 | if (fn > 31 || !(intel_host->dsm_fns & (1 << fn))) | |
146 | return -EOPNOTSUPP; | |
147 | ||
148 | return __intel_dsm(intel_host, dev, fn, result); | |
149 | } | |
150 | ||
151 | static void intel_dsm_init(struct intel_host *intel_host, struct device *dev, | |
152 | struct mmc_host *mmc) | |
153 | { | |
154 | int err; | |
155 | ||
156 | err = __intel_dsm(intel_host, dev, INTEL_DSM_FNS, &intel_host->dsm_fns); | |
157 | if (err) { | |
158 | pr_debug("%s: DSM not supported, error %d\n", | |
159 | mmc_hostname(mmc), err); | |
160 | return; | |
161 | } | |
162 | ||
163 | pr_debug("%s: DSM function mask %#x\n", | |
164 | mmc_hostname(mmc), intel_host->dsm_fns); | |
165 | } | |
166 | ||
167 | static int intel_start_signal_voltage_switch(struct mmc_host *mmc, | |
168 | struct mmc_ios *ios) | |
169 | { | |
170 | struct device *dev = mmc_dev(mmc); | |
171 | struct sdhci_acpi_host *c = dev_get_drvdata(dev); | |
172 | struct intel_host *intel_host = sdhci_acpi_priv(c); | |
173 | unsigned int fn; | |
174 | u32 result = 0; | |
175 | int err; | |
176 | ||
177 | err = sdhci_start_signal_voltage_switch(mmc, ios); | |
178 | if (err) | |
179 | return err; | |
180 | ||
181 | switch (ios->signal_voltage) { | |
182 | case MMC_SIGNAL_VOLTAGE_330: | |
183 | fn = INTEL_DSM_V33_SWITCH; | |
184 | break; | |
185 | case MMC_SIGNAL_VOLTAGE_180: | |
186 | fn = INTEL_DSM_V18_SWITCH; | |
187 | break; | |
188 | default: | |
189 | return 0; | |
190 | } | |
191 | ||
192 | err = intel_dsm(intel_host, dev, fn, &result); | |
193 | pr_debug("%s: %s DSM fn %u error %d result %u\n", | |
194 | mmc_hostname(mmc), __func__, fn, err, result); | |
195 | ||
196 | return 0; | |
197 | } | |
198 | ||
b04fa064 AH |
199 | static void sdhci_acpi_int_hw_reset(struct sdhci_host *host) |
200 | { | |
201 | u8 reg; | |
202 | ||
203 | reg = sdhci_readb(host, SDHCI_POWER_CONTROL); | |
204 | reg |= 0x10; | |
205 | sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); | |
206 | /* For eMMC, minimum is 1us but give it 9us for good measure */ | |
207 | udelay(9); | |
208 | reg &= ~0x10; | |
209 | sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); | |
210 | /* For eMMC, minimum is 200us but give it 300us for good measure */ | |
211 | usleep_range(300, 1000); | |
212 | } | |
213 | ||
c4e05037 | 214 | static const struct sdhci_ops sdhci_acpi_ops_dflt = { |
1771059c | 215 | .set_clock = sdhci_set_clock, |
2317f56c | 216 | .set_bus_width = sdhci_set_bus_width, |
03231f9b | 217 | .reset = sdhci_reset, |
96d7b78c | 218 | .set_uhs_signaling = sdhci_set_uhs_signaling, |
c4e05037 AH |
219 | }; |
220 | ||
b04fa064 | 221 | static const struct sdhci_ops sdhci_acpi_ops_int = { |
1771059c | 222 | .set_clock = sdhci_set_clock, |
2317f56c | 223 | .set_bus_width = sdhci_set_bus_width, |
03231f9b | 224 | .reset = sdhci_reset, |
96d7b78c | 225 | .set_uhs_signaling = sdhci_set_uhs_signaling, |
b04fa064 AH |
226 | .hw_reset = sdhci_acpi_int_hw_reset, |
227 | }; | |
228 | ||
229 | static const struct sdhci_acpi_chip sdhci_acpi_chip_int = { | |
230 | .ops = &sdhci_acpi_ops_int, | |
231 | }; | |
232 | ||
6e1c7d61 AH |
233 | #ifdef CONFIG_X86 |
234 | ||
235 | static bool sdhci_acpi_byt(void) | |
236 | { | |
237 | static const struct x86_cpu_id byt[] = { | |
2811e5d5 | 238 | { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT }, |
6e1c7d61 AH |
239 | {} |
240 | }; | |
241 | ||
242 | return x86_match_cpu(byt); | |
243 | } | |
244 | ||
17753d16 AH |
245 | static bool sdhci_acpi_cht(void) |
246 | { | |
247 | static const struct x86_cpu_id cht[] = { | |
248 | { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_AIRMONT }, | |
249 | {} | |
250 | }; | |
251 | ||
252 | return x86_match_cpu(cht); | |
253 | } | |
254 | ||
6e1c7d61 AH |
255 | #define BYT_IOSF_SCCEP 0x63 |
256 | #define BYT_IOSF_OCP_NETCTRL0 0x1078 | |
257 | #define BYT_IOSF_OCP_TIMEOUT_BASE GENMASK(10, 8) | |
258 | ||
259 | static void sdhci_acpi_byt_setting(struct device *dev) | |
260 | { | |
261 | u32 val = 0; | |
262 | ||
263 | if (!sdhci_acpi_byt()) | |
264 | return; | |
265 | ||
266 | if (iosf_mbi_read(BYT_IOSF_SCCEP, MBI_CR_READ, BYT_IOSF_OCP_NETCTRL0, | |
267 | &val)) { | |
268 | dev_err(dev, "%s read error\n", __func__); | |
269 | return; | |
270 | } | |
271 | ||
272 | if (!(val & BYT_IOSF_OCP_TIMEOUT_BASE)) | |
273 | return; | |
274 | ||
275 | val &= ~BYT_IOSF_OCP_TIMEOUT_BASE; | |
276 | ||
277 | if (iosf_mbi_write(BYT_IOSF_SCCEP, MBI_CR_WRITE, BYT_IOSF_OCP_NETCTRL0, | |
278 | val)) { | |
279 | dev_err(dev, "%s write error\n", __func__); | |
280 | return; | |
281 | } | |
282 | ||
283 | dev_dbg(dev, "%s completed\n", __func__); | |
284 | } | |
285 | ||
286 | static bool sdhci_acpi_byt_defer(struct device *dev) | |
287 | { | |
288 | if (!sdhci_acpi_byt()) | |
289 | return false; | |
290 | ||
291 | if (!iosf_mbi_available()) | |
292 | return true; | |
293 | ||
294 | sdhci_acpi_byt_setting(dev); | |
295 | ||
296 | return false; | |
297 | } | |
298 | ||
17753d16 AH |
299 | static bool sdhci_acpi_cht_pci_wifi(unsigned int vendor, unsigned int device, |
300 | unsigned int slot, unsigned int parent_slot) | |
301 | { | |
302 | struct pci_dev *dev, *parent, *from = NULL; | |
303 | ||
304 | while (1) { | |
305 | dev = pci_get_device(vendor, device, from); | |
306 | pci_dev_put(from); | |
307 | if (!dev) | |
308 | break; | |
309 | parent = pci_upstream_bridge(dev); | |
310 | if (ACPI_COMPANION(&dev->dev) && PCI_SLOT(dev->devfn) == slot && | |
311 | parent && PCI_SLOT(parent->devfn) == parent_slot && | |
312 | !pci_upstream_bridge(parent)) { | |
313 | pci_dev_put(dev); | |
314 | return true; | |
315 | } | |
316 | from = dev; | |
317 | } | |
318 | ||
319 | return false; | |
320 | } | |
321 | ||
322 | /* | |
323 | * GPDwin uses PCI wifi which conflicts with SDIO's use of | |
324 | * acpi_device_fix_up_power() on child device nodes. Identifying GPDwin is | |
325 | * problematic, but since SDIO is only used for wifi, the presence of the PCI | |
326 | * wifi card in the expected slot with an ACPI companion node, is used to | |
327 | * indicate that acpi_device_fix_up_power() should be avoided. | |
328 | */ | |
329 | static inline bool sdhci_acpi_no_fixup_child_power(const char *hid, | |
330 | const char *uid) | |
331 | { | |
332 | return sdhci_acpi_cht() && | |
333 | !strcmp(hid, "80860F14") && | |
334 | !strcmp(uid, "2") && | |
335 | sdhci_acpi_cht_pci_wifi(0x14e4, 0x43ec, 0, 28); | |
336 | } | |
337 | ||
6e1c7d61 AH |
338 | #else |
339 | ||
340 | static inline void sdhci_acpi_byt_setting(struct device *dev) | |
341 | { | |
342 | } | |
343 | ||
344 | static inline bool sdhci_acpi_byt_defer(struct device *dev) | |
345 | { | |
346 | return false; | |
347 | } | |
348 | ||
17753d16 AH |
349 | static inline bool sdhci_acpi_no_fixup_child_power(const char *hid, |
350 | const char *uid) | |
351 | { | |
352 | return false; | |
353 | } | |
354 | ||
6e1c7d61 AH |
355 | #endif |
356 | ||
6a645dd8 AH |
357 | static int bxt_get_cd(struct mmc_host *mmc) |
358 | { | |
359 | int gpio_cd = mmc_gpio_get_cd(mmc); | |
360 | struct sdhci_host *host = mmc_priv(mmc); | |
361 | unsigned long flags; | |
362 | int ret = 0; | |
363 | ||
364 | if (!gpio_cd) | |
365 | return 0; | |
366 | ||
6a645dd8 AH |
367 | spin_lock_irqsave(&host->lock, flags); |
368 | ||
369 | if (host->flags & SDHCI_DEVICE_DEAD) | |
370 | goto out; | |
371 | ||
372 | ret = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT); | |
373 | out: | |
374 | spin_unlock_irqrestore(&host->lock, flags); | |
375 | ||
6a645dd8 AH |
376 | return ret; |
377 | } | |
378 | ||
159cd328 AH |
379 | static int intel_probe_slot(struct platform_device *pdev, const char *hid, |
380 | const char *uid) | |
578b36b6 GY |
381 | { |
382 | struct sdhci_acpi_host *c = platform_get_drvdata(pdev); | |
1c451c13 | 383 | struct intel_host *intel_host = sdhci_acpi_priv(c); |
159cd328 | 384 | struct sdhci_host *host = c->host; |
578b36b6 | 385 | |
8024379e AH |
386 | if (hid && uid && !strcmp(hid, "80860F14") && !strcmp(uid, "1") && |
387 | sdhci_readl(host, SDHCI_CAPABILITIES) == 0x446cc8b2 && | |
388 | sdhci_readl(host, SDHCI_CAPABILITIES_1) == 0x00000807) | |
389 | host->timeout_clk = 1000; /* 1000 kHz i.e. 1 MHz */ | |
390 | ||
d3e97407 | 391 | if (hid && !strcmp(hid, "80865ACA")) |
6a645dd8 AH |
392 | host->mmc_host_ops.get_cd = bxt_get_cd; |
393 | ||
1c451c13 AH |
394 | intel_dsm_init(intel_host, &pdev->dev, host->mmc); |
395 | ||
396 | host->mmc_host_ops.start_signal_voltage_switch = | |
397 | intel_start_signal_voltage_switch; | |
398 | ||
578b36b6 GY |
399 | return 0; |
400 | } | |
401 | ||
07a58883 | 402 | static const struct sdhci_acpi_slot sdhci_acpi_slot_int_emmc = { |
b04fa064 | 403 | .chip = &sdhci_acpi_chip_int, |
f25c3372 | 404 | .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE | |
9d65cb88 | 405 | MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR | |
c80f275f | 406 | MMC_CAP_CMD_DURING_TFR | MMC_CAP_WAIT_WHILE_BUSY, |
07a58883 | 407 | .flags = SDHCI_ACPI_RUNTIME_PM, |
e1f5633a | 408 | .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, |
e839b134 AH |
409 | .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | |
410 | SDHCI_QUIRK2_STOP_WITH_TC | | |
411 | SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400, | |
159cd328 | 412 | .probe_slot = intel_probe_slot, |
1c451c13 | 413 | .priv_size = sizeof(struct intel_host), |
07a58883 AH |
414 | }; |
415 | ||
e5571397 | 416 | static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = { |
e1f5633a AH |
417 | .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION | |
418 | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, | |
e5571397 | 419 | .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON, |
9d65cb88 | 420 | .caps = MMC_CAP_NONREMOVABLE | MMC_CAP_POWER_OFF_CARD | |
265984b3 | 421 | MMC_CAP_WAIT_WHILE_BUSY, |
e5571397 AH |
422 | .flags = SDHCI_ACPI_RUNTIME_PM, |
423 | .pm_caps = MMC_PM_KEEP_POWER, | |
159cd328 | 424 | .probe_slot = intel_probe_slot, |
1c451c13 | 425 | .priv_size = sizeof(struct intel_host), |
e5571397 AH |
426 | }; |
427 | ||
07a58883 | 428 | static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = { |
4fd4409c AH |
429 | .flags = SDHCI_ACPI_SD_CD | SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL | |
430 | SDHCI_ACPI_RUNTIME_PM, | |
e1f5633a | 431 | .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, |
934e31b9 AH |
432 | .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON | |
433 | SDHCI_QUIRK2_STOP_WITH_TC, | |
d3e97407 | 434 | .caps = MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_AGGRESSIVE_PM, |
159cd328 | 435 | .probe_slot = intel_probe_slot, |
1c451c13 | 436 | .priv_size = sizeof(struct intel_host), |
07a58883 AH |
437 | }; |
438 | ||
70cce2af PE |
439 | static const struct sdhci_acpi_slot sdhci_acpi_slot_qcom_sd_3v = { |
440 | .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION, | |
441 | .quirks2 = SDHCI_QUIRK2_NO_1_8_V, | |
442 | .caps = MMC_CAP_NONREMOVABLE, | |
443 | }; | |
444 | ||
445 | static const struct sdhci_acpi_slot sdhci_acpi_slot_qcom_sd = { | |
446 | .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION, | |
447 | .caps = MMC_CAP_NONREMOVABLE, | |
448 | }; | |
449 | ||
07a58883 AH |
450 | struct sdhci_acpi_uid_slot { |
451 | const char *hid; | |
452 | const char *uid; | |
453 | const struct sdhci_acpi_slot *slot; | |
454 | }; | |
455 | ||
456 | static const struct sdhci_acpi_uid_slot sdhci_acpi_uids[] = { | |
e839b134 AH |
457 | { "80865ACA", NULL, &sdhci_acpi_slot_int_sd }, |
458 | { "80865ACC", NULL, &sdhci_acpi_slot_int_emmc }, | |
459 | { "80865AD0", NULL, &sdhci_acpi_slot_int_sdio }, | |
07a58883 | 460 | { "80860F14" , "1" , &sdhci_acpi_slot_int_emmc }, |
db52d4f8 | 461 | { "80860F14" , "2" , &sdhci_acpi_slot_int_sdio }, |
07a58883 | 462 | { "80860F14" , "3" , &sdhci_acpi_slot_int_sd }, |
aad95dc4 | 463 | { "80860F16" , NULL, &sdhci_acpi_slot_int_sd }, |
07a58883 | 464 | { "INT33BB" , "2" , &sdhci_acpi_slot_int_sdio }, |
7147eaf3 | 465 | { "INT33BB" , "3" , &sdhci_acpi_slot_int_sd }, |
07a58883 | 466 | { "INT33C6" , NULL, &sdhci_acpi_slot_int_sdio }, |
07c001c1 | 467 | { "INT3436" , NULL, &sdhci_acpi_slot_int_sdio }, |
d0ed8e6b | 468 | { "INT344D" , NULL, &sdhci_acpi_slot_int_sdio }, |
0cd2f044 | 469 | { "PNP0FFF" , "3" , &sdhci_acpi_slot_int_sd }, |
07a58883 | 470 | { "PNP0D40" }, |
70cce2af PE |
471 | { "QCOM8051", NULL, &sdhci_acpi_slot_qcom_sd_3v }, |
472 | { "QCOM8052", NULL, &sdhci_acpi_slot_qcom_sd }, | |
07a58883 AH |
473 | { }, |
474 | }; | |
475 | ||
c4e05037 | 476 | static const struct acpi_device_id sdhci_acpi_ids[] = { |
e839b134 AH |
477 | { "80865ACA" }, |
478 | { "80865ACC" }, | |
479 | { "80865AD0" }, | |
07a58883 | 480 | { "80860F14" }, |
aad95dc4 | 481 | { "80860F16" }, |
07a58883 AH |
482 | { "INT33BB" }, |
483 | { "INT33C6" }, | |
07c001c1 | 484 | { "INT3436" }, |
d0ed8e6b | 485 | { "INT344D" }, |
07a58883 | 486 | { "PNP0D40" }, |
70cce2af PE |
487 | { "QCOM8051" }, |
488 | { "QCOM8052" }, | |
c4e05037 AH |
489 | { }, |
490 | }; | |
491 | MODULE_DEVICE_TABLE(acpi, sdhci_acpi_ids); | |
492 | ||
3db35251 AH |
493 | static const struct sdhci_acpi_slot *sdhci_acpi_get_slot(const char *hid, |
494 | const char *uid) | |
c4e05037 | 495 | { |
07a58883 AH |
496 | const struct sdhci_acpi_uid_slot *u; |
497 | ||
498 | for (u = sdhci_acpi_uids; u->hid; u++) { | |
499 | if (strcmp(u->hid, hid)) | |
500 | continue; | |
501 | if (!u->uid) | |
502 | return u->slot; | |
503 | if (uid && !strcmp(u->uid, uid)) | |
504 | return u->slot; | |
505 | } | |
c4e05037 AH |
506 | return NULL; |
507 | } | |
508 | ||
4e608e4e | 509 | static int sdhci_acpi_probe(struct platform_device *pdev) |
c4e05037 AH |
510 | { |
511 | struct device *dev = &pdev->dev; | |
f07b7952 | 512 | const struct sdhci_acpi_slot *slot; |
e5bbf307 | 513 | struct acpi_device *device, *child; |
c4e05037 AH |
514 | struct sdhci_acpi_host *c; |
515 | struct sdhci_host *host; | |
516 | struct resource *iomem; | |
517 | resource_size_t len; | |
f07b7952 | 518 | size_t priv_size; |
c4e05037 | 519 | const char *hid; |
3db35251 | 520 | const char *uid; |
87875655 | 521 | int err; |
c4e05037 | 522 | |
cd25c7be AS |
523 | device = ACPI_COMPANION(dev); |
524 | if (!device) | |
c4e05037 AH |
525 | return -ENODEV; |
526 | ||
17753d16 | 527 | hid = acpi_device_hid(device); |
a2038497 | 528 | uid = acpi_device_uid(device); |
17753d16 | 529 | |
f07b7952 AH |
530 | slot = sdhci_acpi_get_slot(hid, uid); |
531 | ||
e5bbf307 AH |
532 | /* Power on the SDHCI controller and its children */ |
533 | acpi_device_fix_up_power(device); | |
17753d16 AH |
534 | if (!sdhci_acpi_no_fixup_child_power(hid, uid)) { |
535 | list_for_each_entry(child, &device->children, node) | |
536 | if (child->status.present && child->status.enabled) | |
537 | acpi_device_fix_up_power(child); | |
538 | } | |
e5bbf307 | 539 | |
6e1c7d61 AH |
540 | if (sdhci_acpi_byt_defer(dev)) |
541 | return -EPROBE_DEFER; | |
542 | ||
c4e05037 AH |
543 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
544 | if (!iomem) | |
545 | return -ENOMEM; | |
546 | ||
547 | len = resource_size(iomem); | |
548 | if (len < 0x100) | |
549 | dev_err(dev, "Invalid iomem size!\n"); | |
550 | ||
551 | if (!devm_request_mem_region(dev, iomem->start, len, dev_name(dev))) | |
552 | return -ENOMEM; | |
553 | ||
f07b7952 AH |
554 | priv_size = slot ? slot->priv_size : 0; |
555 | host = sdhci_alloc_host(dev, sizeof(struct sdhci_acpi_host) + priv_size); | |
c4e05037 AH |
556 | if (IS_ERR(host)) |
557 | return PTR_ERR(host); | |
558 | ||
559 | c = sdhci_priv(host); | |
560 | c->host = host; | |
f07b7952 | 561 | c->slot = slot; |
c4e05037 AH |
562 | c->pdev = pdev; |
563 | c->use_runtime_pm = sdhci_acpi_flag(c, SDHCI_ACPI_RUNTIME_PM); | |
564 | ||
565 | platform_set_drvdata(pdev, c); | |
566 | ||
567 | host->hw_name = "ACPI"; | |
568 | host->ops = &sdhci_acpi_ops_dflt; | |
569 | host->irq = platform_get_irq(pdev, 0); | |
570 | ||
571 | host->ioaddr = devm_ioremap_nocache(dev, iomem->start, | |
572 | resource_size(iomem)); | |
573 | if (host->ioaddr == NULL) { | |
574 | err = -ENOMEM; | |
575 | goto err_free; | |
576 | } | |
577 | ||
c4e05037 | 578 | if (c->slot) { |
578b36b6 | 579 | if (c->slot->probe_slot) { |
7dafca83 | 580 | err = c->slot->probe_slot(pdev, hid, uid); |
578b36b6 GY |
581 | if (err) |
582 | goto err_free; | |
583 | } | |
c4e05037 AH |
584 | if (c->slot->chip) { |
585 | host->ops = c->slot->chip->ops; | |
586 | host->quirks |= c->slot->chip->quirks; | |
587 | host->quirks2 |= c->slot->chip->quirks2; | |
588 | host->mmc->caps |= c->slot->chip->caps; | |
589 | host->mmc->caps2 |= c->slot->chip->caps2; | |
590 | host->mmc->pm_caps |= c->slot->chip->pm_caps; | |
591 | } | |
592 | host->quirks |= c->slot->quirks; | |
593 | host->quirks2 |= c->slot->quirks2; | |
594 | host->mmc->caps |= c->slot->caps; | |
595 | host->mmc->caps2 |= c->slot->caps2; | |
596 | host->mmc->pm_caps |= c->slot->pm_caps; | |
597 | } | |
598 | ||
0d3e3350 AH |
599 | host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP; |
600 | ||
a61abe6e | 601 | if (sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD)) { |
4fd4409c AH |
602 | bool v = sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL); |
603 | ||
e28d6f04 ZR |
604 | err = mmc_gpiod_request_cd(host->mmc, NULL, 0, v, 0, NULL); |
605 | if (err) { | |
606 | if (err == -EPROBE_DEFER) | |
607 | goto err_free; | |
4fd4409c | 608 | dev_warn(dev, "failed to setup card detect gpio\n"); |
a61abe6e | 609 | c->use_runtime_pm = false; |
4fd4409c | 610 | } |
a61abe6e AH |
611 | } |
612 | ||
4fd4409c AH |
613 | err = sdhci_add_host(host); |
614 | if (err) | |
615 | goto err_free; | |
616 | ||
c4e05037 | 617 | if (c->use_runtime_pm) { |
1d1ff458 | 618 | pm_runtime_set_active(dev); |
c4e05037 AH |
619 | pm_suspend_ignore_children(dev, 1); |
620 | pm_runtime_set_autosuspend_delay(dev, 50); | |
621 | pm_runtime_use_autosuspend(dev); | |
622 | pm_runtime_enable(dev); | |
623 | } | |
624 | ||
4e6a2ef9 FZ |
625 | device_enable_async_suspend(dev); |
626 | ||
c4e05037 AH |
627 | return 0; |
628 | ||
629 | err_free: | |
0406157f WD |
630 | if (c->slot && c->slot->free_slot) |
631 | c->slot->free_slot(pdev); | |
632 | ||
c4e05037 AH |
633 | sdhci_free_host(c->host); |
634 | return err; | |
635 | } | |
636 | ||
4e608e4e | 637 | static int sdhci_acpi_remove(struct platform_device *pdev) |
c4e05037 AH |
638 | { |
639 | struct sdhci_acpi_host *c = platform_get_drvdata(pdev); | |
640 | struct device *dev = &pdev->dev; | |
641 | int dead; | |
642 | ||
643 | if (c->use_runtime_pm) { | |
644 | pm_runtime_get_sync(dev); | |
645 | pm_runtime_disable(dev); | |
646 | pm_runtime_put_noidle(dev); | |
647 | } | |
648 | ||
578b36b6 GY |
649 | if (c->slot && c->slot->remove_slot) |
650 | c->slot->remove_slot(pdev); | |
651 | ||
c4e05037 AH |
652 | dead = (sdhci_readl(c->host, SDHCI_INT_STATUS) == ~0); |
653 | sdhci_remove_host(c->host, dead); | |
0406157f WD |
654 | |
655 | if (c->slot && c->slot->free_slot) | |
656 | c->slot->free_slot(pdev); | |
657 | ||
c4e05037 AH |
658 | sdhci_free_host(c->host); |
659 | ||
660 | return 0; | |
661 | } | |
662 | ||
663 | #ifdef CONFIG_PM_SLEEP | |
664 | ||
665 | static int sdhci_acpi_suspend(struct device *dev) | |
666 | { | |
667 | struct sdhci_acpi_host *c = dev_get_drvdata(dev); | |
d38dcad4 | 668 | struct sdhci_host *host = c->host; |
c4e05037 | 669 | |
d38dcad4 AH |
670 | if (host->tuning_mode != SDHCI_TUNING_MODE_3) |
671 | mmc_retune_needed(host->mmc); | |
672 | ||
673 | return sdhci_suspend_host(host); | |
c4e05037 AH |
674 | } |
675 | ||
676 | static int sdhci_acpi_resume(struct device *dev) | |
677 | { | |
678 | struct sdhci_acpi_host *c = dev_get_drvdata(dev); | |
679 | ||
6e1c7d61 AH |
680 | sdhci_acpi_byt_setting(&c->pdev->dev); |
681 | ||
c4e05037 AH |
682 | return sdhci_resume_host(c->host); |
683 | } | |
684 | ||
c4e05037 AH |
685 | #endif |
686 | ||
162d6f98 | 687 | #ifdef CONFIG_PM |
c4e05037 AH |
688 | |
689 | static int sdhci_acpi_runtime_suspend(struct device *dev) | |
690 | { | |
691 | struct sdhci_acpi_host *c = dev_get_drvdata(dev); | |
d38dcad4 AH |
692 | struct sdhci_host *host = c->host; |
693 | ||
694 | if (host->tuning_mode != SDHCI_TUNING_MODE_3) | |
695 | mmc_retune_needed(host->mmc); | |
c4e05037 | 696 | |
d38dcad4 | 697 | return sdhci_runtime_suspend_host(host); |
c4e05037 AH |
698 | } |
699 | ||
700 | static int sdhci_acpi_runtime_resume(struct device *dev) | |
701 | { | |
702 | struct sdhci_acpi_host *c = dev_get_drvdata(dev); | |
703 | ||
6e1c7d61 AH |
704 | sdhci_acpi_byt_setting(&c->pdev->dev); |
705 | ||
c4e05037 AH |
706 | return sdhci_runtime_resume_host(c->host); |
707 | } | |
708 | ||
c4e05037 AH |
709 | #endif |
710 | ||
711 | static const struct dev_pm_ops sdhci_acpi_pm_ops = { | |
dafed447 | 712 | SET_SYSTEM_SLEEP_PM_OPS(sdhci_acpi_suspend, sdhci_acpi_resume) |
1d75f74b | 713 | SET_RUNTIME_PM_OPS(sdhci_acpi_runtime_suspend, |
9b449e99 | 714 | sdhci_acpi_runtime_resume, NULL) |
c4e05037 AH |
715 | }; |
716 | ||
717 | static struct platform_driver sdhci_acpi_driver = { | |
718 | .driver = { | |
719 | .name = "sdhci-acpi", | |
c4e05037 AH |
720 | .acpi_match_table = sdhci_acpi_ids, |
721 | .pm = &sdhci_acpi_pm_ops, | |
722 | }, | |
723 | .probe = sdhci_acpi_probe, | |
4e608e4e | 724 | .remove = sdhci_acpi_remove, |
c4e05037 AH |
725 | }; |
726 | ||
727 | module_platform_driver(sdhci_acpi_driver); | |
728 | ||
729 | MODULE_DESCRIPTION("Secure Digital Host Controller Interface ACPI driver"); | |
730 | MODULE_AUTHOR("Adrian Hunter"); | |
731 | MODULE_LICENSE("GPL v2"); |