1 /* $Id: hysdn_init.c,v 1.6.6.6 2001/09/23 22:24:54 kai Exp $
3 * Linux driver for HYSDN cards, init functions.
5 * Author Werner Cornelius (werner@titro.de) for Hypercope GmbH
6 * Copyright 1999 by Werner Cornelius (werner@titro.de)
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/poll.h>
16 #include <linux/vmalloc.h>
17 #include <linux/slab.h>
18 #include <linux/pci.h>
20 #include "hysdn_defs.h"
22 static struct pci_device_id hysdn_pci_tbl
[] = {
23 { PCI_VENDOR_ID_HYPERCOPE
, PCI_DEVICE_ID_HYPERCOPE_PLX
,
24 PCI_ANY_ID
, PCI_SUBDEVICE_ID_HYPERCOPE_METRO
, 0, 0, BD_METRO
},
25 { PCI_VENDOR_ID_HYPERCOPE
, PCI_DEVICE_ID_HYPERCOPE_PLX
,
26 PCI_ANY_ID
, PCI_SUBDEVICE_ID_HYPERCOPE_CHAMP2
, 0, 0, BD_CHAMP2
},
27 { PCI_VENDOR_ID_HYPERCOPE
, PCI_DEVICE_ID_HYPERCOPE_PLX
,
28 PCI_ANY_ID
, PCI_SUBDEVICE_ID_HYPERCOPE_ERGO
, 0, 0, BD_ERGO
},
29 { PCI_VENDOR_ID_HYPERCOPE
, PCI_DEVICE_ID_HYPERCOPE_PLX
,
30 PCI_ANY_ID
, PCI_SUBDEVICE_ID_HYPERCOPE_OLD_ERGO
, 0, 0, BD_ERGO
},
32 { } /* Terminating entry */
34 MODULE_DEVICE_TABLE(pci
, hysdn_pci_tbl
);
35 MODULE_DESCRIPTION("ISDN4Linux: Driver for HYSDN cards");
36 MODULE_AUTHOR("Werner Cornelius");
37 MODULE_LICENSE("GPL");
39 static char *hysdn_init_revision
= "$Revision: 1.6.6.6 $";
40 static int cardmax
; /* number of found cards */
41 hysdn_card
*card_root
= NULL
; /* pointer to first card */
42 static hysdn_card
*card_last
= NULL
; /* pointer to first card */
45 /****************************************************************************/
46 /* The module startup and shutdown code. Only compiled when used as module. */
47 /* Using the driver as module is always advisable, because the booting */
48 /* image becomes smaller and the driver code is only loaded when needed. */
49 /* Additionally newer versions may be activated without rebooting. */
50 /****************************************************************************/
52 /******************************************************/
53 /* extract revision number from string for log output */
54 /******************************************************/
56 hysdn_getrev(const char *revision
)
61 if ((p
= strchr(revision
, ':'))) {
71 /****************************************************************************/
72 /* init_module is called once when the module is loaded to do all necessary */
73 /* things like autodetect... */
74 /* If the return value of this function is 0 the init has been successful */
75 /* and the module is added to the list in /proc/modules, otherwise an error */
76 /* is assumed and the module will not be kept in memory. */
77 /****************************************************************************/
79 static int __devinit
hysdn_pci_init_one(struct pci_dev
*akt_pcidev
,
80 const struct pci_device_id
*ent
)
85 rc
= pci_enable_device(akt_pcidev
);
89 if (!(card
= kzalloc(sizeof(hysdn_card
), GFP_KERNEL
))) {
90 printk(KERN_ERR
"HYSDN: unable to alloc device mem \n");
94 card
->myid
= cardmax
; /* set own id */
95 card
->bus
= akt_pcidev
->bus
->number
;
96 card
->devfn
= akt_pcidev
->devfn
; /* slot + function */
97 card
->subsysid
= akt_pcidev
->subsystem_device
;
98 card
->irq
= akt_pcidev
->irq
;
99 card
->iobase
= pci_resource_start(akt_pcidev
, PCI_REG_PLX_IO_BASE
);
100 card
->plxbase
= pci_resource_start(akt_pcidev
, PCI_REG_PLX_MEM_BASE
);
101 card
->membase
= pci_resource_start(akt_pcidev
, PCI_REG_MEMORY_BASE
);
102 card
->brdtype
= BD_NONE
; /* unknown */
103 card
->debug_flags
= DEF_DEB_FLAGS
; /* set default debug */
104 card
->faxchans
= 0; /* default no fax channels */
105 card
->bchans
= 2; /* and 2 b-channels */
106 card
->brdtype
= ent
->driver_data
;
108 if (ergo_inithardware(card
)) {
109 printk(KERN_WARNING
"HYSDN: card at io 0x%04x already in use\n", card
->iobase
);
115 card
->next
= NULL
; /*end of chain */
117 card_last
->next
= card
; /* pointer to next card */
120 card_last
= card
; /* new chain end */
122 pci_set_drvdata(akt_pcidev
, card
);
128 pci_disable_device(akt_pcidev
);
132 static void __devexit
hysdn_pci_remove_one(struct pci_dev
*akt_pcidev
)
134 hysdn_card
*card
= pci_get_drvdata(akt_pcidev
);
136 pci_set_drvdata(akt_pcidev
, NULL
);
139 card
->stopcard(card
);
141 #ifdef CONFIG_HYSDN_CAPI
142 hycapi_capi_release(card
);
145 if (card
->releasehardware
)
146 card
->releasehardware(card
); /* free all hardware resources */
148 if (card
== card_root
) {
149 card_root
= card_root
->next
;
153 hysdn_card
*tmp
= card_root
;
155 if (tmp
->next
== card
)
156 tmp
->next
= card
->next
;
163 pci_disable_device(akt_pcidev
);
166 static struct pci_driver hysdn_pci_driver
= {
168 .id_table
= hysdn_pci_tbl
,
169 .probe
= hysdn_pci_init_one
,
170 .remove
= __devexit_p(hysdn_pci_remove_one
),
173 static int hysdn_have_procfs
;
181 strcpy(tmp
, hysdn_init_revision
);
182 printk(KERN_NOTICE
"HYSDN: module Rev: %s loaded\n", hysdn_getrev(tmp
));
183 strcpy(tmp
, hysdn_net_revision
);
184 printk(KERN_NOTICE
"HYSDN: network interface Rev: %s \n", hysdn_getrev(tmp
));
186 rc
= pci_register_driver(&hysdn_pci_driver
);
190 printk(KERN_INFO
"HYSDN: %d card(s) found.\n", cardmax
);
192 if (!hysdn_procconf_init())
193 hysdn_have_procfs
= 1;
195 #ifdef CONFIG_HYSDN_CAPI
198 printk(KERN_ERR
"HYCAPI: init failed\n");
200 if (hysdn_have_procfs
)
201 hysdn_procconf_release();
203 pci_unregister_driver(&hysdn_pci_driver
);
207 #endif /* CONFIG_HYSDN_CAPI */
209 return 0; /* no error */
213 /***********************************************************************/
214 /* cleanup_module is called when the module is released by the kernel. */
215 /* The routine is only called if init_module has been successful and */
216 /* the module counter has a value of 0. Otherwise this function will */
217 /* not be called. This function must release all resources still allo- */
218 /* cated as after the return from this function the module code will */
219 /* be removed from memory. */
220 /***********************************************************************/
224 if (hysdn_have_procfs
)
225 hysdn_procconf_release();
227 pci_unregister_driver(&hysdn_pci_driver
);
229 #ifdef CONFIG_HYSDN_CAPI
231 #endif /* CONFIG_HYSDN_CAPI */
233 printk(KERN_NOTICE
"HYSDN: module unloaded\n");
234 } /* cleanup_module */
236 module_init(hysdn_init
);
237 module_exit(hysdn_exit
);