pcmcia: move driver name to struct pcmcia_driver
[deliverable/linux.git] / drivers / staging / wlags49_h2 / wl_cs.c
1 /*******************************************************************************
2 * Agere Systems Inc.
3 * Wireless device driver for Linux (wlags49).
4 *
5 * Copyright (c) 1998-2003 Agere Systems Inc.
6 * All rights reserved.
7 * http://www.agere.com
8 *
9 * Initially developed by TriplePoint, Inc.
10 * http://www.triplepoint.com
11 *
12 *------------------------------------------------------------------------------
13 *
14 * This file contains processing and initialization specific to Card Services
15 * devices (PCMCIA, CF).
16 *
17 *------------------------------------------------------------------------------
18 *
19 * SOFTWARE LICENSE
20 *
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.
25 *
26 * Copyright (c) 2003 Agere Systems Inc.
27 * All rights reserved.
28 *
29 * Redistribution and use in source or binary forms, with or without
30 * modifications, are permitted provided that the following conditions are met:
31 *
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.
36 *
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.
40 *
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.
44 *
45 * Disclaimer
46 *
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.
59 *
60 ******************************************************************************/
61
62 /*******************************************************************************
63 * include files
64 ******************************************************************************/
65 #include <wl_version.h>
66
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/system.h>
78 #include <asm/bitops.h>
79
80 #include <linux/netdevice.h>
81 #include <linux/etherdevice.h>
82 #include <linux/skbuff.h>
83 #include <linux/if_arp.h>
84 #include <linux/ioport.h>
85
86 #include <pcmcia/cistpl.h>
87 #include <pcmcia/cisreg.h>
88 #include <pcmcia/ciscode.h>
89 #include <pcmcia/ds.h>
90 #include <debug.h>
91
92 #include <hcf.h>
93 #include <dhf.h>
94 #include <hcfdef.h>
95
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>
103
104
105 /*******************************************************************************
106 * global definitions
107 ******************************************************************************/
108 #if DBG
109 extern dbg_info_t *DbgInfo;
110 #endif /* DBG */
111
112
113 /*******************************************************************************
114 * wl_adapter_attach()
115 *******************************************************************************
116 *
117 * DESCRIPTION:
118 *
119 * Creates an instance of the driver, allocating local data structures for
120 * one device. The device is registered with Card Services.
121 *
122 * PARAMETERS:
123 *
124 * none
125 *
126 * RETURNS:
127 *
128 * pointer to an allocated dev_link_t structure
129 * NULL on failure
130 *
131 ******************************************************************************/
132 static int wl_adapter_attach(struct pcmcia_device *link)
133 {
134 struct net_device *dev;
135 struct wl_private *lp;
136 /*--------------------------------------------------------------------*/
137
138 DBG_FUNC("wl_adapter_attach");
139 DBG_ENTER(DbgInfo);
140
141 dev = wl_device_alloc();
142 if (dev == NULL) {
143 DBG_ERROR(DbgInfo, "wl_device_alloc returned NULL\n");
144 return -ENOMEM;
145 }
146
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;
152
153 link->priv = dev;
154 lp = wl_priv(dev);
155 lp->link = link;
156
157 wl_adapter_insert(link);
158
159 DBG_LEAVE(DbgInfo);
160 return 0;
161 } /* wl_adapter_attach */
162 /*============================================================================*/
163
164
165
166 /*******************************************************************************
167 * wl_adapter_detach()
168 *******************************************************************************
169 *
170 * DESCRIPTION:
171 *
172 * This deletes a driver "instance". The device is de-registered with Card
173 * Services. If it has been released, then the net device is unregistered, and
174 * all local data structures are freed. Otherwise, the structures will be
175 * freed when the device is released.
176 *
177 * PARAMETERS:
178 *
179 * link - pointer to the dev_link_t structure representing the device to
180 * detach
181 *
182 * RETURNS:
183 *
184 * N/A
185 *
186 ******************************************************************************/
187 static void wl_adapter_detach(struct pcmcia_device *link)
188 {
189 struct net_device *dev = link->priv;
190 /*--------------------------------------------------------------------*/
191
192 DBG_FUNC("wl_adapter_detach");
193 DBG_ENTER(DbgInfo);
194 DBG_PARAM(DbgInfo, "link", "0x%p", link);
195
196 wl_adapter_release(link);
197
198 if (dev) {
199 unregister_wlags_sysfs(dev);
200 unregister_netdev(dev);
201 }
202
203 wl_device_dealloc(dev);
204
205 DBG_LEAVE(DbgInfo);
206 } /* wl_adapter_detach */
207 /*============================================================================*/
208
209
210 /*******************************************************************************
211 * wl_adapter_release()
212 *******************************************************************************
213 *
214 * DESCRIPTION:
215 *
216 * After a card is removed, this routine will release the PCMCIA
217 * configuration. If the device is still open, this will be postponed until it
218 * is closed.
219 *
220 * PARAMETERS:
221 *
222 * arg - a u_long representing a pointer to a dev_link_t structure for the
223 * device to be released.
224 *
225 * RETURNS:
226 *
227 * N/A
228 *
229 ******************************************************************************/
230 void wl_adapter_release(struct pcmcia_device *link)
231 {
232 DBG_FUNC("wl_adapter_release");
233 DBG_ENTER(DbgInfo);
234 DBG_PARAM(DbgInfo, "link", "0x%p", link);
235
236 /* Stop hardware */
237 wl_remove(link->priv);
238
239 pcmcia_disable_device(link);
240
241 DBG_LEAVE(DbgInfo);
242 } /* wl_adapter_release */
243 /*============================================================================*/
244
245 static int wl_adapter_suspend(struct pcmcia_device *link)
246 {
247 struct net_device *dev = link->priv;
248
249 /* if (link->open) { */
250 netif_device_detach(dev);
251 wl_suspend(dev);
252 /* CHECK! pcmcia_release_configuration(link->handle); */
253 /* } */
254
255 return 0;
256 } /* wl_adapter_suspend */
257
258 static int wl_adapter_resume(struct pcmcia_device *link)
259 {
260 struct net_device *dev = link->priv;
261
262 wl_resume(dev);
263
264 netif_device_attach(dev);
265
266 return 0;
267 } /* wl_adapter_resume */
268
269 /*******************************************************************************
270 * wl_adapter_insert()
271 *******************************************************************************
272 *
273 * DESCRIPTION:
274 *
275 * wl_adapter_insert() is scheduled to run after a CARD_INSERTION event is
276 * received, to configure the PCMCIA socket, and to make the ethernet device
277 * available to the system.
278 *
279 * PARAMETERS:
280 *
281 * link - pointer to the dev_link_t structure representing the device to
282 * insert
283 *
284 * RETURNS:
285 *
286 * N/A
287 *
288 ******************************************************************************/
289 void wl_adapter_insert(struct pcmcia_device *link)
290 {
291 struct net_device *dev;
292 int i;
293 int ret;
294 /*--------------------------------------------------------------------*/
295
296 DBG_FUNC("wl_adapter_insert");
297 DBG_ENTER(DbgInfo);
298 DBG_PARAM(DbgInfo, "link", "0x%p", link);
299
300 dev = link->priv;
301
302 /* Do we need to allocate an interrupt? */
303 link->config_flags |= CONF_ENABLE_IRQ;
304 link->io_lines = 6;
305
306 ret = pcmcia_request_io(link);
307 if (ret != 0)
308 goto failed;
309
310 ret = pcmcia_request_irq(link, (void *) wl_isr);
311 if (ret != 0)
312 goto failed;
313
314 ret = pcmcia_enable_device(link);
315 if (ret != 0)
316 goto failed;
317
318 dev->irq = link->irq;
319 dev->base_addr = link->resource[0]->start;
320
321 SET_NETDEV_DEV(dev, &link->dev);
322 if (register_netdev(dev) != 0) {
323 printk("%s: register_netdev() failed\n", MODULE_NAME);
324 goto failed;
325 }
326
327 register_wlags_sysfs(dev);
328
329 printk(KERN_INFO "%s: Wireless, io_addr %#03lx, irq %d, ""mac_address ",
330 dev->name, dev->base_addr, dev->irq);
331 for (i = 0; i < ETH_ALEN; i++)
332 printk("%02X%c", dev->dev_addr[i], ((i < (ETH_ALEN-1)) ? ':' : '\n'));
333
334 DBG_LEAVE(DbgInfo);
335 return;
336
337 failed:
338 wl_adapter_release(link);
339
340 DBG_LEAVE(DbgInfo);
341 return;
342 } /* wl_adapter_insert */
343 /*============================================================================*/
344
345
346 /*******************************************************************************
347 * wl_adapter_open()
348 *******************************************************************************
349 *
350 * DESCRIPTION:
351 *
352 * Open the device.
353 *
354 * PARAMETERS:
355 *
356 * dev - a pointer to a net_device structure representing the network
357 * device to open.
358 *
359 * RETURNS:
360 *
361 * 0 on success
362 * errno value otherwise
363 *
364 ******************************************************************************/
365 int wl_adapter_open(struct net_device *dev)
366 {
367 struct wl_private *lp = wl_priv(dev);
368 struct pcmcia_device *link = lp->link;
369 int result = 0;
370 int hcf_status = HCF_SUCCESS;
371 /*--------------------------------------------------------------------*/
372
373 DBG_FUNC("wl_adapter_open");
374 DBG_ENTER(DbgInfo);
375 DBG_PRINT("%s\n", VERSION_INFO);
376 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
377
378 if (!pcmcia_dev_present(link)) {
379 DBG_LEAVE(DbgInfo);
380 return -ENODEV;
381 }
382
383 link->open++;
384
385 hcf_status = wl_open(dev);
386
387 if (hcf_status != HCF_SUCCESS) {
388 link->open--;
389 result = -ENODEV;
390 }
391
392 DBG_LEAVE(DbgInfo);
393 return result;
394 } /* wl_adapter_open */
395 /*============================================================================*/
396
397
398 /*******************************************************************************
399 * wl_adapter_close()
400 *******************************************************************************
401 *
402 * DESCRIPTION:
403 *
404 * Close the device.
405 *
406 * PARAMETERS:
407 *
408 * dev - a pointer to a net_device structure representing the network
409 * device to close.
410 *
411 * RETURNS:
412 *
413 * 0 on success
414 * errno value otherwise
415 *
416 ******************************************************************************/
417 int wl_adapter_close(struct net_device *dev)
418 {
419 struct wl_private *lp = wl_priv(dev);
420 struct pcmcia_device *link = lp->link;
421 /*--------------------------------------------------------------------*/
422
423 DBG_FUNC("wl_adapter_close");
424 DBG_ENTER(DbgInfo);
425 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
426
427 if (link == NULL) {
428 DBG_LEAVE(DbgInfo);
429 return -ENODEV;
430 }
431
432 DBG_TRACE(DbgInfo, "%s: Shutting down adapter.\n", dev->name);
433 wl_close(dev);
434
435 link->open--;
436
437 DBG_LEAVE(DbgInfo);
438 return 0;
439 } /* wl_adapter_close */
440 /*============================================================================*/
441
442 static struct pcmcia_device_id wl_adapter_ids[] = {
443 #if !((HCF_TYPE) & HCF_TYPE_HII5)
444 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0003),
445 PCMCIA_DEVICE_PROD_ID12("Agere Systems", "Wireless PC Card Model 0110",
446 0x33103a9b, 0xe175b0dd),
447 #else
448 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0004),
449 PCMCIA_DEVICE_PROD_ID12("Linksys", "WCF54G_Wireless-G_CompactFlash_Card",
450 0x0733cc81, 0x98a599e1),
451 #endif /* (HCF_TYPE) & HCF_TYPE_HII5 */
452 PCMCIA_DEVICE_NULL,
453 };
454 MODULE_DEVICE_TABLE(pcmcia, wl_adapter_ids);
455
456 static struct pcmcia_driver wlags49_driver = {
457 .owner = THIS_MODULE,
458 .name = DRIVER_NAME,
459 .probe = wl_adapter_attach,
460 .remove = wl_adapter_detach,
461 .id_table = wl_adapter_ids,
462 .suspend = wl_adapter_suspend,
463 .resume = wl_adapter_resume,
464 };
465
466
467
468 /*******************************************************************************
469 * wl_adapter_init_module()
470 *******************************************************************************
471 *
472 * DESCRIPTION:
473 *
474 * Called by init_module() to perform PCMCIA driver initialization.
475 *
476 * PARAMETERS:
477 *
478 * N/A
479 *
480 * RETURNS:
481 *
482 * 0 on success
483 * -1 on error
484 *
485 ******************************************************************************/
486 int wl_adapter_init_module(void)
487 {
488 int ret;
489 /*--------------------------------------------------------------------*/
490
491 DBG_FUNC("wl_adapter_init_module");
492 DBG_ENTER(DbgInfo);
493 DBG_TRACE(DbgInfo, "wl_adapter_init_module() -- PCMCIA\n");
494
495 ret = pcmcia_register_driver(&wlags49_driver);
496
497 DBG_LEAVE(DbgInfo);
498 return ret;
499 } /* wl_adapter_init_module */
500 /*============================================================================*/
501
502
503 /*******************************************************************************
504 * wl_adapter_cleanup_module()
505 *******************************************************************************
506 *
507 * DESCRIPTION:
508 *
509 * Called by cleanup_module() to perform driver uninitialization.
510 *
511 * PARAMETERS:
512 *
513 * N/A
514 *
515 * RETURNS:
516 *
517 * N/A
518 *
519 ******************************************************************************/
520 void wl_adapter_cleanup_module(void)
521 {
522 DBG_FUNC("wl_adapter_cleanup_module");
523 DBG_ENTER(DbgInfo);
524 DBG_TRACE(DbgInfo, "wl_adapter_cleanup_module() -- PCMCIA\n");
525
526
527 pcmcia_unregister_driver(&wlags49_driver);
528
529 DBG_LEAVE(DbgInfo);
530 return;
531 } /* wl_adapter_cleanup_module */
532 /*============================================================================*/
533
534
535 /*******************************************************************************
536 * wl_adapter_is_open()
537 *******************************************************************************
538 *
539 * DESCRIPTION:
540 *
541 * Check with Card Services to determine if this device is open.
542 *
543 * PARAMETERS:
544 *
545 * dev - a pointer to the net_device structure whose open status will be
546 * checked
547 *
548 * RETURNS:
549 *
550 * nonzero if device is open
551 * 0 otherwise
552 *
553 ******************************************************************************/
554 int wl_adapter_is_open(struct net_device *dev)
555 {
556 struct wl_private *lp = wl_priv(dev);
557 struct pcmcia_device *link = lp->link;
558
559 if (!pcmcia_dev_present(link))
560 return 0;
561
562 return link->open;
563 } /* wl_adapter_is_open */
564 /*============================================================================*/
565
566
567 #if DBG
568
569 /*******************************************************************************
570 * DbgEvent()
571 *******************************************************************************
572 *
573 * DESCRIPTION:
574 *
575 * Converts the card serivces events to text for debugging.
576 *
577 * PARAMETERS:
578 *
579 * mask - a integer representing the error(s) being reported by Card
580 * Services.
581 *
582 * RETURNS:
583 *
584 * a pointer to a string describing the error(s)
585 *
586 ******************************************************************************/
587 const char *DbgEvent(int mask)
588 {
589 static char DbgBuffer[256];
590 char *pBuf;
591 /*--------------------------------------------------------------------*/
592
593 pBuf = DbgBuffer;
594 *pBuf = '\0';
595
596
597 if (mask & CS_EVENT_WRITE_PROTECT)
598 strcat(pBuf, "WRITE_PROTECT ");
599
600 if (mask & CS_EVENT_CARD_LOCK)
601 strcat(pBuf, "CARD_LOCK ");
602
603 if (mask & CS_EVENT_CARD_INSERTION)
604 strcat(pBuf, "CARD_INSERTION ");
605
606 if (mask & CS_EVENT_CARD_REMOVAL)
607 strcat(pBuf, "CARD_REMOVAL ");
608
609 if (mask & CS_EVENT_BATTERY_DEAD)
610 strcat(pBuf, "BATTERY_DEAD ");
611
612 if (mask & CS_EVENT_BATTERY_LOW)
613 strcat(pBuf, "BATTERY_LOW ");
614
615 if (mask & CS_EVENT_READY_CHANGE)
616 strcat(pBuf, "READY_CHANGE ");
617
618 if (mask & CS_EVENT_CARD_DETECT)
619 strcat(pBuf, "CARD_DETECT ");
620
621 if (mask & CS_EVENT_RESET_REQUEST)
622 strcat(pBuf, "RESET_REQUEST ");
623
624 if (mask & CS_EVENT_RESET_PHYSICAL)
625 strcat(pBuf, "RESET_PHYSICAL ");
626
627 if (mask & CS_EVENT_CARD_RESET)
628 strcat(pBuf, "CARD_RESET ");
629
630 if (mask & CS_EVENT_REGISTRATION_COMPLETE)
631 strcat(pBuf, "REGISTRATION_COMPLETE ");
632
633 /* if (mask & CS_EVENT_RESET_COMPLETE)
634 strcat(pBuf, "RESET_COMPLETE "); */
635
636 if (mask & CS_EVENT_PM_SUSPEND)
637 strcat(pBuf, "PM_SUSPEND ");
638
639 if (mask & CS_EVENT_PM_RESUME)
640 strcat(pBuf, "PM_RESUME ");
641
642 if (mask & CS_EVENT_INSERTION_REQUEST)
643 strcat(pBuf, "INSERTION_REQUEST ");
644
645 if (mask & CS_EVENT_EJECTION_REQUEST)
646 strcat(pBuf, "EJECTION_REQUEST ");
647
648 if (mask & CS_EVENT_MTD_REQUEST)
649 strcat(pBuf, "MTD_REQUEST ");
650
651 if (mask & CS_EVENT_ERASE_COMPLETE)
652 strcat(pBuf, "ERASE_COMPLETE ");
653
654 if (mask & CS_EVENT_REQUEST_ATTENTION)
655 strcat(pBuf, "REQUEST_ATTENTION ");
656
657 if (mask & CS_EVENT_CB_DETECT)
658 strcat(pBuf, "CB_DETECT ");
659
660 if (mask & CS_EVENT_3VCARD)
661 strcat(pBuf, "3VCARD ");
662
663 if (mask & CS_EVENT_XVCARD)
664 strcat(pBuf, "XVCARD ");
665
666
667 if (*pBuf) {
668 pBuf[strlen(pBuf) - 1] = '\0';
669 } else {
670 if (mask != 0x0)
671 sprintf(pBuf, "<<0x%08x>>", mask);
672 }
673
674 return pBuf;
675 } /* DbgEvent */
676 /*============================================================================*/
677
678 #endif /* DBG */
This page took 0.072161 seconds and 5 git commands to generate.