t1pci.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /* $Id: t1pci.c,v 1.1.2.2 2004/01/16 21:09:27 keil Exp $
  2. *
  3. * Module for AVM T1 PCI-card.
  4. *
  5. * Copyright 1999 by Carsten Paeth <calle@calle.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/config.h>
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/delay.h>
  16. #include <linux/mm.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/ioport.h>
  19. #include <linux/pci.h>
  20. #include <linux/capi.h>
  21. #include <linux/init.h>
  22. #include <asm/io.h>
  23. #include <linux/isdn/capicmd.h>
  24. #include <linux/isdn/capiutil.h>
  25. #include <linux/isdn/capilli.h>
  26. #include "avmcard.h"
  27. #undef CONFIG_T1PCI_DEBUG
  28. #undef CONFIG_T1PCI_POLLDEBUG
  29. /* ------------------------------------------------------------- */
  30. static char *revision = "$Revision: 1.1.2.2 $";
  31. /* ------------------------------------------------------------- */
  32. static struct pci_device_id t1pci_pci_tbl[] = {
  33. { PCI_VENDOR_ID_AVM, PCI_DEVICE_ID_AVM_T1, PCI_ANY_ID, PCI_ANY_ID },
  34. { } /* Terminating entry */
  35. };
  36. MODULE_DEVICE_TABLE(pci, t1pci_pci_tbl);
  37. MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM T1 PCI card");
  38. MODULE_AUTHOR("Carsten Paeth");
  39. MODULE_LICENSE("GPL");
  40. /* ------------------------------------------------------------- */
  41. static char *t1pci_procinfo(struct capi_ctr *ctrl);
  42. static int t1pci_add_card(struct capicardparams *p, struct pci_dev *pdev)
  43. {
  44. avmcard *card;
  45. avmctrl_info *cinfo;
  46. int retval;
  47. card = b1_alloc_card(1);
  48. if (!card) {
  49. printk(KERN_WARNING "t1pci: no memory.\n");
  50. retval = -ENOMEM;
  51. goto err;
  52. }
  53. card->dma = avmcard_dma_alloc("t1pci", pdev, 2048+128, 2048+128);
  54. if (!card->dma) {
  55. printk(KERN_WARNING "t1pci: no memory.\n");
  56. retval = -ENOMEM;
  57. goto err_free;
  58. }
  59. cinfo = card->ctrlinfo;
  60. sprintf(card->name, "t1pci-%x", p->port);
  61. card->port = p->port;
  62. card->irq = p->irq;
  63. card->membase = p->membase;
  64. card->cardtype = avm_t1pci;
  65. if (!request_region(card->port, AVMB1_PORTLEN, card->name)) {
  66. printk(KERN_WARNING "t1pci: ports 0x%03x-0x%03x in use.\n",
  67. card->port, card->port + AVMB1_PORTLEN);
  68. retval = -EBUSY;
  69. goto err_free_dma;
  70. }
  71. card->mbase = ioremap(card->membase, 64);
  72. if (!card->mbase) {
  73. printk(KERN_NOTICE "t1pci: can't remap memory at 0x%lx\n",
  74. card->membase);
  75. retval = -EIO;
  76. goto err_release_region;
  77. }
  78. b1dma_reset(card);
  79. retval = t1pci_detect(card);
  80. if (retval != 0) {
  81. if (retval < 6)
  82. printk(KERN_NOTICE "t1pci: NO card at 0x%x (%d)\n",
  83. card->port, retval);
  84. else
  85. printk(KERN_NOTICE "t1pci: card at 0x%x, but cable not connected or T1 has no power (%d)\n",
  86. card->port, retval);
  87. retval = -EIO;
  88. goto err_unmap;
  89. }
  90. b1dma_reset(card);
  91. retval = request_irq(card->irq, b1dma_interrupt, SA_SHIRQ, card->name, card);
  92. if (retval) {
  93. printk(KERN_ERR "t1pci: unable to get IRQ %d.\n", card->irq);
  94. retval = -EBUSY;
  95. goto err_unmap;
  96. }
  97. cinfo->capi_ctrl.owner = THIS_MODULE;
  98. cinfo->capi_ctrl.driver_name = "t1pci";
  99. cinfo->capi_ctrl.driverdata = cinfo;
  100. cinfo->capi_ctrl.register_appl = b1dma_register_appl;
  101. cinfo->capi_ctrl.release_appl = b1dma_release_appl;
  102. cinfo->capi_ctrl.send_message = b1dma_send_message;
  103. cinfo->capi_ctrl.load_firmware = b1dma_load_firmware;
  104. cinfo->capi_ctrl.reset_ctr = b1dma_reset_ctr;
  105. cinfo->capi_ctrl.procinfo = t1pci_procinfo;
  106. cinfo->capi_ctrl.ctr_read_proc = b1dmactl_read_proc;
  107. strcpy(cinfo->capi_ctrl.name, card->name);
  108. retval = attach_capi_ctr(&cinfo->capi_ctrl);
  109. if (retval) {
  110. printk(KERN_ERR "t1pci: attach controller failed.\n");
  111. retval = -EBUSY;
  112. goto err_free_irq;
  113. }
  114. card->cardnr = cinfo->capi_ctrl.cnr;
  115. printk(KERN_INFO "t1pci: AVM T1 PCI at i/o %#x, irq %d, mem %#lx\n",
  116. card->port, card->irq, card->membase);
  117. pci_set_drvdata(pdev, card);
  118. return 0;
  119. err_free_irq:
  120. free_irq(card->irq, card);
  121. err_unmap:
  122. iounmap(card->mbase);
  123. err_release_region:
  124. release_region(card->port, AVMB1_PORTLEN);
  125. err_free_dma:
  126. avmcard_dma_free(card->dma);
  127. err_free:
  128. b1_free_card(card);
  129. err:
  130. return retval;
  131. }
  132. /* ------------------------------------------------------------- */
  133. static void t1pci_remove(struct pci_dev *pdev)
  134. {
  135. avmcard *card = pci_get_drvdata(pdev);
  136. avmctrl_info *cinfo = card->ctrlinfo;
  137. b1dma_reset(card);
  138. detach_capi_ctr(&cinfo->capi_ctrl);
  139. free_irq(card->irq, card);
  140. iounmap(card->mbase);
  141. release_region(card->port, AVMB1_PORTLEN);
  142. avmcard_dma_free(card->dma);
  143. b1_free_card(card);
  144. }
  145. /* ------------------------------------------------------------- */
  146. static char *t1pci_procinfo(struct capi_ctr *ctrl)
  147. {
  148. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  149. if (!cinfo)
  150. return "";
  151. sprintf(cinfo->infobuf, "%s %s 0x%x %d 0x%lx",
  152. cinfo->cardname[0] ? cinfo->cardname : "-",
  153. cinfo->version[VER_DRIVER] ? cinfo->version[VER_DRIVER] : "-",
  154. cinfo->card ? cinfo->card->port : 0x0,
  155. cinfo->card ? cinfo->card->irq : 0,
  156. cinfo->card ? cinfo->card->membase : 0
  157. );
  158. return cinfo->infobuf;
  159. }
  160. /* ------------------------------------------------------------- */
  161. static int __devinit t1pci_probe(struct pci_dev *dev,
  162. const struct pci_device_id *ent)
  163. {
  164. struct capicardparams param;
  165. int retval;
  166. if (pci_enable_device(dev) < 0) {
  167. printk(KERN_ERR "t1pci: failed to enable AVM-T1-PCI\n");
  168. return -ENODEV;
  169. }
  170. pci_set_master(dev);
  171. param.port = pci_resource_start(dev, 1);
  172. param.irq = dev->irq;
  173. param.membase = pci_resource_start(dev, 0);
  174. printk(KERN_INFO "t1pci: PCI BIOS reports AVM-T1-PCI at i/o %#x, irq %d, mem %#x\n",
  175. param.port, param.irq, param.membase);
  176. retval = t1pci_add_card(&param, dev);
  177. if (retval != 0) {
  178. printk(KERN_ERR "t1pci: no AVM-T1-PCI at i/o %#x, irq %d detected, mem %#x\n",
  179. param.port, param.irq, param.membase);
  180. return -ENODEV;
  181. }
  182. return 0;
  183. }
  184. static struct pci_driver t1pci_pci_driver = {
  185. .name = "t1pci",
  186. .id_table = t1pci_pci_tbl,
  187. .probe = t1pci_probe,
  188. .remove = t1pci_remove,
  189. };
  190. static struct capi_driver capi_driver_t1pci = {
  191. .name = "t1pci",
  192. .revision = "1.0",
  193. };
  194. static int __init t1pci_init(void)
  195. {
  196. char *p;
  197. char rev[32];
  198. int err;
  199. if ((p = strchr(revision, ':')) != 0 && p[1]) {
  200. strlcpy(rev, p + 2, 32);
  201. if ((p = strchr(rev, '$')) != 0 && p > rev)
  202. *(p-1) = 0;
  203. } else
  204. strcpy(rev, "1.0");
  205. err = pci_register_driver(&t1pci_pci_driver);
  206. if (!err) {
  207. strlcpy(capi_driver_t1pci.revision, rev, 32);
  208. register_capi_driver(&capi_driver_t1pci);
  209. printk(KERN_INFO "t1pci: revision %s\n", rev);
  210. }
  211. return err;
  212. }
  213. static void __exit t1pci_exit(void)
  214. {
  215. unregister_capi_driver(&capi_driver_t1pci);
  216. pci_unregister_driver(&t1pci_pci_driver);
  217. }
  218. module_init(t1pci_init);
  219. module_exit(t1pci_exit);