]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/net/wireless/prism54/islpci_hotplug.c
PCI: remove useless pci driver method
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / prism54 / islpci_hotplug.c
1 /*
2  *  Copyright (C) 2002 Intersil Americas Inc.
3  *  Copyright (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License 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
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  */
19
20 #include <linux/module.h>
21 #include <linux/pci.h>
22 #include <linux/delay.h>
23 #include <linux/init.h> /* For __init, __exit */
24 #include <linux/dma-mapping.h>
25
26 #include "prismcompat.h"
27 #include "islpci_dev.h"
28 #include "islpci_mgt.h"         /* for pc_debug */
29 #include "isl_oid.h"
30
31 MODULE_AUTHOR("[Intersil] R.Bastings and W.Termorshuizen, The prism54.org Development Team <prism54-devel@prism54.org>");
32 MODULE_DESCRIPTION("The Prism54 802.11 Wireless LAN adapter");
33 MODULE_LICENSE("GPL");
34
35 static int      init_pcitm = 0;
36 module_param(init_pcitm, int, 0);
37
38 /* In this order: vendor, device, subvendor, subdevice, class, class_mask,
39  * driver_data
40  * If you have an update for this please contact prism54-devel@prism54.org
41  * The latest list can be found at http://prism54.org/supported_cards.php */
42 static const struct pci_device_id prism54_id_tbl[] = {
43         /* Intersil PRISM Duette/Prism GT Wireless LAN adapter */
44         {
45          0x1260, 0x3890,
46          PCI_ANY_ID, PCI_ANY_ID,
47          0, 0, 0
48         },
49
50         /* 3COM 3CRWE154G72 Wireless LAN adapter */
51         {
52          0x10b7, 0x6001,
53          PCI_ANY_ID, PCI_ANY_ID,
54          0, 0, 0
55         },
56
57         /* Intersil PRISM Indigo Wireless LAN adapter */
58         {
59          0x1260, 0x3877,
60          PCI_ANY_ID, PCI_ANY_ID,
61          0, 0, 0
62         },
63
64         /* Intersil PRISM Javelin/Xbow Wireless LAN adapter */
65         {
66          0x1260, 0x3886,
67          PCI_ANY_ID, PCI_ANY_ID,
68          0, 0, 0
69         },
70
71         /* End of list */
72         {0,0,0,0,0,0,0}
73 };
74
75 /* register the device with the Hotplug facilities of the kernel */
76 MODULE_DEVICE_TABLE(pci, prism54_id_tbl);
77
78 static int prism54_probe(struct pci_dev *, const struct pci_device_id *);
79 static void prism54_remove(struct pci_dev *);
80 static int prism54_suspend(struct pci_dev *, pm_message_t state);
81 static int prism54_resume(struct pci_dev *);
82
83 static struct pci_driver prism54_driver = {
84         .name = DRV_NAME,
85         .id_table = prism54_id_tbl,
86         .probe = prism54_probe,
87         .remove = prism54_remove,
88         .suspend = prism54_suspend,
89         .resume = prism54_resume,
90 };
91
92 /******************************************************************************
93     Module initialization functions
94 ******************************************************************************/
95
96 int
97 prism54_probe(struct pci_dev *pdev, const struct pci_device_id *id)
98 {
99         struct net_device *ndev;
100         u8 latency_tmr;
101         u32 mem_addr;
102         islpci_private *priv;
103         int rvalue;
104
105         /* Enable the pci device */
106         if (pci_enable_device(pdev)) {
107                 printk(KERN_ERR "%s: pci_enable_device() failed.\n", DRV_NAME);
108                 return -ENODEV;
109         }
110
111         /* check whether the latency timer is set correctly */
112         pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency_tmr);
113 #if VERBOSE > SHOW_ERROR_MESSAGES
114         DEBUG(SHOW_TRACING, "latency timer: %x\n", latency_tmr);
115 #endif
116         if (latency_tmr < PCIDEVICE_LATENCY_TIMER_MIN) {
117                 /* set the latency timer */
118                 pci_write_config_byte(pdev, PCI_LATENCY_TIMER,
119                                       PCIDEVICE_LATENCY_TIMER_VAL);
120         }
121
122         /* enable PCI DMA */
123         if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
124                 printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME);
125                 goto do_pci_disable_device;
126         }
127
128         /* 0x40 is the programmable timer to configure the response timeout (TRDY_TIMEOUT)
129          * 0x41 is the programmable timer to configure the retry timeout (RETRY_TIMEOUT)
130          *      The RETRY_TIMEOUT is used to set the number of retries that the core, as a
131          *      Master, will perform before abandoning a cycle. The default value for
132          *      RETRY_TIMEOUT is 0x80, which far exceeds the PCI 2.1 requirement for new
133          *      devices. A write of zero to the RETRY_TIMEOUT register disables this
134          *      function to allow use with any non-compliant legacy devices that may
135          *      execute more retries.
136          *
137          *      Writing zero to both these two registers will disable both timeouts and
138          *      *can* solve problems caused by devices that are slow to respond.
139          *      Make this configurable - MSW
140          */
141         if ( init_pcitm >= 0 ) {
142                 pci_write_config_byte(pdev, 0x40, (u8)init_pcitm);
143                 pci_write_config_byte(pdev, 0x41, (u8)init_pcitm);
144         } else {
145                 printk(KERN_INFO "PCI TRDY/RETRY unchanged\n");
146         }
147
148         /* request the pci device I/O regions */
149         rvalue = pci_request_regions(pdev, DRV_NAME);
150         if (rvalue) {
151                 printk(KERN_ERR "%s: pci_request_regions failure (rc=%d)\n",
152                        DRV_NAME, rvalue);
153                 goto do_pci_disable_device;
154         }
155
156         /* check if the memory window is indeed set */
157         rvalue = pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &mem_addr);
158         if (rvalue || !mem_addr) {
159                 printk(KERN_ERR "%s: PCI device memory region not configured; fix your BIOS or CardBus bridge/drivers\n",
160                        DRV_NAME);
161                 goto do_pci_release_regions;
162         }
163
164         /* enable PCI bus-mastering */
165         DEBUG(SHOW_TRACING, "%s: pci_set_master(pdev)\n", DRV_NAME);
166         pci_set_master(pdev);
167
168         /* enable MWI */
169         if (!pci_set_mwi(pdev))
170                 printk(KERN_INFO "%s: pci_set_mwi(pdev) succeeded\n", DRV_NAME);
171
172         /* setup the network device interface and its structure */
173         if (!(ndev = islpci_setup(pdev))) {
174                 /* error configuring the driver as a network device */
175                 printk(KERN_ERR "%s: could not configure network device\n",
176                        DRV_NAME);
177                 goto do_pci_clear_mwi;
178         }
179
180         priv = netdev_priv(ndev);
181         islpci_set_state(priv, PRV_STATE_PREBOOT); /* we are attempting to boot */
182
183         /* card is in unknown state yet, might have some interrupts pending */
184         isl38xx_disable_interrupts(priv->device_base);
185
186         /* request for the interrupt before uploading the firmware */
187         rvalue = request_irq(pdev->irq, &islpci_interrupt,
188                              IRQF_SHARED, ndev->name, priv);
189
190         if (rvalue) {
191                 /* error, could not hook the handler to the irq */
192                 printk(KERN_ERR "%s: could not install IRQ handler\n",
193                        ndev->name);
194                 goto do_unregister_netdev;
195         }
196
197         /* firmware upload is triggered in islpci_open */
198
199         return 0;
200
201       do_unregister_netdev:
202         unregister_netdev(ndev);
203         islpci_free_memory(priv);
204         pci_set_drvdata(pdev, NULL);
205         free_netdev(ndev);
206         priv = NULL;
207       do_pci_clear_mwi:
208         pci_clear_mwi(pdev);
209       do_pci_release_regions:
210         pci_release_regions(pdev);
211       do_pci_disable_device:
212         pci_disable_device(pdev);
213         return -EIO;
214 }
215
216 /* set by cleanup_module */
217 static volatile int __in_cleanup_module = 0;
218
219 /* this one removes one(!!) instance only */
220 void
221 prism54_remove(struct pci_dev *pdev)
222 {
223         struct net_device *ndev = pci_get_drvdata(pdev);
224         islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
225         BUG_ON(!priv);
226
227         if (!__in_cleanup_module) {
228                 printk(KERN_DEBUG "%s: hot unplug detected\n", ndev->name);
229                 islpci_set_state(priv, PRV_STATE_OFF);
230         }
231
232         printk(KERN_DEBUG "%s: removing device\n", ndev->name);
233
234         unregister_netdev(ndev);
235
236         /* free the interrupt request */
237
238         if (islpci_get_state(priv) != PRV_STATE_OFF) {
239                 isl38xx_disable_interrupts(priv->device_base);
240                 islpci_set_state(priv, PRV_STATE_OFF);
241                 /* This bellow causes a lockup at rmmod time. It might be
242                  * because some interrupts still linger after rmmod time,
243                  * see bug #17 */
244                 /* pci_set_power_state(pdev, 3);*/      /* try to power-off */
245         }
246
247         free_irq(pdev->irq, priv);
248
249         /* free the PCI memory and unmap the remapped page */
250         islpci_free_memory(priv);
251
252         pci_set_drvdata(pdev, NULL);
253         free_netdev(ndev);
254         priv = NULL;
255
256         pci_clear_mwi(pdev);
257
258         pci_release_regions(pdev);
259
260         pci_disable_device(pdev);
261 }
262
263 int
264 prism54_suspend(struct pci_dev *pdev, pm_message_t state)
265 {
266         struct net_device *ndev = pci_get_drvdata(pdev);
267         islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
268         BUG_ON(!priv);
269
270
271         pci_save_state(pdev);
272
273         /* tell the device not to trigger interrupts for now... */
274         isl38xx_disable_interrupts(priv->device_base);
275
276         /* from now on assume the hardware was already powered down
277            and don't touch it anymore */
278         islpci_set_state(priv, PRV_STATE_OFF);
279
280         netif_stop_queue(ndev);
281         netif_device_detach(ndev);
282
283         return 0;
284 }
285
286 int
287 prism54_resume(struct pci_dev *pdev)
288 {
289         struct net_device *ndev = pci_get_drvdata(pdev);
290         islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
291         int err;
292
293         BUG_ON(!priv);
294
295         printk(KERN_NOTICE "%s: got resume request\n", ndev->name);
296
297         err = pci_enable_device(pdev);
298         if (err) {
299                 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
300                        ndev->name);
301                 return err;
302         }
303
304         pci_restore_state(pdev);
305
306         /* alright let's go into the PREBOOT state */
307         islpci_reset(priv, 1);
308
309         netif_device_attach(ndev);
310         netif_start_queue(ndev);
311
312         return 0;
313 }
314
315 static int __init
316 prism54_module_init(void)
317 {
318         printk(KERN_INFO "Loaded %s driver, version %s\n",
319                DRV_NAME, DRV_VERSION);
320
321         __bug_on_wrong_struct_sizes ();
322
323         return pci_register_driver(&prism54_driver);
324 }
325
326 /* by the time prism54_module_exit() terminates, as a postcondition
327  * all instances will have been destroyed by calls to
328  * prism54_remove() */
329 static void __exit
330 prism54_module_exit(void)
331 {
332         __in_cleanup_module = 1;
333
334         pci_unregister_driver(&prism54_driver);
335
336         printk(KERN_INFO "Unloaded %s driver\n", DRV_NAME);
337
338         __in_cleanup_module = 0;
339 }
340
341 /* register entry points */
342 module_init(prism54_module_init);
343 module_exit(prism54_module_exit);
344 /* EOF */