* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / isdn / eicon / eicon_pci.c
blobc1919e9f810c4f432259c3da3a1f81de14148905
1 /* $Id: eicon_pci.c,v 1.10 1999/08/22 20:26:49 calle Exp $
3 * ISDN low-level module for Eicon.Diehl active ISDN-Cards.
4 * Hardware-specific code for PCI cards.
6 * Copyright 1998,99 by Armin Schindler (mac@melware.de)
7 * Copyright 1999 Cytronics & Melware (info@melware.de)
9 * Thanks to Eicon Technology Diehl GmbH & Co. oHG for
10 * documents, informations and hardware.
12 * Deutsche Telekom AG for S2M support.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * $Log: eicon_pci.c,v $
29 * Revision 1.10 1999/08/22 20:26:49 calle
30 * backported changes from kernel 2.3.14:
31 * - several #include "config.h" gone, others come.
32 * - "struct device" changed to "struct net_device" in 2.3.14, added a
33 * define in isdn_compat.h for older kernel versions.
35 * Revision 1.9 1999/08/11 21:01:11 keil
36 * new PCI codefix
38 * Revision 1.8 1999/08/10 16:02:20 calle
39 * struct pci_dev changed in 2.3.13. Made the necessary changes.
41 * Revision 1.7 1999/06/09 19:31:29 armin
42 * Wrong PLX size for request_region() corrected.
43 * Added first MCA code from Erik Weber.
45 * Revision 1.6 1999/04/01 12:48:37 armin
46 * Changed some log outputs.
48 * Revision 1.5 1999/03/29 11:19:49 armin
49 * I/O stuff now in seperate file (eicon_io.c)
50 * Old ISA type cards (S,SX,SCOM,Quadro,S2M) implemented.
52 * Revision 1.4 1999/03/02 12:37:48 armin
53 * Added some important checks.
54 * Analog Modem with DSP.
55 * Channels will be added to Link-Level after loading firmware.
57 * Revision 1.3 1999/01/24 20:14:24 armin
58 * Changed and added debug stuff.
59 * Better data sending. (still problems with tty's flip buffer)
61 * Revision 1.2 1999/01/10 18:46:06 armin
62 * Bug with wrong values in HLC fixed.
63 * Bytes to send are counted and limited now.
65 * Revision 1.1 1999/01/01 18:09:45 armin
66 * First checkin of new eicon driver.
67 * DIVA-Server BRI/PCI and PRI/PCI are supported.
68 * Old diehl code is obsolete.
73 #include <linux/config.h>
74 #include <linux/pci.h>
76 #include "eicon.h"
77 #include "eicon_pci.h"
80 char *eicon_pci_revision = "$Revision: 1.10 $";
82 #if CONFIG_PCI /* intire stuff is only for PCI */
84 #undef EICON_PCI_DEBUG
86 int eicon_pci_find_card(char *ID)
88 if (pci_present()) {
89 struct pci_dev *pdev = NULL;
90 int pci_nextindex=0, pci_cards=0, pci_akt=0;
91 int pci_type = PCI_MAESTRA;
92 int NoMorePCICards = FALSE;
93 char *ram, *reg, *cfg;
94 unsigned int pram=0, preg=0, pcfg=0;
95 char did[12];
96 eicon_pci_card *aparms;
98 if (!(aparms = (eicon_pci_card *) kmalloc(sizeof(eicon_pci_card), GFP_KERNEL))) {
99 printk(KERN_WARNING
100 "eicon_pci: Could not allocate card-struct.\n");
101 return 0;
104 for (pci_cards = 0; pci_cards < 0x0f; pci_cards++)
106 do {
107 if ((pdev = pci_find_device(PCI_VENDOR_EICON,
108 pci_type,
109 pdev)))
111 pci_nextindex++;
112 break;
114 else {
115 pci_nextindex = 0;
116 switch (pci_type) /* switch to next card type */
118 case PCI_MAESTRA:
119 pci_type = PCI_MAESTRAQ; break;
120 case PCI_MAESTRAQ:
121 pci_type = PCI_MAESTRAQ_U; break;
122 case PCI_MAESTRAQ_U:
123 pci_type = PCI_MAESTRAP; break;
124 default:
125 case PCI_MAESTRAP:
126 NoMorePCICards = TRUE;
130 while (!NoMorePCICards);
131 if (NoMorePCICards)
133 if (pci_cards < 1) {
134 printk(KERN_INFO "Eicon: No supported PCI cards found.\n");
135 kfree(aparms);
136 return 0;
138 else
140 printk(KERN_INFO "Eicon: %d PCI card%s registered.\n",
141 pci_cards, (pci_cards > 1) ? "s":"");
142 kfree(aparms);
143 return (pci_cards);
147 pci_akt = 0;
148 switch(pci_type)
150 case PCI_MAESTRA:
151 printk(KERN_INFO "Eicon: DIVA Server BRI/PCI detected !\n");
152 aparms->type = EICON_CTYPE_MAESTRA;
154 aparms->irq = pdev->irq;
155 preg = get_pcibase(pdev, 2) & 0xfffffffc;
156 pcfg = get_pcibase(pdev, 1) & 0xffffff80;
158 #ifdef EICON_PCI_DEBUG
159 printk(KERN_DEBUG "eicon_pci: irq=%d\n", aparms->irq);
160 printk(KERN_DEBUG "eicon_pci: reg=0x%x\n", preg);
161 printk(KERN_DEBUG "eicon_pci: cfg=0x%x\n", pcfg);
162 #endif
163 pci_akt = 1;
164 break;
166 case PCI_MAESTRAQ:
167 case PCI_MAESTRAQ_U:
168 printk(KERN_ERR "Eicon: DIVA Server 4BRI/PCI detected but not supported !\n");
169 pci_cards--;
170 pci_akt = 0;
171 break;
173 case PCI_MAESTRAP:
174 printk(KERN_INFO "Eicon: DIVA Server PRI/PCI detected !\n");
175 aparms->type = EICON_CTYPE_MAESTRAP; /*includes 9M,30M*/
176 aparms->irq = pdev->irq;
177 pram = get_pcibase(pdev, 0) & 0xfffff000;
178 preg = get_pcibase(pdev, 2) & 0xfffff000;
179 pcfg = get_pcibase(pdev, 4) & 0xfffff000;
181 #ifdef EICON_PCI_DEBUG
182 printk(KERN_DEBUG "eicon_pci: irq=%d\n", aparms->irq);
183 printk(KERN_DEBUG "eicon_pci: ram=0x%x\n",
184 (pram));
185 printk(KERN_DEBUG "eicon_pci: reg=0x%x\n",
186 (preg));
187 printk(KERN_DEBUG "eicon_pci: cfg=0x%x\n",
188 (pcfg));
189 #endif
190 pci_akt = 1;
191 break;
192 default:
193 printk(KERN_ERR "eicon_pci: Unknown PCI card detected !\n");
194 pci_cards--;
195 pci_akt = 0;
196 break;
199 if (pci_akt) {
200 /* remapping memory */
201 switch(pci_type)
203 case PCI_MAESTRA:
204 aparms->PCIreg = (unsigned int) preg;
205 aparms->PCIcfg = (unsigned int) pcfg;
206 if (check_region((aparms->PCIreg), 0x20)) {
207 printk(KERN_WARNING "eicon_pci: reg port already in use !\n");
208 aparms->PCIreg = 0;
209 break;
210 } else {
211 request_region(aparms->PCIreg, 0x20, "eicon reg");
213 if (check_region((aparms->PCIcfg), 0x80)) {
214 printk(KERN_WARNING "eicon_pci: cfg port already in use !\n");
215 aparms->PCIcfg = 0;
216 release_region(aparms->PCIreg, 0x20);
217 break;
218 } else {
219 request_region(aparms->PCIcfg, 0x80, "eicon cfg");
221 break;
222 case PCI_MAESTRAQ:
223 case PCI_MAESTRAQ_U:
224 case PCI_MAESTRAP:
225 aparms->shmem = (eicon_pci_shmem *) ioremap(pram, 0x10000);
226 ram = (u8 *) ((u32)aparms->shmem + MP_SHARED_RAM_OFFSET);
227 reg = ioremap(preg, 0x4000);
228 cfg = ioremap(pcfg, 0x1000);
229 aparms->PCIram = (unsigned int) ram;
230 aparms->PCIreg = (unsigned int) reg;
231 aparms->PCIcfg = (unsigned int) cfg;
232 break;
234 if ((!aparms->PCIreg) || (!aparms->PCIcfg)) {
235 printk(KERN_ERR "eicon_pci: Card could not be added !\n");
236 pci_cards--;
237 } else {
238 aparms->mvalid = 1;
240 sprintf(did, "%s%d", (strlen(ID) < 1) ? "eicon":ID, pci_cards);
242 printk(KERN_INFO "%s: DriverID: '%s'\n",eicon_ctype_name[aparms->type] , did);
244 if (!(eicon_addcard(aparms->type, (int) aparms, aparms->irq, did))) {
245 printk(KERN_ERR "eicon_pci: Card could not be added !\n");
246 pci_cards--;
252 } else
253 printk(KERN_ERR "eicon_pci: Kernel compiled with PCI but no PCI-bios found !\n");
254 return 0;
258 * Checks protocol file id for "F#xxxx" string fragment to
259 * extract the features, supported by this protocol version.
260 * binary representation of the feature string value is returned
261 * in *value. The function returns 0 if feature string was not
262 * found or has a wrong format, else 1.
264 static int GetProtFeatureValue(char *sw_id, int *value)
266 __u8 i, offset;
268 while (*sw_id)
270 if ((sw_id[0] == 'F') && (sw_id[1] == '#'))
272 sw_id = &sw_id[2];
273 for (i=0, *value=0; i<4; i++, sw_id++)
275 if ((*sw_id >= '0') && (*sw_id <= '9'))
277 offset = '0';
279 else if ((*sw_id >= 'A') && (*sw_id <= 'F'))
281 offset = 'A' + 10;
283 else if ((*sw_id >= 'a') && (*sw_id <= 'f'))
285 offset = 'a' + 10;
287 else
289 return 0;
291 *value |= (*sw_id - offset) << (4*(3-i));
293 return 1;
295 else
297 sw_id++;
300 return 0;
304 void
305 eicon_pci_printpar(eicon_pci_card *card) {
306 switch (card->type) {
307 case EICON_CTYPE_MAESTRA:
308 printk(KERN_INFO "%s at 0x%x / 0x%x, irq %d\n",
309 eicon_ctype_name[card->type],
310 (unsigned int)card->PCIreg,
311 (unsigned int)card->PCIcfg,
312 card->irq);
313 break;
314 case EICON_CTYPE_MAESTRAQ:
315 case EICON_CTYPE_MAESTRAQ_U:
316 case EICON_CTYPE_MAESTRAP:
317 printk(KERN_INFO "%s at 0x%x, irq %d\n",
318 eicon_ctype_name[card->type],
319 (unsigned int)card->shmem,
320 card->irq);
321 #ifdef EICON_PCI_DEBUG
322 printk(KERN_INFO "eicon_pci: remapped ram= 0x%x\n",(unsigned int)card->PCIram);
323 printk(KERN_INFO "eicon_pci: remapped reg= 0x%x\n",(unsigned int)card->PCIreg);
324 printk(KERN_INFO "eicon_pci: remapped cfg= 0x%x\n",(unsigned int)card->PCIcfg);
325 #endif
326 break;
331 static void
332 eicon_pci_release_shmem(eicon_pci_card *card) {
333 if (!card->master)
334 return;
335 if (card->mvalid) {
336 switch (card->type) {
337 case EICON_CTYPE_MAESTRA:
338 /* reset board */
339 outb(0, card->PCIcfg + 0x4c); /* disable interrupts from PLX */
340 outb(0, card->PCIreg + M_RESET);
341 SLEEP(20);
342 outb(0, card->PCIreg + M_ADDRH);
343 outw(0, card->PCIreg + M_ADDR);
344 outw(0, card->PCIreg + M_DATA);
346 release_region(card->PCIreg, 0x20);
347 release_region(card->PCIcfg, 0x80);
348 break;
349 case EICON_CTYPE_MAESTRAQ:
350 case EICON_CTYPE_MAESTRAQ_U:
351 case EICON_CTYPE_MAESTRAP:
352 /* reset board */
353 writeb(_MP_RISC_RESET | _MP_LED1 | _MP_LED2, card->PCIreg + MP_RESET);
354 SLEEP(20);
355 writeb(0, card->PCIreg + MP_RESET);
356 SLEEP(20);
358 iounmap((void *)card->shmem);
359 iounmap((void *)card->PCIreg);
360 iounmap((void *)card->PCIcfg);
361 break;
364 card->mvalid = 0;
367 static void
368 eicon_pci_release_irq(eicon_pci_card *card) {
369 if (!card->master)
370 return;
371 if (card->ivalid)
372 free_irq(card->irq, card);
373 card->ivalid = 0;
376 void
377 eicon_pci_release(eicon_pci_card *card) {
378 eicon_pci_release_irq(card);
379 eicon_pci_release_shmem(card);
383 * Upload buffer content to adapters shared memory
384 * on verify error, 1 is returned and a message is printed on screen
385 * else 0 is returned
386 * Can serve IO-Type and Memory type adapters
388 int eicon_upload(t_dsp_download_space *p_para,
389 __u16 length, /* byte count */
390 __u8 *buffer,
391 int verify)
393 __u32 i, dwdata = 0, val = 0, timeout;
394 __u16 data;
395 eicon_pci_boot *boot = 0;
397 switch (p_para->type) /* actions depend on type of union */
399 case DL_PARA_IO_TYPE:
400 for (i=0; i<length; i+=2)
402 outb ((u8) ((p_para->dat.io.r3addr + i) >> 16), p_para->dat.io.ioADDRH);
403 outw ((u16) (p_para->dat.io.r3addr + i), p_para->dat.io.ioADDR);
404 /* outw (((u16 *)code)[i >> 1], p_para->dat.io.ioDATA); */
405 outw (*(u16 *)&buffer[i], p_para->dat.io.ioDATA);
407 if (verify) /* check written block */
409 for (i=0; i<length; i+=2)
411 outb ((u8) ((p_para->dat.io.r3addr + i) >> 16), p_para->dat.io.ioADDRH);
412 outw ((u16) (p_para->dat.io.r3addr + i), p_para->dat.io.ioADDR);
413 data = inw(p_para->dat.io.ioDATA);
414 if (data != *(u16 *)&buffer[i])
416 p_para->dat.io.r3addr += i;
417 p_para->dat.io.BadData = data;
418 p_para->dat.io.GoodData = *(u16 *)&buffer[i];
419 return 1;
423 break;
425 case DL_PARA_MEM_TYPE:
426 boot = p_para->dat.mem.boot;
427 writel(p_para->dat.mem.r3addr, &boot->addr);
428 for (i=0; i<length; i+=4)
430 writel(((u32 *)buffer)[i >> 2], &boot->data[i]);
432 if (verify) /* check written block */
434 for (i=0; i<length; i+=4)
436 dwdata = readl(&boot->data[i]);
437 if (((u32 *)buffer)[i >> 2] != dwdata)
439 p_para->dat.mem.r3addr += i;
440 p_para->dat.mem.BadData = dwdata;
441 p_para->dat.mem.GoodData = ((u32 *)buffer)[i >> 2];
442 return 1;
446 writel(((length + 3) / 4), &boot->len); /* len in dwords */
447 writel(2, &boot->cmd);
449 timeout = jiffies + 20;
450 while (timeout > jiffies) {
451 val = readl(&boot->cmd);
452 if (!val) break;
453 SLEEP(2);
455 if (val)
457 p_para->dat.mem.timeout = 1;
458 return 1;
460 break;
462 return 0;
466 /* show header information of code file */
467 static
468 int eicon_pci_print_hdr(unsigned char *code, int offset)
470 unsigned char hdr[80];
471 int i, fvalue = 0;
473 i = 0;
474 while ((i < (sizeof(hdr) -1))
475 && (code[offset + i] != '\0')
476 && (code[offset + i] != '\r')
477 && (code[offset + i] != '\n'))
479 hdr[i] = code[offset + i];
480 i++;
482 hdr[i] = '\0';
483 printk(KERN_DEBUG "Eicon: loading %s\n", hdr);
484 if (GetProtFeatureValue(hdr, &fvalue)) return(fvalue);
485 else return(0);
490 * Configure a card, download code into BRI card,
491 * check if we get interrupts and return 0 on succes.
492 * Return -ERRNO on failure.
495 eicon_pci_load_bri(eicon_pci_card *card, eicon_pci_codebuf *cb) {
496 int i,j;
497 int timeout;
498 unsigned int offset, offp=0, size, length;
499 int signature = 0;
500 int FeatureValue = 0;
501 eicon_pci_codebuf cbuf;
502 t_dsp_download_space dl_para;
503 t_dsp_download_desc dsp_download_table;
504 unsigned char *code;
505 unsigned int reg;
506 unsigned int cfg;
508 if (copy_from_user(&cbuf, cb, sizeof(eicon_pci_codebuf)))
509 return -EFAULT;
511 reg = card->PCIreg;
512 cfg = card->PCIcfg;
514 /* reset board */
515 outb(0, reg + M_RESET);
516 SLEEP(10);
517 outb(0, reg + M_ADDRH);
518 outw(0, reg + M_ADDR);
519 outw(0, reg + M_DATA);
521 #ifdef EICON_PCI_DEBUG
522 printk(KERN_DEBUG "eicon_pci: reset card\n");
523 #endif
525 /* clear shared memory */
526 outb(0xff, reg + M_ADDRH);
527 outw(0, reg + M_ADDR);
528 for(i = 0; i < 0xffff; i++) outw(0, reg + M_DATA);
529 SLEEP(10);
531 #ifdef EICON_PCI_DEBUG
532 printk(KERN_DEBUG "eicon_pci: clear shared memory\n");
533 #endif
535 /* download protocol and dsp file */
537 #ifdef EICON_PCI_DEBUG
538 printk(KERN_DEBUG "eicon_pci: downloading firmware...\n");
539 #endif
541 /* Allocate code-buffer */
542 if (!(code = kmalloc(400, GFP_KERNEL))) {
543 printk(KERN_WARNING "eicon_pci_boot: Couldn't allocate code buffer\n");
544 return -ENOMEM;
547 /* prepare protocol upload */
548 dl_para.type = DL_PARA_IO_TYPE;
549 dl_para.dat.io.ioADDR = reg + M_ADDR;
550 dl_para.dat.io.ioADDRH = reg + M_ADDRH;
551 dl_para.dat.io.ioDATA = reg + M_DATA;
553 for (j = 0; j <= cbuf.dsp_code_num; j++)
555 if (j == 0) size = cbuf.protocol_len;
556 else size = cbuf.dsp_code_len[j];
558 offset = 0;
560 if (j == 0) dl_para.dat.io.r3addr = 0;
561 if (j == 1) dl_para.dat.io.r3addr = M_DSP_CODE_BASE +
562 ((sizeof(__u32) + (sizeof(dsp_download_table) * 35) + 3) &0xfffffffc);
563 if (j == 2) dl_para.dat.io.r3addr = M_DSP_CODE_BASE;
564 if (j == 3) dl_para.dat.io.r3addr = M_DSP_CODE_BASE + sizeof(__u32);
566 do /* download block of up to 400 bytes */
568 length = ((size - offset) >= 400) ? 400 : (size - offset);
570 if (copy_from_user(code, (&cb->code) + offp + offset, length)) {
571 kfree(code);
572 return -EFAULT;
575 if ((offset == 0) && (j < 2)) {
576 FeatureValue = eicon_pci_print_hdr(code, j ? 0x00 : 0x80);
577 #ifdef EICON_PCI_DEBUG
578 if (FeatureValue) printk(KERN_DEBUG "eicon_pci: Feature Value : 0x%04x.\n", FeatureValue);
579 #endif
580 if ((j==0) && (!(FeatureValue & PROTCAP_TELINDUS))) {
581 printk(KERN_ERR "eicon_pci: Protocol Code cannot handle Telindus\n");
582 kfree(code);
583 return -EFAULT;
585 ((eicon_card *)card->card)->Feature = FeatureValue;
588 if (eicon_upload(&dl_para, length, code, 1))
590 printk(KERN_ERR "eicon_pci: code block check failed at 0x%x !\n",dl_para.dat.io.r3addr);
591 kfree(code);
592 return -EIO;
594 /* move onto next block */
595 offset += length;
596 dl_para.dat.io.r3addr += length;
597 } while (offset < size);
599 #ifdef EICON_PCI_DEBUG
600 printk(KERN_DEBUG "Eicon: %d bytes loaded.\n", offset);
601 #endif
602 offp += size;
604 kfree(code);
606 /* clear signature */
607 outb(0xff, reg + M_ADDRH);
608 outw(0x1e, reg + M_ADDR);
609 outw(0, reg + M_DATA);
611 #ifdef EICON_PCI_DEBUG
612 printk(KERN_DEBUG "eicon_pci: copy configuration data into shared memory...\n");
613 #endif
614 /* copy configuration data into shared memory */
615 outw(8, reg + M_ADDR); outb(cbuf.tei, reg + M_DATA);
616 outw(9, reg + M_ADDR); outb(cbuf.nt2, reg + M_DATA);
617 outw(10,reg + M_ADDR); outb(0, reg + M_DATA);
618 outw(11,reg + M_ADDR); outb(cbuf.WatchDog, reg + M_DATA);
619 outw(12,reg + M_ADDR); outb(cbuf.Permanent, reg + M_DATA);
620 outw(13,reg + M_ADDR); outb(0, reg + M_DATA); /* XInterface */
621 outw(14,reg + M_ADDR); outb(cbuf.StableL2, reg + M_DATA);
622 outw(15,reg + M_ADDR); outb(cbuf.NoOrderCheck, reg + M_DATA);
623 outw(16,reg + M_ADDR); outb(0, reg + M_DATA); /* HandsetType */
624 outw(17,reg + M_ADDR); outb(0, reg + M_DATA); /* SigFlags */
625 outw(18,reg + M_ADDR); outb(cbuf.LowChannel, reg + M_DATA);
626 outw(19,reg + M_ADDR); outb(cbuf.ProtVersion, reg + M_DATA);
627 outw(20,reg + M_ADDR); outb(cbuf.Crc4, reg + M_DATA);
628 outw(21,reg + M_ADDR); outb((cbuf.Loopback) ? 2:0, reg + M_DATA);
630 for (i=0;i<32;i++)
632 outw( 32+i, reg + M_ADDR); outb(cbuf.l[0].oad[i], reg + M_DATA);
633 outw( 64+i, reg + M_ADDR); outb(cbuf.l[0].osa[i], reg + M_DATA);
634 outw( 96+i, reg + M_ADDR); outb(cbuf.l[0].spid[i], reg + M_DATA);
635 outw(128+i, reg + M_ADDR); outb(cbuf.l[1].oad[i], reg + M_DATA);
636 outw(160+i, reg + M_ADDR); outb(cbuf.l[1].osa[i], reg + M_DATA);
637 outw(192+i, reg + M_ADDR); outb(cbuf.l[1].spid[i], reg + M_DATA);
640 #ifdef EICON_PCI_DEBUG
641 printk(KERN_ERR "eicon_pci: starting CPU...\n");
642 #endif
643 /* let the CPU run */
644 outw(0x08, reg + M_RESET);
646 timeout = jiffies + (5*HZ);
647 while (timeout > jiffies) {
648 outw(0x1e, reg + M_ADDR);
649 signature = inw(reg + M_DATA);
650 if (signature == DIVAS_SIGNATURE) break;
651 SLEEP(2);
653 if (signature != DIVAS_SIGNATURE)
655 #ifdef EICON_PCI_DEBUG
656 printk(KERN_ERR "eicon_pci: signature 0x%x expected 0x%x\n",signature,DIVAS_SIGNATURE);
657 #endif
658 printk(KERN_ERR "eicon_pci: Timeout, protocol code not running !\n");
659 return -EIO;
661 #ifdef EICON_PCI_DEBUG
662 printk(KERN_DEBUG "eicon_pci: Protocol code running, signature OK\n");
663 #endif
665 /* get serial number and number of channels supported by card */
666 outb(0xff, reg + M_ADDRH);
667 outw(0x3f6, reg + M_ADDR);
668 card->channels = inw(reg + M_DATA);
669 card->serial = (u32)inw(cfg + 0x22) << 16 | (u32)inw(cfg + 0x26);
670 printk(KERN_INFO "Eicon: Supported channels : %d\n", card->channels);
671 printk(KERN_INFO "Eicon: Card serial no. = %lu\n", card->serial);
673 /* test interrupt */
674 card->irqprobe = 1;
676 if (!card->ivalid) {
677 if (request_irq(card->irq, &eicon_irq, 0, "Eicon PCI ISDN", card->card))
679 printk(KERN_ERR "eicon_pci: Couldn't request irq %d\n", card->irq);
680 return -EIO;
683 card->ivalid = 1;
685 #ifdef EICON_PCI_DEBUG
686 printk(KERN_DEBUG "eicon_pci: testing interrupt\n");
687 #endif
688 /* Trigger an interrupt and check if it is delivered */
689 outb(0x41, cfg + 0x4c); /* enable PLX for interrupts */
690 outb(0x89, reg + M_RESET); /* place int request */
692 timeout = jiffies + 20;
693 while (timeout > jiffies) {
694 if (card->irqprobe != 1) break;
695 SLEEP(5);
697 if (card->irqprobe == 1) {
698 free_irq(card->irq, card);
699 card->ivalid = 0;
700 printk(KERN_ERR "eicon_pci: Getting no interrupts !\n");
701 return -EIO;
704 /* initializing some variables */
705 ((eicon_card *)card->card)->ReadyInt = 0;
706 for(j=0; j<256; j++) ((eicon_card *)card->card)->IdTable[j] = NULL;
707 for(j=0; j< (card->channels + 1); j++) {
708 ((eicon_card *)card->card)->bch[j].e.busy = 0;
709 ((eicon_card *)card->card)->bch[j].e.D3Id = 0;
710 ((eicon_card *)card->card)->bch[j].e.B2Id = 0;
711 ((eicon_card *)card->card)->bch[j].e.ref = 0;
712 ((eicon_card *)card->card)->bch[j].e.Req = 0;
713 ((eicon_card *)card->card)->bch[j].e.complete = 1;
714 ((eicon_card *)card->card)->bch[j].fsm_state = EICON_STATE_NULL;
717 printk(KERN_INFO "Eicon: Card successfully started\n");
719 return 0;
724 * Configure a card, download code into PRI card,
725 * check if we get interrupts and return 0 on succes.
726 * Return -ERRNO on failure.
729 eicon_pci_load_pri(eicon_pci_card *card, eicon_pci_codebuf *cb) {
730 eicon_pci_boot *boot;
731 eicon_pr_ram *prram;
732 int i,j;
733 int timeout;
734 int FeatureValue = 0;
735 unsigned int offset, offp=0, size, length;
736 unsigned long int signature = 0;
737 t_dsp_download_space dl_para;
738 t_dsp_download_desc dsp_download_table;
739 eicon_pci_codebuf cbuf;
740 unsigned char *code;
741 unsigned char req_int;
742 char *ram, *reg, *cfg;
744 if (copy_from_user(&cbuf, cb, sizeof(eicon_pci_codebuf)))
745 return -EFAULT;
747 boot = &card->shmem->boot;
748 ram = (char *)card->PCIram;
749 reg = (char *)card->PCIreg;
750 cfg = (char *)card->PCIcfg;
751 prram = (eicon_pr_ram *)ram;
753 /* reset board */
754 writeb(_MP_RISC_RESET | _MP_LED1 | _MP_LED2, card->PCIreg + MP_RESET);
755 SLEEP(20);
756 writeb(0, card->PCIreg + MP_RESET);
757 SLEEP(20);
759 /* set command count to 0 */
760 writel(0, &boot->reserved);
762 /* check if CPU increments the life word */
763 i = readw(&boot->live);
764 SLEEP(20);
765 if (i == readw(&boot->live)) {
766 printk(KERN_ERR "eicon_pci: card is reset, but CPU not running !\n");
767 return -EIO;
769 #ifdef EICON_PCI_DEBUG
770 printk(KERN_DEBUG "eicon_pci: reset card OK (CPU running)\n");
771 #endif
773 /* download firmware : DSP and Protocol */
774 #ifdef EICON_PCI_DEBUG
775 printk(KERN_DEBUG "eicon_pci: downloading firmware...\n");
776 #endif
778 /* Allocate code-buffer */
779 if (!(code = kmalloc(400, GFP_KERNEL))) {
780 printk(KERN_WARNING "eicon_pci_boot: Couldn't allocate code buffer\n");
781 return -ENOMEM;
784 /* prepare protocol upload */
785 dl_para.type = DL_PARA_MEM_TYPE;
786 dl_para.dat.mem.boot = boot;
788 for (j = 0; j <= cbuf.dsp_code_num; j++)
790 if (j==0) size = cbuf.protocol_len;
791 else size = cbuf.dsp_code_len[j];
793 if (j==1) writel(MP_DSP_ADDR, &boot->addr); /* DSP code entry point */
795 if (j == 0) dl_para.dat.io.r3addr = MP_PROTOCOL_ADDR;
796 if (j == 1) dl_para.dat.io.r3addr = MP_DSP_CODE_BASE +
797 ((sizeof(__u32) + (sizeof(dsp_download_table) * 35) + 3) &0xfffffffc);
798 if (j == 2) dl_para.dat.io.r3addr = MP_DSP_CODE_BASE;
799 if (j == 3) dl_para.dat.io.r3addr = MP_DSP_CODE_BASE + sizeof(__u32);
801 offset = 0;
802 do /* download block of up to 400 bytes */
804 length = ((size - offset) >= 400) ? 400 : (size - offset);
806 if (copy_from_user(code, (&cb->code) + offp + offset, length)) {
807 kfree(code);
808 return -EFAULT;
811 if ((offset == 0) && (j < 2)) {
812 FeatureValue = eicon_pci_print_hdr(code, j ? 0x00 : 0x80);
813 #ifdef EICON_PCI_DEBUG
814 if (FeatureValue) printk(KERN_DEBUG "eicon_pci: Feature Value : 0x%x.\n", FeatureValue);
815 #endif
816 if ((j==0) && (!(FeatureValue & PROTCAP_TELINDUS))) {
817 printk(KERN_ERR "eicon_pci: Protocol Code cannot handle Telindus\n");
818 kfree(code);
819 return -EFAULT;
821 ((eicon_card *)card->card)->Feature = FeatureValue;
824 if (eicon_upload(&dl_para, length, code, 1))
826 if (dl_para.dat.mem.timeout == 0)
827 printk(KERN_ERR "eicon_pci: code block check failed at 0x%x !\n",dl_para.dat.io.r3addr);
828 else
829 printk(KERN_ERR "eicon_pci: timeout, no ACK to load !\n");
830 kfree(code);
831 return -EIO;
834 /* move onto next block */
835 offset += length;
836 dl_para.dat.mem.r3addr += length;
837 } while (offset < size);
838 #ifdef EICON_PCI_DEBUG
839 printk(KERN_DEBUG "eicon_pci: %d bytes loaded.\n", offset);
840 #endif
841 offp += size;
843 kfree(code);
845 /* initialize the adapter data structure */
846 #ifdef EICON_PCI_DEBUG
847 printk(KERN_DEBUG "eicon_pci: copy configuration data into shared memory...\n");
848 #endif
849 /* clear out config space */
850 for (i = 0; i < 256; i++) writeb(0, &ram[i]);
852 /* copy configuration down to the card */
853 writeb(cbuf.tei, &ram[8]);
854 writeb(cbuf.nt2, &ram[9]);
855 writeb(0, &ram[10]);
856 writeb(cbuf.WatchDog, &ram[11]);
857 writeb(cbuf.Permanent, &ram[12]);
858 writeb(cbuf.XInterface, &ram[13]);
859 writeb(cbuf.StableL2, &ram[14]);
860 writeb(cbuf.NoOrderCheck, &ram[15]);
861 writeb(cbuf.HandsetType, &ram[16]);
862 writeb(0, &ram[17]);
863 writeb(cbuf.LowChannel, &ram[18]);
864 writeb(cbuf.ProtVersion, &ram[19]);
865 writeb(cbuf.Crc4, &ram[20]);
866 for (i = 0; i < 32; i++)
868 writeb(cbuf.l[0].oad[i], &ram[32 + i]);
869 writeb(cbuf.l[0].osa[i], &ram[64 + i]);
870 writeb(cbuf.l[0].spid[i], &ram[96 + i]);
871 writeb(cbuf.l[1].oad[i], &ram[128 + i]);
872 writeb(cbuf.l[1].osa[i], &ram[160 + i]);
873 writeb(cbuf.l[1].spid[i], &ram[192 + i]);
875 #ifdef EICON_PCI_DEBUG
876 printk(KERN_DEBUG "eicon_pci: configured card OK\n");
877 #endif
879 /* start adapter */
880 #ifdef EICON_PCI_DEBUG
881 printk(KERN_DEBUG "eicon_pci: tell card to start...\n");
882 #endif
883 writel(MP_PROTOCOL_ADDR, &boot->addr); /* RISC code entry point */
884 writel(3, &boot->cmd); /* DIVAS_START_CMD */
886 /* wait till card ACKs */
887 timeout = jiffies + (5*HZ);
888 while (timeout > jiffies) {
889 signature = readl(&boot->signature);
890 if ((signature >> 16) == DIVAS_SIGNATURE) break;
891 SLEEP(2);
893 if ((signature >> 16) != DIVAS_SIGNATURE)
895 #ifdef EICON_PCI_DEBUG
896 printk(KERN_ERR "eicon_pci: signature 0x%lx expected 0x%x\n",(signature >> 16),DIVAS_SIGNATURE);
897 #endif
898 printk(KERN_ERR "eicon_pci: timeout, protocol code not running !\n");
899 return -EIO;
901 #ifdef EICON_PCI_DEBUG
902 printk(KERN_DEBUG "eicon_pci: Protocol code running, signature OK\n");
903 #endif
905 /* get serial number and number of channels supported by card */
906 card->channels = readb(&ram[0x3f6]);
907 card->serial = readl(&ram[0x3f0]);
908 printk(KERN_INFO "Eicon: Supported channels : %d\n", card->channels);
909 printk(KERN_INFO "Eicon: Card serial no. = %lu\n", card->serial);
911 /* test interrupt */
912 readb(&ram[0x3fe]);
913 writeb(0, &ram[0x3fe]); /* reset any pending interrupt */
914 readb(&ram[0x3fe]);
916 writew(MP_IRQ_RESET_VAL, &cfg[MP_IRQ_RESET]);
917 writew(0, &cfg[MP_IRQ_RESET + 2]);
919 card->irqprobe = 1;
921 if (!card->ivalid) {
922 if (request_irq(card->irq, &eicon_irq, 0, "Eicon PCI ISDN", card->card))
924 printk(KERN_ERR "eicon_pci: Couldn't request irq %d\n", card->irq);
925 return -EIO;
928 card->ivalid = 1;
930 req_int = readb(&prram->ReadyInt);
931 #ifdef EICON_PCI_DEBUG
932 printk(KERN_DEBUG "eicon_pci: testing interrupt\n");
933 #endif
934 req_int++;
935 /* Trigger an interrupt and check if it is delivered */
936 writeb(req_int, &prram->ReadyInt);
938 timeout = jiffies + 20;
939 while (timeout > jiffies) {
940 if (card->irqprobe != 1) break;
941 SLEEP(2);
943 if (card->irqprobe == 1) {
944 free_irq(card->irq, card);
945 card->ivalid = 0;
946 printk(KERN_ERR "eicon_pci: Getting no interrupts !\n");
947 return -EIO;
950 /* initializing some variables */
951 ((eicon_card *)card->card)->ReadyInt = 0;
952 for(j=0; j<256; j++) ((eicon_card *)card->card)->IdTable[j] = NULL;
953 for(j=0; j< (card->channels + 1); j++) {
954 ((eicon_card *)card->card)->bch[j].e.busy = 0;
955 ((eicon_card *)card->card)->bch[j].e.D3Id = 0;
956 ((eicon_card *)card->card)->bch[j].e.B2Id = 0;
957 ((eicon_card *)card->card)->bch[j].e.ref = 0;
958 ((eicon_card *)card->card)->bch[j].e.Req = 0;
959 ((eicon_card *)card->card)->bch[j].e.complete = 1;
960 ((eicon_card *)card->card)->bch[j].fsm_state = EICON_STATE_NULL;
963 printk(KERN_INFO "Eicon: Card successfully started\n");
965 return 0;
968 #endif /* CONFIG_PCI */