blob: 84760ddbc3325cba6cfdc8b219c3d70f32e0a5ab [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;
76 dev->dev.power.power_state = PMSG_ON;
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080077
78 if (!dev->irq) {
79 dev_err(&dev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 "Found HC with no IRQ. Check BIOS/PCI %s setup!\n",
81 pci_name(dev));
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080082 retval = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 goto err1;
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080084 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080086 hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 if (!hcd) {
88 retval = -ENOMEM;
89 goto err1;
90 }
91
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080092 if (driver->flags & HCD_MEMORY) {
93 /* EHCI, OHCI */
94 hcd->rsrc_start = pci_resource_start(dev, 0);
95 hcd->rsrc_len = pci_resource_len(dev, 0);
96 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 driver->description)) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -080098 dev_dbg(&dev->dev, "controller already in use\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 retval = -EBUSY;
100 goto err2;
101 }
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800102 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 if (hcd->regs == NULL) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800104 dev_dbg(&dev->dev, "error mapping memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 retval = -EFAULT;
106 goto err3;
107 }
108
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800109 } else {
110 /* UHCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 int region;
112
113 for (region = 0; region < PCI_ROM_RESOURCE; region++) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800114 if (!(pci_resource_flags(dev, region) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 IORESOURCE_IO))
116 continue;
117
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800118 hcd->rsrc_start = pci_resource_start(dev, region);
119 hcd->rsrc_len = pci_resource_len(dev, region);
120 if (request_region(hcd->rsrc_start, hcd->rsrc_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 driver->description))
122 break;
123 }
124 if (region == PCI_ROM_RESOURCE) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800125 dev_dbg(&dev->dev, "no i/o regions available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 retval = -EBUSY;
127 goto err1;
128 }
129 }
130
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800131 pci_set_master(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Alan Stern442258e2007-12-06 14:47:08 -0500133 retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 if (retval != 0)
135 goto err4;
136 return retval;
137
138 err4:
139 if (driver->flags & HCD_MEMORY) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800140 iounmap(hcd->regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 err3:
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800142 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 } else
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800144 release_region(hcd->rsrc_start, hcd->rsrc_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 err2:
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800146 usb_put_hcd(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 err1:
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800148 pci_disable_device(dev);
149 dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 return retval;
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800151}
Greg Kroah-Hartman782e70c2008-01-25 11:12:21 -0600152EXPORT_SYMBOL_GPL(usb_hcd_pci_probe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154
155/* may be called without controller electrically present */
156/* may be called with controller, bus, and devices active */
157
158/**
159 * usb_hcd_pci_remove - shutdown processing for PCI-based HCDs
160 * @dev: USB Host Controller being removed
161 * Context: !in_interrupt()
162 *
163 * Reverses the effect of usb_hcd_pci_probe(), first invoking
164 * the HCD's stop() method. It is always called from a thread
165 * context, normally "rmmod", "apmd", or something similar.
166 *
167 * Store this function in the HCD's struct pci_driver as remove().
168 */
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800169void usb_hcd_pci_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170{
171 struct usb_hcd *hcd;
172
173 hcd = pci_get_drvdata(dev);
174 if (!hcd)
175 return;
176
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800177 usb_remove_hcd(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 if (hcd->driver->flags & HCD_MEMORY) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800179 iounmap(hcd->regs);
180 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 } else {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800182 release_region(hcd->rsrc_start, hcd->rsrc_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 }
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800184 usb_put_hcd(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 pci_disable_device(dev);
186}
Greg Kroah-Hartman782e70c2008-01-25 11:12:21 -0600187EXPORT_SYMBOL_GPL(usb_hcd_pci_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189
190#ifdef CONFIG_PM
191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192/**
193 * usb_hcd_pci_suspend - power management suspend of a PCI-based HCD
194 * @dev: USB Host Controller being suspended
David Brownellc6053ec2005-04-18 17:39:22 -0700195 * @message: semantics in flux
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 *
197 * Store this function in the HCD's struct pci_driver as suspend().
198 */
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800199int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t message)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
201 struct usb_hcd *hcd;
202 int retval = 0;
203 int has_pci_pm;
204
205 hcd = pci_get_drvdata(dev);
206
David Brownell5f827ea2005-09-22 22:38:16 -0700207 /* Root hub suspend should have stopped all downstream traffic,
208 * and all bus master traffic. And done so for both the interface
209 * and the stub usb_device (which we check here). But maybe it
210 * didn't; writing sysfs power/state files ignores such rules...
211 *
212 * We must ignore the FREEZE vs SUSPEND distinction here, because
213 * otherwise the swsusp will save (and restore) garbage state.
214 */
Alan Sternf3fd77c2007-05-04 11:54:28 -0400215 if (!(hcd->state == HC_STATE_SUSPENDED ||
216 hcd->state == HC_STATE_HALT))
David Brownell5f827ea2005-09-22 22:38:16 -0700217 return -EBUSY;
218
219 if (hcd->driver->suspend) {
220 retval = hcd->driver->suspend(hcd, message);
Andrew Morton02669492006-03-23 01:38:34 -0800221 suspend_report_result(hcd->driver->suspend, retval);
222 if (retval)
David Brownell5f827ea2005-09-22 22:38:16 -0700223 goto done;
David Brownell5f827ea2005-09-22 22:38:16 -0700224 }
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +1100225 synchronize_irq(dev->irq);
David Brownell5f827ea2005-09-22 22:38:16 -0700226
David Brownellc6053ec2005-04-18 17:39:22 -0700227 /* FIXME until the generic PM interfaces change a lot more, this
228 * can't use PCI D1 and D2 states. For example, the confusion
229 * between messages and states will need to vanish, and messages
230 * will need to provide a target system state again.
231 *
232 * It'll be important to learn characteristics of the target state,
233 * especially on embedded hardware where the HCD will often be in
234 * charge of an external VBUS power supply and one or more clocks.
235 * Some target system states will leave them active; others won't.
236 * (With PCI, that's often handled by platform BIOS code.)
237 */
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 /* even when the PCI layer rejects some of the PCI calls
240 * below, HCs can try global suspend and reduce DMA traffic.
241 * PM-sensitive HCDs may already have done this.
242 */
243 has_pci_pm = pci_find_capability(dev, PCI_CAP_ID_PM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
David Brownell5f827ea2005-09-22 22:38:16 -0700245 /* Downstream ports from this root hub should already be quiesced, so
246 * there will be no DMA activity. Now we can shut down the upstream
247 * link (except maybe for PME# resume signaling) and enter some PCI
248 * low power state, if the hardware allows.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 */
David Brownell5f827ea2005-09-22 22:38:16 -0700250 if (hcd->state == HC_STATE_SUSPENDED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
David Brownellc6053ec2005-04-18 17:39:22 -0700252 /* no DMA or IRQs except when HC is active */
253 if (dev->current_state == PCI_D0) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800254 pci_save_state(dev);
255 pci_disable_device(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 }
257
Alan Stern269954e2007-11-19 15:57:45 -0500258 if (message.event == PM_EVENT_FREEZE ||
259 message.event == PM_EVENT_PRETHAW) {
260 dev_dbg(hcd->self.controller, "--> no state change\n");
261 goto done;
262 }
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 if (!has_pci_pm) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800265 dev_dbg(hcd->self.controller, "--> PCI D0/legacy\n");
David Brownell5f827ea2005-09-22 22:38:16 -0700266 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
268
David Brownellc6053ec2005-04-18 17:39:22 -0700269 /* NOTE: dev->current_state becomes nonzero only here, and
270 * only for devices that support PCI PM. Also, exiting
271 * PCI_D3 (but not PCI_D1 or PCI_D2) is allowed to reset
272 * some device state (e.g. as part of clock reinit).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 */
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800274 retval = pci_set_power_state(dev, PCI_D3hot);
Andrew Morton02669492006-03-23 01:38:34 -0800275 suspend_report_result(pci_set_power_state, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 if (retval == 0) {
David Brownellfb669cc2006-01-24 08:40:27 -0800277 int wake = device_can_wakeup(&hcd->self.root_hub->dev);
278
279 wake = wake && device_may_wakeup(hcd->self.controller);
280
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800281 dev_dbg(hcd->self.controller, "--> PCI D3%s\n",
David Brownellfb669cc2006-01-24 08:40:27 -0800282 wake ? "/wakeup" : "");
David Brownell5f827ea2005-09-22 22:38:16 -0700283
284 /* Ignore these return values. We rely on pci code to
285 * reject requests the hardware can't implement, rather
286 * than coding the same thing.
287 */
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800288 (void) pci_enable_wake(dev, PCI_D3hot, wake);
289 (void) pci_enable_wake(dev, PCI_D3cold, wake);
David Brownell5f827ea2005-09-22 22:38:16 -0700290 } else {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800291 dev_dbg(&dev->dev, "PCI D3 suspend fail, %d\n",
David Brownellc6053ec2005-04-18 17:39:22 -0700292 retval);
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800293 (void) usb_hcd_pci_resume(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 }
David Brownell5f827ea2005-09-22 22:38:16 -0700295
David Brownell18584992006-08-14 23:11:06 -0700296 } else if (hcd->state != HC_STATE_HALT) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800297 dev_dbg(hcd->self.controller, "hcd state %d; not suspended\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 hcd->state);
David Brownellc6053ec2005-04-18 17:39:22 -0700299 WARN_ON(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 retval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 }
302
David Brownell5f827ea2005-09-22 22:38:16 -0700303done:
David Brownell21b18612005-11-23 15:45:42 -0800304 if (retval == 0) {
David Brownell5f827ea2005-09-22 22:38:16 -0700305 dev->dev.power.power_state = PMSG_SUSPEND;
David Brownell21b18612005-11-23 15:45:42 -0800306
307#ifdef CONFIG_PPC_PMAC
308 /* Disable ASIC clocks for USB */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100309 if (machine_is(powermac)) {
David Brownell21b18612005-11-23 15:45:42 -0800310 struct device_node *of_node;
311
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800312 of_node = pci_device_to_OF_node(dev);
David Brownell21b18612005-11-23 15:45:42 -0800313 if (of_node)
314 pmac_call_feature(PMAC_FTR_USB_ENABLE,
315 of_node, 0, 0);
316 }
317#endif
318 }
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 return retval;
321}
Greg Kroah-Hartman782e70c2008-01-25 11:12:21 -0600322EXPORT_SYMBOL_GPL(usb_hcd_pci_suspend);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324/**
325 * usb_hcd_pci_resume - power management resume of a PCI-based HCD
326 * @dev: USB Host Controller being resumed
327 *
328 * Store this function in the HCD's struct pci_driver as resume().
329 */
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800330int usb_hcd_pci_resume(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
332 struct usb_hcd *hcd;
333 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335 hcd = pci_get_drvdata(dev);
336 if (hcd->state != HC_STATE_SUSPENDED) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800337 dev_dbg(hcd->self.controller,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 "can't resume, not suspended!\n");
339 return 0;
340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
David Brownell21b18612005-11-23 15:45:42 -0800342#ifdef CONFIG_PPC_PMAC
343 /* Reenable ASIC clocks for USB */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100344 if (machine_is(powermac)) {
David Brownell21b18612005-11-23 15:45:42 -0800345 struct device_node *of_node;
346
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800347 of_node = pci_device_to_OF_node(dev);
David Brownell21b18612005-11-23 15:45:42 -0800348 if (of_node)
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800349 pmac_call_feature(PMAC_FTR_USB_ENABLE,
David Brownell21b18612005-11-23 15:45:42 -0800350 of_node, 0, 1);
351 }
352#endif
353
David Brownellc6053ec2005-04-18 17:39:22 -0700354 /* NOTE: chip docs cover clean "real suspend" cases (what Linux
355 * calls "standby", "suspend to RAM", and so on). There are also
356 * dirty cases when swsusp fakes a suspend in "shutdown" mode.
357 */
358 if (dev->current_state != PCI_D0) {
359#ifdef DEBUG
360 int pci_pm;
361 u16 pmcr;
362
363 pci_pm = pci_find_capability(dev, PCI_CAP_ID_PM);
364 pci_read_config_word(dev, pci_pm + PCI_PM_CTRL, &pmcr);
365 pmcr &= PCI_PM_CTRL_STATE_MASK;
366 if (pmcr) {
367 /* Clean case: power to USB and to HC registers was
368 * maintained; remote wakeup is easy.
369 */
370 dev_dbg(hcd->self.controller, "resume from PCI D%d\n",
371 pmcr);
372 } else {
373 /* Clean: HC lost Vcc power, D0 uninitialized
374 * + Vaux may have preserved port and transceiver
375 * state ... for remote wakeup from D3cold
376 * + or not; HCD must reinit + re-enumerate
377 *
378 * Dirty: D0 semi-initialized cases with swsusp
379 * + after BIOS init
380 * + after Linux init (HCD statically linked)
381 */
382 dev_dbg(hcd->self.controller,
383 "PCI D0, from previous PCI D%d\n",
384 dev->current_state);
385 }
386#endif
David Brownell5f827ea2005-09-22 22:38:16 -0700387 /* yes, ignore these results too... */
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800388 (void) pci_enable_wake(dev, dev->current_state, 0);
389 (void) pci_enable_wake(dev, PCI_D3cold, 0);
David Brownellc6053ec2005-04-18 17:39:22 -0700390 } else {
391 /* Same basic cases: clean (powered/not), dirty */
392 dev_dbg(hcd->self.controller, "PCI legacy resume\n");
393 }
394
395 /* NOTE: the PCI API itself is asymmetric here. We don't need to
396 * pci_set_power_state(PCI_D0) since that's part of re-enabling;
397 * but that won't re-enable bus mastering. Yet pci_disable_device()
398 * explicitly disables bus mastering...
399 */
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800400 retval = pci_enable_device(dev);
David Brownellc6053ec2005-04-18 17:39:22 -0700401 if (retval < 0) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800402 dev_err(hcd->self.controller,
David Brownellc6053ec2005-04-18 17:39:22 -0700403 "can't re-enable after resume, %d!\n", retval);
404 return retval;
405 }
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800406 pci_set_master(dev);
407 pci_restore_state(dev);
David Brownellc6053ec2005-04-18 17:39:22 -0700408
409 dev->dev.power.power_state = PMSG_ON;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +1100411 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
David Brownell5f827ea2005-09-22 22:38:16 -0700413 if (hcd->driver->resume) {
414 retval = hcd->driver->resume(hcd);
415 if (retval) {
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800416 dev_err(hcd->self.controller,
David Brownell5f827ea2005-09-22 22:38:16 -0700417 "PCI post-resume error %d!\n", retval);
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800418 usb_hc_died(hcd);
David Brownell5f827ea2005-09-22 22:38:16 -0700419 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 }
421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 return retval;
423}
Greg Kroah-Hartman782e70c2008-01-25 11:12:21 -0600424EXPORT_SYMBOL_GPL(usb_hcd_pci_resume);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426#endif /* CONFIG_PM */
427
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700428/**
429 * usb_hcd_pci_shutdown - shutdown host controller
430 * @dev: USB Host Controller being shutdown
431 */
Greg Kroah-Hartman34bbe4c2008-01-30 15:21:33 -0800432void usb_hcd_pci_shutdown(struct pci_dev *dev)
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700433{
434 struct usb_hcd *hcd;
435
436 hcd = pci_get_drvdata(dev);
437 if (!hcd)
438 return;
439
440 if (hcd->driver->shutdown)
441 hcd->driver->shutdown(hcd);
442}
Greg Kroah-Hartman782e70c2008-01-25 11:12:21 -0600443EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444