avma1_cs.c 9.2 KB

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