teles_cs.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 <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. int i;
  86. IsdnCard_t icard;
  87. dev_dbg(&link->dev, "teles_config(0x%p)\n", link);
  88. i = pcmcia_loop_config(link, teles_cs_configcheck, NULL);
  89. if (i != 0)
  90. goto cs_failed;
  91. if (!link->irq)
  92. goto cs_failed;
  93. i = pcmcia_enable_device(link);
  94. if (i != 0)
  95. goto cs_failed;
  96. icard.para[0] = link->irq;
  97. icard.para[1] = link->resource[0]->start;
  98. icard.protocol = protocol;
  99. icard.typ = ISDN_CTYPE_TELESPCMCIA;
  100. i = hisax_init_pcmcia(link, &(((local_info_t*)link->priv)->busy), &icard);
  101. if (i < 0) {
  102. printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n",
  103. i, (unsigned int) link->resource[0]->start);
  104. teles_cs_release(link);
  105. return -ENODEV;
  106. }
  107. ((local_info_t*)link->priv)->cardnr = i;
  108. return 0;
  109. cs_failed:
  110. teles_cs_release(link);
  111. return -ENODEV;
  112. } /* teles_cs_config */
  113. static void teles_cs_release(struct pcmcia_device *link)
  114. {
  115. local_info_t *local = link->priv;
  116. dev_dbg(&link->dev, "teles_cs_release(0x%p)\n", link);
  117. if (local) {
  118. if (local->cardnr >= 0) {
  119. /* no unregister function with hisax */
  120. HiSax_closecard(local->cardnr);
  121. }
  122. }
  123. pcmcia_disable_device(link);
  124. } /* teles_cs_release */
  125. static int teles_suspend(struct pcmcia_device *link)
  126. {
  127. local_info_t *dev = link->priv;
  128. dev->busy = 1;
  129. return 0;
  130. }
  131. static int teles_resume(struct pcmcia_device *link)
  132. {
  133. local_info_t *dev = link->priv;
  134. dev->busy = 0;
  135. return 0;
  136. }
  137. static const struct pcmcia_device_id teles_ids[] = {
  138. PCMCIA_DEVICE_PROD_ID12("TELES", "S0/PC", 0x67b50eae, 0xe9e70119),
  139. PCMCIA_DEVICE_NULL,
  140. };
  141. MODULE_DEVICE_TABLE(pcmcia, teles_ids);
  142. static struct pcmcia_driver teles_cs_driver = {
  143. .owner = THIS_MODULE,
  144. .name = "teles_cs",
  145. .probe = teles_probe,
  146. .remove = __devexit_p(teles_detach),
  147. .id_table = teles_ids,
  148. .suspend = teles_suspend,
  149. .resume = teles_resume,
  150. };
  151. static int __init init_teles_cs(void)
  152. {
  153. return pcmcia_register_driver(&teles_cs_driver);
  154. }
  155. static void __exit exit_teles_cs(void)
  156. {
  157. pcmcia_unregister_driver(&teles_cs_driver);
  158. }
  159. module_init(init_teles_cs);
  160. module_exit(exit_teles_cs);