Remove all #inclusions of asm/system.h
[linux-2.6.git] / drivers / staging / wlags49_h2 / wl_cs.c
blob7084f414846e946e1d557f322a8da87f738b36c2
1 /*******************************************************************************
2 * Agere Systems Inc.
3 * Wireless device driver for Linux (wlags49).
5 * Copyright (c) 1998-2003 Agere Systems Inc.
6 * All rights reserved.
7 * http://www.agere.com
9 * Initially developed by TriplePoint, Inc.
10 * http://www.triplepoint.com
12 *------------------------------------------------------------------------------
14 * This file contains processing and initialization specific to Card Services
15 * devices (PCMCIA, CF).
17 *------------------------------------------------------------------------------
19 * SOFTWARE LICENSE
21 * This software is provided subject to the following terms and conditions,
22 * which you should read carefully before using the software. Using this
23 * software indicates your acceptance of these terms and conditions. If you do
24 * not agree with these terms and conditions, do not use the software.
26 * Copyright (c) 2003 Agere Systems Inc.
27 * All rights reserved.
29 * Redistribution and use in source or binary forms, with or without
30 * modifications, are permitted provided that the following conditions are met:
32 * . Redistributions of source code must retain the above copyright notice, this
33 * list of conditions and the following Disclaimer as comments in the code as
34 * well as in the documentation and/or other materials provided with the
35 * distribution.
37 * . Redistributions in binary form must reproduce the above copyright notice,
38 * this list of conditions and the following Disclaimer in the documentation
39 * and/or other materials provided with the distribution.
41 * . Neither the name of Agere Systems Inc. nor the names of the contributors
42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission.
45 * Disclaimer
47 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
48 * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
49 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY
50 * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
51 * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
52 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
53 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
54 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55 * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
58 * DAMAGE.
60 ******************************************************************************/
62 /*******************************************************************************
63 * include files
64 ******************************************************************************/
65 #include <wl_version.h>
67 #include <linux/kernel.h>
68 #include <linux/sched.h>
69 #include <linux/ptrace.h>
70 #include <linux/ctype.h>
71 #include <linux/string.h>
72 #include <linux/timer.h>
73 #include <linux/interrupt.h>
74 #include <linux/in.h>
75 #include <linux/delay.h>
76 #include <asm/io.h>
77 #include <asm/bitops.h>
79 #include <linux/netdevice.h>
80 #include <linux/etherdevice.h>
81 #include <linux/skbuff.h>
82 #include <linux/if_arp.h>
83 #include <linux/ioport.h>
84 #include <linux/module.h>
86 #include <pcmcia/cistpl.h>
87 #include <pcmcia/cisreg.h>
88 #include <pcmcia/ciscode.h>
89 #include <pcmcia/ds.h>
90 #include <debug.h>
92 #include <hcf.h>
93 #include <dhf.h>
94 #include <hcfdef.h>
96 #include <wl_if.h>
97 #include <wl_internal.h>
98 #include <wl_util.h>
99 #include <wl_main.h>
100 #include <wl_netdev.h>
101 #include <wl_cs.h>
102 #include <wl_sysfs.h>
105 /*******************************************************************************
106 * global definitions
107 ******************************************************************************/
108 #if DBG
109 extern dbg_info_t *DbgInfo;
110 #endif /* DBG */
113 /*******************************************************************************
114 * wl_adapter_attach()
115 *******************************************************************************
117 * DESCRIPTION:
119 * Creates an instance of the driver, allocating local data structures for
120 * one device. The device is registered with Card Services.
122 * PARAMETERS:
124 * none
126 * RETURNS:
128 * pointer to an allocated dev_link_t structure
129 * NULL on failure
131 ******************************************************************************/
132 static int wl_adapter_attach(struct pcmcia_device *link)
134 struct net_device *dev;
135 struct wl_private *lp;
136 /*--------------------------------------------------------------------*/
138 DBG_FUNC("wl_adapter_attach");
139 DBG_ENTER(DbgInfo);
141 dev = wl_device_alloc();
142 if (dev == NULL) {
143 DBG_ERROR(DbgInfo, "wl_device_alloc returned NULL\n");
144 return -ENOMEM;
147 link->resource[0]->end = HCF_NUM_IO_PORTS;
148 link->resource[0]->flags= IO_DATA_PATH_WIDTH_16;
149 link->config_flags |= CONF_ENABLE_IRQ;
150 link->config_index = 5;
151 link->config_regs = PRESENT_OPTION;
153 link->priv = dev;
154 lp = wl_priv(dev);
155 lp->link = link;
157 wl_adapter_insert(link);
159 DBG_LEAVE(DbgInfo);
160 return 0;
161 } /* wl_adapter_attach */
162 /*============================================================================*/
166 static void wl_adapter_detach(struct pcmcia_device *link)
168 struct net_device *dev = link->priv;
169 /*--------------------------------------------------------------------*/
171 DBG_FUNC("wl_adapter_detach");
172 DBG_ENTER(DbgInfo);
173 DBG_PARAM(DbgInfo, "link", "0x%p", link);
175 wl_adapter_release(link);
177 if (dev) {
178 unregister_wlags_sysfs(dev);
179 unregister_netdev(dev);
182 wl_device_dealloc(dev);
184 DBG_LEAVE(DbgInfo);
185 } /* wl_adapter_detach */
186 /*============================================================================*/
189 void wl_adapter_release(struct pcmcia_device *link)
191 DBG_FUNC("wl_adapter_release");
192 DBG_ENTER(DbgInfo);
193 DBG_PARAM(DbgInfo, "link", "0x%p", link);
195 /* Stop hardware */
196 wl_remove(link->priv);
198 pcmcia_disable_device(link);
200 DBG_LEAVE(DbgInfo);
201 } /* wl_adapter_release */
202 /*============================================================================*/
204 static int wl_adapter_suspend(struct pcmcia_device *link)
206 struct net_device *dev = link->priv;
208 /* if (link->open) { */
209 netif_device_detach(dev);
210 wl_suspend(dev);
211 /* CHECK! pcmcia_release_configuration(link->handle); */
212 /* } */
214 return 0;
215 } /* wl_adapter_suspend */
217 static int wl_adapter_resume(struct pcmcia_device *link)
219 struct net_device *dev = link->priv;
221 wl_resume(dev);
223 netif_device_attach(dev);
225 return 0;
226 } /* wl_adapter_resume */
228 void wl_adapter_insert(struct pcmcia_device *link)
230 struct net_device *dev;
231 int ret;
232 /*--------------------------------------------------------------------*/
234 DBG_FUNC("wl_adapter_insert");
235 DBG_ENTER(DbgInfo);
236 DBG_PARAM(DbgInfo, "link", "0x%p", link);
238 dev = link->priv;
240 /* Do we need to allocate an interrupt? */
241 link->config_flags |= CONF_ENABLE_IRQ;
242 link->io_lines = 6;
244 ret = pcmcia_request_io(link);
245 if (ret != 0)
246 goto failed;
248 ret = pcmcia_request_irq(link, (void *) wl_isr);
249 if (ret != 0)
250 goto failed;
252 ret = pcmcia_enable_device(link);
253 if (ret != 0)
254 goto failed;
256 dev->irq = link->irq;
257 dev->base_addr = link->resource[0]->start;
259 SET_NETDEV_DEV(dev, &link->dev);
260 if (register_netdev(dev) != 0) {
261 printk("%s: register_netdev() failed\n", MODULE_NAME);
262 goto failed;
265 register_wlags_sysfs(dev);
267 printk(KERN_INFO "%s: Wireless, io_addr %#03lx, irq %d, mac_address"
268 " %pM\n", dev->name, dev->base_addr, dev->irq, dev->dev_addr);
270 DBG_LEAVE(DbgInfo);
271 return;
273 failed:
274 wl_adapter_release(link);
276 DBG_LEAVE(DbgInfo);
277 return;
278 } /* wl_adapter_insert */
279 /*============================================================================*/
282 /*******************************************************************************
283 * wl_adapter_open()
284 *******************************************************************************
286 * DESCRIPTION:
288 * Open the device.
290 * PARAMETERS:
292 * dev - a pointer to a net_device structure representing the network
293 * device to open.
295 * RETURNS:
297 * 0 on success
298 * errno value otherwise
300 ******************************************************************************/
301 int wl_adapter_open(struct net_device *dev)
303 struct wl_private *lp = wl_priv(dev);
304 struct pcmcia_device *link = lp->link;
305 int result = 0;
306 int hcf_status = HCF_SUCCESS;
307 /*--------------------------------------------------------------------*/
309 DBG_FUNC("wl_adapter_open");
310 DBG_ENTER(DbgInfo);
311 DBG_PRINT("%s\n", VERSION_INFO);
312 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
314 if (!pcmcia_dev_present(link)) {
315 DBG_LEAVE(DbgInfo);
316 return -ENODEV;
319 link->open++;
321 hcf_status = wl_open(dev);
323 if (hcf_status != HCF_SUCCESS) {
324 link->open--;
325 result = -ENODEV;
328 DBG_LEAVE(DbgInfo);
329 return result;
330 } /* wl_adapter_open */
331 /*============================================================================*/
334 /*******************************************************************************
335 * wl_adapter_close()
336 *******************************************************************************
338 * DESCRIPTION:
340 * Close the device.
342 * PARAMETERS:
344 * dev - a pointer to a net_device structure representing the network
345 * device to close.
347 * RETURNS:
349 * 0 on success
350 * errno value otherwise
352 ******************************************************************************/
353 int wl_adapter_close(struct net_device *dev)
355 struct wl_private *lp = wl_priv(dev);
356 struct pcmcia_device *link = lp->link;
357 /*--------------------------------------------------------------------*/
359 DBG_FUNC("wl_adapter_close");
360 DBG_ENTER(DbgInfo);
361 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
363 if (link == NULL) {
364 DBG_LEAVE(DbgInfo);
365 return -ENODEV;
368 DBG_TRACE(DbgInfo, "%s: Shutting down adapter.\n", dev->name);
369 wl_close(dev);
371 link->open--;
373 DBG_LEAVE(DbgInfo);
374 return 0;
375 } /* wl_adapter_close */
376 /*============================================================================*/
378 static const struct pcmcia_device_id wl_adapter_ids[] = {
379 #if !((HCF_TYPE) & HCF_TYPE_HII5)
380 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0003),
381 PCMCIA_DEVICE_PROD_ID12("Agere Systems", "Wireless PC Card Model 0110",
382 0x33103a9b, 0xe175b0dd),
383 #else
384 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0004),
385 PCMCIA_DEVICE_PROD_ID12("Linksys", "WCF54G_Wireless-G_CompactFlash_Card",
386 0x0733cc81, 0x98a599e1),
387 #endif /* (HCF_TYPE) & HCF_TYPE_HII5 */
388 PCMCIA_DEVICE_NULL,
390 MODULE_DEVICE_TABLE(pcmcia, wl_adapter_ids);
392 static struct pcmcia_driver wlags49_driver = {
393 .owner = THIS_MODULE,
394 .name = DRIVER_NAME,
395 .probe = wl_adapter_attach,
396 .remove = wl_adapter_detach,
397 .id_table = wl_adapter_ids,
398 .suspend = wl_adapter_suspend,
399 .resume = wl_adapter_resume,
404 /*******************************************************************************
405 * wl_adapter_init_module()
406 *******************************************************************************
408 * DESCRIPTION:
410 * Called by init_module() to perform PCMCIA driver initialization.
412 * PARAMETERS:
414 * N/A
416 * RETURNS:
418 * 0 on success
419 * -1 on error
421 ******************************************************************************/
422 int wl_adapter_init_module(void)
424 int ret;
425 /*--------------------------------------------------------------------*/
427 DBG_FUNC("wl_adapter_init_module");
428 DBG_ENTER(DbgInfo);
429 DBG_TRACE(DbgInfo, "wl_adapter_init_module() -- PCMCIA\n");
431 ret = pcmcia_register_driver(&wlags49_driver);
433 DBG_LEAVE(DbgInfo);
434 return ret;
435 } /* wl_adapter_init_module */
436 /*============================================================================*/
439 /*******************************************************************************
440 * wl_adapter_cleanup_module()
441 *******************************************************************************
443 * DESCRIPTION:
445 * Called by cleanup_module() to perform driver uninitialization.
447 * PARAMETERS:
449 * N/A
451 * RETURNS:
453 * N/A
455 ******************************************************************************/
456 void wl_adapter_cleanup_module(void)
458 DBG_FUNC("wl_adapter_cleanup_module");
459 DBG_ENTER(DbgInfo);
460 DBG_TRACE(DbgInfo, "wl_adapter_cleanup_module() -- PCMCIA\n");
463 pcmcia_unregister_driver(&wlags49_driver);
465 DBG_LEAVE(DbgInfo);
466 return;
467 } /* wl_adapter_cleanup_module */
468 /*============================================================================*/
471 /*******************************************************************************
472 * wl_adapter_is_open()
473 *******************************************************************************
475 * DESCRIPTION:
477 * Check with Card Services to determine if this device is open.
479 * PARAMETERS:
481 * dev - a pointer to the net_device structure whose open status will be
482 * checked
484 * RETURNS:
486 * nonzero if device is open
487 * 0 otherwise
489 ******************************************************************************/
490 int wl_adapter_is_open(struct net_device *dev)
492 struct wl_private *lp = wl_priv(dev);
493 struct pcmcia_device *link = lp->link;
495 if (!pcmcia_dev_present(link))
496 return 0;
498 return link->open;
499 } /* wl_adapter_is_open */
500 /*============================================================================*/