hcd-pci.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. * (C) Copyright David Brownell 2000-2002
  3. *
  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. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/pci.h>
  21. #include <linux/usb.h>
  22. #include <linux/usb/hcd.h>
  23. #include <asm/io.h>
  24. #include <asm/irq.h>
  25. #ifdef CONFIG_PPC_PMAC
  26. #include <asm/machdep.h>
  27. #include <asm/pmac_feature.h>
  28. #include <asm/prom.h>
  29. #endif
  30. #include "usb.h"
  31. /* PCI-based HCs are common, but plenty of non-PCI HCs are used too */
  32. /*
  33. * Coordinate handoffs between EHCI and companion controllers
  34. * during EHCI probing and system resume.
  35. */
  36. static DECLARE_RWSEM(companions_rwsem);
  37. #define CL_UHCI PCI_CLASS_SERIAL_USB_UHCI
  38. #define CL_OHCI PCI_CLASS_SERIAL_USB_OHCI
  39. #define CL_EHCI PCI_CLASS_SERIAL_USB_EHCI
  40. static inline int is_ohci_or_uhci(struct pci_dev *pdev)
  41. {
  42. return pdev->class == CL_OHCI || pdev->class == CL_UHCI;
  43. }
  44. typedef void (*companion_fn)(struct pci_dev *pdev, struct usb_hcd *hcd,
  45. struct pci_dev *companion, struct usb_hcd *companion_hcd);
  46. /* Iterate over PCI devices in the same slot as pdev and call fn for each */
  47. static void for_each_companion(struct pci_dev *pdev, struct usb_hcd *hcd,
  48. companion_fn fn)
  49. {
  50. struct pci_dev *companion;
  51. struct usb_hcd *companion_hcd;
  52. unsigned int slot = PCI_SLOT(pdev->devfn);
  53. /*
  54. * Iterate through other PCI functions in the same slot.
  55. * If the function's drvdata isn't set then it isn't bound to
  56. * a USB host controller driver, so skip it.
  57. */
  58. companion = NULL;
  59. for_each_pci_dev(companion) {
  60. if (companion->bus != pdev->bus ||
  61. PCI_SLOT(companion->devfn) != slot)
  62. continue;
  63. /*
  64. * Companion device should be either UHCI,OHCI or EHCI host
  65. * controller, otherwise skip.
  66. */
  67. if (companion->class != CL_UHCI && companion->class != CL_OHCI &&
  68. companion->class != CL_EHCI)
  69. continue;
  70. companion_hcd = pci_get_drvdata(companion);
  71. if (!companion_hcd || !companion_hcd->self.root_hub)
  72. continue;
  73. fn(pdev, hcd, companion, companion_hcd);
  74. }
  75. }
  76. /*
  77. * We're about to add an EHCI controller, which will unceremoniously grab
  78. * all the port connections away from its companions. To prevent annoying
  79. * error messages, lock the companion's root hub and gracefully unconfigure
  80. * it beforehand. Leave it locked until the EHCI controller is all set.
  81. */
  82. static void ehci_pre_add(struct pci_dev *pdev, struct usb_hcd *hcd,
  83. struct pci_dev *companion, struct usb_hcd *companion_hcd)
  84. {
  85. struct usb_device *udev;
  86. if (is_ohci_or_uhci(companion)) {
  87. udev = companion_hcd->self.root_hub;
  88. usb_lock_device(udev);
  89. usb_set_configuration(udev, 0);
  90. }
  91. }
  92. /*
  93. * Adding the EHCI controller has either succeeded or failed. Set the
  94. * companion pointer accordingly, and in either case, reconfigure and
  95. * unlock the root hub.
  96. */
  97. static void ehci_post_add(struct pci_dev *pdev, struct usb_hcd *hcd,
  98. struct pci_dev *companion, struct usb_hcd *companion_hcd)
  99. {
  100. struct usb_device *udev;
  101. if (is_ohci_or_uhci(companion)) {
  102. if (dev_get_drvdata(&pdev->dev)) { /* Succeeded */
  103. dev_dbg(&pdev->dev, "HS companion for %s\n",
  104. dev_name(&companion->dev));
  105. companion_hcd->self.hs_companion = &hcd->self;
  106. }
  107. udev = companion_hcd->self.root_hub;
  108. usb_set_configuration(udev, 1);
  109. usb_unlock_device(udev);
  110. }
  111. }
  112. /*
  113. * We just added a non-EHCI controller. Find the EHCI controller to
  114. * which it is a companion, and store a pointer to the bus structure.
  115. */
  116. static void non_ehci_add(struct pci_dev *pdev, struct usb_hcd *hcd,
  117. struct pci_dev *companion, struct usb_hcd *companion_hcd)
  118. {
  119. if (is_ohci_or_uhci(pdev) && companion->class == CL_EHCI) {
  120. dev_dbg(&pdev->dev, "FS/LS companion for %s\n",
  121. dev_name(&companion->dev));
  122. hcd->self.hs_companion = &companion_hcd->self;
  123. }
  124. }
  125. /* We are removing an EHCI controller. Clear the companions' pointers. */
  126. static void ehci_remove(struct pci_dev *pdev, struct usb_hcd *hcd,
  127. struct pci_dev *companion, struct usb_hcd *companion_hcd)
  128. {
  129. if (is_ohci_or_uhci(companion))
  130. companion_hcd->self.hs_companion = NULL;
  131. }
  132. #ifdef CONFIG_PM
  133. /* An EHCI controller must wait for its companions before resuming. */
  134. static void ehci_wait_for_companions(struct pci_dev *pdev, struct usb_hcd *hcd,
  135. struct pci_dev *companion, struct usb_hcd *companion_hcd)
  136. {
  137. if (is_ohci_or_uhci(companion))
  138. device_pm_wait_for_dev(&pdev->dev, &companion->dev);
  139. }
  140. #endif /* CONFIG_PM */
  141. /*-------------------------------------------------------------------------*/
  142. /* configure so an HC device and id are always provided */
  143. /* always called with process context; sleeping is OK */
  144. /**
  145. * usb_hcd_pci_probe - initialize PCI-based HCDs
  146. * @dev: USB Host Controller being probed
  147. * @id: pci hotplug id connecting controller to HCD framework
  148. * Context: !in_interrupt()
  149. *
  150. * Allocates basic PCI resources for this USB host controller, and
  151. * then invokes the start() method for the HCD associated with it
  152. * through the hotplug entry's driver_data.
  153. *
  154. * Store this function in the HCD's struct pci_driver as probe().
  155. *
  156. * Return: 0 if successful.
  157. */
  158. int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  159. {
  160. struct hc_driver *driver;
  161. struct usb_hcd *hcd;
  162. int retval;
  163. int hcd_irq = 0;
  164. if (usb_disabled())
  165. return -ENODEV;
  166. if (!id)
  167. return -EINVAL;
  168. driver = (struct hc_driver *)id->driver_data;
  169. if (!driver)
  170. return -EINVAL;
  171. if (pci_enable_device(dev) < 0)
  172. return -ENODEV;
  173. /*
  174. * The xHCI driver has its own irq management
  175. * make sure irq setup is not touched for xhci in generic hcd code
  176. */
  177. if ((driver->flags & HCD_MASK) < HCD_USB3) {
  178. if (!dev->irq) {
  179. dev_err(&dev->dev,
  180. "Found HC with no IRQ. Check BIOS/PCI %s setup!\n",
  181. pci_name(dev));
  182. retval = -ENODEV;
  183. goto disable_pci;
  184. }
  185. hcd_irq = dev->irq;
  186. }
  187. hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev));
  188. if (!hcd) {
  189. retval = -ENOMEM;
  190. goto disable_pci;
  191. }
  192. hcd->amd_resume_bug = (usb_hcd_amd_remote_wakeup_quirk(dev) &&
  193. driver->flags & (HCD_USB11 | HCD_USB3)) ? 1 : 0;
  194. if (driver->flags & HCD_MEMORY) {
  195. /* EHCI, OHCI */
  196. hcd->rsrc_start = pci_resource_start(dev, 0);
  197. hcd->rsrc_len = pci_resource_len(dev, 0);
  198. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  199. driver->description)) {
  200. dev_dbg(&dev->dev, "controller already in use\n");
  201. retval = -EBUSY;
  202. goto put_hcd;
  203. }
  204. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  205. if (hcd->regs == NULL) {
  206. dev_dbg(&dev->dev, "error mapping memory\n");
  207. retval = -EFAULT;
  208. goto release_mem_region;
  209. }
  210. } else {
  211. /* UHCI */
  212. int region;
  213. for (region = 0; region < PCI_ROM_RESOURCE; region++) {
  214. if (!(pci_resource_flags(dev, region) &
  215. IORESOURCE_IO))
  216. continue;
  217. hcd->rsrc_start = pci_resource_start(dev, region);
  218. hcd->rsrc_len = pci_resource_len(dev, region);
  219. if (request_region(hcd->rsrc_start, hcd->rsrc_len,
  220. driver->description))
  221. break;
  222. }
  223. if (region == PCI_ROM_RESOURCE) {
  224. dev_dbg(&dev->dev, "no i/o regions available\n");
  225. retval = -EBUSY;
  226. goto put_hcd;
  227. }
  228. }
  229. pci_set_master(dev);
  230. /* Note: dev_set_drvdata must be called while holding the rwsem */
  231. if (dev->class == CL_EHCI) {
  232. down_write(&companions_rwsem);
  233. dev_set_drvdata(&dev->dev, hcd);
  234. for_each_companion(dev, hcd, ehci_pre_add);
  235. retval = usb_add_hcd(hcd, hcd_irq, IRQF_SHARED);
  236. if (retval != 0)
  237. dev_set_drvdata(&dev->dev, NULL);
  238. for_each_companion(dev, hcd, ehci_post_add);
  239. up_write(&companions_rwsem);
  240. } else {
  241. down_read(&companions_rwsem);
  242. dev_set_drvdata(&dev->dev, hcd);
  243. retval = usb_add_hcd(hcd, hcd_irq, IRQF_SHARED);
  244. if (retval != 0)
  245. dev_set_drvdata(&dev->dev, NULL);
  246. else
  247. for_each_companion(dev, hcd, non_ehci_add);
  248. up_read(&companions_rwsem);
  249. }
  250. if (retval != 0)
  251. goto unmap_registers;
  252. device_wakeup_enable(hcd->self.controller);
  253. if (pci_dev_run_wake(dev))
  254. pm_runtime_put_noidle(&dev->dev);
  255. return retval;
  256. unmap_registers:
  257. if (driver->flags & HCD_MEMORY) {
  258. iounmap(hcd->regs);
  259. release_mem_region:
  260. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  261. } else
  262. release_region(hcd->rsrc_start, hcd->rsrc_len);
  263. put_hcd:
  264. usb_put_hcd(hcd);
  265. disable_pci:
  266. pci_disable_device(dev);
  267. dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval);
  268. return retval;
  269. }
  270. EXPORT_SYMBOL_GPL(usb_hcd_pci_probe);
  271. /* may be called without controller electrically present */
  272. /* may be called with controller, bus, and devices active */
  273. /**
  274. * usb_hcd_pci_remove - shutdown processing for PCI-based HCDs
  275. * @dev: USB Host Controller being removed
  276. * Context: !in_interrupt()
  277. *
  278. * Reverses the effect of usb_hcd_pci_probe(), first invoking
  279. * the HCD's stop() method. It is always called from a thread
  280. * context, normally "rmmod", "apmd", or something similar.
  281. *
  282. * Store this function in the HCD's struct pci_driver as remove().
  283. */
  284. void usb_hcd_pci_remove(struct pci_dev *dev)
  285. {
  286. struct usb_hcd *hcd;
  287. hcd = pci_get_drvdata(dev);
  288. if (!hcd)
  289. return;
  290. if (pci_dev_run_wake(dev))
  291. pm_runtime_get_noresume(&dev->dev);
  292. /* Fake an interrupt request in order to give the driver a chance
  293. * to test whether the controller hardware has been removed (e.g.,
  294. * cardbus physical eject).
  295. */
  296. local_irq_disable();
  297. usb_hcd_irq(0, hcd);
  298. local_irq_enable();
  299. /* Note: dev_set_drvdata must be called while holding the rwsem */
  300. if (dev->class == CL_EHCI) {
  301. down_write(&companions_rwsem);
  302. for_each_companion(dev, hcd, ehci_remove);
  303. usb_remove_hcd(hcd);
  304. dev_set_drvdata(&dev->dev, NULL);
  305. up_write(&companions_rwsem);
  306. } else {
  307. /* Not EHCI; just clear the companion pointer */
  308. down_read(&companions_rwsem);
  309. hcd->self.hs_companion = NULL;
  310. usb_remove_hcd(hcd);
  311. dev_set_drvdata(&dev->dev, NULL);
  312. up_read(&companions_rwsem);
  313. }
  314. if (hcd->driver->flags & HCD_MEMORY) {
  315. iounmap(hcd->regs);
  316. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  317. } else {
  318. release_region(hcd->rsrc_start, hcd->rsrc_len);
  319. }
  320. usb_put_hcd(hcd);
  321. pci_disable_device(dev);
  322. }
  323. EXPORT_SYMBOL_GPL(usb_hcd_pci_remove);
  324. /**
  325. * usb_hcd_pci_shutdown - shutdown host controller
  326. * @dev: USB Host Controller being shutdown
  327. */
  328. void usb_hcd_pci_shutdown(struct pci_dev *dev)
  329. {
  330. struct usb_hcd *hcd;
  331. hcd = pci_get_drvdata(dev);
  332. if (!hcd)
  333. return;
  334. if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) &&
  335. hcd->driver->shutdown) {
  336. hcd->driver->shutdown(hcd);
  337. if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0)
  338. free_irq(hcd->irq, hcd);
  339. pci_disable_device(dev);
  340. }
  341. }
  342. EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown);
  343. #ifdef CONFIG_PM
  344. #ifdef CONFIG_PPC_PMAC
  345. static void powermac_set_asic(struct pci_dev *pci_dev, int enable)
  346. {
  347. /* Enanble or disable ASIC clocks for USB */
  348. if (machine_is(powermac)) {
  349. struct device_node *of_node;
  350. of_node = pci_device_to_OF_node(pci_dev);
  351. if (of_node)
  352. pmac_call_feature(PMAC_FTR_USB_ENABLE,
  353. of_node, 0, enable);
  354. }
  355. }
  356. #else
  357. static inline void powermac_set_asic(struct pci_dev *pci_dev, int enable)
  358. {}
  359. #endif /* CONFIG_PPC_PMAC */
  360. static int check_root_hub_suspended(struct device *dev)
  361. {
  362. struct pci_dev *pci_dev = to_pci_dev(dev);
  363. struct usb_hcd *hcd = pci_get_drvdata(pci_dev);
  364. if (HCD_RH_RUNNING(hcd)) {
  365. dev_warn(dev, "Root hub is not suspended\n");
  366. return -EBUSY;
  367. }
  368. if (hcd->shared_hcd) {
  369. hcd = hcd->shared_hcd;
  370. if (HCD_RH_RUNNING(hcd)) {
  371. dev_warn(dev, "Secondary root hub is not suspended\n");
  372. return -EBUSY;
  373. }
  374. }
  375. return 0;
  376. }
  377. static int suspend_common(struct device *dev, bool do_wakeup)
  378. {
  379. struct pci_dev *pci_dev = to_pci_dev(dev);
  380. struct usb_hcd *hcd = pci_get_drvdata(pci_dev);
  381. int retval;
  382. /* Root hub suspend should have stopped all downstream traffic,
  383. * and all bus master traffic. And done so for both the interface
  384. * and the stub usb_device (which we check here). But maybe it
  385. * didn't; writing sysfs power/state files ignores such rules...
  386. */
  387. retval = check_root_hub_suspended(dev);
  388. if (retval)
  389. return retval;
  390. if (hcd->driver->pci_suspend && !HCD_DEAD(hcd)) {
  391. /* Optimization: Don't suspend if a root-hub wakeup is
  392. * pending and it would cause the HCD to wake up anyway.
  393. */
  394. if (do_wakeup && HCD_WAKEUP_PENDING(hcd))
  395. return -EBUSY;
  396. if (do_wakeup && hcd->shared_hcd &&
  397. HCD_WAKEUP_PENDING(hcd->shared_hcd))
  398. return -EBUSY;
  399. retval = hcd->driver->pci_suspend(hcd, do_wakeup);
  400. suspend_report_result(hcd->driver->pci_suspend, retval);
  401. /* Check again in case wakeup raced with pci_suspend */
  402. if ((retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) ||
  403. (retval == 0 && do_wakeup && hcd->shared_hcd &&
  404. HCD_WAKEUP_PENDING(hcd->shared_hcd))) {
  405. if (hcd->driver->pci_resume)
  406. hcd->driver->pci_resume(hcd, false);
  407. retval = -EBUSY;
  408. }
  409. if (retval)
  410. return retval;
  411. }
  412. /* If MSI-X is enabled, the driver will have synchronized all vectors
  413. * in pci_suspend(). If MSI or legacy PCI is enabled, that will be
  414. * synchronized here.
  415. */
  416. if (!hcd->msix_enabled)
  417. synchronize_irq(pci_dev->irq);
  418. /* Downstream ports from this root hub should already be quiesced, so
  419. * there will be no DMA activity. Now we can shut down the upstream
  420. * link (except maybe for PME# resume signaling). We'll enter a
  421. * low power state during suspend_noirq, if the hardware allows.
  422. */
  423. pci_disable_device(pci_dev);
  424. return retval;
  425. }
  426. static int resume_common(struct device *dev, int event)
  427. {
  428. struct pci_dev *pci_dev = to_pci_dev(dev);
  429. struct usb_hcd *hcd = pci_get_drvdata(pci_dev);
  430. int retval;
  431. if (HCD_RH_RUNNING(hcd) ||
  432. (hcd->shared_hcd &&
  433. HCD_RH_RUNNING(hcd->shared_hcd))) {
  434. dev_dbg(dev, "can't resume, not suspended!\n");
  435. return 0;
  436. }
  437. retval = pci_enable_device(pci_dev);
  438. if (retval < 0) {
  439. dev_err(dev, "can't re-enable after resume, %d!\n", retval);
  440. return retval;
  441. }
  442. pci_set_master(pci_dev);
  443. if (hcd->driver->pci_resume && !HCD_DEAD(hcd)) {
  444. /*
  445. * Only EHCI controllers have to wait for their companions.
  446. * No locking is needed because PCI controller drivers do not
  447. * get unbound during system resume.
  448. */
  449. if (pci_dev->class == CL_EHCI && event != PM_EVENT_AUTO_RESUME)
  450. for_each_companion(pci_dev, hcd,
  451. ehci_wait_for_companions);
  452. retval = hcd->driver->pci_resume(hcd,
  453. event == PM_EVENT_RESTORE);
  454. if (retval) {
  455. dev_err(dev, "PCI post-resume error %d!\n", retval);
  456. if (hcd->shared_hcd)
  457. usb_hc_died(hcd->shared_hcd);
  458. usb_hc_died(hcd);
  459. }
  460. }
  461. return retval;
  462. }
  463. #ifdef CONFIG_PM_SLEEP
  464. static int hcd_pci_suspend(struct device *dev)
  465. {
  466. return suspend_common(dev, device_may_wakeup(dev));
  467. }
  468. static int hcd_pci_suspend_noirq(struct device *dev)
  469. {
  470. struct pci_dev *pci_dev = to_pci_dev(dev);
  471. struct usb_hcd *hcd = pci_get_drvdata(pci_dev);
  472. int retval;
  473. retval = check_root_hub_suspended(dev);
  474. if (retval)
  475. return retval;
  476. pci_save_state(pci_dev);
  477. /* If the root hub is dead rather than suspended, disallow remote
  478. * wakeup. usb_hc_died() should ensure that both hosts are marked as
  479. * dying, so we only need to check the primary roothub.
  480. */
  481. if (HCD_DEAD(hcd))
  482. device_set_wakeup_enable(dev, 0);
  483. dev_dbg(dev, "wakeup: %d\n", device_may_wakeup(dev));
  484. /* Possibly enable remote wakeup,
  485. * choose the appropriate low-power state, and go to that state.
  486. */
  487. retval = pci_prepare_to_sleep(pci_dev);
  488. if (retval == -EIO) { /* Low-power not supported */
  489. dev_dbg(dev, "--> PCI D0 legacy\n");
  490. retval = 0;
  491. } else if (retval == 0) {
  492. dev_dbg(dev, "--> PCI %s\n",
  493. pci_power_name(pci_dev->current_state));
  494. } else {
  495. suspend_report_result(pci_prepare_to_sleep, retval);
  496. return retval;
  497. }
  498. powermac_set_asic(pci_dev, 0);
  499. return retval;
  500. }
  501. static int hcd_pci_resume_noirq(struct device *dev)
  502. {
  503. struct pci_dev *pci_dev = to_pci_dev(dev);
  504. powermac_set_asic(pci_dev, 1);
  505. /* Go back to D0 and disable remote wakeup */
  506. pci_back_from_sleep(pci_dev);
  507. return 0;
  508. }
  509. static int hcd_pci_resume(struct device *dev)
  510. {
  511. return resume_common(dev, PM_EVENT_RESUME);
  512. }
  513. static int hcd_pci_restore(struct device *dev)
  514. {
  515. return resume_common(dev, PM_EVENT_RESTORE);
  516. }
  517. #else
  518. #define hcd_pci_suspend NULL
  519. #define hcd_pci_suspend_noirq NULL
  520. #define hcd_pci_resume_noirq NULL
  521. #define hcd_pci_resume NULL
  522. #define hcd_pci_restore NULL
  523. #endif /* CONFIG_PM_SLEEP */
  524. static int hcd_pci_runtime_suspend(struct device *dev)
  525. {
  526. int retval;
  527. retval = suspend_common(dev, true);
  528. if (retval == 0)
  529. powermac_set_asic(to_pci_dev(dev), 0);
  530. dev_dbg(dev, "hcd_pci_runtime_suspend: %d\n", retval);
  531. return retval;
  532. }
  533. static int hcd_pci_runtime_resume(struct device *dev)
  534. {
  535. int retval;
  536. powermac_set_asic(to_pci_dev(dev), 1);
  537. retval = resume_common(dev, PM_EVENT_AUTO_RESUME);
  538. dev_dbg(dev, "hcd_pci_runtime_resume: %d\n", retval);
  539. return retval;
  540. }
  541. const struct dev_pm_ops usb_hcd_pci_pm_ops = {
  542. .suspend = hcd_pci_suspend,
  543. .suspend_noirq = hcd_pci_suspend_noirq,
  544. .resume_noirq = hcd_pci_resume_noirq,
  545. .resume = hcd_pci_resume,
  546. .freeze = check_root_hub_suspended,
  547. .freeze_noirq = check_root_hub_suspended,
  548. .thaw_noirq = NULL,
  549. .thaw = NULL,
  550. .poweroff = hcd_pci_suspend,
  551. .poweroff_noirq = hcd_pci_suspend_noirq,
  552. .restore_noirq = hcd_pci_resume_noirq,
  553. .restore = hcd_pci_restore,
  554. .runtime_suspend = hcd_pci_runtime_suspend,
  555. .runtime_resume = hcd_pci_runtime_resume,
  556. };
  557. EXPORT_SYMBOL_GPL(usb_hcd_pci_pm_ops);
  558. #endif /* CONFIG_PM */