Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
t1pci.c
Go to the documentation of this file.
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 <[email protected]>
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 
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 
28 #undef CONFIG_T1PCI_DEBUG
29 #undef CONFIG_T1PCI_POLLDEBUG
30 
31 /* ------------------------------------------------------------- */
32 static char *revision = "$Revision: 1.1.2.2 $";
33 /* ------------------------------------------------------------- */
34 
35 static struct pci_device_id t1pci_pci_tbl[] = {
37  { } /* Terminating entry */
38 };
39 
40 MODULE_DEVICE_TABLE(pci, t1pci_pci_tbl);
41 MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM T1 PCI card");
42 MODULE_AUTHOR("Carsten Paeth");
43 MODULE_LICENSE("GPL");
44 
45 /* ------------------------------------------------------------- */
46 
47 static char *t1pci_procinfo(struct capi_ctr *ctrl);
48 
49 static int t1pci_add_card(struct capicardparams *p, struct pci_dev *pdev)
50 {
51  avmcard *card;
52  avmctrl_info *cinfo;
53  int retval;
54 
55  card = b1_alloc_card(1);
56  if (!card) {
57  printk(KERN_WARNING "t1pci: no memory.\n");
58  retval = -ENOMEM;
59  goto err;
60  }
61 
62  card->dma = avmcard_dma_alloc("t1pci", pdev, 2048 + 128, 2048 + 128);
63  if (!card->dma) {
64  printk(KERN_WARNING "t1pci: no memory.\n");
65  retval = -ENOMEM;
66  goto err_free;
67  }
68 
69  cinfo = card->ctrlinfo;
70  sprintf(card->name, "t1pci-%x", p->port);
71  card->port = p->port;
72  card->irq = p->irq;
73  card->membase = p->membase;
74  card->cardtype = avm_t1pci;
75 
76  if (!request_region(card->port, AVMB1_PORTLEN, card->name)) {
77  printk(KERN_WARNING "t1pci: ports 0x%03x-0x%03x in use.\n",
78  card->port, card->port + AVMB1_PORTLEN);
79  retval = -EBUSY;
80  goto err_free_dma;
81  }
82 
83  card->mbase = ioremap(card->membase, 64);
84  if (!card->mbase) {
85  printk(KERN_NOTICE "t1pci: can't remap memory at 0x%lx\n",
86  card->membase);
87  retval = -EIO;
88  goto err_release_region;
89  }
90 
91  b1dma_reset(card);
92 
93  retval = t1pci_detect(card);
94  if (retval != 0) {
95  if (retval < 6)
96  printk(KERN_NOTICE "t1pci: NO card at 0x%x (%d)\n",
97  card->port, retval);
98  else
99  printk(KERN_NOTICE "t1pci: card at 0x%x, but cable not connected or T1 has no power (%d)\n",
100  card->port, retval);
101  retval = -EIO;
102  goto err_unmap;
103  }
104  b1dma_reset(card);
105 
106  retval = request_irq(card->irq, b1dma_interrupt, IRQF_SHARED, card->name, card);
107  if (retval) {
108  printk(KERN_ERR "t1pci: unable to get IRQ %d.\n", card->irq);
109  retval = -EBUSY;
110  goto err_unmap;
111  }
112 
113  cinfo->capi_ctrl.owner = THIS_MODULE;
114  cinfo->capi_ctrl.driver_name = "t1pci";
115  cinfo->capi_ctrl.driverdata = cinfo;
116  cinfo->capi_ctrl.register_appl = b1dma_register_appl;
117  cinfo->capi_ctrl.release_appl = b1dma_release_appl;
118  cinfo->capi_ctrl.send_message = b1dma_send_message;
119  cinfo->capi_ctrl.load_firmware = b1dma_load_firmware;
120  cinfo->capi_ctrl.reset_ctr = b1dma_reset_ctr;
121  cinfo->capi_ctrl.procinfo = t1pci_procinfo;
122  cinfo->capi_ctrl.proc_fops = &b1dmactl_proc_fops;
123  strcpy(cinfo->capi_ctrl.name, card->name);
124 
125  retval = attach_capi_ctr(&cinfo->capi_ctrl);
126  if (retval) {
127  printk(KERN_ERR "t1pci: attach controller failed.\n");
128  retval = -EBUSY;
129  goto err_free_irq;
130  }
131  card->cardnr = cinfo->capi_ctrl.cnr;
132 
133  printk(KERN_INFO "t1pci: AVM T1 PCI at i/o %#x, irq %d, mem %#lx\n",
134  card->port, card->irq, card->membase);
135 
136  pci_set_drvdata(pdev, card);
137  return 0;
138 
139 err_free_irq:
140  free_irq(card->irq, card);
141 err_unmap:
142  iounmap(card->mbase);
143 err_release_region:
145 err_free_dma:
146  avmcard_dma_free(card->dma);
147 err_free:
148  b1_free_card(card);
149 err:
150  return retval;
151 }
152 
153 /* ------------------------------------------------------------- */
154 
155 static void t1pci_remove(struct pci_dev *pdev)
156 {
157  avmcard *card = pci_get_drvdata(pdev);
158  avmctrl_info *cinfo = card->ctrlinfo;
159 
160  b1dma_reset(card);
161 
162  detach_capi_ctr(&cinfo->capi_ctrl);
163  free_irq(card->irq, card);
164  iounmap(card->mbase);
166  avmcard_dma_free(card->dma);
167  b1_free_card(card);
168 }
169 
170 /* ------------------------------------------------------------- */
171 
172 static char *t1pci_procinfo(struct capi_ctr *ctrl)
173 {
174  avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
175 
176  if (!cinfo)
177  return "";
178  sprintf(cinfo->infobuf, "%s %s 0x%x %d 0x%lx",
179  cinfo->cardname[0] ? cinfo->cardname : "-",
180  cinfo->version[VER_DRIVER] ? cinfo->version[VER_DRIVER] : "-",
181  cinfo->card ? cinfo->card->port : 0x0,
182  cinfo->card ? cinfo->card->irq : 0,
183  cinfo->card ? cinfo->card->membase : 0
184  );
185  return cinfo->infobuf;
186 }
187 
188 /* ------------------------------------------------------------- */
189 
190 static int __devinit t1pci_probe(struct pci_dev *dev,
191  const struct pci_device_id *ent)
192 {
193  struct capicardparams param;
194  int retval;
195 
196  if (pci_enable_device(dev) < 0) {
197  printk(KERN_ERR "t1pci: failed to enable AVM-T1-PCI\n");
198  return -ENODEV;
199  }
200  pci_set_master(dev);
201 
202  param.port = pci_resource_start(dev, 1);
203  param.irq = dev->irq;
204  param.membase = pci_resource_start(dev, 0);
205 
206  printk(KERN_INFO "t1pci: PCI BIOS reports AVM-T1-PCI at i/o %#x, irq %d, mem %#x\n",
207  param.port, param.irq, param.membase);
208 
209  retval = t1pci_add_card(&param, dev);
210  if (retval != 0) {
211  printk(KERN_ERR "t1pci: no AVM-T1-PCI at i/o %#x, irq %d detected, mem %#x\n",
212  param.port, param.irq, param.membase);
213  pci_disable_device(dev);
214  return -ENODEV;
215  }
216  return 0;
217 }
218 
219 static struct pci_driver t1pci_pci_driver = {
220  .name = "t1pci",
221  .id_table = t1pci_pci_tbl,
222  .probe = t1pci_probe,
223  .remove = t1pci_remove,
224 };
225 
226 static struct capi_driver capi_driver_t1pci = {
227  .name = "t1pci",
228  .revision = "1.0",
229 };
230 
231 static int __init t1pci_init(void)
232 {
233  char *p;
234  char rev[32];
235  int err;
236 
237  if ((p = strchr(revision, ':')) != NULL && p[1]) {
238  strlcpy(rev, p + 2, 32);
239  if ((p = strchr(rev, '$')) != NULL && p > rev)
240  *(p - 1) = 0;
241  } else
242  strcpy(rev, "1.0");
243 
244  err = pci_register_driver(&t1pci_pci_driver);
245  if (!err) {
246  strlcpy(capi_driver_t1pci.revision, rev, 32);
247  register_capi_driver(&capi_driver_t1pci);
248  printk(KERN_INFO "t1pci: revision %s\n", rev);
249  }
250  return err;
251 }
252 
253 static void __exit t1pci_exit(void)
254 {
255  unregister_capi_driver(&capi_driver_t1pci);
256  pci_unregister_driver(&t1pci_pci_driver);
257 }
258 
259 module_init(t1pci_init);
260 module_exit(t1pci_exit);