avma1_cs.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * PCMCIA client driver for AVM A1 / Fritz!PCMCIA
  3. *
  4. * Author Carsten Paeth
  5. * Copyright 1998-2001 by Carsten Paeth <calle@calle.in-berlin.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/slab.h>
  16. #include <linux/string.h>
  17. #include <asm/io.h>
  18. #include <asm/system.h>
  19. #include <pcmcia/cistpl.h>
  20. #include <pcmcia/ds.h>
  21. #include "hisax_cfg.h"
  22. MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for AVM A1/Fritz!PCMCIA cards");
  23. MODULE_AUTHOR("Carsten Paeth");
  24. MODULE_LICENSE("GPL");
  25. /*====================================================================*/
  26. /* Parameters that can be set with 'insmod' */
  27. static int isdnprot = 2;
  28. module_param(isdnprot, int, 0);
  29. /*====================================================================*/
  30. /*
  31. The event() function is this driver's Card Services event handler.
  32. It will be called by Card Services when an appropriate card status
  33. event is received. The config() and release() entry points are
  34. used to configure or release a socket, in response to card insertion
  35. and ejection events. They are invoked from the skeleton event
  36. handler.
  37. */
  38. static int avma1cs_config(struct pcmcia_device *link) __devinit ;
  39. static void avma1cs_release(struct pcmcia_device *link);
  40. /*
  41. The attach() and detach() entry points are used to create and destroy
  42. "instances" of the driver, where each instance represents everything
  43. needed to manage one actual PCMCIA card.
  44. */
  45. static void avma1cs_detach(struct pcmcia_device *p_dev) __devexit ;
  46. /*======================================================================
  47. avma1cs_attach() creates an "instance" of the driver, allocating
  48. local data structures for one device. The device is registered
  49. with Card Services.
  50. The dev_link structure is initialized, but we don't actually
  51. configure the card at this point -- we wait until we receive a
  52. card insertion event.
  53. ======================================================================*/
  54. static int __devinit avma1cs_probe(struct pcmcia_device *p_dev)
  55. {
  56. dev_dbg(&p_dev->dev, "avma1cs_attach()\n");
  57. /* General socket configuration */
  58. p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
  59. p_dev->config_index = 1;
  60. p_dev->config_regs = PRESENT_OPTION;
  61. return avma1cs_config(p_dev);
  62. } /* avma1cs_attach */
  63. /*======================================================================
  64. This deletes a driver "instance". The device is de-registered
  65. with Card Services. If it has been released, all local data
  66. structures are freed. Otherwise, the structures will be freed
  67. when the device is released.
  68. ======================================================================*/
  69. static void __devexit avma1cs_detach(struct pcmcia_device *link)
  70. {
  71. dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link);
  72. avma1cs_release(link);
  73. kfree(link->priv);
  74. } /* avma1cs_detach */
  75. /*======================================================================
  76. avma1cs_config() is scheduled to run after a CARD_INSERTION event
  77. is received, to configure the PCMCIA socket, and to make the
  78. ethernet device available to the system.
  79. ======================================================================*/
  80. static int avma1cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
  81. {
  82. p_dev->resource[0]->end = 16;
  83. p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  84. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
  85. p_dev->io_lines = 5;
  86. return pcmcia_request_io(p_dev);
  87. }
  88. static int __devinit avma1cs_config(struct pcmcia_device *link)
  89. {
  90. int i = -1;
  91. char devname[128];
  92. IsdnCard_t icard;
  93. int busy = 0;
  94. dev_dbg(&link->dev, "avma1cs_config(0x%p)\n", link);
  95. devname[0] = 0;
  96. if (link->prod_id[1])
  97. strlcpy(devname, link->prod_id[1], sizeof(devname));
  98. if (pcmcia_loop_config(link, avma1cs_configcheck, NULL))
  99. return -ENODEV;
  100. do {
  101. /*
  102. * allocate an interrupt line
  103. */
  104. if (!link->irq) {
  105. /* undo */
  106. pcmcia_disable_device(link);
  107. break;
  108. }
  109. /*
  110. * configure the PCMCIA socket
  111. */
  112. i = pcmcia_enable_device(link);
  113. if (i != 0) {
  114. pcmcia_disable_device(link);
  115. break;
  116. }
  117. } while (0);
  118. /* If any step failed, release any partially configured state */
  119. if (i != 0) {
  120. avma1cs_release(link);
  121. return -ENODEV;
  122. }
  123. icard.para[0] = link->irq;
  124. icard.para[1] = link->resource[0]->start;
  125. icard.protocol = isdnprot;
  126. icard.typ = ISDN_CTYPE_A1_PCMCIA;
  127. i = hisax_init_pcmcia(link, &busy, &icard);
  128. if (i < 0) {
  129. printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 "
  130. "PCMCIA %d at i/o %#x\n", i,
  131. (unsigned int) link->resource[0]->start);
  132. avma1cs_release(link);
  133. return -ENODEV;
  134. }
  135. link->priv = (void *) (unsigned long) i;
  136. return 0;
  137. } /* avma1cs_config */
  138. /*======================================================================
  139. After a card is removed, avma1cs_release() will unregister the net
  140. device, and release the PCMCIA configuration. If the device is
  141. still open, this will be postponed until it is closed.
  142. ======================================================================*/
  143. static void avma1cs_release(struct pcmcia_device *link)
  144. {
  145. unsigned long minor = (unsigned long) link->priv;
  146. dev_dbg(&link->dev, "avma1cs_release(0x%p)\n", link);
  147. /* now unregister function with hisax */
  148. HiSax_closecard(minor);
  149. pcmcia_disable_device(link);
  150. } /* avma1cs_release */
  151. static struct pcmcia_device_id avma1cs_ids[] = {
  152. PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
  153. PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b),
  154. PCMCIA_DEVICE_NULL
  155. };
  156. MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids);
  157. static struct pcmcia_driver avma1cs_driver = {
  158. .owner = THIS_MODULE,
  159. .name = "avma1_cs",
  160. .probe = avma1cs_probe,
  161. .remove = __devexit_p(avma1cs_detach),
  162. .id_table = avma1cs_ids,
  163. };
  164. /*====================================================================*/
  165. static int __init init_avma1_cs(void)
  166. {
  167. return pcmcia_register_driver(&avma1cs_driver);
  168. }
  169. static void __exit exit_avma1_cs(void)
  170. {
  171. pcmcia_unregister_driver(&avma1cs_driver);
  172. }
  173. module_init(init_avma1_cs);
  174. module_exit(exit_avma1_cs);