orinoco_pci.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* orinoco_pci.h
  2. *
  3. * Common code for all Orinoco drivers for PCI devices, including
  4. * both native PCI and PCMCIA-to-PCI bridges.
  5. *
  6. * Copyright (C) 2005, Pavel Roskin.
  7. * See orinoco.c for license.
  8. */
  9. #ifndef _ORINOCO_PCI_H
  10. #define _ORINOCO_PCI_H
  11. #include <linux/netdevice.h>
  12. /* Driver specific data */
  13. struct orinoco_pci_card {
  14. void __iomem *bridge_io;
  15. void __iomem *attr_io;
  16. };
  17. #ifdef CONFIG_PM
  18. static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  19. {
  20. struct net_device *dev = pci_get_drvdata(pdev);
  21. struct orinoco_private *priv = netdev_priv(dev);
  22. unsigned long flags;
  23. int err;
  24. err = orinoco_lock(priv, &flags);
  25. if (err) {
  26. printk(KERN_ERR "%s: cannot lock hardware for suspend\n",
  27. dev->name);
  28. return err;
  29. }
  30. err = __orinoco_down(dev);
  31. if (err)
  32. printk(KERN_WARNING "%s: error %d bringing interface down "
  33. "for suspend\n", dev->name, err);
  34. netif_device_detach(dev);
  35. priv->hw_unavailable++;
  36. orinoco_unlock(priv, &flags);
  37. free_irq(pdev->irq, dev);
  38. pci_save_state(pdev);
  39. pci_disable_device(pdev);
  40. pci_set_power_state(pdev, PCI_D3hot);
  41. return 0;
  42. }
  43. static int orinoco_pci_resume(struct pci_dev *pdev)
  44. {
  45. struct net_device *dev = pci_get_drvdata(pdev);
  46. struct orinoco_private *priv = netdev_priv(dev);
  47. unsigned long flags;
  48. int err;
  49. pci_set_power_state(pdev, 0);
  50. pci_enable_device(pdev);
  51. pci_restore_state(pdev);
  52. err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
  53. dev->name, dev);
  54. if (err) {
  55. printk(KERN_ERR "%s: cannot re-allocate IRQ on resume\n",
  56. dev->name);
  57. pci_disable_device(pdev);
  58. return -EBUSY;
  59. }
  60. err = orinoco_reinit_firmware(dev);
  61. if (err) {
  62. printk(KERN_ERR "%s: error %d re-initializing firmware "
  63. "on resume\n", dev->name, err);
  64. return err;
  65. }
  66. spin_lock_irqsave(&priv->lock, flags);
  67. netif_device_attach(dev);
  68. priv->hw_unavailable--;
  69. if (priv->open && (! priv->hw_unavailable)) {
  70. err = __orinoco_up(dev);
  71. if (err)
  72. printk(KERN_ERR "%s: Error %d restarting card on resume\n",
  73. dev->name, err);
  74. }
  75. spin_unlock_irqrestore(&priv->lock, flags);
  76. return 0;
  77. }
  78. #else
  79. #define orinoco_pci_suspend NULL
  80. #define orinoco_pci_resume NULL
  81. #endif
  82. #endif /* _ORINOCO_PCI_H */