teles_cs.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* $Id: teles_cs.c,v 1.1.2.2 2004/01/25 15:07:06 keil Exp $ */
  2. /*======================================================================
  3. A teles S0 PCMCIA client driver
  4. Based on skeleton by David Hinds, dhinds@allegro.stanford.edu
  5. Written by Christof Petig, christof.petig@wtal.de
  6. Also inspired by ELSA PCMCIA driver
  7. by Klaus Lichtenwalder <Lichtenwalder@ACM.org>
  8. Extensions to new hisax_pcmcia by Karsten Keil
  9. minor changes to be compatible with kernel 2.4.x
  10. by Jan.Schubert@GMX.li
  11. ======================================================================*/
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/ptrace.h>
  16. #include <linux/slab.h>
  17. #include <linux/string.h>
  18. #include <linux/timer.h>
  19. #include <linux/ioport.h>
  20. #include <asm/io.h>
  21. #include <pcmcia/cistpl.h>
  22. #include <pcmcia/cisreg.h>
  23. #include <pcmcia/ds.h>
  24. #include "hisax_cfg.h"
  25. MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for Teles PCMCIA cards");
  26. MODULE_AUTHOR("Christof Petig, christof.petig@wtal.de, Karsten Keil, kkeil@suse.de");
  27. MODULE_LICENSE("GPL");
  28. /*====================================================================*/
  29. /* Parameters that can be set with 'insmod' */
  30. static int protocol = 2; /* EURO-ISDN Default */
  31. module_param(protocol, int, 0);
  32. static int teles_cs_config(struct pcmcia_device *link);
  33. static void teles_cs_release(struct pcmcia_device *link);
  34. static void teles_detach(struct pcmcia_device *p_dev);
  35. typedef struct local_info_t {
  36. struct pcmcia_device *p_dev;
  37. int busy;
  38. int cardnr;
  39. } local_info_t;
  40. static int teles_probe(struct pcmcia_device *link)
  41. {
  42. local_info_t *local;
  43. dev_dbg(&link->dev, "teles_attach()\n");
  44. /* Allocate space for private device-specific data */
  45. local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
  46. if (!local) return -ENOMEM;
  47. local->cardnr = -1;
  48. local->p_dev = link;
  49. link->priv = local;
  50. link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
  51. return teles_cs_config(link);
  52. } /* teles_attach */
  53. static void teles_detach(struct pcmcia_device *link)
  54. {
  55. local_info_t *info = link->priv;
  56. dev_dbg(&link->dev, "teles_detach(0x%p)\n", link);
  57. info->busy = 1;
  58. teles_cs_release(link);
  59. kfree(info);
  60. } /* teles_detach */
  61. static int teles_cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
  62. {
  63. int j;
  64. p_dev->io_lines = 5;
  65. p_dev->resource[0]->end = 96;
  66. p_dev->resource[0]->flags &= IO_DATA_PATH_WIDTH;
  67. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
  68. if ((p_dev->resource[0]->end) && p_dev->resource[0]->start) {
  69. printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
  70. if (!pcmcia_request_io(p_dev))
  71. return 0;
  72. } else {
  73. printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
  74. for (j = 0x2f0; j > 0x100; j -= 0x10) {
  75. p_dev->resource[0]->start = j;
  76. if (!pcmcia_request_io(p_dev))
  77. return 0;
  78. }
  79. }
  80. return -ENODEV;
  81. }
  82. static int teles_cs_config(struct pcmcia_device *link)
  83. {
  84. int i;
  85. IsdnCard_t icard;
  86. dev_dbg(&link->dev, "teles_config(0x%p)\n", link);
  87. i = pcmcia_loop_config(link, teles_cs_configcheck, NULL);
  88. if (i != 0)
  89. goto cs_failed;
  90. if (!link->irq)
  91. goto cs_failed;
  92. i = pcmcia_enable_device(link);
  93. if (i != 0)
  94. goto cs_failed;
  95. icard.para[0] = link->irq;
  96. icard.para[1] = link->resource[0]->start;
  97. icard.protocol = protocol;
  98. icard.typ = ISDN_CTYPE_TELESPCMCIA;
  99. i = hisax_init_pcmcia(link, &(((local_info_t *)link->priv)->busy), &icard);
  100. if (i < 0) {
  101. printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n",
  102. i, (unsigned int) link->resource[0]->start);
  103. teles_cs_release(link);
  104. return -ENODEV;
  105. }
  106. ((local_info_t *)link->priv)->cardnr = i;
  107. return 0;
  108. cs_failed:
  109. teles_cs_release(link);
  110. return -ENODEV;
  111. } /* teles_cs_config */
  112. static void teles_cs_release(struct pcmcia_device *link)
  113. {
  114. local_info_t *local = link->priv;
  115. dev_dbg(&link->dev, "teles_cs_release(0x%p)\n", link);
  116. if (local) {
  117. if (local->cardnr >= 0) {
  118. /* no unregister function with hisax */
  119. HiSax_closecard(local->cardnr);
  120. }
  121. }
  122. pcmcia_disable_device(link);
  123. } /* teles_cs_release */
  124. static int teles_suspend(struct pcmcia_device *link)
  125. {
  126. local_info_t *dev = link->priv;
  127. dev->busy = 1;
  128. return 0;
  129. }
  130. static int teles_resume(struct pcmcia_device *link)
  131. {
  132. local_info_t *dev = link->priv;
  133. dev->busy = 0;
  134. return 0;
  135. }
  136. static const struct pcmcia_device_id teles_ids[] = {
  137. PCMCIA_DEVICE_PROD_ID12("TELES", "S0/PC", 0x67b50eae, 0xe9e70119),
  138. PCMCIA_DEVICE_NULL,
  139. };
  140. MODULE_DEVICE_TABLE(pcmcia, teles_ids);
  141. static struct pcmcia_driver teles_cs_driver = {
  142. .owner = THIS_MODULE,
  143. .name = "teles_cs",
  144. .probe = teles_probe,
  145. .remove = teles_detach,
  146. .id_table = teles_ids,
  147. .suspend = teles_suspend,
  148. .resume = teles_resume,
  149. };
  150. module_pcmcia_driver(teles_cs_driver);