sdhci-acpi.c (113a87f868b2f2e086790a68e8b9e41d8f0c3295) sdhci-acpi.c (a61abe6eebfda1add8cb54e6e10384ea747d68a5)
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.

--- 17 unchanged lines hidden (view full) ---

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>
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.

--- 17 unchanged lines hidden (view full) ---

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/gpio.h>
34#include <linux/interrupt.h>
35#include <linux/acpi.h>
35#include <linux/interrupt.h>
36#include <linux/acpi.h>
37#include <linux/acpi_gpio.h>
36#include <linux/pm.h>
37#include <linux/pm_runtime.h>
38
39#include <linux/mmc/host.h>
40#include <linux/mmc/pm.h>
41#include <linux/mmc/sdhci.h>
42
43#include "sdhci.h"

--- 52 unchanged lines hidden (view full) ---

96static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = {
97 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
98 .caps = MMC_CAP_NONREMOVABLE | MMC_CAP_POWER_OFF_CARD,
99 .flags = SDHCI_ACPI_RUNTIME_PM,
100 .pm_caps = MMC_PM_KEEP_POWER,
101};
102
103static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = {
38#include <linux/pm.h>
39#include <linux/pm_runtime.h>
40
41#include <linux/mmc/host.h>
42#include <linux/mmc/pm.h>
43#include <linux/mmc/sdhci.h>
44
45#include "sdhci.h"

--- 52 unchanged lines hidden (view full) ---

98static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = {
99 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
100 .caps = MMC_CAP_NONREMOVABLE | MMC_CAP_POWER_OFF_CARD,
101 .flags = SDHCI_ACPI_RUNTIME_PM,
102 .pm_caps = MMC_PM_KEEP_POWER,
103};
104
105static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = {
106 .flags = SDHCI_ACPI_SD_CD | SDHCI_ACPI_RUNTIME_PM,
107 .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON,
104};
105
106struct sdhci_acpi_uid_slot {
107 const char *hid;
108 const char *uid;
109 const struct sdhci_acpi_slot *slot;
110};
111

--- 44 unchanged lines hidden (view full) ---

156 uid = info->unique_id.string;
157
158 slot = sdhci_acpi_get_slot_by_ids(hid, uid);
159
160 kfree(info);
161 return slot;
162}
163
108};
109
110struct sdhci_acpi_uid_slot {
111 const char *hid;
112 const char *uid;
113 const struct sdhci_acpi_slot *slot;
114};
115

--- 44 unchanged lines hidden (view full) ---

160 uid = info->unique_id.string;
161
162 slot = sdhci_acpi_get_slot_by_ids(hid, uid);
163
164 kfree(info);
165 return slot;
166}
167
168#ifdef CONFIG_PM_RUNTIME
169
170static irqreturn_t sdhci_acpi_sd_cd(int irq, void *dev_id)
171{
172 mmc_detect_change(dev_id, msecs_to_jiffies(200));
173 return IRQ_HANDLED;
174}
175
176static int sdhci_acpi_add_own_cd(struct device *dev, int gpio,
177 struct mmc_host *mmc)
178{
179 unsigned long flags;
180 int err, irq;
181
182 if (gpio < 0) {
183 err = gpio;
184 goto out;
185 }
186
187 err = devm_gpio_request_one(dev, gpio, GPIOF_DIR_IN, "sd_cd");
188 if (err)
189 goto out;
190
191 irq = gpio_to_irq(gpio);
192 if (irq < 0)
193 goto out_free;
194
195 flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;
196 err = devm_request_irq(dev, irq, sdhci_acpi_sd_cd, flags, "sd_cd", mmc);
197 if (err)
198 goto out_free;
199
200 return 0;
201
202out_free:
203 devm_gpio_free(dev, gpio);
204out:
205 dev_warn(dev, "failed to setup card detect wake up\n");
206 return err;
207}
208
209#else
210
211static int sdhci_acpi_add_own_cd(struct device *dev, int gpio,
212 struct mmc_host *mmc)
213{
214 return 0;
215}
216
217#endif
218
164static int sdhci_acpi_probe(struct platform_device *pdev)
165{
166 struct device *dev = &pdev->dev;
167 acpi_handle handle = ACPI_HANDLE(dev);
168 struct acpi_device *device;
169 struct sdhci_acpi_host *c;
170 struct sdhci_host *host;
171 struct resource *iomem;
172 resource_size_t len;
173 const char *hid;
219static int sdhci_acpi_probe(struct platform_device *pdev)
220{
221 struct device *dev = &pdev->dev;
222 acpi_handle handle = ACPI_HANDLE(dev);
223 struct acpi_device *device;
224 struct sdhci_acpi_host *c;
225 struct sdhci_host *host;
226 struct resource *iomem;
227 resource_size_t len;
228 const char *hid;
174 int err;
229 int err, gpio;
175
176 if (acpi_bus_get_device(handle, &device))
177 return -ENODEV;
178
179 if (acpi_bus_get_status(device) || !device->status.present)
180 return -ENODEV;
181
182 hid = acpi_device_hid(device);

--- 8 unchanged lines hidden (view full) ---

191
192 if (!devm_request_mem_region(dev, iomem->start, len, dev_name(dev)))
193 return -ENOMEM;
194
195 host = sdhci_alloc_host(dev, sizeof(struct sdhci_acpi_host));
196 if (IS_ERR(host))
197 return PTR_ERR(host);
198
230
231 if (acpi_bus_get_device(handle, &device))
232 return -ENODEV;
233
234 if (acpi_bus_get_status(device) || !device->status.present)
235 return -ENODEV;
236
237 hid = acpi_device_hid(device);

--- 8 unchanged lines hidden (view full) ---

246
247 if (!devm_request_mem_region(dev, iomem->start, len, dev_name(dev)))
248 return -ENOMEM;
249
250 host = sdhci_alloc_host(dev, sizeof(struct sdhci_acpi_host));
251 if (IS_ERR(host))
252 return PTR_ERR(host);
253
254 gpio = acpi_get_gpio_by_index(dev, 0, NULL);
255
199 c = sdhci_priv(host);
200 c->host = host;
201 c->slot = sdhci_acpi_get_slot(handle, hid);
202 c->pdev = pdev;
203 c->use_runtime_pm = sdhci_acpi_flag(c, SDHCI_ACPI_RUNTIME_PM);
204
205 platform_set_drvdata(pdev, c);
206

--- 39 unchanged lines hidden (view full) ---

246 }
247
248 host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
249
250 err = sdhci_add_host(host);
251 if (err)
252 goto err_free;
253
256 c = sdhci_priv(host);
257 c->host = host;
258 c->slot = sdhci_acpi_get_slot(handle, hid);
259 c->pdev = pdev;
260 c->use_runtime_pm = sdhci_acpi_flag(c, SDHCI_ACPI_RUNTIME_PM);
261
262 platform_set_drvdata(pdev, c);
263

--- 39 unchanged lines hidden (view full) ---

303 }
304
305 host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
306
307 err = sdhci_add_host(host);
308 if (err)
309 goto err_free;
310
311 if (sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD)) {
312 if (sdhci_acpi_add_own_cd(dev, gpio, host->mmc))
313 c->use_runtime_pm = false;
314 }
315
254 if (c->use_runtime_pm) {
255 pm_runtime_set_active(dev);
256 pm_suspend_ignore_children(dev, 1);
257 pm_runtime_set_autosuspend_delay(dev, 50);
258 pm_runtime_use_autosuspend(dev);
259 pm_runtime_enable(dev);
260 }
261

--- 102 unchanged lines hidden ---
316 if (c->use_runtime_pm) {
317 pm_runtime_set_active(dev);
318 pm_suspend_ignore_children(dev, 1);
319 pm_runtime_set_autosuspend_delay(dev, 50);
320 pm_runtime_use_autosuspend(dev);
321 pm_runtime_enable(dev);
322 }
323

--- 102 unchanged lines hidden ---