avma1_cs.c 6.9 KB

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