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