IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / isdn / hardware / eicon / divasmain.c
CommitLineData
1da177e4
LT
1/* $Id: divasmain.c,v 1.55.4.6 2005/02/09 19:28:20 armin Exp $
2 *
3 * Low level driver for Eicon DIVA Server ISDN cards.
4 *
5 * Copyright 2000-2003 by Armin Schindler (mac@melware.de)
6 * Copyright 2000-2003 Cytronics & Melware (info@melware.de)
7 *
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
10 */
11
1da177e4
LT
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/kernel.h>
15#include <linux/sched.h>
1da177e4
LT
16#include <asm/uaccess.h>
17#include <asm/io.h>
18#include <linux/ioport.h>
19#include <linux/workqueue.h>
20#include <linux/pci.h>
21#include <linux/smp_lock.h>
22#include <linux/interrupt.h>
23#include <linux/list.h>
24#include <linux/poll.h>
25#include <linux/kmod.h>
26
27#include "platform.h"
28#undef ID_MASK
29#undef N_DATA
30#include "pc.h"
31#include "di_defs.h"
32#include "divasync.h"
33#include "diva.h"
34#include "di.h"
35#include "io.h"
36#include "xdi_msg.h"
37#include "xdi_adapter.h"
38#include "xdi_vers.h"
39#include "diva_dma.h"
40#include "diva_pci.h"
41
42static char *main_revision = "$Revision: 1.55.4.6 $";
43
44static int major;
45
46static int dbgmask;
47
48MODULE_DESCRIPTION("Kernel driver for Eicon DIVA Server cards");
49MODULE_AUTHOR("Cytronics & Melware, Eicon Networks");
50MODULE_LICENSE("GPL");
51
52module_param(dbgmask, int, 0);
53MODULE_PARM_DESC(dbgmask, "initial debug mask");
54
55static char *DRIVERNAME =
56 "Eicon DIVA Server driver (http://www.melware.net)";
57static char *DRIVERLNAME = "divas";
58static char *DEVNAME = "Divas";
59char *DRIVERRELEASE_DIVAS = "2.0";
60
7d12e780 61extern irqreturn_t diva_os_irq_wrapper(int irq, void *context);
1da177e4
LT
62extern int create_divas_proc(void);
63extern void remove_divas_proc(void);
64extern void diva_get_vserial_number(PISDN_ADAPTER IoAdapter, char *buf);
65extern int divasfunc_init(int dbgmask);
66extern void divasfunc_exit(void);
67
68typedef struct _diva_os_thread_dpc {
69 struct tasklet_struct divas_task;
70 diva_os_soft_isr_t *psoft_isr;
71} diva_os_thread_dpc_t;
72
73/* --------------------------------------------------------------------------
74 PCI driver interface section
75 -------------------------------------------------------------------------- */
76/*
77 vendor, device Vendor and device ID to match (or PCI_ANY_ID)
78 subvendor, Subsystem vendor and device ID to match (or PCI_ANY_ID)
79 subdevice
80 class, Device class to match. The class_mask tells which bits
81 class_mask of the class are honored during the comparison.
82 driver_data Data private to the driver.
83 */
84
85#if !defined(PCI_DEVICE_ID_EICON_MAESTRAP_2)
86#define PCI_DEVICE_ID_EICON_MAESTRAP_2 0xE015
87#endif
88
89#if !defined(PCI_DEVICE_ID_EICON_4BRI_VOIP)
90#define PCI_DEVICE_ID_EICON_4BRI_VOIP 0xE016
91#endif
92
93#if !defined(PCI_DEVICE_ID_EICON_4BRI_2_VOIP)
94#define PCI_DEVICE_ID_EICON_4BRI_2_VOIP 0xE017
95#endif
96
97#if !defined(PCI_DEVICE_ID_EICON_BRI2M_2)
98#define PCI_DEVICE_ID_EICON_BRI2M_2 0xE018
99#endif
100
101#if !defined(PCI_DEVICE_ID_EICON_MAESTRAP_2_VOIP)
102#define PCI_DEVICE_ID_EICON_MAESTRAP_2_VOIP 0xE019
103#endif
104
105#if !defined(PCI_DEVICE_ID_EICON_2F)
106#define PCI_DEVICE_ID_EICON_2F 0xE01A
107#endif
108
109#if !defined(PCI_DEVICE_ID_EICON_BRI2M_2_VOIP)
110#define PCI_DEVICE_ID_EICON_BRI2M_2_VOIP 0xE01B
111#endif
112
113/*
114 This table should be sorted by PCI device ID
115 */
116static struct pci_device_id divas_pci_tbl[] = {
117/* Diva Server BRI-2M PCI 0xE010 */
118 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_MAESTRA,
119 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_MAESTRA_PCI},
120/* Diva Server 4BRI-8M PCI 0xE012 */
121 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_MAESTRAQ,
122 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_Q_8M_PCI},
123/* Diva Server 4BRI-8M 2.0 PCI 0xE013 */
124 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_MAESTRAQ_U,
125 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_Q_8M_V2_PCI},
126/* Diva Server PRI-30M PCI 0xE014 */
127 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_MAESTRAP,
128 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_P_30M_PCI},
129/* Diva Server PRI 2.0 adapter 0xE015 */
130 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_MAESTRAP_2,
131 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_P_30M_V2_PCI},
132/* Diva Server Voice 4BRI-8M PCI 0xE016 */
133 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_4BRI_VOIP,
134 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_VOICE_Q_8M_PCI},
135/* Diva Server Voice 4BRI-8M 2.0 PCI 0xE017 */
136 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_4BRI_2_VOIP,
137 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_VOICE_Q_8M_V2_PCI},
138/* Diva Server BRI-2M 2.0 PCI 0xE018 */
139 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_BRI2M_2,
140 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_B_2M_V2_PCI},
141/* Diva Server Voice PRI 2.0 PCI 0xE019 */
142 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_MAESTRAP_2_VOIP,
143 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
144 CARDTYPE_DIVASRV_VOICE_P_30M_V2_PCI},
145/* Diva Server 2FX 0xE01A */
146 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_2F,
147 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_B_2F_PCI},
148/* Diva Server Voice BRI-2M 2.0 PCI 0xE01B */
149 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_BRI2M_2_VOIP,
150 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_VOICE_B_2M_V2_PCI},
151 {0,} /* 0 terminated list. */
152};
153MODULE_DEVICE_TABLE(pci, divas_pci_tbl);
154
155static int divas_init_one(struct pci_dev *pdev,
156 const struct pci_device_id *ent);
157static void __devexit divas_remove_one(struct pci_dev *pdev);
158
159static struct pci_driver diva_pci_driver = {
160 .name = "divas",
161 .probe = divas_init_one,
162 .remove = __devexit_p(divas_remove_one),
163 .id_table = divas_pci_tbl,
164};
165
166/*********************************************************
167 ** little helper functions
168 *********************************************************/
169static char *getrev(const char *revision)
170{
171 char *rev;
172 char *p;
173 if ((p = strchr(revision, ':'))) {
174 rev = p + 2;
175 p = strchr(rev, '$');
176 *--p = 0;
177 } else
178 rev = "1.0";
179 return rev;
180}
181
182void diva_log_info(unsigned char *format, ...)
183{
184 va_list args;
185 unsigned char line[160];
186
187 va_start(args, format);
188 vsprintf(line, format, args);
189 va_end(args);
190
191 printk(KERN_INFO "%s: %s\n", DRIVERLNAME, line);
192}
193
194void divas_get_version(char *p)
195{
196 char tmprev[32];
197
198 strcpy(tmprev, main_revision);
199 sprintf(p, "%s: %s(%s) %s(%s) major=%d\n", DRIVERLNAME, DRIVERRELEASE_DIVAS,
200 getrev(tmprev), diva_xdi_common_code_build, DIVA_BUILD, major);
201}
202
203/* --------------------------------------------------------------------------
204 PCI Bus services
205 -------------------------------------------------------------------------- */
206byte diva_os_get_pci_bus(void *pci_dev_handle)
207{
208 struct pci_dev *pdev = (struct pci_dev *) pci_dev_handle;
209 return ((byte) pdev->bus->number);
210}
211
212byte diva_os_get_pci_func(void *pci_dev_handle)
213{
214 struct pci_dev *pdev = (struct pci_dev *) pci_dev_handle;
215 return ((byte) pdev->devfn);
216}
217
218unsigned long divasa_get_pci_irq(unsigned char bus, unsigned char func,
219 void *pci_dev_handle)
220{
221 unsigned char irq = 0;
222 struct pci_dev *dev = (struct pci_dev *) pci_dev_handle;
223
224 irq = dev->irq;
225
226 return ((unsigned long) irq);
227}
228
229unsigned long divasa_get_pci_bar(unsigned char bus, unsigned char func,
230 int bar, void *pci_dev_handle)
231{
232 unsigned long ret = 0;
233 struct pci_dev *dev = (struct pci_dev *) pci_dev_handle;
234
235 if (bar < 6) {
236 ret = dev->resource[bar].start;
237 }
238
239 DBG_TRC(("GOT BAR[%d]=%08x", bar, ret));
240
241 {
242 unsigned long type = (ret & 0x00000001);
243 if (type & PCI_BASE_ADDRESS_SPACE_IO) {
244 DBG_TRC((" I/O"));
245 ret &= PCI_BASE_ADDRESS_IO_MASK;
246 } else {
247 DBG_TRC((" memory"));
248 ret &= PCI_BASE_ADDRESS_MEM_MASK;
249 }
250 DBG_TRC((" final=%08x", ret));
251 }
252
253 return (ret);
254}
255
256void PCIwrite(byte bus, byte func, int offset, void *data, int length,
257 void *pci_dev_handle)
258{
259 struct pci_dev *dev = (struct pci_dev *) pci_dev_handle;
260
261 switch (length) {
262 case 1: /* byte */
263 pci_write_config_byte(dev, offset,
264 *(unsigned char *) data);
265 break;
266 case 2: /* word */
267 pci_write_config_word(dev, offset,
268 *(unsigned short *) data);
269 break;
270 case 4: /* dword */
271 pci_write_config_dword(dev, offset,
272 *(unsigned int *) data);
273 break;
274
275 default: /* buffer */
276 if (!(length % 4) && !(length & 0x03)) { /* Copy as dword */
277 dword *p = (dword *) data;
278 length /= 4;
279
280 while (length--) {
281 pci_write_config_dword(dev, offset,
282 *(unsigned int *)
283 p++);
284 }
285 } else { /* copy as byte stream */
286 byte *p = (byte *) data;
287
288 while (length--) {
289 pci_write_config_byte(dev, offset,
290 *(unsigned char *)
291 p++);
292 }
293 }
294 }
295}
296
297void PCIread(byte bus, byte func, int offset, void *data, int length,
298 void *pci_dev_handle)
299{
300 struct pci_dev *dev = (struct pci_dev *) pci_dev_handle;
301
302 switch (length) {
303 case 1: /* byte */
304 pci_read_config_byte(dev, offset, (unsigned char *) data);
305 break;
306 case 2: /* word */
307 pci_read_config_word(dev, offset, (unsigned short *) data);
308 break;
309 case 4: /* dword */
310 pci_read_config_dword(dev, offset, (unsigned int *) data);
311 break;
312
313 default: /* buffer */
314 if (!(length % 4) && !(length & 0x03)) { /* Copy as dword */
315 dword *p = (dword *) data;
316 length /= 4;
317
318 while (length--) {
319 pci_read_config_dword(dev, offset,
320 (unsigned int *)
321 p++);
322 }
323 } else { /* copy as byte stream */
324 byte *p = (byte *) data;
325
326 while (length--) {
327 pci_read_config_byte(dev, offset,
328 (unsigned char *)
329 p++);
330 }
331 }
332 }
333}
334
335/*
336 Init map with DMA pages. It is not problem if some allocations fail -
337 the channels that will not get one DMA page will use standard PIO
338 interface
339 */
340static void *diva_pci_alloc_consistent(struct pci_dev *hwdev,
341 size_t size,
342 dma_addr_t * dma_handle,
343 void **addr_handle)
344{
345 void *addr = pci_alloc_consistent(hwdev, size, dma_handle);
346
347 *addr_handle = addr;
348
349 return (addr);
350}
351
352void diva_init_dma_map(void *hdev,
353 struct _diva_dma_map_entry **ppmap, int nentries)
354{
355 struct pci_dev *pdev = (struct pci_dev *) hdev;
356 struct _diva_dma_map_entry *pmap =
357 diva_alloc_dma_map(hdev, nentries);
358
359 if (pmap) {
360 int i;
361 dma_addr_t dma_handle;
362 void *cpu_addr;
363 void *addr_handle;
364
365 for (i = 0; i < nentries; i++) {
366 if (!(cpu_addr = diva_pci_alloc_consistent(pdev,
367 PAGE_SIZE,
368 &dma_handle,
369 &addr_handle)))
370 {
371 break;
372 }
373 diva_init_dma_map_entry(pmap, i, cpu_addr,
374 (dword) dma_handle,
375 addr_handle);
376 DBG_TRC(("dma map alloc [%d]=(%08lx:%08x:%08lx)",
377 i, (unsigned long) cpu_addr,
378 (dword) dma_handle,
379 (unsigned long) addr_handle))}
380 }
381
382 *ppmap = pmap;
383}
384
385/*
386 Free all contained in the map entries and memory used by the map
387 Should be always called after adapter removal from DIDD array
388 */
389void diva_free_dma_map(void *hdev, struct _diva_dma_map_entry *pmap)
390{
391 struct pci_dev *pdev = (struct pci_dev *) hdev;
392 int i;
393 dword phys_addr;
394 void *cpu_addr;
395 dma_addr_t dma_handle;
396 void *addr_handle;
397
398 for (i = 0; (pmap != 0); i++) {
399 diva_get_dma_map_entry(pmap, i, &cpu_addr, &phys_addr);
400 if (!cpu_addr) {
401 break;
402 }
403 addr_handle = diva_get_entry_handle(pmap, i);
404 dma_handle = (dma_addr_t) phys_addr;
405 pci_free_consistent(pdev, PAGE_SIZE, addr_handle,
406 dma_handle);
407 DBG_TRC(("dma map free [%d]=(%08lx:%08x:%08lx)", i,
408 (unsigned long) cpu_addr, (dword) dma_handle,
409 (unsigned long) addr_handle))
410 }
411
412 diva_free_dma_mapping(pmap);
413}
414
415
416/*********************************************************
417 ** I/O port utilities
418 *********************************************************/
419
420int
421diva_os_register_io_port(void *adapter, int on, unsigned long port,
422 unsigned long length, const char *name, int id)
423{
424 if (on) {
425 if (!request_region(port, length, name)) {
426 DBG_ERR(("A: I/O: can't register port=%08x", port))
427 return (-1);
428 }
429 } else {
430 release_region(port, length);
431 }
432 return (0);
433}
434
435void __iomem *divasa_remap_pci_bar(diva_os_xdi_adapter_t *a, int id, unsigned long bar, unsigned long area_length)
436{
437 void __iomem *ret = ioremap(bar, area_length);
438 DBG_TRC(("remap(%08x)->%p", bar, ret));
439 return (ret);
440}
441
442void divasa_unmap_pci_bar(void __iomem *bar)
443{
444 if (bar) {
445 iounmap(bar);
446 }
447}
448
449/*********************************************************
450 ** I/O port access
451 *********************************************************/
452byte __inline__ inpp(void __iomem *addr)
453{
454 return (inb((unsigned long) addr));
455}
456
457word __inline__ inppw(void __iomem *addr)
458{
459 return (inw((unsigned long) addr));
460}
461
462void __inline__ inppw_buffer(void __iomem *addr, void *P, int length)
463{
464 insw((unsigned long) addr, (word *) P, length >> 1);
465}
466
467void __inline__ outppw_buffer(void __iomem *addr, void *P, int length)
468{
469 outsw((unsigned long) addr, (word *) P, length >> 1);
470}
471
472void __inline__ outppw(void __iomem *addr, word w)
473{
474 outw(w, (unsigned long) addr);
475}
476
477void __inline__ outpp(void __iomem *addr, word p)
478{
479 outb(p, (unsigned long) addr);
480}
481
482/* --------------------------------------------------------------------------
483 IRQ request / remove
484 -------------------------------------------------------------------------- */
485int diva_os_register_irq(void *context, byte irq, const char *name)
486{
487 int result = request_irq(irq, diva_os_irq_wrapper,
9ba02bec 488 IRQF_DISABLED | IRQF_SHARED, name, context);
1da177e4
LT
489 return (result);
490}
491
492void diva_os_remove_irq(void *context, byte irq)
493{
494 free_irq(irq, context);
495}
496
497/* --------------------------------------------------------------------------
498 DPC framework implementation
499 -------------------------------------------------------------------------- */
500static void diva_os_dpc_proc(unsigned long context)
501{
502 diva_os_thread_dpc_t *psoft_isr = (diva_os_thread_dpc_t *) context;
503 diva_os_soft_isr_t *pisr = psoft_isr->psoft_isr;
504
505 (*(pisr->callback)) (pisr, pisr->callback_context);
506}
507
508int diva_os_initialize_soft_isr(diva_os_soft_isr_t * psoft_isr,
509 diva_os_soft_isr_callback_t callback,
510 void *callback_context)
511{
512 diva_os_thread_dpc_t *pdpc;
513
514 pdpc = (diva_os_thread_dpc_t *) diva_os_malloc(0, sizeof(*pdpc));
515 if (!(psoft_isr->object = pdpc)) {
516 return (-1);
517 }
518 memset(pdpc, 0x00, sizeof(*pdpc));
519 psoft_isr->callback = callback;
520 psoft_isr->callback_context = callback_context;
521 pdpc->psoft_isr = psoft_isr;
522 tasklet_init(&pdpc->divas_task, diva_os_dpc_proc, (unsigned long)pdpc);
523
524 return (0);
525}
526
527int diva_os_schedule_soft_isr(diva_os_soft_isr_t * psoft_isr)
528{
529 if (psoft_isr && psoft_isr->object) {
530 diva_os_thread_dpc_t *pdpc =
531 (diva_os_thread_dpc_t *) psoft_isr->object;
532
533 tasklet_schedule(&pdpc->divas_task);
534 }
535
536 return (1);
537}
538
539int diva_os_cancel_soft_isr(diva_os_soft_isr_t * psoft_isr)
540{
541 return (0);
542}
543
544void diva_os_remove_soft_isr(diva_os_soft_isr_t * psoft_isr)
545{
546 if (psoft_isr && psoft_isr->object) {
547 diva_os_thread_dpc_t *pdpc =
548 (diva_os_thread_dpc_t *) psoft_isr->object;
549 void *mem;
550
551 tasklet_kill(&pdpc->divas_task);
552 flush_scheduled_work();
553 mem = psoft_isr->object;
554 psoft_isr->object = NULL;
555 diva_os_free(0, mem);
556 }
557}
558
559/*
560 * kernel/user space copy functions
561 */
562static int
563xdi_copy_to_user(void *os_handle, void __user *dst, const void *src, int length)
564{
565 if (copy_to_user(dst, src, length)) {
566 return (-EFAULT);
567 }
568 return (length);
569}
570
571static int
572xdi_copy_from_user(void *os_handle, void *dst, const void __user *src, int length)
573{
574 if (copy_from_user(dst, src, length)) {
575 return (-EFAULT);
576 }
577 return (length);
578}
579
580/*
581 * device node operations
582 */
583static int divas_open(struct inode *inode, struct file *file)
584{
585 return (0);
586}
587
588static int divas_release(struct inode *inode, struct file *file)
589{
590 if (file->private_data) {
591 diva_xdi_close_adapter(file->private_data, file);
592 }
593 return (0);
594}
595
596static ssize_t divas_write(struct file *file, const char __user *buf,
597 size_t count, loff_t * ppos)
598{
599 int ret = -EINVAL;
600
601 if (!file->private_data) {
602 file->private_data = diva_xdi_open_adapter(file, buf,
603 count,
604 xdi_copy_from_user);
605 }
606 if (!file->private_data) {
607 return (-ENODEV);
608 }
609
610 ret = diva_xdi_write(file->private_data, file,
611 buf, count, xdi_copy_from_user);
612 switch (ret) {
613 case -1: /* Message should be removed from rx mailbox first */
614 ret = -EBUSY;
615 break;
616 case -2: /* invalid adapter was specified in this call */
617 ret = -ENOMEM;
618 break;
619 case -3:
620 ret = -ENXIO;
621 break;
622 }
623 DBG_TRC(("write: ret %d", ret));
624 return (ret);
625}
626
627static ssize_t divas_read(struct file *file, char __user *buf,
628 size_t count, loff_t * ppos)
629{
630 int ret = -EINVAL;
631
632 if (!file->private_data) {
633 file->private_data = diva_xdi_open_adapter(file, buf,
634 count,
635 xdi_copy_from_user);
636 }
637 if (!file->private_data) {
638 return (-ENODEV);
639 }
640
641 ret = diva_xdi_read(file->private_data, file,
642 buf, count, xdi_copy_to_user);
643 switch (ret) {
644 case -1: /* RX mailbox is empty */
645 ret = -EAGAIN;
646 break;
647 case -2: /* no memory, mailbox was cleared, last command is failed */
648 ret = -ENOMEM;
649 break;
650 case -3: /* can't copy to user, retry */
651 ret = -EFAULT;
652 break;
653 }
654 DBG_TRC(("read: ret %d", ret));
655 return (ret);
656}
657
658static unsigned int divas_poll(struct file *file, poll_table * wait)
659{
660 if (!file->private_data) {
661 return (POLLERR);
662 }
663 return (POLLIN | POLLRDNORM);
664}
665
666static struct file_operations divas_fops = {
667 .owner = THIS_MODULE,
668 .llseek = no_llseek,
669 .read = divas_read,
670 .write = divas_write,
671 .poll = divas_poll,
672 .open = divas_open,
673 .release = divas_release
674};
675
676static void divas_unregister_chrdev(void)
677{
1da177e4
LT
678 unregister_chrdev(major, DEVNAME);
679}
680
681static int DIVA_INIT_FUNCTION divas_register_chrdev(void)
682{
683 if ((major = register_chrdev(0, DEVNAME, &divas_fops)) < 0)
684 {
685 printk(KERN_ERR "%s: failed to create /dev entry.\n",
686 DRIVERLNAME);
687 return (0);
688 }
1da177e4
LT
689
690 return (1);
691}
692
693/* --------------------------------------------------------------------------
694 PCI driver section
695 -------------------------------------------------------------------------- */
696static int __devinit divas_init_one(struct pci_dev *pdev,
697 const struct pci_device_id *ent)
698{
699 void *pdiva = NULL;
700 u8 pci_latency;
701 u8 new_latency = 32;
702
703 DBG_TRC(("%s bus: %08x fn: %08x insertion.\n",
704 CardProperties[ent->driver_data].Name,
705 pdev->bus->number, pdev->devfn))
706 printk(KERN_INFO "%s: %s bus: %08x fn: %08x insertion.\n",
707 DRIVERLNAME, CardProperties[ent->driver_data].Name,
708 pdev->bus->number, pdev->devfn);
709
710 if (pci_enable_device(pdev)) {
711 DBG_TRC(("%s: %s bus: %08x fn: %08x device init failed.\n",
712 DRIVERLNAME,
713 CardProperties[ent->driver_data].Name,
714 pdev->bus->number,
715 pdev->devfn))
716 printk(KERN_ERR
717 "%s: %s bus: %08x fn: %08x device init failed.\n",
718 DRIVERLNAME,
719 CardProperties[ent->driver_data].
720 Name, pdev->bus->number,
721 pdev->devfn);
722 return (-EIO);
723 }
724
725 pci_set_master(pdev);
726
727 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency);
728 if (!pci_latency) {
729 DBG_TRC(("%s: bus: %08x fn: %08x fix latency.\n",
730 DRIVERLNAME, pdev->bus->number, pdev->devfn))
731 printk(KERN_INFO
732 "%s: bus: %08x fn: %08x fix latency.\n",
733 DRIVERLNAME, pdev->bus->number, pdev->devfn);
734 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, new_latency);
735 }
736
737 if (!(pdiva = diva_driver_add_card(pdev, ent->driver_data))) {
738 DBG_TRC(("%s: %s bus: %08x fn: %08x card init failed.\n",
739 DRIVERLNAME,
740 CardProperties[ent->driver_data].Name,
741 pdev->bus->number,
742 pdev->devfn))
743 printk(KERN_ERR
744 "%s: %s bus: %08x fn: %08x card init failed.\n",
745 DRIVERLNAME,
746 CardProperties[ent->driver_data].
747 Name, pdev->bus->number,
748 pdev->devfn);
749 return (-EIO);
750 }
751
752 pci_set_drvdata(pdev, pdiva);
753
754 return (0);
755}
756
757static void __devexit divas_remove_one(struct pci_dev *pdev)
758{
759 void *pdiva = pci_get_drvdata(pdev);
760
761 DBG_TRC(("bus: %08x fn: %08x removal.\n",
762 pdev->bus->number, pdev->devfn))
763 printk(KERN_INFO "%s: bus: %08x fn: %08x removal.\n",
764 DRIVERLNAME, pdev->bus->number, pdev->devfn);
765
766 if (pdiva) {
767 diva_driver_remove_card(pdiva);
768 }
769
770}
771
772/* --------------------------------------------------------------------------
773 Driver Load / Startup
774 -------------------------------------------------------------------------- */
775static int DIVA_INIT_FUNCTION divas_init(void)
776{
777 char tmprev[50];
778 int ret = 0;
779
780 printk(KERN_INFO "%s\n", DRIVERNAME);
781 printk(KERN_INFO "%s: Rel:%s Rev:", DRIVERLNAME, DRIVERRELEASE_DIVAS);
782 strcpy(tmprev, main_revision);
783 printk("%s Build: %s(%s)\n", getrev(tmprev),
784 diva_xdi_common_code_build, DIVA_BUILD);
785 printk(KERN_INFO "%s: support for: ", DRIVERLNAME);
786#ifdef CONFIG_ISDN_DIVAS_BRIPCI
787 printk("BRI/PCI ");
788#endif
789#ifdef CONFIG_ISDN_DIVAS_PRIPCI
790 printk("PRI/PCI ");
791#endif
792 printk("adapters\n");
793
794 if (!divasfunc_init(dbgmask)) {
795 printk(KERN_ERR "%s: failed to connect to DIDD.\n",
796 DRIVERLNAME);
797 ret = -EIO;
798 goto out;
799 }
800
801 if (!divas_register_chrdev()) {
802#ifdef MODULE
803 divasfunc_exit();
804#endif
805 ret = -EIO;
806 goto out;
807 }
808
809 if (!create_divas_proc()) {
810#ifdef MODULE
811 remove_divas_proc();
812 divas_unregister_chrdev();
813 divasfunc_exit();
814#endif
815 printk(KERN_ERR "%s: failed to create proc entry.\n",
816 DRIVERLNAME);
817 ret = -EIO;
818 goto out;
819 }
820
821 if ((ret = pci_register_driver(&diva_pci_driver))) {
822#ifdef MODULE
823 remove_divas_proc();
824 divas_unregister_chrdev();
825 divasfunc_exit();
826#endif
827 printk(KERN_ERR "%s: failed to init pci driver.\n",
828 DRIVERLNAME);
829 goto out;
830 }
831 printk(KERN_INFO "%s: started with major %d\n", DRIVERLNAME, major);
832
833 out:
834 return (ret);
835}
836
837/* --------------------------------------------------------------------------
838 Driver Unload
839 -------------------------------------------------------------------------- */
840static void DIVA_EXIT_FUNCTION divas_exit(void)
841{
842 pci_unregister_driver(&diva_pci_driver);
843 remove_divas_proc();
844 divas_unregister_chrdev();
845 divasfunc_exit();
846
847 printk(KERN_INFO "%s: module unloaded.\n", DRIVERLNAME);
848}
849
850module_init(divas_init);
851module_exit(divas_exit);