elsa_cs.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*======================================================================
  2. An elsa_cs PCMCIA client driver
  3. This driver is for the Elsa PCM ISDN Cards, i.e. the MicroLink
  4. The contents of this file are subject to the Mozilla Public
  5. License Version 1.1 (the "License"); you may not use this file
  6. except in compliance with the License. You may obtain a copy of
  7. the License at http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS
  9. IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10. implied. See the License for the specific language governing
  11. rights and limitations under the License.
  12. The initial developer of the original code is David A. Hinds
  13. <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
  14. are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  15. Modifications from dummy_cs.c are Copyright (C) 1999-2001 Klaus
  16. Lichtenwalder <Lichtenwalder@ACM.org>. All Rights Reserved.
  17. Alternatively, the contents of this file may be used under the
  18. terms of the GNU General Public License version 2 (the "GPL"), in
  19. which case the provisions of the GPL are applicable instead of the
  20. above. If you wish to allow the use of your version of this file
  21. only under the terms of the GPL and not to allow others to use
  22. your version of this file under the MPL, indicate your decision
  23. by deleting the provisions above and replace them with the notice
  24. and other provisions required by the GPL. If you do not delete
  25. the provisions above, a recipient may use your version of this
  26. file under either the MPL or the GPL.
  27. ======================================================================*/
  28. #include <linux/module.h>
  29. #include <linux/kernel.h>
  30. #include <linux/init.h>
  31. #include <linux/ptrace.h>
  32. #include <linux/slab.h>
  33. #include <linux/string.h>
  34. #include <linux/timer.h>
  35. #include <linux/ioport.h>
  36. #include <asm/io.h>
  37. #include <pcmcia/cistpl.h>
  38. #include <pcmcia/cisreg.h>
  39. #include <pcmcia/ds.h>
  40. #include "hisax_cfg.h"
  41. MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for Elsa PCM cards");
  42. MODULE_AUTHOR("Klaus Lichtenwalder");
  43. MODULE_LICENSE("Dual MPL/GPL");
  44. /*====================================================================*/
  45. /* Parameters that can be set with 'insmod' */
  46. static int protocol = 2; /* EURO-ISDN Default */
  47. module_param(protocol, int, 0);
  48. static int elsa_cs_config(struct pcmcia_device *link);
  49. static void elsa_cs_release(struct pcmcia_device *link);
  50. static void elsa_cs_detach(struct pcmcia_device *p_dev);
  51. typedef struct local_info_t {
  52. struct pcmcia_device *p_dev;
  53. int busy;
  54. int cardnr;
  55. } local_info_t;
  56. static int elsa_cs_probe(struct pcmcia_device *link)
  57. {
  58. local_info_t *local;
  59. dev_dbg(&link->dev, "elsa_cs_attach()\n");
  60. /* Allocate space for private device-specific data */
  61. local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
  62. if (!local) return -ENOMEM;
  63. local->p_dev = link;
  64. link->priv = local;
  65. local->cardnr = -1;
  66. return elsa_cs_config(link);
  67. } /* elsa_cs_attach */
  68. static void elsa_cs_detach(struct pcmcia_device *link)
  69. {
  70. local_info_t *info = link->priv;
  71. dev_dbg(&link->dev, "elsa_cs_detach(0x%p)\n", link);
  72. info->busy = 1;
  73. elsa_cs_release(link);
  74. kfree(info);
  75. } /* elsa_cs_detach */
  76. static int elsa_cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
  77. {
  78. int j;
  79. p_dev->io_lines = 3;
  80. p_dev->resource[0]->end = 8;
  81. p_dev->resource[0]->flags &= IO_DATA_PATH_WIDTH;
  82. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
  83. if ((p_dev->resource[0]->end) && p_dev->resource[0]->start) {
  84. printk(KERN_INFO "(elsa_cs: looks like the 96 model)\n");
  85. if (!pcmcia_request_io(p_dev))
  86. return 0;
  87. } else {
  88. printk(KERN_INFO "(elsa_cs: looks like the 97 model)\n");
  89. for (j = 0x2f0; j > 0x100; j -= 0x10) {
  90. p_dev->resource[0]->start = j;
  91. if (!pcmcia_request_io(p_dev))
  92. return 0;
  93. }
  94. }
  95. return -ENODEV;
  96. }
  97. static int elsa_cs_config(struct pcmcia_device *link)
  98. {
  99. int i;
  100. IsdnCard_t icard;
  101. dev_dbg(&link->dev, "elsa_config(0x%p)\n", link);
  102. link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
  103. i = pcmcia_loop_config(link, elsa_cs_configcheck, NULL);
  104. if (i != 0)
  105. goto failed;
  106. if (!link->irq)
  107. goto failed;
  108. i = pcmcia_enable_device(link);
  109. if (i != 0)
  110. goto failed;
  111. icard.para[0] = link->irq;
  112. icard.para[1] = link->resource[0]->start;
  113. icard.protocol = protocol;
  114. icard.typ = ISDN_CTYPE_ELSA_PCMCIA;
  115. i = hisax_init_pcmcia(link, &(((local_info_t *)link->priv)->busy), &icard);
  116. if (i < 0) {
  117. printk(KERN_ERR "elsa_cs: failed to initialize Elsa "
  118. "PCMCIA %d with %pR\n", i, link->resource[0]);
  119. elsa_cs_release(link);
  120. } else
  121. ((local_info_t *)link->priv)->cardnr = i;
  122. return 0;
  123. failed:
  124. elsa_cs_release(link);
  125. return -ENODEV;
  126. } /* elsa_cs_config */
  127. static void elsa_cs_release(struct pcmcia_device *link)
  128. {
  129. local_info_t *local = link->priv;
  130. dev_dbg(&link->dev, "elsa_cs_release(0x%p)\n", link);
  131. if (local) {
  132. if (local->cardnr >= 0) {
  133. /* no unregister function with hisax */
  134. HiSax_closecard(local->cardnr);
  135. }
  136. }
  137. pcmcia_disable_device(link);
  138. } /* elsa_cs_release */
  139. static int elsa_suspend(struct pcmcia_device *link)
  140. {
  141. local_info_t *dev = link->priv;
  142. dev->busy = 1;
  143. return 0;
  144. }
  145. static int elsa_resume(struct pcmcia_device *link)
  146. {
  147. local_info_t *dev = link->priv;
  148. dev->busy = 0;
  149. return 0;
  150. }
  151. static const struct pcmcia_device_id elsa_ids[] = {
  152. PCMCIA_DEVICE_PROD_ID12("ELSA AG (Aachen, Germany)", "MicroLink ISDN/MC ", 0x983de2c4, 0x333ba257),
  153. PCMCIA_DEVICE_PROD_ID12("ELSA GmbH, Aachen", "MicroLink ISDN/MC ", 0x639e5718, 0x333ba257),
  154. PCMCIA_DEVICE_NULL
  155. };
  156. MODULE_DEVICE_TABLE(pcmcia, elsa_ids);
  157. static struct pcmcia_driver elsa_cs_driver = {
  158. .owner = THIS_MODULE,
  159. .name = "elsa_cs",
  160. .probe = elsa_cs_probe,
  161. .remove = elsa_cs_detach,
  162. .id_table = elsa_ids,
  163. .suspend = elsa_suspend,
  164. .resume = elsa_resume,
  165. };
  166. module_pcmcia_driver(elsa_cs_driver);