avm_cs.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* $Id: avm_cs.c,v 1.4.6.3 2001/09/23 22:24:33 kai Exp $
  2. *
  3. * A PCMCIA client driver for AVM B1/M1/M2
  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/init.h>
  14. #include <linux/ptrace.h>
  15. #include <linux/string.h>
  16. #include <linux/tty.h>
  17. #include <linux/serial.h>
  18. #include <linux/major.h>
  19. #include <asm/io.h>
  20. #include <asm/system.h>
  21. #include <pcmcia/cs.h>
  22. #include <pcmcia/cistpl.h>
  23. #include <pcmcia/ciscode.h>
  24. #include <pcmcia/ds.h>
  25. #include <pcmcia/cisreg.h>
  26. #include <linux/skbuff.h>
  27. #include <linux/capi.h>
  28. #include <linux/b1lli.h>
  29. #include <linux/b1pcmcia.h>
  30. /*====================================================================*/
  31. MODULE_DESCRIPTION("CAPI4Linux: PCMCIA client driver for AVM B1/M1/M2");
  32. MODULE_AUTHOR("Carsten Paeth");
  33. MODULE_LICENSE("GPL");
  34. /*====================================================================*/
  35. /*
  36. The event() function is this driver's Card Services event handler.
  37. It will be called by Card Services when an appropriate card status
  38. event is received. The config() and release() entry points are
  39. used to configure or release a socket, in response to card insertion
  40. and ejection events. They are invoked from the skeleton event
  41. handler.
  42. */
  43. static int avmcs_config(struct pcmcia_device *link);
  44. static void avmcs_release(struct pcmcia_device *link);
  45. /*
  46. The attach() and detach() entry points are used to create and destroy
  47. "instances" of the driver, where each instance represents everything
  48. needed to manage one actual PCMCIA card.
  49. */
  50. static void avmcs_detach(struct pcmcia_device *p_dev);
  51. /*======================================================================
  52. avmcs_attach() creates an "instance" of the driver, allocating
  53. local data structures for one device. The device is registered
  54. with Card Services.
  55. The dev_link structure is initialized, but we don't actually
  56. configure the card at this point -- we wait until we receive a
  57. card insertion event.
  58. ======================================================================*/
  59. static int avmcs_probe(struct pcmcia_device *p_dev)
  60. {
  61. /* The io structure describes IO port mapping */
  62. p_dev->resource[0]->end = 16;
  63. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
  64. /* General socket configuration */
  65. p_dev->conf.Attributes = CONF_ENABLE_IRQ;
  66. p_dev->conf.IntType = INT_MEMORY_AND_IO;
  67. p_dev->conf.ConfigIndex = 1;
  68. p_dev->conf.Present = PRESENT_OPTION;
  69. return avmcs_config(p_dev);
  70. } /* avmcs_attach */
  71. /*======================================================================
  72. This deletes a driver "instance". The device is de-registered
  73. with Card Services. If it has been released, all local data
  74. structures are freed. Otherwise, the structures will be freed
  75. when the device is released.
  76. ======================================================================*/
  77. static void avmcs_detach(struct pcmcia_device *link)
  78. {
  79. avmcs_release(link);
  80. } /* avmcs_detach */
  81. /*======================================================================
  82. avmcs_config() is scheduled to run after a CARD_INSERTION event
  83. is received, to configure the PCMCIA socket, and to make the
  84. ethernet device available to the system.
  85. ======================================================================*/
  86. static int avmcs_configcheck(struct pcmcia_device *p_dev,
  87. cistpl_cftable_entry_t *cf,
  88. cistpl_cftable_entry_t *dflt,
  89. unsigned int vcc,
  90. void *priv_data)
  91. {
  92. if (cf->io.nwin <= 0)
  93. return -ENODEV;
  94. p_dev->resource[0]->start = cf->io.win[0].base;
  95. p_dev->resource[0]->end = cf->io.win[0].len;
  96. return pcmcia_request_io(p_dev);
  97. }
  98. static int avmcs_config(struct pcmcia_device *link)
  99. {
  100. int i = -1;
  101. char devname[128];
  102. int cardtype;
  103. int (*addcard)(unsigned int port, unsigned irq);
  104. devname[0] = 0;
  105. if (link->prod_id[1])
  106. strlcpy(devname, link->prod_id[1], sizeof(devname));
  107. /*
  108. * find IO port
  109. */
  110. if (pcmcia_loop_config(link, avmcs_configcheck, NULL))
  111. return -ENODEV;
  112. do {
  113. if (!link->irq) {
  114. /* undo */
  115. pcmcia_disable_device(link);
  116. break;
  117. }
  118. /*
  119. * configure the PCMCIA socket
  120. */
  121. i = pcmcia_request_configuration(link, &link->conf);
  122. if (i != 0) {
  123. pcmcia_disable_device(link);
  124. break;
  125. }
  126. } while (0);
  127. if (devname[0]) {
  128. char *s = strrchr(devname, ' ');
  129. if (!s)
  130. s = devname;
  131. else s++;
  132. if (strcmp("M1", s) == 0) {
  133. cardtype = AVM_CARDTYPE_M1;
  134. } else if (strcmp("M2", s) == 0) {
  135. cardtype = AVM_CARDTYPE_M2;
  136. } else {
  137. cardtype = AVM_CARDTYPE_B1;
  138. }
  139. } else
  140. cardtype = AVM_CARDTYPE_B1;
  141. /* If any step failed, release any partially configured state */
  142. if (i != 0) {
  143. avmcs_release(link);
  144. return -ENODEV;
  145. }
  146. switch (cardtype) {
  147. case AVM_CARDTYPE_M1: addcard = b1pcmcia_addcard_m1; break;
  148. case AVM_CARDTYPE_M2: addcard = b1pcmcia_addcard_m2; break;
  149. default:
  150. case AVM_CARDTYPE_B1: addcard = b1pcmcia_addcard_b1; break;
  151. }
  152. if ((i = (*addcard)(link->resource[0]->start, link->irq)) < 0) {
  153. dev_err(&link->dev,
  154. "avm_cs: failed to add AVM-Controller at i/o %#x, irq %d\n",
  155. (unsigned int) link->resource[0]->start, link->irq);
  156. avmcs_release(link);
  157. return -ENODEV;
  158. }
  159. return 0;
  160. } /* avmcs_config */
  161. /*======================================================================
  162. After a card is removed, avmcs_release() will unregister the net
  163. device, and release the PCMCIA configuration. If the device is
  164. still open, this will be postponed until it is closed.
  165. ======================================================================*/
  166. static void avmcs_release(struct pcmcia_device *link)
  167. {
  168. b1pcmcia_delcard(link->resource[0]->start, link->irq);
  169. pcmcia_disable_device(link);
  170. } /* avmcs_release */
  171. static struct pcmcia_device_id avmcs_ids[] = {
  172. PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335),
  173. PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M1", 0x95d42008, 0x81e10430),
  174. PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M2", 0x95d42008, 0x18e8558a),
  175. PCMCIA_DEVICE_NULL
  176. };
  177. MODULE_DEVICE_TABLE(pcmcia, avmcs_ids);
  178. static struct pcmcia_driver avmcs_driver = {
  179. .owner = THIS_MODULE,
  180. .drv = {
  181. .name = "avm_cs",
  182. },
  183. .probe = avmcs_probe,
  184. .remove = avmcs_detach,
  185. .id_table = avmcs_ids,
  186. };
  187. static int __init avmcs_init(void)
  188. {
  189. return pcmcia_register_driver(&avmcs_driver);
  190. }
  191. static void __exit avmcs_exit(void)
  192. {
  193. pcmcia_unregister_driver(&avmcs_driver);
  194. }
  195. module_init(avmcs_init);
  196. module_exit(avmcs_exit);