avma1_cs.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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);
  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);
  48. /*
  49. A linked list of "instances" of the skeleton device. Each actual
  50. PCMCIA card corresponds to one device instance, and is described
  51. by one struct pcmcia_device structure (defined in ds.h).
  52. You may not want to use a linked list for this -- for example, the
  53. memory card driver uses an array of struct pcmcia_device pointers, where minor
  54. device numbers are used to derive the corresponding array index.
  55. */
  56. /*
  57. A driver needs to provide a dev_node_t structure for each device
  58. on a card. In some cases, there is only one device per card (for
  59. example, ethernet cards, modems). In other cases, there may be
  60. many actual or logical devices (SCSI adapters, memory cards with
  61. multiple partitions). The dev_node_t structures need to be kept
  62. in a linked list starting at the 'dev' field of a struct pcmcia_device
  63. structure. We allocate them in the card's private data structure,
  64. because they generally can't be allocated dynamically.
  65. */
  66. typedef struct local_info_t {
  67. dev_node_t node;
  68. } local_info_t;
  69. /*======================================================================
  70. avma1cs_attach() creates an "instance" of the driver, allocating
  71. local data structures for one device. The device is registered
  72. with Card Services.
  73. The dev_link structure is initialized, but we don't actually
  74. configure the card at this point -- we wait until we receive a
  75. card insertion event.
  76. ======================================================================*/
  77. static int avma1cs_probe(struct pcmcia_device *p_dev)
  78. {
  79. local_info_t *local;
  80. dev_dbg(&p_dev->dev, "avma1cs_attach()\n");
  81. /* Allocate space for private device-specific data */
  82. local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
  83. if (!local)
  84. return -ENOMEM;
  85. p_dev->priv = local;
  86. /* The io structure describes IO port mapping */
  87. p_dev->io.NumPorts1 = 16;
  88. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  89. p_dev->io.NumPorts2 = 16;
  90. p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_16;
  91. p_dev->io.IOAddrLines = 5;
  92. /* Interrupt setup */
  93. p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
  94. /* General socket configuration */
  95. p_dev->conf.Attributes = CONF_ENABLE_IRQ;
  96. p_dev->conf.IntType = INT_MEMORY_AND_IO;
  97. p_dev->conf.ConfigIndex = 1;
  98. p_dev->conf.Present = PRESENT_OPTION;
  99. return avma1cs_config(p_dev);
  100. } /* avma1cs_attach */
  101. /*======================================================================
  102. This deletes a driver "instance". The device is de-registered
  103. with Card Services. If it has been released, all local data
  104. structures are freed. Otherwise, the structures will be freed
  105. when the device is released.
  106. ======================================================================*/
  107. static void avma1cs_detach(struct pcmcia_device *link)
  108. {
  109. dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link);
  110. avma1cs_release(link);
  111. kfree(link->priv);
  112. } /* avma1cs_detach */
  113. /*======================================================================
  114. avma1cs_config() is scheduled to run after a CARD_INSERTION event
  115. is received, to configure the PCMCIA socket, and to make the
  116. ethernet device available to the system.
  117. ======================================================================*/
  118. static int avma1cs_configcheck(struct pcmcia_device *p_dev,
  119. cistpl_cftable_entry_t *cf,
  120. cistpl_cftable_entry_t *dflt,
  121. unsigned int vcc,
  122. void *priv_data)
  123. {
  124. if (cf->io.nwin <= 0)
  125. return -ENODEV;
  126. p_dev->io.BasePort1 = cf->io.win[0].base;
  127. p_dev->io.NumPorts1 = cf->io.win[0].len;
  128. p_dev->io.NumPorts2 = 0;
  129. printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n",
  130. p_dev->io.BasePort1,
  131. p_dev->io.BasePort1+p_dev->io.NumPorts1-1);
  132. return pcmcia_request_io(p_dev, &p_dev->io);
  133. }
  134. static int avma1cs_config(struct pcmcia_device *link)
  135. {
  136. local_info_t *dev;
  137. int i;
  138. char devname[128];
  139. IsdnCard_t icard;
  140. int busy = 0;
  141. dev = link->priv;
  142. dev_dbg(&link->dev, "avma1cs_config(0x%p)\n", link);
  143. devname[0] = 0;
  144. if (link->prod_id[1])
  145. strlcpy(devname, link->prod_id[1], sizeof(devname));
  146. if (pcmcia_loop_config(link, avma1cs_configcheck, NULL))
  147. return -ENODEV;
  148. do {
  149. /*
  150. * allocate an interrupt line
  151. */
  152. i = pcmcia_request_irq(link, &link->irq);
  153. if (i != 0) {
  154. /* undo */
  155. pcmcia_disable_device(link);
  156. break;
  157. }
  158. /*
  159. * configure the PCMCIA socket
  160. */
  161. i = pcmcia_request_configuration(link, &link->conf);
  162. if (i != 0) {
  163. pcmcia_disable_device(link);
  164. break;
  165. }
  166. } while (0);
  167. /* At this point, the dev_node_t structure(s) should be
  168. initialized and arranged in a linked list at link->dev. */
  169. strcpy(dev->node.dev_name, "A1");
  170. dev->node.major = 45;
  171. dev->node.minor = 0;
  172. link->dev_node = &dev->node;
  173. /* If any step failed, release any partially configured state */
  174. if (i != 0) {
  175. avma1cs_release(link);
  176. return -ENODEV;
  177. }
  178. printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n",
  179. link->io.BasePort1, link->irq.AssignedIRQ);
  180. icard.para[0] = link->irq.AssignedIRQ;
  181. icard.para[1] = link->io.BasePort1;
  182. icard.protocol = isdnprot;
  183. icard.typ = ISDN_CTYPE_A1_PCMCIA;
  184. i = hisax_init_pcmcia(link, &busy, &icard);
  185. if (i < 0) {
  186. printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 PCMCIA %d at i/o %#x\n", i, link->io.BasePort1);
  187. avma1cs_release(link);
  188. return -ENODEV;
  189. }
  190. dev->node.minor = i;
  191. return 0;
  192. } /* avma1cs_config */
  193. /*======================================================================
  194. After a card is removed, avma1cs_release() will unregister the net
  195. device, and release the PCMCIA configuration. If the device is
  196. still open, this will be postponed until it is closed.
  197. ======================================================================*/
  198. static void avma1cs_release(struct pcmcia_device *link)
  199. {
  200. local_info_t *local = link->priv;
  201. dev_dbg(&link->dev, "avma1cs_release(0x%p)\n", link);
  202. /* now unregister function with hisax */
  203. HiSax_closecard(local->node.minor);
  204. pcmcia_disable_device(link);
  205. } /* avma1cs_release */
  206. static struct pcmcia_device_id avma1cs_ids[] = {
  207. PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
  208. PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b),
  209. PCMCIA_DEVICE_NULL
  210. };
  211. MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids);
  212. static struct pcmcia_driver avma1cs_driver = {
  213. .owner = THIS_MODULE,
  214. .drv = {
  215. .name = "avma1_cs",
  216. },
  217. .probe = avma1cs_probe,
  218. .remove = avma1cs_detach,
  219. .id_table = avma1cs_ids,
  220. };
  221. /*====================================================================*/
  222. static int __init init_avma1_cs(void)
  223. {
  224. return(pcmcia_register_driver(&avma1cs_driver));
  225. }
  226. static void __exit exit_avma1_cs(void)
  227. {
  228. pcmcia_unregister_driver(&avma1cs_driver);
  229. }
  230. module_init(init_avma1_cs);
  231. module_exit(exit_avma1_cs);