- Linus: more PageDirty / swapcache handling
[davej-history.git] / drivers / isdn / hysdn / hysdn_init.c
blobc3443b74b2270a43e6d60c1dc4da20f52969e370
1 /* $Id: hysdn_init.c,v 1.6.6.1 2000/11/28 12:02:47 kai Exp $
3 * Linux driver for HYSDN cards, init functions.
4 * written by Werner Cornelius (werner@titro.de) for Hypercope GmbH
6 * Copyright 1999 by Werner Cornelius (werner@titro.de)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <linux/config.h>
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/version.h>
28 #include <linux/poll.h>
29 #include <linux/vmalloc.h>
30 #include <linux/malloc.h>
31 #include <linux/pci.h>
33 #include "hysdn_defs.h"
35 static char *hysdn_init_revision = "$Revision: 1.6.6.1 $";
36 int cardmax; /* number of found cards */
37 hysdn_card *card_root = NULL; /* pointer to first card */
39 /**********************************************/
40 /* table assigning PCI-sub ids to board types */
41 /* the last entry contains all 0 */
42 /**********************************************/
43 static struct {
44 word subid; /* PCI sub id */
45 uchar cardtyp; /* card type assigned */
46 } pci_subid_map[] = {
49 PCI_SUBDEVICE_ID_HYPERCOPE_METRO, BD_METRO
52 PCI_SUBDEVICE_ID_HYPERCOPE_CHAMP2, BD_CHAMP2
55 PCI_SUBDEVICE_ID_HYPERCOPE_ERGO, BD_ERGO
58 PCI_SUBDEVICE_ID_HYPERCOPE_OLD_ERGO, BD_ERGO
61 0, 0
62 } /* terminating entry */
65 static struct pci_device_id hysdn_pci_tbl[] __initdata = {
66 {PCI_VENDOR_ID_HYPERCOPE, PCI_DEVICE_ID_HYPERCOPE_PLX, PCI_ANY_ID, PCI_SUBDEVICE_ID_HYPERCOPE_METRO},
67 {PCI_VENDOR_ID_HYPERCOPE, PCI_DEVICE_ID_HYPERCOPE_PLX, PCI_ANY_ID, PCI_SUBDEVICE_ID_HYPERCOPE_CHAMP2},
68 {PCI_VENDOR_ID_HYPERCOPE, PCI_DEVICE_ID_HYPERCOPE_PLX, PCI_ANY_ID, PCI_SUBDEVICE_ID_HYPERCOPE_ERGO},
69 {PCI_VENDOR_ID_HYPERCOPE, PCI_DEVICE_ID_HYPERCOPE_PLX, PCI_ANY_ID, PCI_SUBDEVICE_ID_HYPERCOPE_OLD_ERGO},
70 { } /* Terminating entry */
72 MODULE_DEVICE_TABLE(pci, hysdn_pci_tbl);
74 /*********************************************************************/
75 /* search_cards searches for available cards in the pci config data. */
76 /* If a card is found, the card structure is allocated and the cards */
77 /* ressources are reserved. cardmax is incremented. */
78 /*********************************************************************/
79 static void
80 search_cards(void)
82 struct pci_dev *akt_pcidev = NULL;
83 hysdn_card *card, *card_last;
84 int i;
86 card_root = NULL;
87 card_last = NULL;
88 while ((akt_pcidev = pci_find_device(PCI_VENDOR_ID_HYPERCOPE, PCI_DEVICE_ID_HYPERCOPE_PLX,
89 akt_pcidev)) != NULL) {
90 if (pci_enable_device(akt_pcidev))
91 continue;
92 if (!(card = kmalloc(sizeof(hysdn_card), GFP_KERNEL))) {
93 printk(KERN_ERR "HYSDN: unable to alloc device mem \n");
94 return;
96 memset(card, 0, sizeof(hysdn_card));
97 card->myid = cardmax; /* set own id */
98 card->bus = akt_pcidev->bus->number;
99 card->devfn = akt_pcidev->devfn; /* slot + function */
100 card->subsysid = akt_pcidev->subsystem_device;
101 card->irq = akt_pcidev->irq;
102 card->iobase = pci_resource_start(akt_pcidev, PCI_REG_PLX_IO_BASE);
103 card->plxbase = pci_resource_start(akt_pcidev, PCI_REG_PLX_MEM_BASE);
104 card->membase = pci_resource_start(akt_pcidev, PCI_REG_MEMORY_BASE);
105 card->brdtype = BD_NONE; /* unknown */
106 card->debug_flags = DEF_DEB_FLAGS; /* set default debug */
107 card->faxchans = 0; /* default no fax channels */
108 card->bchans = 2; /* and 2 b-channels */
109 for (i = 0; pci_subid_map[i].subid; i++)
110 if (pci_subid_map[i].subid == card->subsysid) {
111 card->brdtype = pci_subid_map[i].cardtyp;
112 break;
114 if (card->brdtype != BD_NONE) {
115 if (ergo_inithardware(card)) {
116 printk(KERN_WARNING "HYSDN: card at io 0x%04x already in use\n", card->iobase);
117 kfree(card);
118 continue;
120 } else {
121 printk(KERN_WARNING "HYSDN: unknown card id 0x%04x\n", card->subsysid);
122 kfree(card); /* release mem */
123 continue;
125 cardmax++;
126 card->next = NULL; /*end of chain */
127 if (card_last)
128 card_last->next = card; /* pointer to next card */
129 else
130 card_root = card;
131 card_last = card; /* new chain end */
132 } /* device found */
133 } /* search_cards */
135 /************************************************************************************/
136 /* free_resources frees the acquired PCI resources and returns the allocated memory */
137 /************************************************************************************/
138 static void
139 free_resources(void)
141 hysdn_card *card;
143 while (card_root) {
144 card = card_root;
145 if (card->releasehardware)
146 card->releasehardware(card); /* free all hardware resources */
147 card_root = card_root->next; /* remove card from chain */
148 kfree(card); /* return mem */
150 } /* while card_root */
151 } /* free_resources */
153 /**************************************************************************/
154 /* stop_cards disables (hardware resets) all cards and disables interrupt */
155 /**************************************************************************/
156 static void
157 stop_cards(void)
159 hysdn_card *card;
161 card = card_root; /* first in chain */
162 while (card) {
163 if (card->stopcard)
164 card->stopcard(card);
165 card = card->next; /* remove card from chain */
166 } /* while card */
167 } /* stop_cards */
170 /****************************************************************************/
171 /* The module startup and shutdown code. Only compiled when used as module. */
172 /* Using the driver as module is always advisable, because the booting */
173 /* image becomes smaller and the driver code is only loaded when needed. */
174 /* Additionally newer versions may be activated without rebooting. */
175 /****************************************************************************/
176 #ifdef CONFIG_MODULES
178 /******************************************************/
179 /* extract revision number from string for log output */
180 /******************************************************/
181 char *
182 hysdn_getrev(const char *revision)
184 char *rev;
185 char *p;
187 if ((p = strchr(revision, ':'))) {
188 rev = p + 2;
189 p = strchr(rev, '$');
190 *--p = 0;
191 } else
192 rev = "???";
193 return rev;
197 /****************************************************************************/
198 /* init_module is called once when the module is loaded to do all necessary */
199 /* things like autodetect... */
200 /* If the return value of this function is 0 the init has been successfull */
201 /* and the module is added to the list in /proc/modules, otherwise an error */
202 /* is assumed and the module will not be kept in memory. */
203 /****************************************************************************/
205 init_module(void)
207 char tmp[50];
209 strcpy(tmp, hysdn_init_revision);
210 printk(KERN_NOTICE "HYSDN: module Rev: %s loaded\n", hysdn_getrev(tmp));
211 strcpy(tmp, hysdn_net_revision);
212 printk(KERN_NOTICE "HYSDN: network interface Rev: %s \n", hysdn_getrev(tmp));
213 if (!pci_present()) {
214 printk(KERN_ERR "HYSDN: no PCI bus present, module not loaded\n");
215 return (-1);
217 search_cards();
218 printk(KERN_INFO "HYSDN: %d card(s) found.\n", cardmax);
220 if (hysdn_procconf_init()) {
221 free_resources(); /* proc file_sys not created */
222 return (-1);
224 #ifdef CONFIG_HYSDN_CAPI
225 if(cardmax > 0) {
226 if(hycapi_init()) {
227 printk(KERN_ERR "HYCAPI: init failed\n");
228 return(-1);
231 #endif /* CONFIG_HYSDN_CAPI */
232 return (0); /* no error */
233 } /* init_module */
236 /***********************************************************************/
237 /* cleanup_module is called when the module is released by the kernel. */
238 /* The routine is only called if init_module has been successfull and */
239 /* the module counter has a value of 0. Otherwise this function will */
240 /* not be called. This function must release all resources still allo- */
241 /* cated as after the return from this function the module code will */
242 /* be removed from memory. */
243 /***********************************************************************/
244 void
245 cleanup_module(void)
247 #ifdef CONFIG_HYSDN_CAPI
248 hysdn_card *card;
249 #endif /* CONFIG_HYSDN_CAPI */
250 stop_cards();
251 #ifdef CONFIG_HYSDN_CAPI
252 card = card_root; /* first in chain */
253 while (card) {
254 hycapi_capi_release(card);
255 card = card->next; /* remove card from chain */
256 } /* while card */
257 hycapi_cleanup();
258 #endif /* CONFIG_HYSDN_CAPI */
259 hysdn_procconf_release();
260 free_resources();
261 printk(KERN_NOTICE "HYSDN: module unloaded\n");
262 } /* cleanup_module */
264 #endif /* CONFIG_MODULES */