avm_cs.c 6.9 KB

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