Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright David Brownell 2000-2002 |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/pci.h> |
David Brownell | 21b1861 | 2005-11-23 15:45:42 -0800 | [diff] [blame] | 22 | #include <linux/usb.h> |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/io.h> |
| 25 | #include <asm/irq.h> |
David Brownell | 21b1861 | 2005-11-23 15:45:42 -0800 | [diff] [blame] | 26 | |
| 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 Brownell | 5f827ea | 2005-09-22 22:38:16 -0700 | [diff] [blame] | 33 | |
| 34 | #include "usb.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "hcd.h" |
| 36 | |
| 37 | |
David Brownell | c6053ec | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 38 | /* PCI-based HCs are common, but plenty of non-PCI HCs are used too */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 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-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 58 | int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
| 60 | struct hc_driver *driver; |
| 61 | struct usb_hcd *hcd; |
| 62 | int retval; |
| 63 | |
| 64 | if (usb_disabled()) |
| 65 | return -ENODEV; |
| 66 | |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 67 | if (!id) |
| 68 | return -EINVAL; |
| 69 | driver = (struct hc_driver *)id->driver_data; |
| 70 | if (!driver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | return -EINVAL; |
| 72 | |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 73 | if (pci_enable_device(dev) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | return -ENODEV; |
David Brownell | c6053ec | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 75 | dev->current_state = PCI_D0; |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 76 | |
| 77 | if (!dev->irq) { |
| 78 | dev_err(&dev->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", |
| 80 | pci_name(dev)); |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 81 | retval = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | goto err1; |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 83 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 85 | hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | if (!hcd) { |
| 87 | retval = -ENOMEM; |
| 88 | goto err1; |
| 89 | } |
| 90 | |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 91 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | driver->description)) { |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 97 | dev_dbg(&dev->dev, "controller already in use\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | retval = -EBUSY; |
| 99 | goto err2; |
| 100 | } |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 101 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | if (hcd->regs == NULL) { |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 103 | dev_dbg(&dev->dev, "error mapping memory\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | retval = -EFAULT; |
| 105 | goto err3; |
| 106 | } |
| 107 | |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 108 | } else { |
| 109 | /* UHCI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | int region; |
| 111 | |
| 112 | for (region = 0; region < PCI_ROM_RESOURCE; region++) { |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 113 | if (!(pci_resource_flags(dev, region) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | IORESOURCE_IO)) |
| 115 | continue; |
| 116 | |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 117 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | driver->description)) |
| 121 | break; |
| 122 | } |
| 123 | if (region == PCI_ROM_RESOURCE) { |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 124 | dev_dbg(&dev->dev, "no i/o regions available\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | retval = -EBUSY; |
| 126 | goto err1; |
| 127 | } |
| 128 | } |
| 129 | |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 130 | pci_set_master(dev); |
Alan Stern | 6fd9086 | 2008-12-17 17:20:38 -0500 | [diff] [blame] | 131 | device_set_wakeup_enable(&dev->dev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Alan Stern | 442258e | 2007-12-06 14:47:08 -0500 | [diff] [blame] | 133 | retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | if (retval != 0) |
| 135 | goto err4; |
| 136 | return retval; |
| 137 | |
| 138 | err4: |
| 139 | if (driver->flags & HCD_MEMORY) { |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 140 | iounmap(hcd->regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | err3: |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 142 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } else |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 144 | release_region(hcd->rsrc_start, hcd->rsrc_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | err2: |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 146 | usb_put_hcd(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | err1: |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 148 | pci_disable_device(dev); |
| 149 | dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | return retval; |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 151 | } |
Greg Kroah-Hartman | 782e70c | 2008-01-25 11:12:21 -0600 | [diff] [blame] | 152 | EXPORT_SYMBOL_GPL(usb_hcd_pci_probe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 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-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 169 | void usb_hcd_pci_remove(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
| 171 | struct usb_hcd *hcd; |
| 172 | |
| 173 | hcd = pci_get_drvdata(dev); |
| 174 | if (!hcd) |
| 175 | return; |
| 176 | |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 177 | usb_remove_hcd(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | if (hcd->driver->flags & HCD_MEMORY) { |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 179 | iounmap(hcd->regs); |
| 180 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } else { |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 182 | release_region(hcd->rsrc_start, hcd->rsrc_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 184 | usb_put_hcd(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | pci_disable_device(dev); |
| 186 | } |
Greg Kroah-Hartman | 782e70c | 2008-01-25 11:12:21 -0600 | [diff] [blame] | 187 | EXPORT_SYMBOL_GPL(usb_hcd_pci_remove); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | |
| 190 | #ifdef CONFIG_PM |
| 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | /** |
| 193 | * usb_hcd_pci_suspend - power management suspend of a PCI-based HCD |
| 194 | * @dev: USB Host Controller being suspended |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 195 | * @message: Power Management message describing this state transition |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | * |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 197 | * Store this function in the HCD's struct pci_driver as .suspend. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | */ |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 199 | int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t message) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | { |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 201 | struct usb_hcd *hcd = pci_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | int retval = 0; |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 203 | int wake, w; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
David Brownell | 5f827ea | 2005-09-22 22:38:16 -0700 | [diff] [blame] | 205 | /* Root hub suspend should have stopped all downstream traffic, |
| 206 | * and all bus master traffic. And done so for both the interface |
| 207 | * and the stub usb_device (which we check here). But maybe it |
| 208 | * didn't; writing sysfs power/state files ignores such rules... |
| 209 | * |
| 210 | * We must ignore the FREEZE vs SUSPEND distinction here, because |
| 211 | * otherwise the swsusp will save (and restore) garbage state. |
| 212 | */ |
Alan Stern | f3fd77c | 2007-05-04 11:54:28 -0400 | [diff] [blame] | 213 | if (!(hcd->state == HC_STATE_SUSPENDED || |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 214 | hcd->state == HC_STATE_HALT)) { |
| 215 | dev_warn(&dev->dev, "Root hub is not suspended\n"); |
| 216 | retval = -EBUSY; |
| 217 | goto done; |
| 218 | } |
| 219 | |
| 220 | /* We might already be suspended (runtime PM -- not yet written) */ |
| 221 | if (dev->current_state != PCI_D0) |
| 222 | goto done; |
David Brownell | 5f827ea | 2005-09-22 22:38:16 -0700 | [diff] [blame] | 223 | |
Alan Stern | 7be7d74 | 2008-04-03 18:03:06 -0400 | [diff] [blame] | 224 | if (hcd->driver->pci_suspend) { |
| 225 | retval = hcd->driver->pci_suspend(hcd, message); |
| 226 | suspend_report_result(hcd->driver->pci_suspend, retval); |
Andrew Morton | 0266949 | 2006-03-23 01:38:34 -0800 | [diff] [blame] | 227 | if (retval) |
David Brownell | 5f827ea | 2005-09-22 22:38:16 -0700 | [diff] [blame] | 228 | goto done; |
David Brownell | 5f827ea | 2005-09-22 22:38:16 -0700 | [diff] [blame] | 229 | } |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 230 | |
Benjamin Herrenschmidt | 8de9840 | 2005-11-25 09:59:46 +1100 | [diff] [blame] | 231 | synchronize_irq(dev->irq); |
David Brownell | 5f827ea | 2005-09-22 22:38:16 -0700 | [diff] [blame] | 232 | |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 233 | /* Don't fail on error to enable wakeup. We rely on pci code |
| 234 | * to reject requests the hardware can't implement, rather |
| 235 | * than coding the same thing. |
David Brownell | c6053ec | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 236 | */ |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 237 | wake = (hcd->state == HC_STATE_SUSPENDED && |
| 238 | device_may_wakeup(&dev->dev)); |
| 239 | w = pci_wake_from_d3(dev, wake); |
| 240 | if (w < 0) |
| 241 | wake = w; |
| 242 | dev_dbg(&dev->dev, "wakeup: %d\n", wake); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
David Brownell | 5f827ea | 2005-09-22 22:38:16 -0700 | [diff] [blame] | 244 | /* Downstream ports from this root hub should already be quiesced, so |
| 245 | * there will be no DMA activity. Now we can shut down the upstream |
| 246 | * link (except maybe for PME# resume signaling) and enter some PCI |
| 247 | * low power state, if the hardware allows. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | */ |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 249 | pci_disable_device(dev); |
| 250 | done: |
| 251 | return retval; |
| 252 | } |
| 253 | EXPORT_SYMBOL_GPL(usb_hcd_pci_suspend); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 255 | /** |
| 256 | * usb_hcd_pci_suspend_late - suspend a PCI-based HCD after IRQs are disabled |
| 257 | * @dev: USB Host Controller being suspended |
| 258 | * @message: Power Management message describing this state transition |
| 259 | * |
| 260 | * Store this function in the HCD's struct pci_driver as .suspend_late. |
| 261 | */ |
| 262 | int usb_hcd_pci_suspend_late(struct pci_dev *dev, pm_message_t message) |
| 263 | { |
| 264 | int retval = 0; |
| 265 | int has_pci_pm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 267 | /* We might already be suspended (runtime PM -- not yet written) */ |
| 268 | if (dev->current_state != PCI_D0) |
| 269 | goto done; |
Alan Stern | 269954e | 2007-11-19 15:57:45 -0500 | [diff] [blame] | 270 | |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 271 | pci_save_state(dev); |
| 272 | |
| 273 | /* Don't change state if we don't need to */ |
| 274 | if (message.event == PM_EVENT_FREEZE || |
| 275 | message.event == PM_EVENT_PRETHAW) { |
| 276 | dev_dbg(&dev->dev, "--> no state change\n"); |
| 277 | goto done; |
| 278 | } |
| 279 | |
| 280 | has_pci_pm = pci_find_capability(dev, PCI_CAP_ID_PM); |
| 281 | if (!has_pci_pm) { |
| 282 | dev_dbg(&dev->dev, "--> PCI D0 legacy\n"); |
| 283 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
David Brownell | c6053ec | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 285 | /* NOTE: dev->current_state becomes nonzero only here, and |
| 286 | * only for devices that support PCI PM. Also, exiting |
| 287 | * PCI_D3 (but not PCI_D1 or PCI_D2) is allowed to reset |
| 288 | * some device state (e.g. as part of clock reinit). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | */ |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 290 | retval = pci_set_power_state(dev, PCI_D3hot); |
Andrew Morton | 0266949 | 2006-03-23 01:38:34 -0800 | [diff] [blame] | 291 | suspend_report_result(pci_set_power_state, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | if (retval == 0) { |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 293 | dev_dbg(&dev->dev, "--> PCI D3\n"); |
David Brownell | 5f827ea | 2005-09-22 22:38:16 -0700 | [diff] [blame] | 294 | } else { |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 295 | dev_dbg(&dev->dev, "PCI D3 suspend fail, %d\n", |
David Brownell | c6053ec | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 296 | retval); |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 297 | pci_restore_state(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
David Brownell | 21b1861 | 2005-11-23 15:45:42 -0800 | [diff] [blame] | 301 | #ifdef CONFIG_PPC_PMAC |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 302 | if (retval == 0) { |
David Brownell | 21b1861 | 2005-11-23 15:45:42 -0800 | [diff] [blame] | 303 | /* Disable ASIC clocks for USB */ |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 304 | if (machine_is(powermac)) { |
David Brownell | 21b1861 | 2005-11-23 15:45:42 -0800 | [diff] [blame] | 305 | struct device_node *of_node; |
| 306 | |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 307 | of_node = pci_device_to_OF_node(dev); |
David Brownell | 21b1861 | 2005-11-23 15:45:42 -0800 | [diff] [blame] | 308 | if (of_node) |
| 309 | pmac_call_feature(PMAC_FTR_USB_ENABLE, |
| 310 | of_node, 0, 0); |
| 311 | } |
David Brownell | 21b1861 | 2005-11-23 15:45:42 -0800 | [diff] [blame] | 312 | } |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 313 | #endif |
David Brownell | 21b1861 | 2005-11-23 15:45:42 -0800 | [diff] [blame] | 314 | |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 315 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | return retval; |
| 317 | } |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 318 | EXPORT_SYMBOL_GPL(usb_hcd_pci_suspend_late); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | /** |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 321 | * usb_hcd_pci_resume_early - resume a PCI-based HCD before IRQs are enabled |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | * @dev: USB Host Controller being resumed |
| 323 | * |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 324 | * Store this function in the HCD's struct pci_driver as .resume_early. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | */ |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 326 | int usb_hcd_pci_resume_early(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | { |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 328 | int retval = 0; |
| 329 | pci_power_t state = dev->current_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
David Brownell | 21b1861 | 2005-11-23 15:45:42 -0800 | [diff] [blame] | 331 | #ifdef CONFIG_PPC_PMAC |
| 332 | /* Reenable ASIC clocks for USB */ |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 333 | if (machine_is(powermac)) { |
David Brownell | 21b1861 | 2005-11-23 15:45:42 -0800 | [diff] [blame] | 334 | struct device_node *of_node; |
| 335 | |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 336 | of_node = pci_device_to_OF_node(dev); |
David Brownell | 21b1861 | 2005-11-23 15:45:42 -0800 | [diff] [blame] | 337 | if (of_node) |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 338 | pmac_call_feature(PMAC_FTR_USB_ENABLE, |
David Brownell | 21b1861 | 2005-11-23 15:45:42 -0800 | [diff] [blame] | 339 | of_node, 0, 1); |
| 340 | } |
| 341 | #endif |
| 342 | |
David Brownell | c6053ec | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 343 | /* NOTE: chip docs cover clean "real suspend" cases (what Linux |
| 344 | * calls "standby", "suspend to RAM", and so on). There are also |
| 345 | * dirty cases when swsusp fakes a suspend in "shutdown" mode. |
| 346 | */ |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 347 | if (state != PCI_D0) { |
David Brownell | c6053ec | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 348 | #ifdef DEBUG |
| 349 | int pci_pm; |
| 350 | u16 pmcr; |
| 351 | |
| 352 | pci_pm = pci_find_capability(dev, PCI_CAP_ID_PM); |
| 353 | pci_read_config_word(dev, pci_pm + PCI_PM_CTRL, &pmcr); |
| 354 | pmcr &= PCI_PM_CTRL_STATE_MASK; |
| 355 | if (pmcr) { |
| 356 | /* Clean case: power to USB and to HC registers was |
| 357 | * maintained; remote wakeup is easy. |
| 358 | */ |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 359 | dev_dbg(&dev->dev, "resume from PCI D%d\n", pmcr); |
David Brownell | c6053ec | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 360 | } else { |
| 361 | /* Clean: HC lost Vcc power, D0 uninitialized |
| 362 | * + Vaux may have preserved port and transceiver |
| 363 | * state ... for remote wakeup from D3cold |
| 364 | * + or not; HCD must reinit + re-enumerate |
| 365 | * |
| 366 | * Dirty: D0 semi-initialized cases with swsusp |
| 367 | * + after BIOS init |
| 368 | * + after Linux init (HCD statically linked) |
| 369 | */ |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 370 | dev_dbg(&dev->dev, "resume from previous PCI D%d\n", |
| 371 | state); |
David Brownell | c6053ec | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 372 | } |
| 373 | #endif |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 374 | |
| 375 | retval = pci_set_power_state(dev, PCI_D0); |
David Brownell | c6053ec | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 376 | } else { |
| 377 | /* Same basic cases: clean (powered/not), dirty */ |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 378 | dev_dbg(&dev->dev, "PCI legacy resume\n"); |
David Brownell | c6053ec | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 381 | if (retval < 0) |
| 382 | dev_err(&dev->dev, "can't resume: %d\n", retval); |
| 383 | else |
| 384 | pci_restore_state(dev); |
| 385 | |
| 386 | return retval; |
| 387 | } |
| 388 | EXPORT_SYMBOL_GPL(usb_hcd_pci_resume_early); |
| 389 | |
| 390 | /** |
| 391 | * usb_hcd_pci_resume - power management resume of a PCI-based HCD |
| 392 | * @dev: USB Host Controller being resumed |
| 393 | * |
| 394 | * Store this function in the HCD's struct pci_driver as .resume. |
| 395 | */ |
| 396 | int usb_hcd_pci_resume(struct pci_dev *dev) |
| 397 | { |
| 398 | struct usb_hcd *hcd; |
| 399 | int retval; |
| 400 | |
| 401 | hcd = pci_get_drvdata(dev); |
| 402 | if (hcd->state != HC_STATE_SUSPENDED) { |
| 403 | dev_dbg(hcd->self.controller, |
| 404 | "can't resume, not suspended!\n"); |
| 405 | return 0; |
| 406 | } |
| 407 | |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 408 | retval = pci_enable_device(dev); |
David Brownell | c6053ec | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 409 | if (retval < 0) { |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 410 | dev_err(&dev->dev, "can't re-enable after resume, %d!\n", |
| 411 | retval); |
David Brownell | c6053ec | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 412 | return retval; |
| 413 | } |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 414 | |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 415 | pci_set_master(dev); |
Alan Stern | a0d4922 | 2008-12-17 15:06:03 -0500 | [diff] [blame] | 416 | |
| 417 | /* yes, ignore this result too... */ |
| 418 | (void) pci_wake_from_d3(dev, 0); |
David Brownell | c6053ec | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 419 | |
Benjamin Herrenschmidt | 8de9840 | 2005-11-25 09:59:46 +1100 | [diff] [blame] | 420 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
Alan Stern | 7be7d74 | 2008-04-03 18:03:06 -0400 | [diff] [blame] | 422 | if (hcd->driver->pci_resume) { |
| 423 | retval = hcd->driver->pci_resume(hcd); |
David Brownell | 5f827ea | 2005-09-22 22:38:16 -0700 | [diff] [blame] | 424 | if (retval) { |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 425 | dev_err(hcd->self.controller, |
David Brownell | 5f827ea | 2005-09-22 22:38:16 -0700 | [diff] [blame] | 426 | "PCI post-resume error %d!\n", retval); |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 427 | usb_hc_died(hcd); |
David Brownell | 5f827ea | 2005-09-22 22:38:16 -0700 | [diff] [blame] | 428 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | return retval; |
| 431 | } |
Greg Kroah-Hartman | 782e70c | 2008-01-25 11:12:21 -0600 | [diff] [blame] | 432 | EXPORT_SYMBOL_GPL(usb_hcd_pci_resume); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
| 434 | #endif /* CONFIG_PM */ |
| 435 | |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 436 | /** |
| 437 | * usb_hcd_pci_shutdown - shutdown host controller |
| 438 | * @dev: USB Host Controller being shutdown |
| 439 | */ |
Greg Kroah-Hartman | 34bbe4c | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 440 | void usb_hcd_pci_shutdown(struct pci_dev *dev) |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 441 | { |
| 442 | struct usb_hcd *hcd; |
| 443 | |
| 444 | hcd = pci_get_drvdata(dev); |
| 445 | if (!hcd) |
| 446 | return; |
| 447 | |
| 448 | if (hcd->driver->shutdown) |
| 449 | hcd->driver->shutdown(hcd); |
| 450 | } |
Greg Kroah-Hartman | 782e70c | 2008-01-25 11:12:21 -0600 | [diff] [blame] | 451 | EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |