3 * Common code for all Orinoco drivers for PCI devices, including
4 * both native PCI and PCMCIA-to-PCI bridges.
6 * Copyright (C) 2005, Pavel Roskin.
7 * See orinoco.c for license.
10 #ifndef _ORINOCO_PCI_H
11 #define _ORINOCO_PCI_H
13 #include <linux/netdevice.h>
15 /* Driver specific data */
16 struct orinoco_pci_card {
17 void __iomem *bridge_io;
18 void __iomem *attr_io;
21 /* Set base address or memory range of the network device based on
22 * the PCI device it's using. Specify BAR of the "main" resource.
23 * To be used after request_irq(). */
24 static inline void orinoco_pci_setup_netdev(struct net_device *dev,
25 struct pci_dev *pdev, int bar)
28 unsigned long start = pci_resource_start(pdev, bar);
29 unsigned long len = pci_resource_len(pdev, bar);
30 unsigned long flags = pci_resource_flags(pdev, bar);
31 unsigned long end = start + len - 1;
34 if (flags & IORESOURCE_IO) {
35 dev->base_addr = start;
38 dev->mem_start = start;
40 range_type = "memory";
43 printk(KERN_DEBUG PFX "%s: irq %d, %s 0x%lx-0x%lx\n",
44 pci_name(pdev), pdev->irq, range_type, start, end);
47 static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state)
49 struct net_device *dev = pci_get_drvdata(pdev);
50 struct orinoco_private *priv = netdev_priv(dev);
54 err = orinoco_lock(priv, &flags);
56 printk(KERN_ERR "%s: cannot lock hardware for suspend\n",
61 err = __orinoco_down(dev);
63 printk(KERN_WARNING "%s: error %d bringing interface down "
64 "for suspend\n", dev->name, err);
66 netif_device_detach(dev);
68 priv->hw_unavailable++;
70 orinoco_unlock(priv, &flags);
72 free_irq(pdev->irq, dev);
74 pci_disable_device(pdev);
75 pci_set_power_state(pdev, PCI_D3hot);
80 static int orinoco_pci_resume(struct pci_dev *pdev)
82 struct net_device *dev = pci_get_drvdata(pdev);
83 struct orinoco_private *priv = netdev_priv(dev);
87 pci_set_power_state(pdev, 0);
88 pci_enable_device(pdev);
89 pci_restore_state(pdev);
91 err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
94 printk(KERN_ERR "%s: cannot re-allocate IRQ on resume\n",
96 pci_disable_device(pdev);
100 err = orinoco_reinit_firmware(dev);
102 printk(KERN_ERR "%s: error %d re-initializing firmware "
103 "on resume\n", dev->name, err);
107 spin_lock_irqsave(&priv->lock, flags);
109 netif_device_attach(dev);
111 priv->hw_unavailable--;
113 if (priv->open && (! priv->hw_unavailable)) {
114 err = __orinoco_up(dev);
116 printk(KERN_ERR "%s: Error %d restarting card on resume\n",
120 spin_unlock_irqrestore(&priv->lock, flags);
125 #endif /* _ORINOCO_PCI_H */