b1pcmcia.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /* $Id: b1pcmcia.c,v 1.1.2.2 2004/01/16 21:09:27 keil Exp $
  2. *
  3. * Module for AVM B1/M1/M2 PCMCIA-card.
  4. *
  5. * Copyright 1999 by Carsten Paeth <calle@calle.de>
  6. *
  7. * This software may be used and distributed according to the terms
  8. * of the GNU General Public License, incorporated herein by reference.
  9. *
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/skbuff.h>
  14. #include <linux/delay.h>
  15. #include <linux/mm.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/ioport.h>
  18. #include <linux/init.h>
  19. #include <asm/io.h>
  20. #include <linux/capi.h>
  21. #include <linux/b1pcmcia.h>
  22. #include <linux/isdn/capicmd.h>
  23. #include <linux/isdn/capiutil.h>
  24. #include <linux/isdn/capilli.h>
  25. #include "avmcard.h"
  26. /* ------------------------------------------------------------- */
  27. static char *revision = "$Revision: 1.1.2.2 $";
  28. /* ------------------------------------------------------------- */
  29. MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM PCMCIA cards");
  30. MODULE_AUTHOR("Carsten Paeth");
  31. MODULE_LICENSE("GPL");
  32. /* ------------------------------------------------------------- */
  33. static void b1pcmcia_remove_ctr(struct capi_ctr *ctrl)
  34. {
  35. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  36. avmcard *card = cinfo->card;
  37. unsigned int port = card->port;
  38. b1_reset(port);
  39. b1_reset(port);
  40. detach_capi_ctr(ctrl);
  41. free_irq(card->irq, card);
  42. b1_free_card(card);
  43. }
  44. /* ------------------------------------------------------------- */
  45. static LIST_HEAD(cards);
  46. static char *b1pcmcia_procinfo(struct capi_ctr *ctrl);
  47. static int b1pcmcia_add_card(unsigned int port, unsigned irq,
  48. enum avmcardtype cardtype)
  49. {
  50. avmctrl_info *cinfo;
  51. avmcard *card;
  52. char *cardname;
  53. int retval;
  54. card = b1_alloc_card(1);
  55. if (!card) {
  56. printk(KERN_WARNING "b1pcmcia: no memory.\n");
  57. retval = -ENOMEM;
  58. goto err;
  59. }
  60. cinfo = card->ctrlinfo;
  61. switch (cardtype) {
  62. case avm_m1: sprintf(card->name, "m1-%x", port); break;
  63. case avm_m2: sprintf(card->name, "m2-%x", port); break;
  64. default: sprintf(card->name, "b1pcmcia-%x", port); break;
  65. }
  66. card->port = port;
  67. card->irq = irq;
  68. card->cardtype = cardtype;
  69. retval = request_irq(card->irq, b1_interrupt, IRQF_SHARED, card->name, card);
  70. if (retval) {
  71. printk(KERN_ERR "b1pcmcia: unable to get IRQ %d.\n",
  72. card->irq);
  73. retval = -EBUSY;
  74. goto err_free;
  75. }
  76. b1_reset(card->port);
  77. if ((retval = b1_detect(card->port, card->cardtype)) != 0) {
  78. printk(KERN_NOTICE "b1pcmcia: NO card at 0x%x (%d)\n",
  79. card->port, retval);
  80. retval = -ENODEV;
  81. goto err_free_irq;
  82. }
  83. b1_reset(card->port);
  84. b1_getrevision(card);
  85. cinfo->capi_ctrl.owner = THIS_MODULE;
  86. cinfo->capi_ctrl.driver_name = "b1pcmcia";
  87. cinfo->capi_ctrl.driverdata = cinfo;
  88. cinfo->capi_ctrl.register_appl = b1_register_appl;
  89. cinfo->capi_ctrl.release_appl = b1_release_appl;
  90. cinfo->capi_ctrl.send_message = b1_send_message;
  91. cinfo->capi_ctrl.load_firmware = b1_load_firmware;
  92. cinfo->capi_ctrl.reset_ctr = b1_reset_ctr;
  93. cinfo->capi_ctrl.procinfo = b1pcmcia_procinfo;
  94. cinfo->capi_ctrl.proc_fops = &b1ctl_proc_fops;
  95. strcpy(cinfo->capi_ctrl.name, card->name);
  96. retval = attach_capi_ctr(&cinfo->capi_ctrl);
  97. if (retval) {
  98. printk(KERN_ERR "b1pcmcia: attach controller failed.\n");
  99. goto err_free_irq;
  100. }
  101. switch (cardtype) {
  102. case avm_m1: cardname = "M1"; break;
  103. case avm_m2: cardname = "M2"; break;
  104. default : cardname = "B1 PCMCIA"; break;
  105. }
  106. printk(KERN_INFO "b1pcmcia: AVM %s at i/o %#x, irq %d, revision %d\n",
  107. cardname, card->port, card->irq, card->revision);
  108. list_add(&card->list, &cards);
  109. return cinfo->capi_ctrl.cnr;
  110. err_free_irq:
  111. free_irq(card->irq, card);
  112. err_free:
  113. b1_free_card(card);
  114. err:
  115. return retval;
  116. }
  117. /* ------------------------------------------------------------- */
  118. static char *b1pcmcia_procinfo(struct capi_ctr *ctrl)
  119. {
  120. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  121. if (!cinfo)
  122. return "";
  123. sprintf(cinfo->infobuf, "%s %s 0x%x %d r%d",
  124. cinfo->cardname[0] ? cinfo->cardname : "-",
  125. cinfo->version[VER_DRIVER] ? cinfo->version[VER_DRIVER] : "-",
  126. cinfo->card ? cinfo->card->port : 0x0,
  127. cinfo->card ? cinfo->card->irq : 0,
  128. cinfo->card ? cinfo->card->revision : 0
  129. );
  130. return cinfo->infobuf;
  131. }
  132. /* ------------------------------------------------------------- */
  133. int b1pcmcia_addcard_b1(unsigned int port, unsigned irq)
  134. {
  135. return b1pcmcia_add_card(port, irq, avm_b1pcmcia);
  136. }
  137. int b1pcmcia_addcard_m1(unsigned int port, unsigned irq)
  138. {
  139. return b1pcmcia_add_card(port, irq, avm_m1);
  140. }
  141. int b1pcmcia_addcard_m2(unsigned int port, unsigned irq)
  142. {
  143. return b1pcmcia_add_card(port, irq, avm_m2);
  144. }
  145. int b1pcmcia_delcard(unsigned int port, unsigned irq)
  146. {
  147. struct list_head *l;
  148. avmcard *card;
  149. list_for_each(l, &cards) {
  150. card = list_entry(l, avmcard, list);
  151. if (card->port == port && card->irq == irq) {
  152. b1pcmcia_remove_ctr(&card->ctrlinfo[0].capi_ctrl);
  153. return 0;
  154. }
  155. }
  156. return -ESRCH;
  157. }
  158. EXPORT_SYMBOL(b1pcmcia_addcard_b1);
  159. EXPORT_SYMBOL(b1pcmcia_addcard_m1);
  160. EXPORT_SYMBOL(b1pcmcia_addcard_m2);
  161. EXPORT_SYMBOL(b1pcmcia_delcard);
  162. static struct capi_driver capi_driver_b1pcmcia = {
  163. .name = "b1pcmcia",
  164. .revision = "1.0",
  165. };
  166. static int __init b1pcmcia_init(void)
  167. {
  168. char *p;
  169. char rev[32];
  170. if ((p = strchr(revision, ':')) != NULL && p[1]) {
  171. strlcpy(rev, p + 2, 32);
  172. if ((p = strchr(rev, '$')) != NULL && p > rev)
  173. *(p-1) = 0;
  174. } else
  175. strcpy(rev, "1.0");
  176. strlcpy(capi_driver_b1pcmcia.revision, rev, 32);
  177. register_capi_driver(&capi_driver_b1pcmcia);
  178. printk(KERN_INFO "b1pci: revision %s\n", rev);
  179. return 0;
  180. }
  181. static void __exit b1pcmcia_exit(void)
  182. {
  183. unregister_capi_driver(&capi_driver_b1pcmcia);
  184. }
  185. module_init(b1pcmcia_init);
  186. module_exit(b1pcmcia_exit);