teles_cs.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. Extentions 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 <asm/system.h>
  22. #include <pcmcia/cistpl.h>
  23. #include <pcmcia/cisreg.h>
  24. #include <pcmcia/ds.h>
  25. #include "hisax_cfg.h"
  26. MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for Teles PCMCIA cards");
  27. MODULE_AUTHOR("Christof Petig, christof.petig@wtal.de, Karsten Keil, kkeil@suse.de");
  28. MODULE_LICENSE("GPL");
  29. /*====================================================================*/
  30. /* Parameters that can be set with 'insmod' */
  31. static int protocol = 2; /* EURO-ISDN Default */
  32. module_param(protocol, int, 0);
  33. static int teles_cs_config(struct pcmcia_device *link) __devinit ;
  34. static void teles_cs_release(struct pcmcia_device *link);
  35. static void teles_detach(struct pcmcia_device *p_dev) __devexit ;
  36. typedef struct local_info_t {
  37. struct pcmcia_device *p_dev;
  38. int busy;
  39. int cardnr;
  40. } local_info_t;
  41. static int __devinit teles_probe(struct pcmcia_device *link)
  42. {
  43. local_info_t *local;
  44. dev_dbg(&link->dev, "teles_attach()\n");
  45. /* Allocate space for private device-specific data */
  46. local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
  47. if (!local) return -ENOMEM;
  48. local->cardnr = -1;
  49. local->p_dev = link;
  50. link->priv = local;
  51. link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
  52. return teles_cs_config(link);
  53. } /* teles_attach */
  54. static void __devexit teles_detach(struct pcmcia_device *link)
  55. {
  56. local_info_t *info = link->priv;
  57. dev_dbg(&link->dev, "teles_detach(0x%p)\n", link);
  58. info->busy = 1;
  59. teles_cs_release(link);
  60. kfree(info);
  61. } /* teles_detach */
  62. static int teles_cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
  63. {
  64. int j;
  65. p_dev->io_lines = 5;
  66. p_dev->resource[0]->end = 96;
  67. p_dev->resource[0]->flags &= IO_DATA_PATH_WIDTH;
  68. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
  69. if ((p_dev->resource[0]->end) && p_dev->resource[0]->start) {
  70. printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
  71. if (!pcmcia_request_io(p_dev))
  72. return 0;
  73. } else {
  74. printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
  75. for (j = 0x2f0; j > 0x100; j -= 0x10) {
  76. p_dev->resource[0]->start = j;
  77. if (!pcmcia_request_io(p_dev))
  78. return 0;
  79. }
  80. }
  81. return -ENODEV;
  82. }
  83. static int __devinit teles_cs_config(struct pcmcia_device *link)
  84. {
  85. local_info_t *dev;
  86. int i;
  87. IsdnCard_t icard;
  88. dev_dbg(&link->dev, "teles_config(0x%p)\n", link);
  89. dev = link->priv;
  90. i = pcmcia_loop_config(link, teles_cs_configcheck, NULL);
  91. if (i != 0)
  92. goto cs_failed;
  93. if (!link->irq)
  94. goto cs_failed;
  95. i = pcmcia_enable_device(link);
  96. if (i != 0)
  97. goto cs_failed;
  98. icard.para[0] = link->irq;
  99. icard.para[1] = link->resource[0]->start;
  100. icard.protocol = protocol;
  101. icard.typ = ISDN_CTYPE_TELESPCMCIA;
  102. i = hisax_init_pcmcia(link, &(((local_info_t*)link->priv)->busy), &icard);
  103. if (i < 0) {
  104. printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n",
  105. i, (unsigned int) link->resource[0]->start);
  106. teles_cs_release(link);
  107. return -ENODEV;
  108. }
  109. ((local_info_t*)link->priv)->cardnr = i;
  110. return 0;
  111. cs_failed:
  112. teles_cs_release(link);
  113. return -ENODEV;
  114. } /* teles_cs_config */
  115. static void teles_cs_release(struct pcmcia_device *link)
  116. {
  117. local_info_t *local = link->priv;
  118. dev_dbg(&link->dev, "teles_cs_release(0x%p)\n", link);
  119. if (local) {
  120. if (local->cardnr >= 0) {
  121. /* no unregister function with hisax */
  122. HiSax_closecard(local->cardnr);
  123. }
  124. }
  125. pcmcia_disable_device(link);
  126. } /* teles_cs_release */
  127. static int teles_suspend(struct pcmcia_device *link)
  128. {
  129. local_info_t *dev = link->priv;
  130. dev->busy = 1;
  131. return 0;
  132. }
  133. static int teles_resume(struct pcmcia_device *link)
  134. {
  135. local_info_t *dev = link->priv;
  136. dev->busy = 0;
  137. return 0;
  138. }
  139. static struct pcmcia_device_id teles_ids[] = {
  140. PCMCIA_DEVICE_PROD_ID12("TELES", "S0/PC", 0x67b50eae, 0xe9e70119),
  141. PCMCIA_DEVICE_NULL,
  142. };
  143. MODULE_DEVICE_TABLE(pcmcia, teles_ids);
  144. static struct pcmcia_driver teles_cs_driver = {
  145. .owner = THIS_MODULE,
  146. .name = "teles_cs",
  147. .probe = teles_probe,
  148. .remove = __devexit_p(teles_detach),
  149. .id_table = teles_ids,
  150. .suspend = teles_suspend,
  151. .resume = teles_resume,
  152. };
  153. static int __init init_teles_cs(void)
  154. {
  155. return pcmcia_register_driver(&teles_cs_driver);
  156. }
  157. static void __exit exit_teles_cs(void)
  158. {
  159. pcmcia_unregister_driver(&teles_cs_driver);
  160. }
  161. module_init(init_teles_cs);
  162. module_exit(exit_teles_cs);