1 /* $Id: tpam_main.c,v 1.1.2.3 2001/09/23 22:25:03 kai Exp $
3 * Turbo PAM ISDN driver for Linux. (Kernel Driver - main routines)
5 * Copyright 2001 Stelian Pop <stelian.pop@fr.alcove.com>, AlcĂ´ve
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
10 * For all support questions please contact: <support@auvertech.fr>
14 #include <linux/module.h>
15 #include <linux/pci.h>
16 #include <linux/sched.h>
17 #include <linux/interrupt.h>
19 #include <linux/init.h>
24 /* Local functions prototypes */
25 static int __devinit tpam_probe(struct pci_dev *, const struct pci_device_id *);
26 static void __devexit tpam_unregister_card(tpam_card *);
27 static void __devexit tpam_remove(struct pci_dev *);
28 static int __init tpam_init(void);
29 static void __exit tpam_exit(void);
32 static tpam_card *cards; /* = NULL; */
35 /* Configurable id of the driver */
36 static char *id = "tpam\0\0\0\0\0\0\0\0\0\0\0\0";
38 MODULE_DESCRIPTION("ISDN4Linux: Driver for TurboPAM ISDN cards");
39 MODULE_AUTHOR("Stelian Pop");
40 MODULE_LICENSE("GPL");
41 MODULE_PARM_DESC(id,"ID-String of the driver");
45 * Finds a board by its driver ID.
47 * driverId: driver ID (as referenced by the IDSN link layer)
49 * Return: the tpam_card structure if found, NULL on error.
51 tpam_card *tpam_findcard(int driverid) {
55 if (p->id == driverid)
63 * Finds a channel number by its ncoid.
68 * Return: the channel number if found, TPAM_CHANNEL_INVALID if not.
70 u32 tpam_findchannel(tpam_card *card, u32 ncoid) {
73 for (i = 0; i < TPAM_NBCHANNEL; ++i)
74 if (card->channels[i].ncoid == ncoid)
75 return card->channels[i].num;
76 return TPAM_CHANNEL_INVALID;
80 * Initializes and registers a new TurboPAM card.
83 * num: the board number
85 * Return: 0 if OK, <0 if error
87 static int __devinit tpam_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) {
91 /* allocate memory for the board structure */
92 if (!(card = (tpam_card *)kmalloc(sizeof(tpam_card), GFP_KERNEL))) {
93 printk(KERN_ERR "TurboPAM: tpam_register_card: "
98 memset((char *)card, 0, sizeof(tpam_card));
100 card->irq = dev->irq;
101 card->lock = SPIN_LOCK_UNLOCKED;
102 sprintf(card->interface.id, "%s%d", id, cards_num);
104 /* request interrupt */
105 if (request_irq(card->irq, &tpam_irq, SA_INTERRUPT | SA_SHIRQ,
106 card->interface.id, card)) {
107 printk(KERN_ERR "TurboPAM: tpam_register_card: "
108 "could not request irq %d\n", card->irq);
113 /* remap board memory */
114 if (!(card->bar0 = (unsigned long) ioremap(pci_resource_start(dev, 0),
116 printk(KERN_ERR "TurboPAM: tpam_register_card: "
117 "unable to remap bar0\n");
118 free_irq(card->irq, card);
123 /* reset the board */
124 readl(card->bar0 + TPAM_RESETPAM_REGISTER);
126 /* initialisation magic :-( */
127 copy_to_pam_dword(card, (void *)0x01800008, 0x00000030);
128 copy_to_pam_dword(card, (void *)0x01800010, 0x00000030);
129 copy_to_pam_dword(card, (void *)0x01800014, 0x42240822);
130 copy_to_pam_dword(card, (void *)0x01800018, 0x07114000);
131 copy_to_pam_dword(card, (void *)0x0180001c, 0x00000400);
132 copy_to_pam_dword(card, (void *)0x01840070, 0x00000010);
134 /* fill the ISDN link layer structure */
135 card->interface.owner = THIS_MODULE;
136 card->interface.channels = TPAM_NBCHANNEL;
137 card->interface.maxbufsize = TPAM_MAXBUFSIZE;
138 card->interface.features =
139 ISDN_FEATURE_P_EURO |
140 ISDN_FEATURE_L2_HDLC |
141 ISDN_FEATURE_L2_MODEM |
142 ISDN_FEATURE_L3_TRANS;
143 card->interface.hl_hdrlen = 0;
144 card->interface.command = tpam_command;
145 card->interface.writebuf_skb = tpam_writebuf_skb;
146 card->interface.writecmd = NULL;
147 card->interface.readstat = NULL;
149 /* register wrt the ISDN link layer */
150 if (!register_isdn(&card->interface)) {
151 printk(KERN_ERR "TurboPAM: tpam_register_card: "
152 "unable to register %s\n", card->interface.id);
153 free_irq(card->irq, card);
154 iounmap((void *)card->bar0);
158 card->id = card->interface.channels;
160 /* initialize all channels */
161 for (i = 0; i < TPAM_NBCHANNEL; ++i) {
162 card->channels[i].num = i;
163 card->channels[i].card = card;
164 card->channels[i].ncoid = TPAM_NCOID_INVALID;
165 card->channels[i].hdlc = 0;
166 card->channels[i].realhdlc = 0;
167 card->channels[i].hdlcshift = 0;
168 skb_queue_head_init(&card->channels[i].sendq);
171 /* initialize the rest of board structure */
172 card->channels_used = 0;
173 card->channels_tested = 0;
176 card->roundrobin = 0;
178 skb_queue_head_init(&card->sendq);
179 skb_queue_head_init(&card->recvq);
180 INIT_WORK(&card->recv_tq, (void *) (void *) tpam_recv_tq, card);
181 INIT_WORK(&card->send_tq, (void *) (void *) tpam_send_tq, card);
183 /* add the board at the end of the list of boards */
195 pci_set_drvdata(dev, card);
201 * Unregisters a TurboPAM board by releasing all its ressources (irq, mem etc).
205 static void __devexit tpam_unregister_card(tpam_card *card) {
208 /* prevent the ISDN link layer that the driver will be unloaded */
209 cmd.command = ISDN_STAT_UNLOAD;
210 cmd.driver = card->id;
211 (* card->interface.statcallb)(&cmd);
213 /* release interrupt */
214 free_irq(card->irq, card);
216 /* release mapped memory */
217 iounmap((void *)card->bar0);
223 static void __devexit tpam_remove(struct pci_dev *pcidev) {
224 tpam_card *card = pci_get_drvdata(pcidev);
227 /* remove from the list of cards */
232 while (c->next != card)
234 c->next = c->next->next;
237 /* unregister each board */
238 tpam_unregister_card(card);
240 /* and free the board structure itself */
244 static struct pci_device_id tpam_pci_tbl[] = {
245 { PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_TURBOPAM,
246 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
250 MODULE_DEVICE_TABLE(pci, tpam_pci_tbl);
252 static struct pci_driver tpam_driver = {
254 .id_table = tpam_pci_tbl,
256 .remove = __devexit_p(tpam_remove),
259 static int __init tpam_init(void) {
262 ret = pci_module_init(&tpam_driver);
265 printk(KERN_INFO "TurboPAM: %d card%s found, driver loaded.\n",
266 cards_num, (cards_num > 1) ? "s" : "");
270 static void __exit tpam_exit(void) {
271 pci_unregister_driver(&tpam_driver);
272 printk(KERN_INFO "TurboPAM: driver unloaded\n");
275 /* Module entry points */
276 module_init(tpam_init);
277 module_exit(tpam_exit);