blob: 99432785f438bd34e0670fd1fb644949d1b0750b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * (C) Copyright David Brownell 2000-2002
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -08003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/pci.h>
David Brownell21b18612005-11-23 15:45:42 -080022#include <linux/usb.h>
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/io.h>
25#include <asm/irq.h>
David Brownell21b18612005-11-23 15:45:42 -080026
27#ifdef CONFIG_PPC_PMAC
28#include <asm/machdep.h>
29#include <asm/pmac_feature.h>
30#include <asm/pci-bridge.h>
31#include <asm/prom.h>
32#endif
David Brownell5f827ea2005-09-22 22:38:16 -070033
34#include "usb.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "hcd.h"
36
37
David Brownellc6053ec2005-04-18 17:39:22 -070038/* PCI-based HCs are common, but plenty of non-PCI HCs are used too */
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40
41/*-------------------------------------------------------------------------*/
42
43/* configure so an HC device and id are always provided */
44/* always called with process context; sleeping is OK */
45
46/**
47 * usb_hcd_pci_probe - initialize PCI-based HCDs
48 * @dev: USB Host Controller being probed
49 * @id: pci hotplug id connecting controller to HCD framework
50 * Context: !in_interrupt()
51 *
52 * Allocates basic PCI resources for this USB host controller, and
53 * then invokes the start() method for the HCD associated with it
54 * through the hotplug entry's driver_data.
55 *
56 * Store this function in the HCD's struct pci_driver as probe().
57 */
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080058int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
60 struct hc_driver *driver;
61 struct usb_hcd *hcd;
62 int retval;
63
64 if (usb_disabled())
65 return -ENODEV;
66
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080067 if (!id)
68 return -EINVAL;
69 driver = (struct hc_driver *)id->driver_data;
70 if (!driver)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 return -EINVAL;
72
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080073 if (pci_enable_device(dev) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 return -ENODEV;
David Brownellc6053ec2005-04-18 17:39:22 -070075 dev->current_state = PCI_D0;
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080076
77 if (!dev->irq) {
78 dev_err(&dev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 "Found HC with no IRQ. Check BIOS/PCI %s setup!\n",
80 pci_name(dev));
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080081 retval = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 goto err1;
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080083 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080085 hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 if (!hcd) {
87 retval = -ENOMEM;
88 goto err1;
89 }
90
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080091 if (driver->flags & HCD_MEMORY) {
92 /* EHCI, OHCI */
93 hcd->rsrc_start = pci_resource_start(dev, 0);
94 hcd->rsrc_len = pci_resource_len(dev, 0);
95 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 driver->description)) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080097 dev_dbg(&dev->dev, "controller already in use\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 retval = -EBUSY;
99 goto err2;
100 }
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800101 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 if (hcd->regs == NULL) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800103 dev_dbg(&dev->dev, "error mapping memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 retval = -EFAULT;
105 goto err3;
106 }
107
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800108 } else {
109 /* UHCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 int region;
111
112 for (region = 0; region < PCI_ROM_RESOURCE; region++) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800113 if (!(pci_resource_flags(dev, region) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 IORESOURCE_IO))
115 continue;
116
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800117 hcd->rsrc_start = pci_resource_start(dev, region);
118 hcd->rsrc_len = pci_resource_len(dev, region);
119 if (request_region(hcd->rsrc_start, hcd->rsrc_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 driver->description))
121 break;
122 }
123 if (region == PCI_ROM_RESOURCE) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800124 dev_dbg(&dev->dev, "no i/o regions available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 retval = -EBUSY;
126 goto err1;
127 }
128 }
129
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800130 pci_set_master(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Alan Stern442258e2007-12-06 14:47:08 -0500132 retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 if (retval != 0)
134 goto err4;
135 return retval;
136
137 err4:
138 if (driver->flags & HCD_MEMORY) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800139 iounmap(hcd->regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 err3:
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800141 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 } else
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800143 release_region(hcd->rsrc_start, hcd->rsrc_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 err2:
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800145 usb_put_hcd(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 err1:
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800147 pci_disable_device(dev);
148 dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 return retval;
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800150}
Greg Kroah-Hartman782e70c2008-01-25 11:12:21 -0600151EXPORT_SYMBOL_GPL(usb_hcd_pci_probe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153
154/* may be called without controller electrically present */
155/* may be called with controller, bus, and devices active */
156
157/**
158 * usb_hcd_pci_remove - shutdown processing for PCI-based HCDs
159 * @dev: USB Host Controller being removed
160 * Context: !in_interrupt()
161 *
162 * Reverses the effect of usb_hcd_pci_probe(), first invoking
163 * the HCD's stop() method. It is always called from a thread
164 * context, normally "rmmod", "apmd", or something similar.
165 *
166 * Store this function in the HCD's struct pci_driver as remove().
167 */
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800168void usb_hcd_pci_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169{
170 struct usb_hcd *hcd;
171
172 hcd = pci_get_drvdata(dev);
173 if (!hcd)
174 return;
175
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800176 usb_remove_hcd(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 if (hcd->driver->flags & HCD_MEMORY) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800178 iounmap(hcd->regs);
179 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 } else {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800181 release_region(hcd->rsrc_start, hcd->rsrc_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 }
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800183 usb_put_hcd(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 pci_disable_device(dev);
185}
Greg Kroah-Hartman782e70c2008-01-25 11:12:21 -0600186EXPORT_SYMBOL_GPL(usb_hcd_pci_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188
189#ifdef CONFIG_PM
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191/**
192 * usb_hcd_pci_suspend - power management suspend of a PCI-based HCD
193 * @dev: USB Host Controller being suspended
Alan Sterna0d49222008-12-17 15:06:03 -0500194 * @message: Power Management message describing this state transition
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 *
Alan Sterna0d49222008-12-17 15:06:03 -0500196 * Store this function in the HCD's struct pci_driver as .suspend.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 */
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800198int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t message)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
Alan Sterna0d49222008-12-17 15:06:03 -0500200 struct usb_hcd *hcd = pci_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 int retval = 0;
Alan Sterna0d49222008-12-17 15:06:03 -0500202 int wake, w;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
David Brownell5f827ea2005-09-22 22:38:16 -0700204 /* Root hub suspend should have stopped all downstream traffic,
205 * and all bus master traffic. And done so for both the interface
206 * and the stub usb_device (which we check here). But maybe it
207 * didn't; writing sysfs power/state files ignores such rules...
208 *
209 * We must ignore the FREEZE vs SUSPEND distinction here, because
210 * otherwise the swsusp will save (and restore) garbage state.
211 */
Alan Sternf3fd77c2007-05-04 11:54:28 -0400212 if (!(hcd->state == HC_STATE_SUSPENDED ||
Alan Sterna0d49222008-12-17 15:06:03 -0500213 hcd->state == HC_STATE_HALT)) {
214 dev_warn(&dev->dev, "Root hub is not suspended\n");
215 retval = -EBUSY;
216 goto done;
217 }
218
219 /* We might already be suspended (runtime PM -- not yet written) */
220 if (dev->current_state != PCI_D0)
221 goto done;
David Brownell5f827ea2005-09-22 22:38:16 -0700222
Alan Stern7be7d742008-04-03 18:03:06 -0400223 if (hcd->driver->pci_suspend) {
224 retval = hcd->driver->pci_suspend(hcd, message);
225 suspend_report_result(hcd->driver->pci_suspend, retval);
Andrew Morton02669492006-03-23 01:38:34 -0800226 if (retval)
David Brownell5f827ea2005-09-22 22:38:16 -0700227 goto done;
David Brownell5f827ea2005-09-22 22:38:16 -0700228 }
Alan Sterna0d49222008-12-17 15:06:03 -0500229
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +1100230 synchronize_irq(dev->irq);
David Brownell5f827ea2005-09-22 22:38:16 -0700231
Alan Sterna0d49222008-12-17 15:06:03 -0500232 /* Don't fail on error to enable wakeup. We rely on pci code
233 * to reject requests the hardware can't implement, rather
234 * than coding the same thing.
David Brownellc6053ec2005-04-18 17:39:22 -0700235 */
Alan Sterna0d49222008-12-17 15:06:03 -0500236 wake = (hcd->state == HC_STATE_SUSPENDED &&
237 device_may_wakeup(&dev->dev));
238 w = pci_wake_from_d3(dev, wake);
239 if (w < 0)
240 wake = w;
241 dev_dbg(&dev->dev, "wakeup: %d\n", wake);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
David Brownell5f827ea2005-09-22 22:38:16 -0700243 /* Downstream ports from this root hub should already be quiesced, so
244 * there will be no DMA activity. Now we can shut down the upstream
245 * link (except maybe for PME# resume signaling) and enter some PCI
246 * low power state, if the hardware allows.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 */
Alan Sterna0d49222008-12-17 15:06:03 -0500248 pci_disable_device(dev);
249 done:
250 return retval;
251}
252EXPORT_SYMBOL_GPL(usb_hcd_pci_suspend);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Alan Sterna0d49222008-12-17 15:06:03 -0500254/**
255 * usb_hcd_pci_suspend_late - suspend a PCI-based HCD after IRQs are disabled
256 * @dev: USB Host Controller being suspended
257 * @message: Power Management message describing this state transition
258 *
259 * Store this function in the HCD's struct pci_driver as .suspend_late.
260 */
261int usb_hcd_pci_suspend_late(struct pci_dev *dev, pm_message_t message)
262{
263 int retval = 0;
264 int has_pci_pm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Alan Sterna0d49222008-12-17 15:06:03 -0500266 /* We might already be suspended (runtime PM -- not yet written) */
267 if (dev->current_state != PCI_D0)
268 goto done;
Alan Stern269954e2007-11-19 15:57:45 -0500269
Alan Sterna0d49222008-12-17 15:06:03 -0500270 pci_save_state(dev);
271
272 /* Don't change state if we don't need to */
273 if (message.event == PM_EVENT_FREEZE ||
274 message.event == PM_EVENT_PRETHAW) {
275 dev_dbg(&dev->dev, "--> no state change\n");
276 goto done;
277 }
278
279 has_pci_pm = pci_find_capability(dev, PCI_CAP_ID_PM);
280 if (!has_pci_pm) {
281 dev_dbg(&dev->dev, "--> PCI D0 legacy\n");
282 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
David Brownellc6053ec2005-04-18 17:39:22 -0700284 /* NOTE: dev->current_state becomes nonzero only here, and
285 * only for devices that support PCI PM. Also, exiting
286 * PCI_D3 (but not PCI_D1 or PCI_D2) is allowed to reset
287 * some device state (e.g. as part of clock reinit).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 */
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800289 retval = pci_set_power_state(dev, PCI_D3hot);
Andrew Morton02669492006-03-23 01:38:34 -0800290 suspend_report_result(pci_set_power_state, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 if (retval == 0) {
Alan Sterna0d49222008-12-17 15:06:03 -0500292 dev_dbg(&dev->dev, "--> PCI D3\n");
David Brownell5f827ea2005-09-22 22:38:16 -0700293 } else {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800294 dev_dbg(&dev->dev, "PCI D3 suspend fail, %d\n",
David Brownellc6053ec2005-04-18 17:39:22 -0700295 retval);
Alan Sterna0d49222008-12-17 15:06:03 -0500296 pci_restore_state(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 }
299
David Brownell21b18612005-11-23 15:45:42 -0800300#ifdef CONFIG_PPC_PMAC
Alan Sterna0d49222008-12-17 15:06:03 -0500301 if (retval == 0) {
David Brownell21b18612005-11-23 15:45:42 -0800302 /* Disable ASIC clocks for USB */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100303 if (machine_is(powermac)) {
David Brownell21b18612005-11-23 15:45:42 -0800304 struct device_node *of_node;
305
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800306 of_node = pci_device_to_OF_node(dev);
David Brownell21b18612005-11-23 15:45:42 -0800307 if (of_node)
308 pmac_call_feature(PMAC_FTR_USB_ENABLE,
309 of_node, 0, 0);
310 }
David Brownell21b18612005-11-23 15:45:42 -0800311 }
Alan Sterna0d49222008-12-17 15:06:03 -0500312#endif
David Brownell21b18612005-11-23 15:45:42 -0800313
Alan Sterna0d49222008-12-17 15:06:03 -0500314 done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 return retval;
316}
Alan Sterna0d49222008-12-17 15:06:03 -0500317EXPORT_SYMBOL_GPL(usb_hcd_pci_suspend_late);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319/**
Alan Sterna0d49222008-12-17 15:06:03 -0500320 * usb_hcd_pci_resume_early - resume a PCI-based HCD before IRQs are enabled
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 * @dev: USB Host Controller being resumed
322 *
Alan Sterna0d49222008-12-17 15:06:03 -0500323 * Store this function in the HCD's struct pci_driver as .resume_early.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 */
Alan Sterna0d49222008-12-17 15:06:03 -0500325int usb_hcd_pci_resume_early(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
Alan Sterna0d49222008-12-17 15:06:03 -0500327 int retval = 0;
328 pci_power_t state = dev->current_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
David Brownell21b18612005-11-23 15:45:42 -0800330#ifdef CONFIG_PPC_PMAC
331 /* Reenable ASIC clocks for USB */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100332 if (machine_is(powermac)) {
David Brownell21b18612005-11-23 15:45:42 -0800333 struct device_node *of_node;
334
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800335 of_node = pci_device_to_OF_node(dev);
David Brownell21b18612005-11-23 15:45:42 -0800336 if (of_node)
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800337 pmac_call_feature(PMAC_FTR_USB_ENABLE,
David Brownell21b18612005-11-23 15:45:42 -0800338 of_node, 0, 1);
339 }
340#endif
341
David Brownellc6053ec2005-04-18 17:39:22 -0700342 /* NOTE: chip docs cover clean "real suspend" cases (what Linux
343 * calls "standby", "suspend to RAM", and so on). There are also
344 * dirty cases when swsusp fakes a suspend in "shutdown" mode.
345 */
Alan Sterna0d49222008-12-17 15:06:03 -0500346 if (state != PCI_D0) {
David Brownellc6053ec2005-04-18 17:39:22 -0700347#ifdef DEBUG
348 int pci_pm;
349 u16 pmcr;
350
351 pci_pm = pci_find_capability(dev, PCI_CAP_ID_PM);
352 pci_read_config_word(dev, pci_pm + PCI_PM_CTRL, &pmcr);
353 pmcr &= PCI_PM_CTRL_STATE_MASK;
354 if (pmcr) {
355 /* Clean case: power to USB and to HC registers was
356 * maintained; remote wakeup is easy.
357 */
Alan Sterna0d49222008-12-17 15:06:03 -0500358 dev_dbg(&dev->dev, "resume from PCI D%d\n", pmcr);
David Brownellc6053ec2005-04-18 17:39:22 -0700359 } else {
360 /* Clean: HC lost Vcc power, D0 uninitialized
361 * + Vaux may have preserved port and transceiver
362 * state ... for remote wakeup from D3cold
363 * + or not; HCD must reinit + re-enumerate
364 *
365 * Dirty: D0 semi-initialized cases with swsusp
366 * + after BIOS init
367 * + after Linux init (HCD statically linked)
368 */
Alan Sterna0d49222008-12-17 15:06:03 -0500369 dev_dbg(&dev->dev, "resume from previous PCI D%d\n",
370 state);
David Brownellc6053ec2005-04-18 17:39:22 -0700371 }
372#endif
Alan Sterna0d49222008-12-17 15:06:03 -0500373
374 retval = pci_set_power_state(dev, PCI_D0);
David Brownellc6053ec2005-04-18 17:39:22 -0700375 } else {
376 /* Same basic cases: clean (powered/not), dirty */
Alan Sterna0d49222008-12-17 15:06:03 -0500377 dev_dbg(&dev->dev, "PCI legacy resume\n");
David Brownellc6053ec2005-04-18 17:39:22 -0700378 }
379
Alan Sterna0d49222008-12-17 15:06:03 -0500380 if (retval < 0)
381 dev_err(&dev->dev, "can't resume: %d\n", retval);
382 else
383 pci_restore_state(dev);
384
385 return retval;
386}
387EXPORT_SYMBOL_GPL(usb_hcd_pci_resume_early);
388
389/**
390 * usb_hcd_pci_resume - power management resume of a PCI-based HCD
391 * @dev: USB Host Controller being resumed
392 *
393 * Store this function in the HCD's struct pci_driver as .resume.
394 */
395int usb_hcd_pci_resume(struct pci_dev *dev)
396{
397 struct usb_hcd *hcd;
398 int retval;
399
400 hcd = pci_get_drvdata(dev);
401 if (hcd->state != HC_STATE_SUSPENDED) {
402 dev_dbg(hcd->self.controller,
403 "can't resume, not suspended!\n");
404 return 0;
405 }
406
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800407 retval = pci_enable_device(dev);
David Brownellc6053ec2005-04-18 17:39:22 -0700408 if (retval < 0) {
Alan Sterna0d49222008-12-17 15:06:03 -0500409 dev_err(&dev->dev, "can't re-enable after resume, %d!\n",
410 retval);
David Brownellc6053ec2005-04-18 17:39:22 -0700411 return retval;
412 }
Alan Sterna0d49222008-12-17 15:06:03 -0500413
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800414 pci_set_master(dev);
Alan Sterna0d49222008-12-17 15:06:03 -0500415
416 /* yes, ignore this result too... */
417 (void) pci_wake_from_d3(dev, 0);
David Brownellc6053ec2005-04-18 17:39:22 -0700418
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +1100419 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Alan Stern7be7d742008-04-03 18:03:06 -0400421 if (hcd->driver->pci_resume) {
422 retval = hcd->driver->pci_resume(hcd);
David Brownell5f827ea2005-09-22 22:38:16 -0700423 if (retval) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800424 dev_err(hcd->self.controller,
David Brownell5f827ea2005-09-22 22:38:16 -0700425 "PCI post-resume error %d!\n", retval);
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800426 usb_hc_died(hcd);
David Brownell5f827ea2005-09-22 22:38:16 -0700427 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 return retval;
430}
Greg Kroah-Hartman782e70c2008-01-25 11:12:21 -0600431EXPORT_SYMBOL_GPL(usb_hcd_pci_resume);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433#endif /* CONFIG_PM */
434
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700435/**
436 * usb_hcd_pci_shutdown - shutdown host controller
437 * @dev: USB Host Controller being shutdown
438 */
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800439void usb_hcd_pci_shutdown(struct pci_dev *dev)
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700440{
441 struct usb_hcd *hcd;
442
443 hcd = pci_get_drvdata(dev);
444 if (!hcd)
445 return;
446
447 if (hcd->driver->shutdown)
448 hcd->driver->shutdown(hcd);
449}
Greg Kroah-Hartman782e70c2008-01-25 11:12:21 -0600450EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451