cris: add arch/cris/include/asm/serial.h
[linux-2.6/next.git] / drivers / net / wireless / prism54 / islpci_hotplug.c
blob9e68e0cb718ee0dfff1e00066aef36f1c04e0e15
1 /*
2 * Copyright (C) 2002 Intersil Americas Inc.
3 * Copyright (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
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
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.
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
20 #include <linux/interrupt.h>
21 #include <linux/module.h>
22 #include <linux/pci.h>
23 #include <linux/delay.h>
24 #include <linux/init.h> /* For __init, __exit */
25 #include <linux/dma-mapping.h>
27 #include "prismcompat.h"
28 #include "islpci_dev.h"
29 #include "islpci_mgt.h" /* for pc_debug */
30 #include "isl_oid.h"
32 MODULE_AUTHOR("[Intersil] R.Bastings and W.Termorshuizen, The prism54.org Development Team <prism54-devel@prism54.org>");
33 MODULE_DESCRIPTION("The Prism54 802.11 Wireless LAN adapter");
34 MODULE_LICENSE("GPL");
36 static int init_pcitm = 0;
37 module_param(init_pcitm, int, 0);
39 /* In this order: vendor, device, subvendor, subdevice, class, class_mask,
40 * driver_data
41 * If you have an update for this please contact prism54-devel@prism54.org
42 * The latest list can be found at http://wireless.kernel.org/en/users/Drivers/p54 */
43 static DEFINE_PCI_DEVICE_TABLE(prism54_id_tbl) = {
44 /* Intersil PRISM Duette/Prism GT Wireless LAN adapter */
46 0x1260, 0x3890,
47 PCI_ANY_ID, PCI_ANY_ID,
48 0, 0, 0
51 /* 3COM 3CRWE154G72 Wireless LAN adapter */
53 PCI_VDEVICE(3COM, 0x6001), 0
56 /* Intersil PRISM Indigo Wireless LAN adapter */
58 0x1260, 0x3877,
59 PCI_ANY_ID, PCI_ANY_ID,
60 0, 0, 0
63 /* Intersil PRISM Javelin/Xbow Wireless LAN adapter */
65 0x1260, 0x3886,
66 PCI_ANY_ID, PCI_ANY_ID,
67 0, 0, 0
70 /* End of list */
71 {0,0,0,0,0,0,0}
74 /* register the device with the Hotplug facilities of the kernel */
75 MODULE_DEVICE_TABLE(pci, prism54_id_tbl);
77 static int prism54_probe(struct pci_dev *, const struct pci_device_id *);
78 static void prism54_remove(struct pci_dev *);
79 static int prism54_suspend(struct pci_dev *, pm_message_t state);
80 static int prism54_resume(struct pci_dev *);
82 static struct pci_driver prism54_driver = {
83 .name = DRV_NAME,
84 .id_table = prism54_id_tbl,
85 .probe = prism54_probe,
86 .remove = prism54_remove,
87 .suspend = prism54_suspend,
88 .resume = prism54_resume,
91 /******************************************************************************
92 Module initialization functions
93 ******************************************************************************/
95 static int
96 prism54_probe(struct pci_dev *pdev, const struct pci_device_id *id)
98 struct net_device *ndev;
99 u8 latency_tmr;
100 u32 mem_addr;
101 islpci_private *priv;
102 int rvalue;
104 /* Enable the pci device */
105 if (pci_enable_device(pdev)) {
106 printk(KERN_ERR "%s: pci_enable_device() failed.\n", DRV_NAME);
107 return -ENODEV;
110 /* check whether the latency timer is set correctly */
111 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency_tmr);
112 #if VERBOSE > SHOW_ERROR_MESSAGES
113 DEBUG(SHOW_TRACING, "latency timer: %x\n", latency_tmr);
114 #endif
115 if (latency_tmr < PCIDEVICE_LATENCY_TIMER_MIN) {
116 /* set the latency timer */
117 pci_write_config_byte(pdev, PCI_LATENCY_TIMER,
118 PCIDEVICE_LATENCY_TIMER_VAL);
121 /* enable PCI DMA */
122 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
123 printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME);
124 goto do_pci_disable_device;
127 /* 0x40 is the programmable timer to configure the response timeout (TRDY_TIMEOUT)
128 * 0x41 is the programmable timer to configure the retry timeout (RETRY_TIMEOUT)
129 * The RETRY_TIMEOUT is used to set the number of retries that the core, as a
130 * Master, will perform before abandoning a cycle. The default value for
131 * RETRY_TIMEOUT is 0x80, which far exceeds the PCI 2.1 requirement for new
132 * devices. A write of zero to the RETRY_TIMEOUT register disables this
133 * function to allow use with any non-compliant legacy devices that may
134 * execute more retries.
136 * Writing zero to both these two registers will disable both timeouts and
137 * *can* solve problems caused by devices that are slow to respond.
138 * Make this configurable - MSW
140 if ( init_pcitm >= 0 ) {
141 pci_write_config_byte(pdev, 0x40, (u8)init_pcitm);
142 pci_write_config_byte(pdev, 0x41, (u8)init_pcitm);
143 } else {
144 printk(KERN_INFO "PCI TRDY/RETRY unchanged\n");
147 /* request the pci device I/O regions */
148 rvalue = pci_request_regions(pdev, DRV_NAME);
149 if (rvalue) {
150 printk(KERN_ERR "%s: pci_request_regions failure (rc=%d)\n",
151 DRV_NAME, rvalue);
152 goto do_pci_disable_device;
155 /* check if the memory window is indeed set */
156 rvalue = pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &mem_addr);
157 if (rvalue || !mem_addr) {
158 printk(KERN_ERR "%s: PCI device memory region not configured; fix your BIOS or CardBus bridge/drivers\n",
159 DRV_NAME);
160 goto do_pci_release_regions;
163 /* enable PCI bus-mastering */
164 DEBUG(SHOW_TRACING, "%s: pci_set_master(pdev)\n", DRV_NAME);
165 pci_set_master(pdev);
167 /* enable MWI */
168 pci_try_set_mwi(pdev);
170 /* setup the network device interface and its structure */
171 if (!(ndev = islpci_setup(pdev))) {
172 /* error configuring the driver as a network device */
173 printk(KERN_ERR "%s: could not configure network device\n",
174 DRV_NAME);
175 goto do_pci_clear_mwi;
178 priv = netdev_priv(ndev);
179 islpci_set_state(priv, PRV_STATE_PREBOOT); /* we are attempting to boot */
181 /* card is in unknown state yet, might have some interrupts pending */
182 isl38xx_disable_interrupts(priv->device_base);
184 /* request for the interrupt before uploading the firmware */
185 rvalue = request_irq(pdev->irq, islpci_interrupt,
186 IRQF_SHARED, ndev->name, priv);
188 if (rvalue) {
189 /* error, could not hook the handler to the irq */
190 printk(KERN_ERR "%s: could not install IRQ handler\n",
191 ndev->name);
192 goto do_unregister_netdev;
195 /* firmware upload is triggered in islpci_open */
197 return 0;
199 do_unregister_netdev:
200 unregister_netdev(ndev);
201 islpci_free_memory(priv);
202 pci_set_drvdata(pdev, NULL);
203 free_netdev(ndev);
204 priv = NULL;
205 do_pci_clear_mwi:
206 pci_clear_mwi(pdev);
207 do_pci_release_regions:
208 pci_release_regions(pdev);
209 do_pci_disable_device:
210 pci_disable_device(pdev);
211 return -EIO;
214 /* set by cleanup_module */
215 static volatile int __in_cleanup_module = 0;
217 /* this one removes one(!!) instance only */
218 static void
219 prism54_remove(struct pci_dev *pdev)
221 struct net_device *ndev = pci_get_drvdata(pdev);
222 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
223 BUG_ON(!priv);
225 if (!__in_cleanup_module) {
226 printk(KERN_DEBUG "%s: hot unplug detected\n", ndev->name);
227 islpci_set_state(priv, PRV_STATE_OFF);
230 printk(KERN_DEBUG "%s: removing device\n", ndev->name);
232 unregister_netdev(ndev);
234 /* free the interrupt request */
236 if (islpci_get_state(priv) != PRV_STATE_OFF) {
237 isl38xx_disable_interrupts(priv->device_base);
238 islpci_set_state(priv, PRV_STATE_OFF);
239 /* This bellow causes a lockup at rmmod time. It might be
240 * because some interrupts still linger after rmmod time,
241 * see bug #17 */
242 /* pci_set_power_state(pdev, 3);*/ /* try to power-off */
245 free_irq(pdev->irq, priv);
247 /* free the PCI memory and unmap the remapped page */
248 islpci_free_memory(priv);
250 pci_set_drvdata(pdev, NULL);
251 free_netdev(ndev);
252 priv = NULL;
254 pci_clear_mwi(pdev);
256 pci_release_regions(pdev);
258 pci_disable_device(pdev);
261 static int
262 prism54_suspend(struct pci_dev *pdev, pm_message_t state)
264 struct net_device *ndev = pci_get_drvdata(pdev);
265 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
266 BUG_ON(!priv);
269 pci_save_state(pdev);
271 /* tell the device not to trigger interrupts for now... */
272 isl38xx_disable_interrupts(priv->device_base);
274 /* from now on assume the hardware was already powered down
275 and don't touch it anymore */
276 islpci_set_state(priv, PRV_STATE_OFF);
278 netif_stop_queue(ndev);
279 netif_device_detach(ndev);
281 return 0;
284 static int
285 prism54_resume(struct pci_dev *pdev)
287 struct net_device *ndev = pci_get_drvdata(pdev);
288 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
289 int err;
291 BUG_ON(!priv);
293 printk(KERN_NOTICE "%s: got resume request\n", ndev->name);
295 err = pci_enable_device(pdev);
296 if (err) {
297 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
298 ndev->name);
299 return err;
302 pci_restore_state(pdev);
304 /* alright let's go into the PREBOOT state */
305 islpci_reset(priv, 1);
307 netif_device_attach(ndev);
308 netif_start_queue(ndev);
310 return 0;
313 static int __init
314 prism54_module_init(void)
316 printk(KERN_INFO "Loaded %s driver, version %s\n",
317 DRV_NAME, DRV_VERSION);
319 __bug_on_wrong_struct_sizes ();
321 return pci_register_driver(&prism54_driver);
324 /* by the time prism54_module_exit() terminates, as a postcondition
325 * all instances will have been destroyed by calls to
326 * prism54_remove() */
327 static void __exit
328 prism54_module_exit(void)
330 __in_cleanup_module = 1;
332 pci_unregister_driver(&prism54_driver);
334 printk(KERN_INFO "Unloaded %s driver\n", DRV_NAME);
336 __in_cleanup_module = 0;
339 /* register entry points */
340 module_init(prism54_module_init);
341 module_exit(prism54_module_exit);
342 /* EOF */