Merge branch 'upstream-fixes' into upstream
[linux-2.6] / drivers / net / wireless / orinoco_pci.h
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
10 #ifndef _ORINOCO_PCI_H
11 #define _ORINOCO_PCI_H
12
13 #include <linux/netdevice.h>
14
15 /* Driver specific data */
16 struct orinoco_pci_card {
17         void __iomem *bridge_io;
18         void __iomem *attr_io;
19 };
20
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)
26 {
27         char *range_type;
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;
32
33         dev->irq = pdev->irq;
34         if (flags & IORESOURCE_IO) {
35                 dev->base_addr = start;
36                 range_type = "ports";
37         } else {
38                 dev->mem_start = start;
39                 dev->mem_end = end;
40                 range_type = "memory";
41         }
42
43         printk(KERN_DEBUG PFX "%s: irq %d, %s 0x%lx-0x%lx\n",
44                pci_name(pdev), pdev->irq, range_type, start, end);
45 }
46
47 static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state)
48 {
49         struct net_device *dev = pci_get_drvdata(pdev);
50         struct orinoco_private *priv = netdev_priv(dev);
51         unsigned long flags;
52         int err;
53
54         err = orinoco_lock(priv, &flags);
55         if (err) {
56                 printk(KERN_ERR "%s: cannot lock hardware for suspend\n",
57                        dev->name);
58                 return err;
59         }
60
61         err = __orinoco_down(dev);
62         if (err)
63                 printk(KERN_WARNING "%s: error %d bringing interface down "
64                        "for suspend\n", dev->name, err);
65         
66         netif_device_detach(dev);
67
68         priv->hw_unavailable++;
69         
70         orinoco_unlock(priv, &flags);
71
72         free_irq(pdev->irq, dev);
73         pci_save_state(pdev);
74         pci_disable_device(pdev);
75         pci_set_power_state(pdev, PCI_D3hot);
76
77         return 0;
78 }
79
80 static int orinoco_pci_resume(struct pci_dev *pdev)
81 {
82         struct net_device *dev = pci_get_drvdata(pdev);
83         struct orinoco_private *priv = netdev_priv(dev);
84         unsigned long flags;
85         int err;
86
87         pci_set_power_state(pdev, 0);
88         pci_enable_device(pdev);
89         pci_restore_state(pdev);
90
91         err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
92                           dev->name, dev);
93         if (err) {
94                 printk(KERN_ERR "%s: cannot re-allocate IRQ on resume\n",
95                        dev->name);
96                 pci_disable_device(pdev);
97                 return -EBUSY;
98         }
99
100         err = orinoco_reinit_firmware(dev);
101         if (err) {
102                 printk(KERN_ERR "%s: error %d re-initializing firmware "
103                        "on resume\n", dev->name, err);
104                 return err;
105         }
106
107         spin_lock_irqsave(&priv->lock, flags);
108
109         netif_device_attach(dev);
110
111         priv->hw_unavailable--;
112
113         if (priv->open && (! priv->hw_unavailable)) {
114                 err = __orinoco_up(dev);
115                 if (err)
116                         printk(KERN_ERR "%s: Error %d restarting card on resume\n",
117                                dev->name, err);
118         }
119         
120         spin_unlock_irqrestore(&priv->lock, flags);
121
122         return 0;
123 }
124
125 #endif /* _ORINOCO_PCI_H */