2 * hfcmulti.c low level driver for hfc-4s/hfc-8s/hfc-e1 based cards
4 * Author Andreas Eversberg (jolly@eversberg.eu)
5 * ported to mqueue mechanism:
6 * Peter Sprenger (sprengermoving-bytes.de)
8 * inspired by existing hfc-pci driver:
9 * Copyright 1999 by Werner Cornelius (werner@isdn-development.de)
10 * Copyright 2008 by Karsten Keil (kkeil@suse.de)
11 * Copyright 2008 by Andreas Eversberg (jolly@eversberg.eu)
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * Thanks to Cologne Chip AG for this great controller!
34 * By default (0), the card is automatically detected.
35 * Or use the following combinations:
36 * Bit 0-7 = 0x00001 = HFC-E1 (1 port)
37 * or Bit 0-7 = 0x00004 = HFC-4S (4 ports)
38 * or Bit 0-7 = 0x00008 = HFC-8S (8 ports)
39 * Bit 8 = 0x00100 = uLaw (instead of aLaw)
40 * Bit 9 = 0x00200 = Disable DTMF detect on all B-channels via hardware
42 * Bit 11 = 0x00800 = Force PCM bus into slave mode. (otherwhise auto)
43 * or Bit 12 = 0x01000 = Force PCM bus into master mode. (otherwhise auto)
45 * Bit 14 = 0x04000 = Use external ram (128K)
46 * Bit 15 = 0x08000 = Use external ram (512K)
47 * Bit 16 = 0x10000 = Use 64 timeslots instead of 32
48 * or Bit 17 = 0x20000 = Use 128 timeslots instead of anything else
50 * Bit 19 = 0x80000 = Send the Watchdog a Signal (Dual E1 with Watchdog)
51 * (all other bits are reserved and shall be 0)
52 * example: 0x20204 one HFC-4S with dtmf detection and 128 timeslots on PCM
55 * port: (optional or required for all ports on all installed cards)
56 * HFC-4S/HFC-8S only bits:
57 * Bit 0 = 0x001 = Use master clock for this S/T interface
58 * (ony once per chip).
59 * Bit 1 = 0x002 = transmitter line setup (non capacitive mode)
60 * Don't use this unless you know what you are doing!
61 * Bit 2 = 0x004 = Disable E-channel. (No E-channel processing)
62 * example: 0x0001,0x0000,0x0000,0x0000 one HFC-4S with master clock
63 * received from port 1
66 * Bit 0 = 0x0001 = interface: 0=copper, 1=optical
67 * Bit 1 = 0x0002 = reserved (later for 32 B-channels transparent mode)
68 * Bit 2 = 0x0004 = Report LOS
69 * Bit 3 = 0x0008 = Report AIS
70 * Bit 4 = 0x0010 = Report SLIP
71 * Bit 5 = 0x0020 = Report RDI
72 * Bit 8 = 0x0100 = Turn off CRC-4 Multiframe Mode, use double frame
74 * Bit 9 = 0x0200 = Force get clock from interface, even in NT mode.
75 * or Bit 10 = 0x0400 = Force put clock to interface, even in TE mode.
76 * Bit 11 = 0x0800 = Use direct RX clock for PCM sync rather than PLL.
78 * Bit 12-13 = 0xX000 = elastic jitter buffer (1-3), Set both bits to 0
80 * (all other bits are reserved and shall be 0)
83 * NOTE: only one debug value must be given for all cards
84 * enable debugging (see hfc_multi.h for debug options)
87 * NOTE: only one poll value must be given for all cards
88 * Give the number of samples for each fifo process.
89 * By default 128 is used. Decrease to reduce delay, increase to
90 * reduce cpu load. If unsure, don't mess with it!
91 * Valid is 8, 16, 32, 64, 128, 256.
94 * NOTE: only one pcm value must be given for every card.
95 * The PCM bus id tells the mISDNdsp module about the connected PCM bus.
96 * By default (0), the PCM bus id is 100 for the card that is PCM master.
97 * If multiple cards are PCM master (because they are not interconnected),
98 * each card with PCM master will have increasing PCM id.
99 * All PCM busses with the same ID are expected to be connected and have
100 * common time slots slots.
101 * Only one chip of the PCM bus must be master, the others slave.
102 * -1 means no support of PCM bus not even.
103 * Omit this value, if all cards are interconnected or none is connected.
104 * If unsure, don't give this parameter.
107 * NOTE: only one poll value must be given for every card.
108 * Also this value must be given for non-E1 cards. If omitted, the E1
109 * card has D-channel on time slot 16, which is default.
110 * If 1..15 or 17..31, an alternate time slot is used for D-channel.
111 * In this case, the application must be able to handle this.
112 * If -1 is given, the D-channel is disabled and all 31 slots can be used
113 * for B-channel. (only for specific applications)
114 * If you don't know how to use it, you don't need it!
117 * NOTE: only one mode value must be given for every card.
118 * -> See hfc_multi.h for HFC_IO_MODE_* values
119 * By default, the IO mode is pci memory IO (MEMIO).
120 * Some cards requre specific IO mode, so it cannot be changed.
121 * It may be usefull to set IO mode to register io (REGIO) to solve
122 * PCI bridge problems.
123 * If unsure, don't give this parameter.
126 * NOTE: only one clockdelay_nt value must be given once for all cards.
127 * Give the value of the clock control register (A_ST_CLK_DLY)
128 * of the S/T interfaces in NT mode.
129 * This register is needed for the TBR3 certification, so don't change it.
132 * NOTE: only one clockdelay_te value must be given once
133 * Give the value of the clock control register (A_ST_CLK_DLY)
134 * of the S/T interfaces in TE mode.
135 * This register is needed for the TBR3 certification, so don't change it.
139 * debug register access (never use this, it will flood your system log)
140 * #define HFC_REGISTER_DEBUG
143 static const char *hfcmulti_revision = "2.02";
145 #include <linux/module.h>
146 #include <linux/pci.h>
147 #include <linux/delay.h>
148 #include <linux/mISDNhw.h>
149 #include <linux/mISDNdsp.h>
152 #define IRQCOUNT_DEBUG
156 #include "hfc_multi.h"
162 #define MAX_PORTS (8 * MAX_CARDS)
164 static LIST_HEAD(HFClist);
165 static spinlock_t HFClock; /* global hfc list lock */
167 static void ph_state_change(struct dchannel *);
168 static void (*hfc_interrupt)(void);
169 static void (*register_interrupt)(void);
170 static int (*unregister_interrupt)(void);
171 static int interrupt_registered;
173 static struct hfc_multi *syncmaster;
174 static int plxsd_master; /* if we have a master card (yet) */
175 static spinlock_t plx_lock; /* may not acquire other lock inside */
181 static int poll_timer = 6; /* default = 128 samples = 16ms */
182 /* number of POLL_TIMER interrupts for G2 timeout (ca 1s) */
183 static int nt_t1_count[] = { 3840, 1920, 960, 480, 240, 120, 60, 30 };
184 #define CLKDEL_TE 0x0f /* CLKDEL in TE mode */
185 #define CLKDEL_NT 0x6c /* CLKDEL in NT mode
186 (0x60 MUST be included!) */
187 static u_char silence = 0xff; /* silence by LAW */
189 #define DIP_4S 0x1 /* DIP Switches for Beronet 1S/2S/4S cards */
190 #define DIP_8S 0x2 /* DIP Switches for Beronet 8S+ cards */
191 #define DIP_E1 0x3 /* DIP Switches for Beronet E1 cards */
197 static uint type[MAX_CARDS];
198 static uint pcm[MAX_CARDS];
199 static uint dslot[MAX_CARDS];
200 static uint iomode[MAX_CARDS];
201 static uint port[MAX_PORTS];
205 static uint clockdelay_te = CLKDEL_TE;
206 static uint clockdelay_nt = CLKDEL_NT;
208 static int HFC_cnt, Port_cnt, PCM_cnt = 99;
210 MODULE_AUTHOR("Andreas Eversberg");
211 MODULE_LICENSE("GPL");
212 module_param(debug, uint, S_IRUGO | S_IWUSR);
213 module_param(poll, uint, S_IRUGO | S_IWUSR);
214 module_param(timer, uint, S_IRUGO | S_IWUSR);
215 module_param(clockdelay_te, uint, S_IRUGO | S_IWUSR);
216 module_param(clockdelay_nt, uint, S_IRUGO | S_IWUSR);
217 module_param_array(type, uint, NULL, S_IRUGO | S_IWUSR);
218 module_param_array(pcm, uint, NULL, S_IRUGO | S_IWUSR);
219 module_param_array(dslot, uint, NULL, S_IRUGO | S_IWUSR);
220 module_param_array(iomode, uint, NULL, S_IRUGO | S_IWUSR);
221 module_param_array(port, uint, NULL, S_IRUGO | S_IWUSR);
223 #ifdef HFC_REGISTER_DEBUG
224 #define HFC_outb(hc, reg, val) \
225 (hc->HFC_outb(hc, reg, val, __func__, __LINE__))
226 #define HFC_outb_nodebug(hc, reg, val) \
227 (hc->HFC_outb_nodebug(hc, reg, val, __func__, __LINE__))
228 #define HFC_inb(hc, reg) \
229 (hc->HFC_inb(hc, reg, __func__, __LINE__))
230 #define HFC_inb_nodebug(hc, reg) \
231 (hc->HFC_inb_nodebug(hc, reg, __func__, __LINE__))
232 #define HFC_inw(hc, reg) \
233 (hc->HFC_inw(hc, reg, __func__, __LINE__))
234 #define HFC_inw_nodebug(hc, reg) \
235 (hc->HFC_inw_nodebug(hc, reg, __func__, __LINE__))
236 #define HFC_wait(hc) \
237 (hc->HFC_wait(hc, __func__, __LINE__))
238 #define HFC_wait_nodebug(hc) \
239 (hc->HFC_wait_nodebug(hc, __func__, __LINE__))
241 #define HFC_outb(hc, reg, val) (hc->HFC_outb(hc, reg, val))
242 #define HFC_outb_nodebug(hc, reg, val) (hc->HFC_outb_nodebug(hc, reg, val))
243 #define HFC_inb(hc, reg) (hc->HFC_inb(hc, reg))
244 #define HFC_inb_nodebug(hc, reg) (hc->HFC_inb_nodebug(hc, reg))
245 #define HFC_inw(hc, reg) (hc->HFC_inw(hc, reg))
246 #define HFC_inw_nodebug(hc, reg) (hc->HFC_inw_nodebug(hc, reg))
247 #define HFC_wait(hc) (hc->HFC_wait(hc))
248 #define HFC_wait_nodebug(hc) (hc->HFC_wait_nodebug(hc))
251 /* HFC_IO_MODE_PCIMEM */
253 #ifdef HFC_REGISTER_DEBUG
254 HFC_outb_pcimem(struct hfc_multi *hc, u_char reg, u_char val,
255 const char *function, int line)
257 HFC_outb_pcimem(struct hfc_multi *hc, u_char reg, u_char val)
260 writeb(val, (hc->pci_membase)+reg);
263 #ifdef HFC_REGISTER_DEBUG
264 HFC_inb_pcimem(struct hfc_multi *hc, u_char reg, const char *function, int line)
266 HFC_inb_pcimem(struct hfc_multi *hc, u_char reg)
269 return readb((hc->pci_membase)+reg);
272 #ifdef HFC_REGISTER_DEBUG
273 HFC_inw_pcimem(struct hfc_multi *hc, u_char reg, const char *function, int line)
275 HFC_inw_pcimem(struct hfc_multi *hc, u_char reg)
278 return readw((hc->pci_membase)+reg);
281 #ifdef HFC_REGISTER_DEBUG
282 HFC_wait_pcimem(struct hfc_multi *hc, const char *function, int line)
284 HFC_wait_pcimem(struct hfc_multi *hc)
287 while (readb((hc->pci_membase)+R_STATUS) & V_BUSY);
290 /* HFC_IO_MODE_REGIO */
292 #ifdef HFC_REGISTER_DEBUG
293 HFC_outb_regio(struct hfc_multi *hc, u_char reg, u_char val,
294 const char *function, int line)
296 HFC_outb_regio(struct hfc_multi *hc, u_char reg, u_char val)
299 outb(reg, (hc->pci_iobase)+4);
300 outb(val, hc->pci_iobase);
303 #ifdef HFC_REGISTER_DEBUG
304 HFC_inb_regio(struct hfc_multi *hc, u_char reg, const char *function, int line)
306 HFC_inb_regio(struct hfc_multi *hc, u_char reg)
309 outb(reg, (hc->pci_iobase)+4);
310 return inb(hc->pci_iobase);
313 #ifdef HFC_REGISTER_DEBUG
314 HFC_inw_regio(struct hfc_multi *hc, u_char reg, const char *function, int line)
316 HFC_inw_regio(struct hfc_multi *hc, u_char reg)
319 outb(reg, (hc->pci_iobase)+4);
320 return inw(hc->pci_iobase);
323 #ifdef HFC_REGISTER_DEBUG
324 HFC_wait_regio(struct hfc_multi *hc, const char *function, int line)
326 HFC_wait_regio(struct hfc_multi *hc)
329 outb(R_STATUS, (hc->pci_iobase)+4);
330 while (inb(hc->pci_iobase) & V_BUSY);
333 #ifdef HFC_REGISTER_DEBUG
335 HFC_outb_debug(struct hfc_multi *hc, u_char reg, u_char val,
336 const char *function, int line)
338 char regname[256] = "", bits[9] = "xxxxxxxx";
342 while (hfc_register_names[++i].name) {
343 if (hfc_register_names[i].reg == reg)
344 strcat(regname, hfc_register_names[i].name);
346 if (regname[0] == '\0')
347 strcpy(regname, "register");
349 bits[7] = '0'+(!!(val&1));
350 bits[6] = '0'+(!!(val&2));
351 bits[5] = '0'+(!!(val&4));
352 bits[4] = '0'+(!!(val&8));
353 bits[3] = '0'+(!!(val&16));
354 bits[2] = '0'+(!!(val&32));
355 bits[1] = '0'+(!!(val&64));
356 bits[0] = '0'+(!!(val&128));
358 "HFC_outb(chip %d, %02x=%s, 0x%02x=%s); in %s() line %d\n",
359 hc->id, reg, regname, val, bits, function, line);
360 HFC_outb_nodebug(hc, reg, val);
363 HFC_inb_debug(struct hfc_multi *hc, u_char reg, const char *function, int line)
365 char regname[256] = "", bits[9] = "xxxxxxxx";
366 u_char val = HFC_inb_nodebug(hc, reg);
370 while (hfc_register_names[i++].name)
372 while (hfc_register_names[++i].name) {
373 if (hfc_register_names[i].reg == reg)
374 strcat(regname, hfc_register_names[i].name);
376 if (regname[0] == '\0')
377 strcpy(regname, "register");
379 bits[7] = '0'+(!!(val&1));
380 bits[6] = '0'+(!!(val&2));
381 bits[5] = '0'+(!!(val&4));
382 bits[4] = '0'+(!!(val&8));
383 bits[3] = '0'+(!!(val&16));
384 bits[2] = '0'+(!!(val&32));
385 bits[1] = '0'+(!!(val&64));
386 bits[0] = '0'+(!!(val&128));
388 "HFC_inb(chip %d, %02x=%s) = 0x%02x=%s; in %s() line %d\n",
389 hc->id, reg, regname, val, bits, function, line);
393 HFC_inw_debug(struct hfc_multi *hc, u_char reg, const char *function, int line)
395 char regname[256] = "";
396 u_short val = HFC_inw_nodebug(hc, reg);
400 while (hfc_register_names[i++].name)
402 while (hfc_register_names[++i].name) {
403 if (hfc_register_names[i].reg == reg)
404 strcat(regname, hfc_register_names[i].name);
406 if (regname[0] == '\0')
407 strcpy(regname, "register");
410 "HFC_inw(chip %d, %02x=%s) = 0x%04x; in %s() line %d\n",
411 hc->id, reg, regname, val, function, line);
415 HFC_wait_debug(struct hfc_multi *hc, const char *function, int line)
417 printk(KERN_DEBUG "HFC_wait(chip %d); in %s() line %d\n",
418 hc->id, function, line);
419 HFC_wait_nodebug(hc);
423 /* write fifo data (REGIO) */
425 write_fifo_regio(struct hfc_multi *hc, u_char *data, int len)
427 outb(A_FIFO_DATA0, (hc->pci_iobase)+4);
429 outl(cpu_to_le32(*(u32 *)data), hc->pci_iobase);
434 outw(cpu_to_le16(*(u16 *)data), hc->pci_iobase);
439 outb(*data, hc->pci_iobase);
444 /* write fifo data (PCIMEM) */
446 write_fifo_pcimem(struct hfc_multi *hc, u_char *data, int len)
449 writel(cpu_to_le32(*(u32 *)data),
450 hc->pci_membase + A_FIFO_DATA0);
455 writew(cpu_to_le16(*(u16 *)data),
456 hc->pci_membase + A_FIFO_DATA0);
461 writeb(*data, hc->pci_membase + A_FIFO_DATA0);
466 /* read fifo data (REGIO) */
468 read_fifo_regio(struct hfc_multi *hc, u_char *data, int len)
470 outb(A_FIFO_DATA0, (hc->pci_iobase)+4);
472 *(u32 *)data = le32_to_cpu(inl(hc->pci_iobase));
477 *(u16 *)data = le16_to_cpu(inw(hc->pci_iobase));
482 *data = inb(hc->pci_iobase);
488 /* read fifo data (PCIMEM) */
490 read_fifo_pcimem(struct hfc_multi *hc, u_char *data, int len)
494 le32_to_cpu(readl(hc->pci_membase + A_FIFO_DATA0));
500 le16_to_cpu(readw(hc->pci_membase + A_FIFO_DATA0));
505 *data = readb(hc->pci_membase + A_FIFO_DATA0);
513 enable_hwirq(struct hfc_multi *hc)
515 hc->hw.r_irq_ctrl |= V_GLOB_IRQ_EN;
516 HFC_outb(hc, R_IRQ_CTRL, hc->hw.r_irq_ctrl);
520 disable_hwirq(struct hfc_multi *hc)
522 hc->hw.r_irq_ctrl &= ~((u_char)V_GLOB_IRQ_EN);
523 HFC_outb(hc, R_IRQ_CTRL, hc->hw.r_irq_ctrl);
527 #define MAX_TDM_CHAN 32
531 enablepcibridge(struct hfc_multi *c)
533 HFC_outb(c, R_BRG_PCM_CFG, (0x0 << 6) | 0x3); /* was _io before */
537 disablepcibridge(struct hfc_multi *c)
539 HFC_outb(c, R_BRG_PCM_CFG, (0x0 << 6) | 0x2); /* was _io before */
543 readpcibridge(struct hfc_multi *hc, unsigned char address)
551 /* slow down a PCI read access by 1 PCI clock cycle */
552 HFC_outb(hc, R_CTRL, 0x4); /*was _io before*/
559 /* select local bridge port address by writing to CIP port */
560 /* data = HFC_inb(c, cipv); * was _io before */
561 outw(cipv, hc->pci_iobase + 4);
562 data = inb(hc->pci_iobase);
564 /* restore R_CTRL for normal PCI read cycle speed */
565 HFC_outb(hc, R_CTRL, 0x0); /* was _io before */
571 writepcibridge(struct hfc_multi *hc, unsigned char address, unsigned char data)
584 /* select local bridge port address by writing to CIP port */
585 outw(cipv, hc->pci_iobase + 4);
586 /* define a 32 bit dword with 4 identical bytes for write sequence */
587 datav = data | ((__u32) data << 8) | ((__u32) data << 16) |
588 ((__u32) data << 24);
591 * write this 32 bit dword to the bridge data port
592 * this will initiate a write sequence of up to 4 writes to the same
593 * address on the local bus interface the number of write accesses
594 * is undefined but >=1 and depends on the next PCI transaction
595 * during write sequence on the local bus
597 outl(datav, hc->pci_iobase);
601 cpld_set_reg(struct hfc_multi *hc, unsigned char reg)
603 /* Do data pin read low byte */
604 HFC_outb(hc, R_GPIO_OUT1, reg);
608 cpld_write_reg(struct hfc_multi *hc, unsigned char reg, unsigned char val)
610 cpld_set_reg(hc, reg);
613 writepcibridge(hc, 1, val);
614 disablepcibridge(hc);
620 cpld_read_reg(struct hfc_multi *hc, unsigned char reg)
622 unsigned char bytein;
624 cpld_set_reg(hc, reg);
626 /* Do data pin read low byte */
627 HFC_outb(hc, R_GPIO_OUT1, reg);
630 bytein = readpcibridge(hc, 1);
631 disablepcibridge(hc);
637 vpm_write_address(struct hfc_multi *hc, unsigned short addr)
639 cpld_write_reg(hc, 0, 0xff & addr);
640 cpld_write_reg(hc, 1, 0x01 & (addr >> 8));
643 inline unsigned short
644 vpm_read_address(struct hfc_multi *c)
647 unsigned short highbit;
649 addr = cpld_read_reg(c, 0);
650 highbit = cpld_read_reg(c, 1);
652 addr = addr | (highbit << 8);
658 vpm_in(struct hfc_multi *c, int which, unsigned short addr)
662 vpm_write_address(c, addr);
670 res = readpcibridge(c, 1);
679 vpm_out(struct hfc_multi *c, int which, unsigned short addr,
682 vpm_write_address(c, addr);
691 writepcibridge(c, 1, data);
699 regin = vpm_in(c, which, addr);
701 printk(KERN_DEBUG "Wrote 0x%x to register 0x%x but got back "
702 "0x%x\n", data, addr, regin);
709 vpm_init(struct hfc_multi *wc)
713 unsigned int i, x, y;
716 for (x = 0; x < NUM_EC; x++) {
719 ver = vpm_in(wc, x, 0x1a0);
720 printk(KERN_DEBUG "VPM: Chip %d: ver %02x\n", x, ver);
723 for (y = 0; y < 4; y++) {
724 vpm_out(wc, x, 0x1a8 + y, 0x00); /* GPIO out */
725 vpm_out(wc, x, 0x1ac + y, 0x00); /* GPIO dir */
726 vpm_out(wc, x, 0x1b0 + y, 0x00); /* GPIO sel */
729 /* Setup TDM path - sets fsync and tdm_clk as inputs */
730 reg = vpm_in(wc, x, 0x1a3); /* misc_con */
731 vpm_out(wc, x, 0x1a3, reg & ~2);
733 /* Setup Echo length (256 taps) */
734 vpm_out(wc, x, 0x022, 1);
735 vpm_out(wc, x, 0x023, 0xff);
737 /* Setup timeslots */
738 vpm_out(wc, x, 0x02f, 0x00);
739 mask = 0x02020202 << (x * 4);
741 /* Setup the tdm channel masks for all chips */
742 for (i = 0; i < 4; i++)
743 vpm_out(wc, x, 0x33 - i, (mask >> (i << 3)) & 0xff);
745 /* Setup convergence rate */
746 printk(KERN_DEBUG "VPM: A-law mode\n");
747 reg = 0x00 | 0x10 | 0x01;
748 vpm_out(wc, x, 0x20, reg);
749 printk(KERN_DEBUG "VPM reg 0x20 is %x\n", reg);
750 /*vpm_out(wc, x, 0x20, (0x00 | 0x08 | 0x20 | 0x10)); */
752 vpm_out(wc, x, 0x24, 0x02);
753 reg = vpm_in(wc, x, 0x24);
754 printk(KERN_DEBUG "NLP Thresh is set to %d (0x%x)\n", reg, reg);
756 /* Initialize echo cans */
757 for (i = 0; i < MAX_TDM_CHAN; i++) {
758 if (mask & (0x00000001 << i))
759 vpm_out(wc, x, i, 0x00);
763 * ARM arch at least disallows a udelay of
764 * more than 2ms... it gives a fake "__bad_udelay"
765 * reference at link-time.
766 * long delays in kernel code are pretty sucky anyway
767 * for now work around it using 5 x 2ms instead of 1 x 10ms
776 /* Put in bypass mode */
777 for (i = 0; i < MAX_TDM_CHAN; i++) {
778 if (mask & (0x00000001 << i))
779 vpm_out(wc, x, i, 0x01);
783 for (i = 0; i < MAX_TDM_CHAN; i++) {
784 if (mask & (0x00000001 << i))
785 vpm_out(wc, x, 0x78 + i, 0x01);
793 vpm_check(struct hfc_multi *hctmp)
797 gpi2 = HFC_inb(hctmp, R_GPI_IN2);
799 if ((gpi2 & 0x3) != 0x3)
800 printk(KERN_DEBUG "Got interrupt 0x%x from VPM!\n", gpi2);
806 * Interface to enable/disable the HW Echocan
808 * these functions are called within a spin_lock_irqsave on
809 * the channel instance lock, so we are not disturbed by irqs
811 * we can later easily change the interface to make other
812 * things configurable, for now we configure the taps
817 vpm_echocan_on(struct hfc_multi *hc, int ch, int taps)
819 unsigned int timeslot;
821 struct bchannel *bch = hc->chan[ch].bch;
826 if (hc->chan[ch].protocol != ISDN_P_B_RAW)
833 skb = _alloc_mISDN_skb(PH_CONTROL_IND, HFC_VOL_CHANGE_TX,
834 sizeof(int), &txadj, GFP_ATOMIC);
836 recv_Bchannel_skb(bch, skb);
839 timeslot = ((ch/4)*8) + ((ch%4)*4) + 1;
842 printk(KERN_NOTICE "vpm_echocan_on called taps [%d] on timeslot %d\n",
845 vpm_out(hc, unit, timeslot, 0x7e);
849 vpm_echocan_off(struct hfc_multi *hc, int ch)
851 unsigned int timeslot;
853 struct bchannel *bch = hc->chan[ch].bch;
859 if (hc->chan[ch].protocol != ISDN_P_B_RAW)
866 skb = _alloc_mISDN_skb(PH_CONTROL_IND, HFC_VOL_CHANGE_TX,
867 sizeof(int), &txadj, GFP_ATOMIC);
869 recv_Bchannel_skb(bch, skb);
872 timeslot = ((ch/4)*8) + ((ch%4)*4) + 1;
875 printk(KERN_NOTICE "vpm_echocan_off called on timeslot %d\n",
878 vpm_out(hc, unit, timeslot, 0x01);
883 * Speech Design resync feature
884 * NOTE: This is called sometimes outside interrupt handler.
885 * We must lock irqsave, so no other interrupt (other card) will occurr!
886 * Also multiple interrupts may nest, so must lock each access (lists, card)!
889 hfcmulti_resync(struct hfc_multi *locked, struct hfc_multi *newmaster, int rm)
891 struct hfc_multi *hc, *next, *pcmmaster = NULL;
892 void __iomem *plx_acc_32;
896 spin_lock_irqsave(&HFClock, flags);
897 spin_lock(&plx_lock); /* must be locked inside other locks */
899 if (debug & DEBUG_HFCMULTI_PLXSD)
900 printk(KERN_DEBUG "%s: RESYNC(syncmaster=0x%p)\n",
901 __func__, syncmaster);
903 /* select new master */
905 if (debug & DEBUG_HFCMULTI_PLXSD)
906 printk(KERN_DEBUG "using provided controller\n");
908 list_for_each_entry_safe(hc, next, &HFClist, list) {
909 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
910 if (hc->syncronized) {
918 /* Disable sync of all cards */
919 list_for_each_entry_safe(hc, next, &HFClist, list) {
920 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
921 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
922 pv = readl(plx_acc_32);
923 pv &= ~PLX_SYNC_O_EN;
924 writel(pv, plx_acc_32);
925 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip)) {
928 if (debug & DEBUG_HFCMULTI_PLXSD)
930 "Schedule SYNC_I\n");
931 hc->e1_resync |= 1; /* get SYNC_I */
939 if (debug & DEBUG_HFCMULTI_PLXSD)
940 printk(KERN_DEBUG "id=%d (0x%p) = syncronized with "
941 "interface.\n", hc->id, hc);
942 /* Enable new sync master */
943 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
944 pv = readl(plx_acc_32);
946 writel(pv, plx_acc_32);
947 /* switch to jatt PLL, if not disabled by RX_SYNC */
948 if (hc->type == 1 && !test_bit(HFC_CHIP_RX_SYNC, &hc->chip)) {
949 if (debug & DEBUG_HFCMULTI_PLXSD)
950 printk(KERN_DEBUG "Schedule jatt PLL\n");
951 hc->e1_resync |= 2; /* switch to jatt */
956 if (debug & DEBUG_HFCMULTI_PLXSD)
958 "id=%d (0x%p) = PCM master syncronized "
959 "with QUARTZ\n", hc->id, hc);
961 /* Use the crystal clock for the PCM
963 if (debug & DEBUG_HFCMULTI_PLXSD)
965 "Schedule QUARTZ for HFC-E1\n");
966 hc->e1_resync |= 4; /* switch quartz */
968 if (debug & DEBUG_HFCMULTI_PLXSD)
970 "QUARTZ is automatically "
971 "enabled by HFC-%dS\n", hc->type);
973 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
974 pv = readl(plx_acc_32);
976 writel(pv, plx_acc_32);
979 printk(KERN_ERR "%s no pcm master, this MUST "
980 "not happen!\n", __func__);
982 syncmaster = newmaster;
984 spin_unlock(&plx_lock);
985 spin_unlock_irqrestore(&HFClock, flags);
988 /* This must be called AND hc must be locked irqsave!!! */
990 plxsd_checksync(struct hfc_multi *hc, int rm)
992 if (hc->syncronized) {
993 if (syncmaster == NULL) {
994 if (debug & DEBUG_HFCMULTI_PLXSD)
995 printk(KERN_WARNING "%s: GOT sync on card %d"
996 " (id=%d)\n", __func__, hc->id + 1,
998 hfcmulti_resync(hc, hc, rm);
1001 if (syncmaster == hc) {
1002 if (debug & DEBUG_HFCMULTI_PLXSD)
1003 printk(KERN_WARNING "%s: LOST sync on card %d"
1004 " (id=%d)\n", __func__, hc->id + 1,
1006 hfcmulti_resync(hc, NULL, rm);
1013 * free hardware resources used by driver
1016 release_io_hfcmulti(struct hfc_multi *hc)
1018 void __iomem *plx_acc_32;
1022 if (debug & DEBUG_HFCMULTI_INIT)
1023 printk(KERN_DEBUG "%s: entered\n", __func__);
1025 /* soft reset also masks all interrupts */
1026 hc->hw.r_cirm |= V_SRES;
1027 HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
1029 hc->hw.r_cirm &= ~V_SRES;
1030 HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
1031 udelay(1000); /* instead of 'wait' that may cause locking */
1033 /* release Speech Design card, if PLX was initialized */
1034 if (test_bit(HFC_CHIP_PLXSD, &hc->chip) && hc->plx_membase) {
1035 if (debug & DEBUG_HFCMULTI_PLXSD)
1036 printk(KERN_DEBUG "%s: release PLXSD card %d\n",
1037 __func__, hc->id + 1);
1038 spin_lock_irqsave(&plx_lock, plx_flags);
1039 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
1040 writel(PLX_GPIOC_INIT, plx_acc_32);
1041 pv = readl(plx_acc_32);
1042 /* Termination off */
1044 /* Disconnect the PCM */
1045 pv |= PLX_SLAVE_EN_N;
1046 pv &= ~PLX_MASTER_EN;
1047 pv &= ~PLX_SYNC_O_EN;
1048 /* Put the DSP in Reset */
1049 pv &= ~PLX_DSP_RES_N;
1050 writel(pv, plx_acc_32);
1051 if (debug & DEBUG_HFCMULTI_INIT)
1052 printk(KERN_WARNING "%s: PCM off: PLX_GPIO=%x\n",
1054 spin_unlock_irqrestore(&plx_lock, plx_flags);
1057 /* disable memory mapped ports / io ports */
1058 test_and_clear_bit(HFC_CHIP_PLXSD, &hc->chip); /* prevent resync */
1059 pci_write_config_word(hc->pci_dev, PCI_COMMAND, 0);
1060 if (hc->pci_membase)
1061 iounmap(hc->pci_membase);
1062 if (hc->plx_membase)
1063 iounmap(hc->plx_membase);
1065 release_region(hc->pci_iobase, 8);
1068 pci_disable_device(hc->pci_dev);
1069 pci_set_drvdata(hc->pci_dev, NULL);
1071 if (debug & DEBUG_HFCMULTI_INIT)
1072 printk(KERN_DEBUG "%s: done\n", __func__);
1076 * function called to reset the HFC chip. A complete software reset of chip
1077 * and fifos is done. All configuration of the chip is done.
1081 init_chip(struct hfc_multi *hc)
1083 u_long flags, val, val2 = 0, rev;
1085 u_char r_conf_en, rval;
1086 void __iomem *plx_acc_32;
1088 u_long plx_flags, hfc_flags;
1090 struct hfc_multi *pos, *next, *plx_last_hc;
1092 spin_lock_irqsave(&hc->lock, flags);
1093 /* reset all registers */
1094 memset(&hc->hw, 0, sizeof(struct hfcm_hw));
1096 /* revision check */
1097 if (debug & DEBUG_HFCMULTI_INIT)
1098 printk(KERN_DEBUG "%s: entered\n", __func__);
1099 val = HFC_inb(hc, R_CHIP_ID)>>4;
1100 if (val != 0x8 && val != 0xc && val != 0xe) {
1101 printk(KERN_INFO "HFC_multi: unknown CHIP_ID:%x\n", (u_int)val);
1105 rev = HFC_inb(hc, R_CHIP_RV);
1107 "HFC_multi: detected HFC with chip ID=0x%lx revision=%ld%s\n",
1108 val, rev, (rev == 0) ? " (old FIFO handling)" : "");
1110 test_and_set_bit(HFC_CHIP_REVISION0, &hc->chip);
1112 "HFC_multi: NOTE: Your chip is revision 0, "
1113 "ask Cologne Chip for update. Newer chips "
1114 "have a better FIFO handling. Old chips "
1115 "still work but may have slightly lower "
1116 "HDLC transmit performance.\n");
1119 printk(KERN_WARNING "HFC_multi: WARNING: This driver doesn't "
1120 "consider chip revision = %ld. The chip / "
1121 "bridge may not work.\n", rev);
1124 /* set s-ram size */
1128 hc->DTMFbase = 0x1000;
1129 if (test_bit(HFC_CHIP_EXRAM_128, &hc->chip)) {
1130 if (debug & DEBUG_HFCMULTI_INIT)
1131 printk(KERN_DEBUG "%s: changing to 128K extenal RAM\n",
1133 hc->hw.r_ctrl |= V_EXT_RAM;
1134 hc->hw.r_ram_sz = 1;
1138 hc->DTMFbase = 0x2000;
1140 if (test_bit(HFC_CHIP_EXRAM_512, &hc->chip)) {
1141 if (debug & DEBUG_HFCMULTI_INIT)
1142 printk(KERN_DEBUG "%s: changing to 512K extenal RAM\n",
1144 hc->hw.r_ctrl |= V_EXT_RAM;
1145 hc->hw.r_ram_sz = 2;
1149 hc->DTMFbase = 0x2000;
1151 hc->max_trans = poll << 1;
1152 if (hc->max_trans > hc->Zlen)
1153 hc->max_trans = hc->Zlen;
1155 /* Speech Design PLX bridge */
1156 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
1157 if (debug & DEBUG_HFCMULTI_PLXSD)
1158 printk(KERN_DEBUG "%s: initializing PLXSD card %d\n",
1159 __func__, hc->id + 1);
1160 spin_lock_irqsave(&plx_lock, plx_flags);
1161 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
1162 writel(PLX_GPIOC_INIT, plx_acc_32);
1163 pv = readl(plx_acc_32);
1164 /* The first and the last cards are terminating the PCM bus */
1165 pv |= PLX_TERM_ON; /* hc is currently the last */
1166 /* Disconnect the PCM */
1167 pv |= PLX_SLAVE_EN_N;
1168 pv &= ~PLX_MASTER_EN;
1169 pv &= ~PLX_SYNC_O_EN;
1170 /* Put the DSP in Reset */
1171 pv &= ~PLX_DSP_RES_N;
1172 writel(pv, plx_acc_32);
1173 spin_unlock_irqrestore(&plx_lock, plx_flags);
1174 if (debug & DEBUG_HFCMULTI_INIT)
1175 printk(KERN_WARNING "%s: slave/term: PLX_GPIO=%x\n",
1178 * If we are the 3rd PLXSD card or higher, we must turn
1179 * termination of last PLXSD card off.
1181 spin_lock_irqsave(&HFClock, hfc_flags);
1184 list_for_each_entry_safe(pos, next, &HFClist, list) {
1185 if (test_bit(HFC_CHIP_PLXSD, &pos->chip)) {
1191 if (plx_count >= 3) {
1192 if (debug & DEBUG_HFCMULTI_PLXSD)
1193 printk(KERN_DEBUG "%s: card %d is between, so "
1194 "we disable termination\n",
1195 __func__, plx_last_hc->id + 1);
1196 spin_lock_irqsave(&plx_lock, plx_flags);
1197 plx_acc_32 = plx_last_hc->plx_membase + PLX_GPIOC;
1198 pv = readl(plx_acc_32);
1200 writel(pv, plx_acc_32);
1201 spin_unlock_irqrestore(&plx_lock, plx_flags);
1202 if (debug & DEBUG_HFCMULTI_INIT)
1203 printk(KERN_WARNING "%s: term off: PLX_GPIO=%x\n",
1206 spin_unlock_irqrestore(&HFClock, hfc_flags);
1207 hc->hw.r_pcm_md0 = V_F0_LEN; /* shift clock for DSP */
1210 /* we only want the real Z2 read-pointer for revision > 0 */
1211 if (!test_bit(HFC_CHIP_REVISION0, &hc->chip))
1212 hc->hw.r_ram_sz |= V_FZ_MD;
1214 /* select pcm mode */
1215 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
1216 if (debug & DEBUG_HFCMULTI_INIT)
1217 printk(KERN_DEBUG "%s: setting PCM into slave mode\n",
1220 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip) && !plxsd_master) {
1221 if (debug & DEBUG_HFCMULTI_INIT)
1222 printk(KERN_DEBUG "%s: setting PCM into master mode\n",
1224 hc->hw.r_pcm_md0 |= V_PCM_MD;
1226 if (debug & DEBUG_HFCMULTI_INIT)
1227 printk(KERN_DEBUG "%s: performing PCM auto detect\n",
1232 HFC_outb(hc, R_CTRL, hc->hw.r_ctrl);
1233 HFC_outb(hc, R_RAM_SZ, hc->hw.r_ram_sz);
1234 HFC_outb(hc, R_FIFO_MD, 0);
1235 hc->hw.r_cirm = V_SRES | V_HFCRES | V_PCMRES | V_STRES | V_RLD_EPR;
1236 HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
1239 HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
1241 HFC_outb(hc, R_RAM_SZ, hc->hw.r_ram_sz);
1243 /* Speech Design PLX bridge pcm and sync mode */
1244 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
1245 spin_lock_irqsave(&plx_lock, plx_flags);
1246 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
1247 pv = readl(plx_acc_32);
1249 if (hc->hw.r_pcm_md0 & V_PCM_MD) {
1250 pv |= PLX_MASTER_EN | PLX_SLAVE_EN_N;
1251 pv |= PLX_SYNC_O_EN;
1252 if (debug & DEBUG_HFCMULTI_INIT)
1253 printk(KERN_WARNING "%s: master: PLX_GPIO=%x\n",
1256 pv &= ~(PLX_MASTER_EN | PLX_SLAVE_EN_N);
1257 pv &= ~PLX_SYNC_O_EN;
1258 if (debug & DEBUG_HFCMULTI_INIT)
1259 printk(KERN_WARNING "%s: slave: PLX_GPIO=%x\n",
1262 writel(pv, plx_acc_32);
1263 spin_unlock_irqrestore(&plx_lock, plx_flags);
1267 HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0x90);
1268 if (hc->slots == 32)
1269 HFC_outb(hc, R_PCM_MD1, 0x00);
1270 if (hc->slots == 64)
1271 HFC_outb(hc, R_PCM_MD1, 0x10);
1272 if (hc->slots == 128)
1273 HFC_outb(hc, R_PCM_MD1, 0x20);
1274 HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0xa0);
1275 if (test_bit(HFC_CHIP_PLXSD, &hc->chip))
1276 HFC_outb(hc, R_PCM_MD2, V_SYNC_SRC); /* sync via SYNC_I / O */
1278 HFC_outb(hc, R_PCM_MD2, 0x00); /* sync from interface */
1279 HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0x00);
1280 for (i = 0; i < 256; i++) {
1281 HFC_outb_nodebug(hc, R_SLOT, i);
1282 HFC_outb_nodebug(hc, A_SL_CFG, 0);
1283 HFC_outb_nodebug(hc, A_CONF, 0);
1284 hc->slot_owner[i] = -1;
1287 /* set clock speed */
1288 if (test_bit(HFC_CHIP_CLOCK2, &hc->chip)) {
1289 if (debug & DEBUG_HFCMULTI_INIT)
1291 "%s: setting double clock\n", __func__);
1292 HFC_outb(hc, R_BRG_PCM_CFG, V_PCM_CLK);
1296 if (test_bit(HFC_CHIP_B410P, &hc->chip)) {
1297 printk(KERN_NOTICE "Setting GPIOs\n");
1298 HFC_outb(hc, R_GPIO_SEL, 0x30);
1299 HFC_outb(hc, R_GPIO_EN1, 0x3);
1301 printk(KERN_NOTICE "calling vpm_init\n");
1305 /* check if R_F0_CNT counts (8 kHz frame count) */
1306 val = HFC_inb(hc, R_F0_CNTL);
1307 val += HFC_inb(hc, R_F0_CNTH) << 8;
1308 if (debug & DEBUG_HFCMULTI_INIT)
1310 "HFC_multi F0_CNT %ld after reset\n", val);
1311 spin_unlock_irqrestore(&hc->lock, flags);
1312 set_current_state(TASK_UNINTERRUPTIBLE);
1313 schedule_timeout((HZ/100)?:1); /* Timeout minimum 10ms */
1314 spin_lock_irqsave(&hc->lock, flags);
1315 val2 = HFC_inb(hc, R_F0_CNTL);
1316 val2 += HFC_inb(hc, R_F0_CNTH) << 8;
1317 if (debug & DEBUG_HFCMULTI_INIT)
1319 "HFC_multi F0_CNT %ld after 10 ms (1st try)\n",
1321 if (val2 >= val+8) { /* 1 ms */
1322 /* it counts, so we keep the pcm mode */
1323 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip))
1324 printk(KERN_INFO "controller is PCM bus MASTER\n");
1326 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip))
1327 printk(KERN_INFO "controller is PCM bus SLAVE\n");
1329 test_and_set_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
1330 printk(KERN_INFO "controller is PCM bus SLAVE "
1331 "(auto detected)\n");
1334 /* does not count */
1335 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip)) {
1337 printk(KERN_ERR "HFC_multi ERROR, getting no 125us "
1338 "pulse. Seems that controller fails.\n");
1342 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
1343 printk(KERN_INFO "controller is PCM bus SLAVE "
1344 "(ignoring missing PCM clock)\n");
1346 /* only one pcm master */
1347 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)
1349 printk(KERN_ERR "HFC_multi ERROR, no clock "
1350 "on another Speech Design card found. "
1351 "Please be sure to connect PCM cable.\n");
1355 /* retry with master clock */
1356 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
1357 spin_lock_irqsave(&plx_lock, plx_flags);
1358 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
1359 pv = readl(plx_acc_32);
1360 pv |= PLX_MASTER_EN | PLX_SLAVE_EN_N;
1361 pv |= PLX_SYNC_O_EN;
1362 writel(pv, plx_acc_32);
1363 spin_unlock_irqrestore(&plx_lock, plx_flags);
1364 if (debug & DEBUG_HFCMULTI_INIT)
1365 printk(KERN_WARNING "%s: master: PLX_GPIO"
1366 "=%x\n", __func__, pv);
1368 hc->hw.r_pcm_md0 |= V_PCM_MD;
1369 HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0x00);
1370 spin_unlock_irqrestore(&hc->lock, flags);
1371 set_current_state(TASK_UNINTERRUPTIBLE);
1372 schedule_timeout((HZ/100)?:1); /* Timeout min. 10ms */
1373 spin_lock_irqsave(&hc->lock, flags);
1374 val2 = HFC_inb(hc, R_F0_CNTL);
1375 val2 += HFC_inb(hc, R_F0_CNTH) << 8;
1376 if (debug & DEBUG_HFCMULTI_INIT)
1377 printk(KERN_DEBUG "HFC_multi F0_CNT %ld after "
1378 "10 ms (2nd try)\n", val2);
1379 if (val2 >= val+8) { /* 1 ms */
1380 test_and_set_bit(HFC_CHIP_PCM_MASTER,
1382 printk(KERN_INFO "controller is PCM bus MASTER "
1383 "(auto detected)\n");
1385 goto controller_fail;
1389 /* Release the DSP Reset */
1390 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
1391 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip))
1393 spin_lock_irqsave(&plx_lock, plx_flags);
1394 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
1395 pv = readl(plx_acc_32);
1396 pv |= PLX_DSP_RES_N;
1397 writel(pv, plx_acc_32);
1398 spin_unlock_irqrestore(&plx_lock, plx_flags);
1399 if (debug & DEBUG_HFCMULTI_INIT)
1400 printk(KERN_WARNING "%s: reset off: PLX_GPIO=%x\n",
1406 printk(KERN_INFO "controller has given PCM BUS ID %d\n",
1409 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip)
1410 || test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
1411 PCM_cnt++; /* SD has proprietary bridging */
1414 printk(KERN_INFO "controller has PCM BUS ID %d "
1415 "(auto selected)\n", hc->pcm);
1419 HFC_outb(hc, R_TI_WD, poll_timer);
1420 hc->hw.r_irqmsk_misc |= V_TI_IRQMSK;
1423 * set up 125us interrupt, only if function pointer is available
1424 * and module parameter timer is set
1426 if (timer && hfc_interrupt && register_interrupt) {
1427 /* only one chip should use this interrupt */
1429 interrupt_registered = 1;
1430 hc->hw.r_irqmsk_misc |= V_PROC_IRQMSK;
1431 /* deactivate other interrupts in ztdummy */
1432 register_interrupt();
1435 /* set E1 state machine IRQ */
1437 hc->hw.r_irqmsk_misc |= V_STA_IRQMSK;
1439 /* set DTMF detection */
1440 if (test_bit(HFC_CHIP_DTMF, &hc->chip)) {
1441 if (debug & DEBUG_HFCMULTI_INIT)
1442 printk(KERN_DEBUG "%s: enabling DTMF detection "
1443 "for all B-channel\n", __func__);
1444 hc->hw.r_dtmf = V_DTMF_EN | V_DTMF_STOP;
1445 if (test_bit(HFC_CHIP_ULAW, &hc->chip))
1446 hc->hw.r_dtmf |= V_ULAW_SEL;
1447 HFC_outb(hc, R_DTMF_N, 102 - 1);
1448 hc->hw.r_irqmsk_misc |= V_DTMF_IRQMSK;
1451 /* conference engine */
1452 if (test_bit(HFC_CHIP_ULAW, &hc->chip))
1453 r_conf_en = V_CONF_EN | V_ULAW;
1455 r_conf_en = V_CONF_EN;
1456 HFC_outb(hc, R_CONF_EN, r_conf_en);
1460 case 1: /* HFC-E1 OEM */
1461 if (test_bit(HFC_CHIP_WATCHDOG, &hc->chip))
1462 HFC_outb(hc, R_GPIO_SEL, 0x32);
1464 HFC_outb(hc, R_GPIO_SEL, 0x30);
1466 HFC_outb(hc, R_GPIO_EN1, 0x0f);
1467 HFC_outb(hc, R_GPIO_OUT1, 0x00);
1469 HFC_outb(hc, R_GPIO_EN0, V_GPIO_EN2 | V_GPIO_EN3);
1472 case 2: /* HFC-4S OEM */
1474 HFC_outb(hc, R_GPIO_SEL, 0xf0);
1475 HFC_outb(hc, R_GPIO_EN1, 0xff);
1476 HFC_outb(hc, R_GPIO_OUT1, 0x00);
1480 /* set master clock */
1481 if (hc->masterclk >= 0) {
1482 if (debug & DEBUG_HFCMULTI_INIT)
1483 printk(KERN_DEBUG "%s: setting ST master clock "
1484 "to port %d (0..%d)\n",
1485 __func__, hc->masterclk, hc->ports-1);
1486 hc->hw.r_st_sync = hc->masterclk | V_AUTO_SYNC;
1487 HFC_outb(hc, R_ST_SYNC, hc->hw.r_st_sync);
1490 /* setting misc irq */
1491 HFC_outb(hc, R_IRQMSK_MISC, hc->hw.r_irqmsk_misc);
1492 if (debug & DEBUG_HFCMULTI_INIT)
1493 printk(KERN_DEBUG "r_irqmsk_misc.2: 0x%x\n",
1494 hc->hw.r_irqmsk_misc);
1496 /* RAM access test */
1497 HFC_outb(hc, R_RAM_ADDR0, 0);
1498 HFC_outb(hc, R_RAM_ADDR1, 0);
1499 HFC_outb(hc, R_RAM_ADDR2, 0);
1500 for (i = 0; i < 256; i++) {
1501 HFC_outb_nodebug(hc, R_RAM_ADDR0, i);
1502 HFC_outb_nodebug(hc, R_RAM_DATA, ((i*3)&0xff));
1504 for (i = 0; i < 256; i++) {
1505 HFC_outb_nodebug(hc, R_RAM_ADDR0, i);
1506 HFC_inb_nodebug(hc, R_RAM_DATA);
1507 rval = HFC_inb_nodebug(hc, R_INT_DATA);
1508 if (rval != ((i * 3) & 0xff)) {
1510 "addr:%x val:%x should:%x\n", i, rval,
1516 printk(KERN_DEBUG "aborting - %d RAM access errors\n", err);
1521 if (debug & DEBUG_HFCMULTI_INIT)
1522 printk(KERN_DEBUG "%s: done\n", __func__);
1524 spin_unlock_irqrestore(&hc->lock, flags);
1530 * control the watchdog
1533 hfcmulti_watchdog(struct hfc_multi *hc)
1537 if (hc->wdcount > 10) {
1539 hc->wdbyte = hc->wdbyte == V_GPIO_OUT2 ?
1540 V_GPIO_OUT3 : V_GPIO_OUT2;
1542 /* printk("Sending Watchdog Kill %x\n",hc->wdbyte); */
1543 HFC_outb(hc, R_GPIO_EN0, V_GPIO_EN2 | V_GPIO_EN3);
1544 HFC_outb(hc, R_GPIO_OUT0, hc->wdbyte);
1554 hfcmulti_leds(struct hfc_multi *hc)
1557 unsigned long leddw;
1558 int i, state, active, leds;
1559 struct dchannel *dch;
1562 hc->ledcount += poll;
1563 if (hc->ledcount > 4096) {
1564 hc->ledcount -= 4096;
1565 hc->ledstate = 0xAFFEAFFE;
1569 case 1: /* HFC-E1 OEM */
1570 /* 2 red blinking: NT mode deactivate
1571 * 2 red steady: TE mode deactivate
1572 * left green: L1 active
1573 * left red: frame sync, but no L1
1574 * right green: L2 active
1576 if (hc->chan[hc->dslot].sync != 2) { /* no frame sync */
1577 if (hc->chan[hc->dslot].dch->dev.D.protocol
1581 } else if (hc->ledcount>>11) {
1590 } else { /* with frame sync */
1591 /* TODO make it work */
1597 leds = (led[0] | (led[1]<<2) | (led[2]<<1) | (led[3]<<3))^0xF;
1598 /* leds are inverted */
1599 if (leds != (int)hc->ledstate) {
1600 HFC_outb_nodebug(hc, R_GPIO_OUT1, leds);
1601 hc->ledstate = leds;
1605 case 2: /* HFC-4S OEM */
1606 /* red blinking = PH_DEACTIVATE NT Mode
1607 * red steady = PH_DEACTIVATE TE Mode
1608 * green steady = PH_ACTIVATE
1610 for (i = 0; i < 4; i++) {
1613 dch = hc->chan[(i << 2) | 2].dch;
1616 if (dch->dev.D.protocol == ISDN_P_NT_S0)
1622 if (state == active) {
1623 led[i] = 1; /* led green */
1625 if (dch->dev.D.protocol == ISDN_P_TE_S0)
1626 /* TE mode: led red */
1629 if (hc->ledcount>>11)
1636 led[i] = 0; /* led off */
1638 if (test_bit(HFC_CHIP_B410P, &hc->chip)) {
1640 for (i = 0; i < 4; i++) {
1643 leds |= (0x2 << (i * 2));
1644 } else if (led[i] == 2) {
1646 leds |= (0x1 << (i * 2));
1649 if (leds != (int)hc->ledstate) {
1650 vpm_out(hc, 0, 0x1a8 + 3, leds);
1651 hc->ledstate = leds;
1654 leds = ((led[3] > 0) << 0) | ((led[1] > 0) << 1) |
1655 ((led[0] > 0) << 2) | ((led[2] > 0) << 3) |
1656 ((led[3] & 1) << 4) | ((led[1] & 1) << 5) |
1657 ((led[0] & 1) << 6) | ((led[2] & 1) << 7);
1658 if (leds != (int)hc->ledstate) {
1659 HFC_outb_nodebug(hc, R_GPIO_EN1, leds & 0x0F);
1660 HFC_outb_nodebug(hc, R_GPIO_OUT1, leds >> 4);
1661 hc->ledstate = leds;
1666 case 3: /* HFC 1S/2S Beronet */
1667 /* red blinking = PH_DEACTIVATE NT Mode
1668 * red steady = PH_DEACTIVATE TE Mode
1669 * green steady = PH_ACTIVATE
1671 for (i = 0; i < 2; i++) {
1674 dch = hc->chan[(i << 2) | 2].dch;
1677 if (dch->dev.D.protocol == ISDN_P_NT_S0)
1683 if (state == active) {
1684 led[i] = 1; /* led green */
1686 if (dch->dev.D.protocol == ISDN_P_TE_S0)
1687 /* TE mode: led red */
1690 if (hc->ledcount >> 11)
1697 led[i] = 0; /* led off */
1701 leds = (led[0] > 0) | ((led[1] > 0)<<1) | ((led[0]&1)<<2)
1703 if (leds != (int)hc->ledstate) {
1704 HFC_outb_nodebug(hc, R_GPIO_EN1,
1705 ((led[0] > 0) << 2) | ((led[1] > 0) << 3));
1706 HFC_outb_nodebug(hc, R_GPIO_OUT1,
1707 ((led[0] & 1) << 2) | ((led[1] & 1) << 3));
1708 hc->ledstate = leds;
1711 case 8: /* HFC 8S+ Beronet */
1714 for (i = 0; i < 8; i++) {
1717 dch = hc->chan[(i << 2) | 2].dch;
1720 if (dch->dev.D.protocol == ISDN_P_NT_S0)
1726 if (state == active) {
1729 if (hc->ledcount >> 11)
1736 leddw = lled << 24 | lled << 16 | lled << 8 | lled;
1737 if (leddw != hc->ledstate) {
1738 /* HFC_outb(hc, R_BRG_PCM_CFG, 1);
1739 HFC_outb(c, R_BRG_PCM_CFG, (0x0 << 6) | 0x3); */
1740 /* was _io before */
1741 HFC_outb_nodebug(hc, R_BRG_PCM_CFG, 1 | V_PCM_CLK);
1742 outw(0x4000, hc->pci_iobase + 4);
1743 outl(leddw, hc->pci_iobase);
1744 HFC_outb_nodebug(hc, R_BRG_PCM_CFG, V_PCM_CLK);
1745 hc->ledstate = leddw;
1751 * read dtmf coefficients
1755 hfcmulti_dtmf(struct hfc_multi *hc)
1760 struct bchannel *bch = NULL;
1765 struct sk_buff *skb;
1766 struct mISDNhead *hh;
1768 if (debug & DEBUG_HFCMULTI_DTMF)
1769 printk(KERN_DEBUG "%s: dtmf detection irq\n", __func__);
1770 for (ch = 0; ch <= 31; ch++) {
1771 /* only process enabled B-channels */
1772 bch = hc->chan[ch].bch;
1775 if (!hc->created[hc->chan[ch].port])
1777 if (!test_bit(FLG_TRANSPARENT, &bch->Flags))
1779 if (debug & DEBUG_HFCMULTI_DTMF)
1780 printk(KERN_DEBUG "%s: dtmf channel %d:",
1782 coeff = &(hc->chan[ch].coeff[hc->chan[ch].coeff_count * 16]);
1784 for (co = 0; co < 8; co++) {
1785 /* read W(n-1) coefficient */
1786 addr = hc->DTMFbase + ((co<<7) | (ch<<2));
1787 HFC_outb_nodebug(hc, R_RAM_ADDR0, addr);
1788 HFC_outb_nodebug(hc, R_RAM_ADDR1, addr>>8);
1789 HFC_outb_nodebug(hc, R_RAM_ADDR2, (addr>>16)
1791 w_float = HFC_inb_nodebug(hc, R_RAM_DATA);
1792 w_float |= (HFC_inb_nodebug(hc, R_RAM_DATA) << 8);
1793 if (debug & DEBUG_HFCMULTI_DTMF)
1794 printk(" %04x", w_float);
1796 /* decode float (see chip doc) */
1797 mantissa = w_float & 0x0fff;
1798 if (w_float & 0x8000)
1799 mantissa |= 0xfffff000;
1800 exponent = (w_float>>12) & 0x7;
1803 mantissa <<= (exponent-1);
1806 /* store coefficient */
1807 coeff[co<<1] = mantissa;
1809 /* read W(n) coefficient */
1810 w_float = HFC_inb_nodebug(hc, R_RAM_DATA);
1811 w_float |= (HFC_inb_nodebug(hc, R_RAM_DATA) << 8);
1812 if (debug & DEBUG_HFCMULTI_DTMF)
1813 printk(" %04x", w_float);
1815 /* decode float (see chip doc) */
1816 mantissa = w_float & 0x0fff;
1817 if (w_float & 0x8000)
1818 mantissa |= 0xfffff000;
1819 exponent = (w_float>>12) & 0x7;
1822 mantissa <<= (exponent-1);
1825 /* store coefficient */
1826 coeff[(co<<1)|1] = mantissa;
1828 if (debug & DEBUG_HFCMULTI_DTMF)
1829 printk("%s: DTMF ready %08x %08x %08x %08x "
1830 "%08x %08x %08x %08x\n", __func__,
1831 coeff[0], coeff[1], coeff[2], coeff[3],
1832 coeff[4], coeff[5], coeff[6], coeff[7]);
1833 hc->chan[ch].coeff_count++;
1834 if (hc->chan[ch].coeff_count == 8) {
1835 hc->chan[ch].coeff_count = 0;
1836 skb = mI_alloc_skb(512, GFP_ATOMIC);
1838 printk(KERN_WARNING "%s: No memory for skb\n",
1842 hh = mISDN_HEAD_P(skb);
1843 hh->prim = PH_CONTROL_IND;
1844 hh->id = DTMF_HFC_COEF;
1845 memcpy(skb_put(skb, 512), hc->chan[ch].coeff, 512);
1846 recv_Bchannel_skb(bch, skb);
1850 /* restart DTMF processing */
1853 HFC_outb_nodebug(hc, R_DTMF, hc->hw.r_dtmf | V_RST_DTMF);
1858 * fill fifo as much as possible
1862 hfcmulti_tx(struct hfc_multi *hc, int ch)
1864 int i, ii, temp, len = 0;
1865 int Zspace, z1, z2; /* must be int for calculation */
1868 int *txpending, slot_tx;
1869 struct bchannel *bch;
1870 struct dchannel *dch;
1871 struct sk_buff **sp = NULL;
1874 bch = hc->chan[ch].bch;
1875 dch = hc->chan[ch].dch;
1876 if ((!dch) && (!bch))
1879 txpending = &hc->chan[ch].txpending;
1880 slot_tx = hc->chan[ch].slot_tx;
1882 if (!test_bit(FLG_ACTIVE, &dch->Flags))
1885 idxp = &dch->tx_idx;
1887 if (!test_bit(FLG_ACTIVE, &bch->Flags))
1890 idxp = &bch->tx_idx;
1895 if ((!len) && *txpending != 1)
1896 return; /* no data */
1898 if (test_bit(HFC_CHIP_B410P, &hc->chip) &&
1899 (hc->chan[ch].protocol == ISDN_P_B_RAW) &&
1900 (hc->chan[ch].slot_rx < 0) &&
1901 (hc->chan[ch].slot_tx < 0))
1902 HFC_outb_nodebug(hc, R_FIFO, 0x20 | (ch << 1));
1904 HFC_outb_nodebug(hc, R_FIFO, ch << 1);
1905 HFC_wait_nodebug(hc);
1907 if (*txpending == 2) {
1909 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_RES_F);
1910 HFC_wait_nodebug(hc);
1911 HFC_outb(hc, A_SUBCH_CFG, 0);
1915 if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
1916 f1 = HFC_inb_nodebug(hc, A_F1);
1917 f2 = HFC_inb_nodebug(hc, A_F2);
1918 while (f2 != (temp = HFC_inb_nodebug(hc, A_F2))) {
1919 if (debug & DEBUG_HFCMULTI_FIFO)
1921 "%s(card %d): reread f2 because %d!=%d\n",
1922 __func__, hc->id + 1, temp, f2);
1923 f2 = temp; /* repeat until F2 is equal */
1925 Fspace = f2 - f1 - 1;
1929 * Old FIFO handling doesn't give us the current Z2 read
1930 * pointer, so we cannot send the next frame before the fifo
1931 * is empty. It makes no difference except for a slightly
1932 * lower performance.
1934 if (test_bit(HFC_CHIP_REVISION0, &hc->chip)) {
1940 /* one frame only for ST D-channels, to allow resending */
1941 if (hc->type != 1 && dch) {
1945 /* F-counter full condition */
1949 z1 = HFC_inw_nodebug(hc, A_Z1) - hc->Zmin;
1950 z2 = HFC_inw_nodebug(hc, A_Z2) - hc->Zmin;
1951 while (z2 != (temp = (HFC_inw_nodebug(hc, A_Z2) - hc->Zmin))) {
1952 if (debug & DEBUG_HFCMULTI_FIFO)
1953 printk(KERN_DEBUG "%s(card %d): reread z2 because "
1954 "%d!=%d\n", __func__, hc->id + 1, temp, z2);
1955 z2 = temp; /* repeat unti Z2 is equal */
1960 Zspace -= 4; /* keep not too full, so pointers will not overrun */
1961 /* fill transparent data only to maxinum transparent load (minus 4) */
1962 if (bch && test_bit(FLG_TRANSPARENT, &bch->Flags))
1963 Zspace = Zspace - hc->Zlen + hc->max_trans;
1964 if (Zspace <= 0) /* no space of 4 bytes */
1969 if (z1 == z2) { /* empty */
1970 /* if done with FIFO audio data during PCM connection */
1971 if (bch && (!test_bit(FLG_HDLC, &bch->Flags)) &&
1972 *txpending && slot_tx >= 0) {
1973 if (debug & DEBUG_HFCMULTI_MODE)
1975 "%s: reconnecting PCM due to no "
1976 "more FIFO data: channel %d "
1978 __func__, ch, slot_tx);
1980 HFC_outb(hc, A_CON_HDLC, 0xc0 | 0x00 |
1981 V_HDLC_TRP | V_IFF);
1982 HFC_outb_nodebug(hc, R_FIFO, ch<<1 | 1);
1983 HFC_wait_nodebug(hc);
1984 HFC_outb(hc, A_CON_HDLC, 0xc0 | 0x00 |
1985 V_HDLC_TRP | V_IFF);
1986 HFC_outb_nodebug(hc, R_FIFO, ch<<1);
1987 HFC_wait_nodebug(hc);
1991 return; /* no data */
1994 /* if audio data and connected slot */
1995 if (bch && (!test_bit(FLG_HDLC, &bch->Flags)) && (!*txpending)
1997 if (debug & DEBUG_HFCMULTI_MODE)
1998 printk(KERN_DEBUG "%s: disconnecting PCM due to "
1999 "FIFO data: channel %d slot_tx %d\n",
2000 __func__, ch, slot_tx);
2001 /* disconnect slot */
2002 HFC_outb(hc, A_CON_HDLC, 0x80 | 0x00 | V_HDLC_TRP | V_IFF);
2003 HFC_outb_nodebug(hc, R_FIFO, ch<<1 | 1);
2004 HFC_wait_nodebug(hc);
2005 HFC_outb(hc, A_CON_HDLC, 0x80 | 0x00 | V_HDLC_TRP | V_IFF);
2006 HFC_outb_nodebug(hc, R_FIFO, ch<<1);
2007 HFC_wait_nodebug(hc);
2012 hc->activity[hc->chan[ch].port] = 1;
2014 /* fill fifo to what we have left */
2016 if (dch || test_bit(FLG_HDLC, &bch->Flags))
2021 d = (*sp)->data + i;
2022 if (ii - i > Zspace)
2024 if (debug & DEBUG_HFCMULTI_FIFO)
2025 printk(KERN_DEBUG "%s(card %d): fifo(%d) has %d bytes space "
2026 "left (z1=%04x, z2=%04x) sending %d of %d bytes %s\n",
2027 __func__, hc->id + 1, ch, Zspace, z1, z2, ii-i, len-i,
2028 temp ? "HDLC":"TRANS");
2031 /* Have to prep the audio data */
2032 hc->write_fifo(hc, d, ii - i);
2035 /* if not all data has been written */
2037 /* NOTE: fifo is started by the calling function */
2041 /* if all data has been written, terminate frame */
2042 if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
2043 /* increment f-counter */
2044 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_INC_F);
2045 HFC_wait_nodebug(hc);
2048 /* send confirm, since get_net_bframe will not do it with trans */
2049 if (bch && test_bit(FLG_TRANSPARENT, &bch->Flags))
2052 /* check for next frame */
2054 if (bch && get_next_bframe(bch)) { /* hdlc is confirmed here */
2058 if (dch && get_next_dframe(dch)) {
2064 * now we have no more data, so in case of transparent,
2065 * we set the last byte in fifo to 'silence' in case we will get
2066 * no more data at all. this prevents sending an undefined value.
2068 if (bch && test_bit(FLG_TRANSPARENT, &bch->Flags))
2069 HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, silence);
2073 /* NOTE: only called if E1 card is in active state */
2075 hfcmulti_rx(struct hfc_multi *hc, int ch)
2078 int Zsize, z1, z2 = 0; /* = 0, to make GCC happy */
2079 int f1 = 0, f2 = 0; /* = 0, to make GCC happy */
2081 struct bchannel *bch;
2082 struct dchannel *dch;
2083 struct sk_buff *skb, **sp = NULL;
2086 bch = hc->chan[ch].bch;
2087 dch = hc->chan[ch].dch;
2088 if ((!dch) && (!bch))
2091 if (!test_bit(FLG_ACTIVE, &dch->Flags))
2094 maxlen = dch->maxlen;
2096 if (!test_bit(FLG_ACTIVE, &bch->Flags))
2099 maxlen = bch->maxlen;
2102 /* on first AND before getting next valid frame, R_FIFO must be written
2104 if (test_bit(HFC_CHIP_B410P, &hc->chip) &&
2105 (hc->chan[ch].protocol == ISDN_P_B_RAW) &&
2106 (hc->chan[ch].slot_rx < 0) &&
2107 (hc->chan[ch].slot_tx < 0))
2108 HFC_outb_nodebug(hc, R_FIFO, 0x20 | (ch<<1) | 1);
2110 HFC_outb_nodebug(hc, R_FIFO, (ch<<1)|1);
2111 HFC_wait_nodebug(hc);
2113 /* ignore if rx is off BUT change fifo (above) to start pending TX */
2114 if (hc->chan[ch].rx_off)
2117 if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
2118 f1 = HFC_inb_nodebug(hc, A_F1);
2119 while (f1 != (temp = HFC_inb_nodebug(hc, A_F1))) {
2120 if (debug & DEBUG_HFCMULTI_FIFO)
2122 "%s(card %d): reread f1 because %d!=%d\n",
2123 __func__, hc->id + 1, temp, f1);
2124 f1 = temp; /* repeat until F1 is equal */
2126 f2 = HFC_inb_nodebug(hc, A_F2);
2128 z1 = HFC_inw_nodebug(hc, A_Z1) - hc->Zmin;
2129 while (z1 != (temp = (HFC_inw_nodebug(hc, A_Z1) - hc->Zmin))) {
2130 if (debug & DEBUG_HFCMULTI_FIFO)
2131 printk(KERN_DEBUG "%s(card %d): reread z2 because "
2132 "%d!=%d\n", __func__, hc->id + 1, temp, z2);
2133 z1 = temp; /* repeat until Z1 is equal */
2135 z2 = HFC_inw_nodebug(hc, A_Z2) - hc->Zmin;
2137 if ((dch || test_bit(FLG_HDLC, &bch->Flags)) && f1 != f2)
2138 /* complete hdlc frame */
2142 /* if buffer is empty */
2147 *sp = mI_alloc_skb(maxlen + 3, GFP_ATOMIC);
2149 printk(KERN_DEBUG "%s: No mem for rx_skb\n",
2155 hc->activity[hc->chan[ch].port] = 1;
2157 /* empty fifo with what we have */
2158 if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
2159 if (debug & DEBUG_HFCMULTI_FIFO)
2160 printk(KERN_DEBUG "%s(card %d): fifo(%d) reading %d "
2161 "bytes (z1=%04x, z2=%04x) HDLC %s (f1=%d, f2=%d) "
2162 "got=%d (again %d)\n", __func__, hc->id + 1, ch,
2163 Zsize, z1, z2, (f1 == f2) ? "fragment" : "COMPLETE",
2164 f1, f2, Zsize + (*sp)->len, again);
2166 if ((Zsize + (*sp)->len) > (maxlen + 3)) {
2167 if (debug & DEBUG_HFCMULTI_FIFO)
2169 "%s(card %d): hdlc-frame too large.\n",
2170 __func__, hc->id + 1);
2172 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_RES_F);
2173 HFC_wait_nodebug(hc);
2177 hc->read_fifo(hc, skb_put(*sp, Zsize), Zsize);
2180 /* increment Z2,F2-counter */
2181 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_INC_F);
2182 HFC_wait_nodebug(hc);
2184 if ((*sp)->len < 4) {
2185 if (debug & DEBUG_HFCMULTI_FIFO)
2187 "%s(card %d): Frame below minimum "
2188 "size\n", __func__, hc->id + 1);
2192 /* there is at least one complete frame, check crc */
2193 if ((*sp)->data[(*sp)->len - 1]) {
2194 if (debug & DEBUG_HFCMULTI_CRC)
2196 "%s: CRC-error\n", __func__);
2200 skb_trim(*sp, (*sp)->len - 3);
2201 if ((*sp)->len < MISDN_COPY_SIZE) {
2203 *sp = mI_alloc_skb(skb->len, GFP_ATOMIC);
2205 memcpy(skb_put(*sp, skb->len),
2206 skb->data, skb->len);
2209 printk(KERN_DEBUG "%s: No mem\n",
2217 if (debug & DEBUG_HFCMULTI_FIFO) {
2218 printk(KERN_DEBUG "%s(card %d):",
2219 __func__, hc->id + 1);
2221 while (temp < (*sp)->len)
2222 printk(" %02x", (*sp)->data[temp++]);
2233 /* there is an incomplete frame */
2236 if (Zsize > skb_tailroom(*sp))
2237 Zsize = skb_tailroom(*sp);
2238 hc->read_fifo(hc, skb_put(*sp, Zsize), Zsize);
2239 if (((*sp)->len) < MISDN_COPY_SIZE) {
2241 *sp = mI_alloc_skb(skb->len, GFP_ATOMIC);
2243 memcpy(skb_put(*sp, skb->len),
2244 skb->data, skb->len);
2247 printk(KERN_DEBUG "%s: No mem\n", __func__);
2254 if (debug & DEBUG_HFCMULTI_FIFO)
2256 "%s(card %d): fifo(%d) reading %d bytes "
2257 "(z1=%04x, z2=%04x) TRANS\n",
2258 __func__, hc->id + 1, ch, Zsize, z1, z2);
2259 /* only bch is transparent */
2270 signal_state_up(struct dchannel *dch, int info, char *msg)
2272 struct sk_buff *skb;
2273 int id, data = info;
2275 if (debug & DEBUG_HFCMULTI_STATE)
2276 printk(KERN_DEBUG "%s: %s\n", __func__, msg);
2278 id = TEI_SAPI | (GROUP_TEI << 8); /* manager address */
2280 skb = _alloc_mISDN_skb(MPH_INFORMATION_IND, id, sizeof(data), &data,
2284 recv_Dchannel_skb(dch, skb);
2288 handle_timer_irq(struct hfc_multi *hc)
2291 struct dchannel *dch;
2294 /* process queued resync jobs */
2295 if (hc->e1_resync) {
2296 /* lock, so e1_resync gets not changed */
2297 spin_lock_irqsave(&HFClock, flags);
2298 if (hc->e1_resync & 1) {
2299 if (debug & DEBUG_HFCMULTI_PLXSD)
2300 printk(KERN_DEBUG "Enable SYNC_I\n");
2301 HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC);
2302 /* disable JATT, if RX_SYNC is set */
2303 if (test_bit(HFC_CHIP_RX_SYNC, &hc->chip))
2304 HFC_outb(hc, R_SYNC_OUT, V_SYNC_E1_RX);
2306 if (hc->e1_resync & 2) {
2307 if (debug & DEBUG_HFCMULTI_PLXSD)
2308 printk(KERN_DEBUG "Enable jatt PLL\n");
2309 HFC_outb(hc, R_SYNC_CTRL, V_SYNC_OFFS);
2311 if (hc->e1_resync & 4) {
2312 if (debug & DEBUG_HFCMULTI_PLXSD)
2314 "Enable QUARTZ for HFC-E1\n");
2315 /* set jatt to quartz */
2316 HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC
2318 /* switch to JATT, in case it is not already */
2319 HFC_outb(hc, R_SYNC_OUT, 0);
2322 spin_unlock_irqrestore(&HFClock, flags);
2325 if (hc->type != 1 || hc->e1_state == 1)
2326 for (ch = 0; ch <= 31; ch++) {
2327 if (hc->created[hc->chan[ch].port]) {
2328 hfcmulti_tx(hc, ch);
2329 /* fifo is started when switching to rx-fifo */
2330 hfcmulti_rx(hc, ch);
2331 if (hc->chan[ch].dch &&
2332 hc->chan[ch].nt_timer > -1) {
2333 dch = hc->chan[ch].dch;
2334 if (!(--hc->chan[ch].nt_timer)) {
2338 DEBUG_HFCMULTI_STATE)
2348 if (hc->type == 1 && hc->created[0]) {
2349 dch = hc->chan[hc->dslot].dch;
2350 if (test_bit(HFC_CFG_REPORT_LOS, &hc->chan[hc->dslot].cfg)) {
2352 temp = HFC_inb_nodebug(hc, R_SYNC_STA) & V_SIG_LOS;
2353 if (!temp && hc->chan[hc->dslot].los)
2354 signal_state_up(dch, L1_SIGNAL_LOS_ON,
2356 if (temp && !hc->chan[hc->dslot].los)
2357 signal_state_up(dch, L1_SIGNAL_LOS_OFF,
2359 hc->chan[hc->dslot].los = temp;
2361 if (test_bit(HFC_CFG_REPORT_AIS, &hc->chan[hc->dslot].cfg)) {
2363 temp = HFC_inb_nodebug(hc, R_SYNC_STA) & V_AIS;
2364 if (!temp && hc->chan[hc->dslot].ais)
2365 signal_state_up(dch, L1_SIGNAL_AIS_ON,
2367 if (temp && !hc->chan[hc->dslot].ais)
2368 signal_state_up(dch, L1_SIGNAL_AIS_OFF,
2370 hc->chan[hc->dslot].ais = temp;
2372 if (test_bit(HFC_CFG_REPORT_SLIP, &hc->chan[hc->dslot].cfg)) {
2374 temp = HFC_inb_nodebug(hc, R_SLIP) & V_FOSLIP_RX;
2375 if (!temp && hc->chan[hc->dslot].slip_rx)
2376 signal_state_up(dch, L1_SIGNAL_SLIP_RX,
2377 " bit SLIP detected RX");
2378 hc->chan[hc->dslot].slip_rx = temp;
2379 temp = HFC_inb_nodebug(hc, R_SLIP) & V_FOSLIP_TX;
2380 if (!temp && hc->chan[hc->dslot].slip_tx)
2381 signal_state_up(dch, L1_SIGNAL_SLIP_TX,
2382 " bit SLIP detected TX");
2383 hc->chan[hc->dslot].slip_tx = temp;
2385 if (test_bit(HFC_CFG_REPORT_RDI, &hc->chan[hc->dslot].cfg)) {
2387 temp = HFC_inb_nodebug(hc, R_RX_SL0_0) & V_A;
2388 if (!temp && hc->chan[hc->dslot].rdi)
2389 signal_state_up(dch, L1_SIGNAL_RDI_ON,
2391 if (temp && !hc->chan[hc->dslot].rdi)
2392 signal_state_up(dch, L1_SIGNAL_RDI_OFF,
2394 hc->chan[hc->dslot].rdi = temp;
2396 temp = HFC_inb_nodebug(hc, R_JATT_DIR);
2397 switch (hc->chan[hc->dslot].sync) {
2399 if ((temp & 0x60) == 0x60) {
2400 if (debug & DEBUG_HFCMULTI_SYNC)
2402 "%s: (id=%d) E1 now "
2405 HFC_outb(hc, R_RX_OFF,
2406 hc->chan[hc->dslot].jitter | V_RX_INIT);
2407 HFC_outb(hc, R_TX_OFF,
2408 hc->chan[hc->dslot].jitter | V_RX_INIT);
2409 hc->chan[hc->dslot].sync = 1;
2410 goto check_framesync;
2414 if ((temp & 0x60) != 0x60) {
2415 if (debug & DEBUG_HFCMULTI_SYNC)
2418 "lost clock sync\n",
2420 hc->chan[hc->dslot].sync = 0;
2424 temp = HFC_inb_nodebug(hc, R_SYNC_STA);
2426 if (debug & DEBUG_HFCMULTI_SYNC)
2429 "now in frame sync\n",
2431 hc->chan[hc->dslot].sync = 2;
2435 if ((temp & 0x60) != 0x60) {
2436 if (debug & DEBUG_HFCMULTI_SYNC)
2438 "%s: (id=%d) E1 lost "
2439 "clock & frame sync\n",
2441 hc->chan[hc->dslot].sync = 0;
2444 temp = HFC_inb_nodebug(hc, R_SYNC_STA);
2446 if (debug & DEBUG_HFCMULTI_SYNC)
2449 "lost frame sync\n",
2451 hc->chan[hc->dslot].sync = 1;
2457 if (test_bit(HFC_CHIP_WATCHDOG, &hc->chip))
2458 hfcmulti_watchdog(hc);
2465 ph_state_irq(struct hfc_multi *hc, u_char r_irq_statech)
2467 struct dchannel *dch;
2470 u_char st_status, temp;
2473 for (ch = 0; ch <= 31; ch++) {
2474 if (hc->chan[ch].dch) {
2475 dch = hc->chan[ch].dch;
2476 if (r_irq_statech & 1) {
2477 HFC_outb_nodebug(hc, R_ST_SEL,
2479 /* undocumented: delay after R_ST_SEL */
2481 /* undocumented: status changes during read */
2482 st_status = HFC_inb_nodebug(hc, A_ST_RD_STATE);
2483 while (st_status != (temp =
2484 HFC_inb_nodebug(hc, A_ST_RD_STATE))) {
2485 if (debug & DEBUG_HFCMULTI_STATE)
2486 printk(KERN_DEBUG "%s: reread "
2487 "STATE because %d!=%d\n",
2490 st_status = temp; /* repeat */
2493 /* Speech Design TE-sync indication */
2494 if (test_bit(HFC_CHIP_PLXSD, &hc->chip) &&
2495 dch->dev.D.protocol == ISDN_P_TE_S0) {
2496 if (st_status & V_FR_SYNC_ST)
2498 (1 << hc->chan[ch].port);
2501 ~(1 << hc->chan[ch].port);
2503 dch->state = st_status & 0x0f;
2504 if (dch->dev.D.protocol == ISDN_P_NT_S0)
2508 if (dch->state == active) {
2509 HFC_outb_nodebug(hc, R_FIFO,
2511 HFC_wait_nodebug(hc);
2512 HFC_outb_nodebug(hc,
2513 R_INC_RES_FIFO, V_RES_F);
2514 HFC_wait_nodebug(hc);
2517 schedule_event(dch, FLG_PHCHANGE);
2518 if (debug & DEBUG_HFCMULTI_STATE)
2520 "%s: S/T newstate %x port %d\n",
2521 __func__, dch->state,
2524 r_irq_statech >>= 1;
2527 if (test_bit(HFC_CHIP_PLXSD, &hc->chip))
2528 plxsd_checksync(hc, 0);
2532 fifo_irq(struct hfc_multi *hc, int block)
2535 struct dchannel *dch;
2536 struct bchannel *bch;
2537 u_char r_irq_fifo_bl;
2539 r_irq_fifo_bl = HFC_inb_nodebug(hc, R_IRQ_FIFO_BL0 + block);
2542 ch = (block << 2) + (j >> 1);
2543 dch = hc->chan[ch].dch;
2544 bch = hc->chan[ch].bch;
2545 if (((!dch) && (!bch)) || (!hc->created[hc->chan[ch].port])) {
2549 if (dch && (r_irq_fifo_bl & (1 << j)) &&
2550 test_bit(FLG_ACTIVE, &dch->Flags)) {
2551 hfcmulti_tx(hc, ch);
2553 HFC_outb_nodebug(hc, R_FIFO, 0);
2554 HFC_wait_nodebug(hc);
2556 if (bch && (r_irq_fifo_bl & (1 << j)) &&
2557 test_bit(FLG_ACTIVE, &bch->Flags)) {
2558 hfcmulti_tx(hc, ch);
2560 HFC_outb_nodebug(hc, R_FIFO, 0);
2561 HFC_wait_nodebug(hc);
2564 if (dch && (r_irq_fifo_bl & (1 << j)) &&
2565 test_bit(FLG_ACTIVE, &dch->Flags)) {
2566 hfcmulti_rx(hc, ch);
2568 if (bch && (r_irq_fifo_bl & (1 << j)) &&
2569 test_bit(FLG_ACTIVE, &bch->Flags)) {
2570 hfcmulti_rx(hc, ch);
2580 hfcmulti_interrupt(int intno, void *dev_id)
2582 #ifdef IRQCOUNT_DEBUG
2583 static int iq1 = 0, iq2 = 0, iq3 = 0, iq4 = 0,
2584 iq5 = 0, iq6 = 0, iqcnt = 0;
2587 struct hfc_multi *hc = dev_id;
2588 struct dchannel *dch;
2589 u_char r_irq_statech, status, r_irq_misc, r_irq_oview;
2591 void __iomem *plx_acc;
2593 u_char e1_syncsta, temp;
2597 printk(KERN_ERR "HFC-multi: Spurious interrupt!\n");
2601 spin_lock(&hc->lock);
2605 printk(KERN_ERR "irq for card %d during irq from "
2606 "card %d, this is no bug.\n", hc->id + 1, irqsem);
2607 irqsem = hc->id + 1;
2610 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
2611 spin_lock_irqsave(&plx_lock, flags);
2612 plx_acc = hc->plx_membase + PLX_INTCSR;
2613 wval = readw(plx_acc);
2614 spin_unlock_irqrestore(&plx_lock, flags);
2615 if (!(wval & PLX_INTCSR_LINTI1_STATUS))
2619 status = HFC_inb_nodebug(hc, R_STATUS);
2620 r_irq_statech = HFC_inb_nodebug(hc, R_IRQ_STATECH);
2621 #ifdef IRQCOUNT_DEBUG
2624 if (status & V_DTMF_STA)
2626 if (status & V_LOST_STA)
2628 if (status & V_EXT_IRQSTA)
2630 if (status & V_MISC_IRQSTA)
2632 if (status & V_FR_IRQSTA)
2634 if (iqcnt++ > 5000) {
2635 printk(KERN_ERR "iq1:%x iq2:%x iq3:%x iq4:%x iq5:%x iq6:%x\n",
2636 iq1, iq2, iq3, iq4, iq5, iq6);
2640 if (!r_irq_statech &&
2641 !(status & (V_DTMF_STA | V_LOST_STA | V_EXT_IRQSTA |
2642 V_MISC_IRQSTA | V_FR_IRQSTA))) {
2643 /* irq is not for us */
2647 if (r_irq_statech) {
2649 ph_state_irq(hc, r_irq_statech);
2651 if (status & V_EXT_IRQSTA)
2652 ; /* external IRQ */
2653 if (status & V_LOST_STA) {
2655 HFC_outb(hc, R_INC_RES_FIFO, V_RES_LOST); /* clear irq! */
2657 if (status & V_MISC_IRQSTA) {
2659 r_irq_misc = HFC_inb_nodebug(hc, R_IRQ_MISC);
2660 if (r_irq_misc & V_STA_IRQ) {
2661 if (hc->type == 1) {
2663 dch = hc->chan[hc->dslot].dch;
2664 e1_syncsta = HFC_inb_nodebug(hc, R_SYNC_STA);
2665 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)
2666 && hc->e1_getclock) {
2667 if (e1_syncsta & V_FR_SYNC_E1)
2668 hc->syncronized = 1;
2670 hc->syncronized = 0;
2672 /* undocumented: status changes during read */
2673 dch->state = HFC_inb_nodebug(hc, R_E1_RD_STA);
2674 while (dch->state != (temp =
2675 HFC_inb_nodebug(hc, R_E1_RD_STA))) {
2676 if (debug & DEBUG_HFCMULTI_STATE)
2677 printk(KERN_DEBUG "%s: reread "
2678 "STATE because %d!=%d\n",
2681 dch->state = temp; /* repeat */
2683 dch->state = HFC_inb_nodebug(hc, R_E1_RD_STA)
2685 schedule_event(dch, FLG_PHCHANGE);
2686 if (debug & DEBUG_HFCMULTI_STATE)
2688 "%s: E1 (id=%d) newstate %x\n",
2689 __func__, hc->id, dch->state);
2690 if (test_bit(HFC_CHIP_PLXSD, &hc->chip))
2691 plxsd_checksync(hc, 0);
2694 if (r_irq_misc & V_TI_IRQ)
2695 handle_timer_irq(hc);
2697 if (r_irq_misc & V_DTMF_IRQ) {
2701 /* TODO: REPLACE !!!! 125 us Interrupts are not acceptable */
2702 if (r_irq_misc & V_IRQ_PROC) {
2703 /* IRQ every 125us */
2705 /* generate 1kHz signal */
2714 if (status & V_FR_IRQSTA) {
2716 r_irq_oview = HFC_inb_nodebug(hc, R_IRQ_OVIEW);
2717 for (i = 0; i < 8; i++) {
2718 if (r_irq_oview & (1 << i))
2726 spin_unlock(&hc->lock);
2733 spin_unlock(&hc->lock);
2739 * timer callback for D-chan busy resolution. Currently no function
2743 hfcmulti_dbusy_timer(struct hfc_multi *hc)
2749 * activate/deactivate hardware for selected channels and mode
2751 * configure B-channel with the given protocol
2752 * ch eqals to the HFC-channel (0-31)
2753 * ch is the number of channel (0-4,4-7,8-11,12-15,16-19,20-23,24-27,28-31
2754 * for S/T, 1-31 for E1)
2755 * the hdlc interrupts will be set/unset
2758 mode_hfcmulti(struct hfc_multi *hc, int ch, int protocol, int slot_tx,
2759 int bank_tx, int slot_rx, int bank_rx)
2761 int flow_tx = 0, flow_rx = 0, routing = 0;
2762 int oslot_tx, oslot_rx;
2765 if (ch < 0 || ch > 31)
2767 oslot_tx = hc->chan[ch].slot_tx;
2768 oslot_rx = hc->chan[ch].slot_rx;
2769 conf = hc->chan[ch].conf;
2771 if (debug & DEBUG_HFCMULTI_MODE)
2773 "%s: card %d channel %d protocol %x slot old=%d new=%d "
2774 "bank new=%d (TX) slot old=%d new=%d bank new=%d (RX)\n",
2775 __func__, hc->id, ch, protocol, oslot_tx, slot_tx,
2776 bank_tx, oslot_rx, slot_rx, bank_rx);
2778 if (oslot_tx >= 0 && slot_tx != oslot_tx) {
2779 /* remove from slot */
2780 if (debug & DEBUG_HFCMULTI_MODE)
2781 printk(KERN_DEBUG "%s: remove from slot %d (TX)\n",
2782 __func__, oslot_tx);
2783 if (hc->slot_owner[oslot_tx<<1] == ch) {
2784 HFC_outb(hc, R_SLOT, oslot_tx << 1);
2785 HFC_outb(hc, A_SL_CFG, 0);
2786 HFC_outb(hc, A_CONF, 0);
2787 hc->slot_owner[oslot_tx<<1] = -1;
2789 if (debug & DEBUG_HFCMULTI_MODE)
2791 "%s: we are not owner of this tx slot "
2792 "anymore, channel %d is.\n",
2793 __func__, hc->slot_owner[oslot_tx<<1]);
2797 if (oslot_rx >= 0 && slot_rx != oslot_rx) {
2798 /* remove from slot */
2799 if (debug & DEBUG_HFCMULTI_MODE)
2801 "%s: remove from slot %d (RX)\n",
2802 __func__, oslot_rx);
2803 if (hc->slot_owner[(oslot_rx << 1) | 1] == ch) {
2804 HFC_outb(hc, R_SLOT, (oslot_rx << 1) | V_SL_DIR);
2805 HFC_outb(hc, A_SL_CFG, 0);
2806 hc->slot_owner[(oslot_rx << 1) | 1] = -1;
2808 if (debug & DEBUG_HFCMULTI_MODE)
2810 "%s: we are not owner of this rx slot "
2811 "anymore, channel %d is.\n",
2813 hc->slot_owner[(oslot_rx << 1) | 1]);
2818 flow_tx = 0x80; /* FIFO->ST */
2819 /* disable pcm slot */
2820 hc->chan[ch].slot_tx = -1;
2821 hc->chan[ch].bank_tx = 0;
2824 if (hc->chan[ch].txpending)
2825 flow_tx = 0x80; /* FIFO->ST */
2827 flow_tx = 0xc0; /* PCM->ST */
2829 routing = bank_tx ? 0xc0 : 0x80;
2830 if (conf >= 0 || bank_tx > 1)
2831 routing = 0x40; /* loop */
2832 if (debug & DEBUG_HFCMULTI_MODE)
2833 printk(KERN_DEBUG "%s: put channel %d to slot %d bank"
2834 " %d flow %02x routing %02x conf %d (TX)\n",
2835 __func__, ch, slot_tx, bank_tx,
2836 flow_tx, routing, conf);
2837 HFC_outb(hc, R_SLOT, slot_tx << 1);
2838 HFC_outb(hc, A_SL_CFG, (ch<<1) | routing);
2839 HFC_outb(hc, A_CONF, (conf < 0) ? 0 : (conf | V_CONF_SL));
2840 hc->slot_owner[slot_tx << 1] = ch;
2841 hc->chan[ch].slot_tx = slot_tx;
2842 hc->chan[ch].bank_tx = bank_tx;
2845 /* disable pcm slot */
2846 flow_rx = 0x80; /* ST->FIFO */
2847 hc->chan[ch].slot_rx = -1;
2848 hc->chan[ch].bank_rx = 0;
2851 if (hc->chan[ch].txpending)
2852 flow_rx = 0x80; /* ST->FIFO */
2854 flow_rx = 0xc0; /* ST->(FIFO,PCM) */
2856 routing = bank_rx?0x80:0xc0; /* reversed */
2857 if (conf >= 0 || bank_rx > 1)
2858 routing = 0x40; /* loop */
2859 if (debug & DEBUG_HFCMULTI_MODE)
2860 printk(KERN_DEBUG "%s: put channel %d to slot %d bank"
2861 " %d flow %02x routing %02x conf %d (RX)\n",
2862 __func__, ch, slot_rx, bank_rx,
2863 flow_rx, routing, conf);
2864 HFC_outb(hc, R_SLOT, (slot_rx<<1) | V_SL_DIR);
2865 HFC_outb(hc, A_SL_CFG, (ch<<1) | V_CH_DIR | routing);
2866 hc->slot_owner[(slot_rx<<1)|1] = ch;
2867 hc->chan[ch].slot_rx = slot_rx;
2868 hc->chan[ch].bank_rx = bank_rx;
2873 /* disable TX fifo */
2874 HFC_outb(hc, R_FIFO, ch << 1);
2876 HFC_outb(hc, A_CON_HDLC, flow_tx | 0x00 | V_IFF);
2877 HFC_outb(hc, A_SUBCH_CFG, 0);
2878 HFC_outb(hc, A_IRQ_MSK, 0);
2879 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
2881 /* disable RX fifo */
2882 HFC_outb(hc, R_FIFO, (ch<<1)|1);
2884 HFC_outb(hc, A_CON_HDLC, flow_rx | 0x00);
2885 HFC_outb(hc, A_SUBCH_CFG, 0);
2886 HFC_outb(hc, A_IRQ_MSK, 0);
2887 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
2889 if (hc->chan[ch].bch && hc->type != 1) {
2890 hc->hw.a_st_ctrl0[hc->chan[ch].port] &=
2891 ((ch & 0x3) == 0)? ~V_B1_EN: ~V_B2_EN;
2892 HFC_outb(hc, R_ST_SEL, hc->chan[ch].port);
2893 /* undocumented: delay after R_ST_SEL */
2895 HFC_outb(hc, A_ST_CTRL0,
2896 hc->hw.a_st_ctrl0[hc->chan[ch].port]);
2898 if (hc->chan[ch].bch) {
2899 test_and_clear_bit(FLG_HDLC, &hc->chan[ch].bch->Flags);
2900 test_and_clear_bit(FLG_TRANSPARENT,
2901 &hc->chan[ch].bch->Flags);
2904 case (ISDN_P_B_RAW): /* B-channel */
2906 if (test_bit(HFC_CHIP_B410P, &hc->chip) &&
2907 (hc->chan[ch].slot_rx < 0) &&
2908 (hc->chan[ch].slot_tx < 0)) {
2911 "Setting B-channel %d to echo cancelable "
2912 "state on PCM slot %d\n", ch,
2913 ((ch / 4) * 8) + ((ch % 4) * 4) + 1);
2915 "Enabling pass through for channel\n");
2916 vpm_out(hc, ch, ((ch / 4) * 8) +
2917 ((ch % 4) * 4) + 1, 0x01);
2920 HFC_outb(hc, R_FIFO, (ch << 1));
2922 HFC_outb(hc, A_CON_HDLC, 0xc0 | V_HDLC_TRP | V_IFF);
2923 HFC_outb(hc, R_SLOT, (((ch / 4) * 8) +
2924 ((ch % 4) * 4) + 1) << 1);
2925 HFC_outb(hc, A_SL_CFG, 0x80 | (ch << 1));
2928 HFC_outb(hc, R_FIFO, 0x20 | (ch << 1) | 1);
2930 HFC_outb(hc, A_CON_HDLC, 0x20 | V_HDLC_TRP | V_IFF);
2931 HFC_outb(hc, A_SUBCH_CFG, 0);
2932 HFC_outb(hc, A_IRQ_MSK, 0);
2933 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
2935 HFC_outb(hc, R_SLOT, ((((ch / 4) * 8) +
2936 ((ch % 4) * 4) + 1) << 1) | 1);
2937 HFC_outb(hc, A_SL_CFG, 0x80 | 0x20 | (ch << 1) | 1);
2941 HFC_outb(hc, R_FIFO, (ch << 1) | 1);
2943 HFC_outb(hc, A_CON_HDLC, 0xc0 | V_HDLC_TRP | V_IFF);
2944 HFC_outb(hc, R_SLOT, ((((ch / 4) * 8) +
2945 ((ch % 4) * 4)) << 1) | 1);
2946 HFC_outb(hc, A_SL_CFG, 0x80 | 0x40 | (ch << 1) | 1);
2949 HFC_outb(hc, R_FIFO, 0x20 | (ch << 1));
2951 HFC_outb(hc, A_CON_HDLC, 0x20 | V_HDLC_TRP | V_IFF);
2952 HFC_outb(hc, A_SUBCH_CFG, 0);
2953 HFC_outb(hc, A_IRQ_MSK, 0);
2954 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
2957 HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, silence);
2958 HFC_outb(hc, R_SLOT, (((ch / 4) * 8) +
2959 ((ch % 4) * 4)) << 1);
2960 HFC_outb(hc, A_SL_CFG, 0x80 | 0x20 | (ch << 1));
2962 /* enable TX fifo */
2963 HFC_outb(hc, R_FIFO, ch << 1);
2965 HFC_outb(hc, A_CON_HDLC, flow_tx | 0x00 |
2966 V_HDLC_TRP | V_IFF);
2967 HFC_outb(hc, A_SUBCH_CFG, 0);
2968 HFC_outb(hc, A_IRQ_MSK, 0);
2969 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
2972 HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, silence);
2973 /* enable RX fifo */
2974 HFC_outb(hc, R_FIFO, (ch<<1)|1);
2976 HFC_outb(hc, A_CON_HDLC, flow_rx | 0x00 | V_HDLC_TRP);
2977 HFC_outb(hc, A_SUBCH_CFG, 0);
2978 HFC_outb(hc, A_IRQ_MSK, 0);
2979 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
2982 if (hc->type != 1) {
2983 hc->hw.a_st_ctrl0[hc->chan[ch].port] |=
2984 ((ch & 0x3) == 0) ? V_B1_EN : V_B2_EN;
2985 HFC_outb(hc, R_ST_SEL, hc->chan[ch].port);
2986 /* undocumented: delay after R_ST_SEL */
2988 HFC_outb(hc, A_ST_CTRL0,
2989 hc->hw.a_st_ctrl0[hc->chan[ch].port]);
2991 if (hc->chan[ch].bch)
2992 test_and_set_bit(FLG_TRANSPARENT,
2993 &hc->chan[ch].bch->Flags);
2995 case (ISDN_P_B_HDLC): /* B-channel */
2996 case (ISDN_P_TE_S0): /* D-channel */
2997 case (ISDN_P_NT_S0):
2998 case (ISDN_P_TE_E1):
2999 case (ISDN_P_NT_E1):
3000 /* enable TX fifo */
3001 HFC_outb(hc, R_FIFO, ch<<1);
3003 if (hc->type == 1 || hc->chan[ch].bch) {
3004 /* E1 or B-channel */
3005 HFC_outb(hc, A_CON_HDLC, flow_tx | 0x04);
3006 HFC_outb(hc, A_SUBCH_CFG, 0);
3008 /* D-Channel without HDLC fill flags */
3009 HFC_outb(hc, A_CON_HDLC, flow_tx | 0x04 | V_IFF);
3010 HFC_outb(hc, A_SUBCH_CFG, 2);
3012 HFC_outb(hc, A_IRQ_MSK, V_IRQ);
3013 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
3015 /* enable RX fifo */
3016 HFC_outb(hc, R_FIFO, (ch<<1)|1);
3018 HFC_outb(hc, A_CON_HDLC, flow_rx | 0x04);
3019 if (hc->type == 1 || hc->chan[ch].bch)
3020 HFC_outb(hc, A_SUBCH_CFG, 0); /* full 8 bits */
3022 HFC_outb(hc, A_SUBCH_CFG, 2); /* 2 bits dchannel */
3023 HFC_outb(hc, A_IRQ_MSK, V_IRQ);
3024 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
3026 if (hc->chan[ch].bch) {
3027 test_and_set_bit(FLG_HDLC, &hc->chan[ch].bch->Flags);
3028 if (hc->type != 1) {
3029 hc->hw.a_st_ctrl0[hc->chan[ch].port] |=
3030 ((ch&0x3) == 0) ? V_B1_EN : V_B2_EN;
3031 HFC_outb(hc, R_ST_SEL, hc->chan[ch].port);
3032 /* undocumented: delay after R_ST_SEL */
3034 HFC_outb(hc, A_ST_CTRL0,
3035 hc->hw.a_st_ctrl0[hc->chan[ch].port]);
3040 printk(KERN_DEBUG "%s: protocol not known %x\n",
3041 __func__, protocol);
3042 hc->chan[ch].protocol = ISDN_P_NONE;
3043 return -ENOPROTOOPT;
3045 hc->chan[ch].protocol = protocol;
3051 * connect/disconnect PCM
3055 hfcmulti_pcm(struct hfc_multi *hc, int ch, int slot_tx, int bank_tx,
3056 int slot_rx, int bank_rx)
3058 if (slot_rx < 0 || slot_rx < 0 || bank_tx < 0 || bank_rx < 0) {
3060 mode_hfcmulti(hc, ch, hc->chan[ch].protocol, -1, 0, -1, 0);
3065 mode_hfcmulti(hc, ch, hc->chan[ch].protocol, slot_tx, bank_tx,
3070 * set/disable conference
3074 hfcmulti_conf(struct hfc_multi *hc, int ch, int num)
3076 if (num >= 0 && num <= 7)
3077 hc->chan[ch].conf = num;
3079 hc->chan[ch].conf = -1;
3080 mode_hfcmulti(hc, ch, hc->chan[ch].protocol, hc->chan[ch].slot_tx,
3081 hc->chan[ch].bank_tx, hc->chan[ch].slot_rx,
3082 hc->chan[ch].bank_rx);
3087 * set/disable sample loop
3090 /* NOTE: this function is experimental and therefore disabled */
3093 * Layer 1 callback function
3096 hfcm_l1callback(struct dchannel *dch, u_int cmd)
3098 struct hfc_multi *hc = dch->hw;
3106 /* start activation */
3107 spin_lock_irqsave(&hc->lock, flags);
3108 if (hc->type == 1) {
3109 if (debug & DEBUG_HFCMULTI_MSG)
3111 "%s: HW_RESET_REQ no BRI\n",
3114 HFC_outb(hc, R_ST_SEL, hc->chan[dch->slot].port);
3115 /* undocumented: delay after R_ST_SEL */
3117 HFC_outb(hc, A_ST_WR_STATE, V_ST_LD_STA | 3); /* F3 */
3118 udelay(6); /* wait at least 5,21us */
3119 HFC_outb(hc, A_ST_WR_STATE, 3);
3120 HFC_outb(hc, A_ST_WR_STATE, 3 | (V_ST_ACT*3));
3123 spin_unlock_irqrestore(&hc->lock, flags);
3124 l1_event(dch->l1, HW_POWERUP_IND);
3127 /* start deactivation */
3128 spin_lock_irqsave(&hc->lock, flags);
3129 if (hc->type == 1) {
3130 if (debug & DEBUG_HFCMULTI_MSG)
3132 "%s: HW_DEACT_REQ no BRI\n",
3135 HFC_outb(hc, R_ST_SEL, hc->chan[dch->slot].port);
3136 /* undocumented: delay after R_ST_SEL */
3138 HFC_outb(hc, A_ST_WR_STATE, V_ST_ACT*2);
3140 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
3142 ~(1 << hc->chan[dch->slot].port);
3143 plxsd_checksync(hc, 0);
3146 skb_queue_purge(&dch->squeue);
3148 dev_kfree_skb(dch->tx_skb);
3153 dev_kfree_skb(dch->rx_skb);
3156 test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
3157 if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags))
3158 del_timer(&dch->timer);
3159 spin_unlock_irqrestore(&hc->lock, flags);
3161 case HW_POWERUP_REQ:
3162 spin_lock_irqsave(&hc->lock, flags);
3163 if (hc->type == 1) {
3164 if (debug & DEBUG_HFCMULTI_MSG)
3166 "%s: HW_POWERUP_REQ no BRI\n",
3169 HFC_outb(hc, R_ST_SEL, hc->chan[dch->slot].port);
3170 /* undocumented: delay after R_ST_SEL */
3172 HFC_outb(hc, A_ST_WR_STATE, 3 | 0x10); /* activate */
3173 udelay(6); /* wait at least 5,21us */
3174 HFC_outb(hc, A_ST_WR_STATE, 3); /* activate */
3176 spin_unlock_irqrestore(&hc->lock, flags);
3178 case PH_ACTIVATE_IND:
3179 test_and_set_bit(FLG_ACTIVE, &dch->Flags);
3180 _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL,
3183 case PH_DEACTIVATE_IND:
3184 test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
3185 _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL,
3189 if (dch->debug & DEBUG_HW)
3190 printk(KERN_DEBUG "%s: unknown command %x\n",
3198 * Layer2 -> Layer 1 Transfer
3202 handle_dmsg(struct mISDNchannel *ch, struct sk_buff *skb)
3204 struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
3205 struct dchannel *dch = container_of(dev, struct dchannel, dev);
3206 struct hfc_multi *hc = dch->hw;
3207 struct mISDNhead *hh = mISDN_HEAD_P(skb);
3216 spin_lock_irqsave(&hc->lock, flags);
3217 ret = dchannel_senddata(dch, skb);
3218 if (ret > 0) { /* direct TX */
3219 id = hh->id; /* skb can be freed */
3220 hfcmulti_tx(hc, dch->slot);
3223 HFC_outb(hc, R_FIFO, 0);
3225 spin_unlock_irqrestore(&hc->lock, flags);
3226 queue_ch_frame(ch, PH_DATA_CNF, id, NULL);
3228 spin_unlock_irqrestore(&hc->lock, flags);
3230 case PH_ACTIVATE_REQ:
3231 if (dch->dev.D.protocol != ISDN_P_TE_S0) {
3232 spin_lock_irqsave(&hc->lock, flags);
3234 if (debug & DEBUG_HFCMULTI_MSG)
3236 "%s: PH_ACTIVATE port %d (0..%d)\n",
3237 __func__, hc->chan[dch->slot].port,
3239 /* start activation */
3240 if (hc->type == 1) {
3241 ph_state_change(dch);
3242 if (debug & DEBUG_HFCMULTI_STATE)
3244 "%s: E1 report state %x \n",
3245 __func__, dch->state);
3247 HFC_outb(hc, R_ST_SEL,
3248 hc->chan[dch->slot].port);
3249 /* undocumented: delay after R_ST_SEL */
3251 HFC_outb(hc, A_ST_WR_STATE, V_ST_LD_STA | 1);
3253 udelay(6); /* wait at least 5,21us */
3254 HFC_outb(hc, A_ST_WR_STATE, 1);
3255 HFC_outb(hc, A_ST_WR_STATE, 1 |
3256 (V_ST_ACT*3)); /* activate */
3259 spin_unlock_irqrestore(&hc->lock, flags);
3261 ret = l1_event(dch->l1, hh->prim);
3263 case PH_DEACTIVATE_REQ:
3264 test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags);
3265 if (dch->dev.D.protocol != ISDN_P_TE_S0) {
3266 spin_lock_irqsave(&hc->lock, flags);
3267 if (debug & DEBUG_HFCMULTI_MSG)
3269 "%s: PH_DEACTIVATE port %d (0..%d)\n",
3270 __func__, hc->chan[dch->slot].port,
3272 /* start deactivation */
3273 if (hc->type == 1) {
3274 if (debug & DEBUG_HFCMULTI_MSG)
3276 "%s: PH_DEACTIVATE no BRI\n",
3279 HFC_outb(hc, R_ST_SEL,
3280 hc->chan[dch->slot].port);
3281 /* undocumented: delay after R_ST_SEL */
3283 HFC_outb(hc, A_ST_WR_STATE, V_ST_ACT * 2);
3287 skb_queue_purge(&dch->squeue);
3289 dev_kfree_skb(dch->tx_skb);
3294 dev_kfree_skb(dch->rx_skb);
3297 test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
3298 if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags))
3299 del_timer(&dch->timer);
3301 if (test_and_clear_bit(FLG_L1_BUSY, &dch->Flags))
3302 dchannel_sched_event(&hc->dch, D_CLEARBUSY);
3305 spin_unlock_irqrestore(&hc->lock, flags);
3307 ret = l1_event(dch->l1, hh->prim);
3316 deactivate_bchannel(struct bchannel *bch)
3318 struct hfc_multi *hc = bch->hw;
3321 spin_lock_irqsave(&hc->lock, flags);
3322 if (test_and_clear_bit(FLG_TX_NEXT, &bch->Flags)) {
3323 dev_kfree_skb(bch->next_skb);
3324 bch->next_skb = NULL;
3327 dev_kfree_skb(bch->tx_skb);
3332 dev_kfree_skb(bch->rx_skb);
3335 hc->chan[bch->slot].coeff_count = 0;
3336 test_and_clear_bit(FLG_ACTIVE, &bch->Flags);
3337 test_and_clear_bit(FLG_TX_BUSY, &bch->Flags);
3338 hc->chan[bch->slot].rx_off = 0;
3339 hc->chan[bch->slot].conf = -1;
3340 mode_hfcmulti(hc, bch->slot, ISDN_P_NONE, -1, 0, -1, 0);
3341 spin_unlock_irqrestore(&hc->lock, flags);
3345 handle_bmsg(struct mISDNchannel *ch, struct sk_buff *skb)
3347 struct bchannel *bch = container_of(ch, struct bchannel, ch);
3348 struct hfc_multi *hc = bch->hw;
3350 struct mISDNhead *hh = mISDN_HEAD_P(skb);
3358 spin_lock_irqsave(&hc->lock, flags);
3359 ret = bchannel_senddata(bch, skb);
3360 if (ret > 0) { /* direct TX */
3361 id = hh->id; /* skb can be freed */
3362 hfcmulti_tx(hc, bch->slot);
3365 HFC_outb_nodebug(hc, R_FIFO, 0);
3366 HFC_wait_nodebug(hc);
3367 if (!test_bit(FLG_TRANSPARENT, &bch->Flags)) {
3368 spin_unlock_irqrestore(&hc->lock, flags);
3369 queue_ch_frame(ch, PH_DATA_CNF, id, NULL);
3371 spin_unlock_irqrestore(&hc->lock, flags);
3373 spin_unlock_irqrestore(&hc->lock, flags);
3375 case PH_ACTIVATE_REQ:
3376 if (debug & DEBUG_HFCMULTI_MSG)
3377 printk(KERN_DEBUG "%s: PH_ACTIVATE ch %d (0..32)\n",
3378 __func__, bch->slot);
3379 spin_lock_irqsave(&hc->lock, flags);
3380 /* activate B-channel if not already activated */
3381 if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags)) {
3382 hc->chan[bch->slot].txpending = 0;
3383 ret = mode_hfcmulti(hc, bch->slot,
3385 hc->chan[bch->slot].slot_tx,
3386 hc->chan[bch->slot].bank_tx,
3387 hc->chan[bch->slot].slot_rx,
3388 hc->chan[bch->slot].bank_rx);
3390 if (ch->protocol == ISDN_P_B_RAW && !hc->dtmf
3391 && test_bit(HFC_CHIP_DTMF, &hc->chip)) {
3394 if (debug & DEBUG_HFCMULTI_DTMF)
3396 "%s: start dtmf decoder\n",
3398 HFC_outb(hc, R_DTMF, hc->hw.r_dtmf |
3404 spin_unlock_irqrestore(&hc->lock, flags);
3406 _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 0, NULL,
3409 case PH_CONTROL_REQ:
3410 spin_lock_irqsave(&hc->lock, flags);
3412 case HFC_SPL_LOOP_ON: /* set sample loop */
3413 if (debug & DEBUG_HFCMULTI_MSG)
3415 "%s: HFC_SPL_LOOP_ON (len = %d)\n",
3416 __func__, skb->len);
3419 case HFC_SPL_LOOP_OFF: /* set silence */
3420 if (debug & DEBUG_HFCMULTI_MSG)
3421 printk(KERN_DEBUG "%s: HFC_SPL_LOOP_OFF\n",
3427 "%s: unknown PH_CONTROL_REQ info %x\n",
3431 spin_unlock_irqrestore(&hc->lock, flags);
3433 case PH_DEACTIVATE_REQ:
3434 deactivate_bchannel(bch); /* locked there */
3435 _queue_data(ch, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0, NULL,
3446 * bchannel control function
3449 channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)
3452 struct dsp_features *features =
3453 (struct dsp_features *)(*((u_long *)&cq->p1));
3454 struct hfc_multi *hc = bch->hw;
3462 case MISDN_CTRL_GETOP:
3463 cq->op = MISDN_CTRL_HFC_OP | MISDN_CTRL_HW_FEATURES_OP
3464 | MISDN_CTRL_RX_OFF;
3466 case MISDN_CTRL_RX_OFF: /* turn off / on rx stream */
3467 hc->chan[bch->slot].rx_off = !!cq->p1;
3468 if (!hc->chan[bch->slot].rx_off) {
3469 /* reset fifo on rx on */
3470 HFC_outb_nodebug(hc, R_FIFO, (bch->slot << 1) | 1);
3471 HFC_wait_nodebug(hc);
3472 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_RES_F);
3473 HFC_wait_nodebug(hc);
3475 if (debug & DEBUG_HFCMULTI_MSG)
3476 printk(KERN_DEBUG "%s: RX_OFF request (nr=%d off=%d)\n",
3477 __func__, bch->nr, hc->chan[bch->slot].rx_off);
3479 case MISDN_CTRL_HW_FEATURES: /* fill features structure */
3480 if (debug & DEBUG_HFCMULTI_MSG)
3481 printk(KERN_DEBUG "%s: HW_FEATURE request\n",
3483 /* create confirm */
3484 features->hfc_id = hc->id;
3485 if (test_bit(HFC_CHIP_DTMF, &hc->chip))
3486 features->hfc_dtmf = 1;
3487 features->hfc_loops = 0;
3488 if (test_bit(HFC_CHIP_B410P, &hc->chip)) {
3489 features->hfc_echocanhw = 1;
3491 features->pcm_id = hc->pcm;
3492 features->pcm_slots = hc->slots;
3493 features->pcm_banks = 2;
3496 case MISDN_CTRL_HFC_PCM_CONN: /* connect to pcm timeslot (0..N) */
3497 slot_tx = cq->p1 & 0xff;
3498 bank_tx = cq->p1 >> 8;
3499 slot_rx = cq->p2 & 0xff;
3500 bank_rx = cq->p2 >> 8;
3501 if (debug & DEBUG_HFCMULTI_MSG)
3503 "%s: HFC_PCM_CONN slot %d bank %d (TX) "
3504 "slot %d bank %d (RX)\n",
3505 __func__, slot_tx, bank_tx,
3507 if (slot_tx < hc->slots && bank_tx <= 2 &&
3508 slot_rx < hc->slots && bank_rx <= 2)
3509 hfcmulti_pcm(hc, bch->slot,
3510 slot_tx, bank_tx, slot_rx, bank_rx);
3513 "%s: HFC_PCM_CONN slot %d bank %d (TX) "
3514 "slot %d bank %d (RX) out of range\n",
3515 __func__, slot_tx, bank_tx,
3520 case MISDN_CTRL_HFC_PCM_DISC: /* release interface from pcm timeslot */
3521 if (debug & DEBUG_HFCMULTI_MSG)
3522 printk(KERN_DEBUG "%s: HFC_PCM_DISC\n",
3524 hfcmulti_pcm(hc, bch->slot, -1, 0, -1, 0);
3526 case MISDN_CTRL_HFC_CONF_JOIN: /* join conference (0..7) */
3527 num = cq->p1 & 0xff;
3528 if (debug & DEBUG_HFCMULTI_MSG)
3529 printk(KERN_DEBUG "%s: HFC_CONF_JOIN conf %d\n",
3532 hfcmulti_conf(hc, bch->slot, num);
3535 "%s: HW_CONF_JOIN conf %d out of range\n",
3540 case MISDN_CTRL_HFC_CONF_SPLIT: /* split conference */
3541 if (debug & DEBUG_HFCMULTI_MSG)
3542 printk(KERN_DEBUG "%s: HFC_CONF_SPLIT\n", __func__);
3543 hfcmulti_conf(hc, bch->slot, -1);
3545 case MISDN_CTRL_HFC_ECHOCAN_ON:
3546 if (debug & DEBUG_HFCMULTI_MSG)
3547 printk(KERN_DEBUG "%s: HFC_ECHOCAN_ON\n", __func__);
3548 if (test_bit(HFC_CHIP_B410P, &hc->chip))
3549 vpm_echocan_on(hc, bch->slot, cq->p1);
3554 case MISDN_CTRL_HFC_ECHOCAN_OFF:
3555 if (debug & DEBUG_HFCMULTI_MSG)
3556 printk(KERN_DEBUG "%s: HFC_ECHOCAN_OFF\n",
3558 if (test_bit(HFC_CHIP_B410P, &hc->chip))
3559 vpm_echocan_off(hc, bch->slot);
3564 printk(KERN_WARNING "%s: unknown Op %x\n",
3573 hfcm_bctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
3575 struct bchannel *bch = container_of(ch, struct bchannel, ch);
3576 struct hfc_multi *hc = bch->hw;
3580 if (bch->debug & DEBUG_HW)
3581 printk(KERN_DEBUG "%s: cmd:%x %p\n",
3582 __func__, cmd, arg);
3585 test_and_clear_bit(FLG_OPEN, &bch->Flags);
3586 if (test_bit(FLG_ACTIVE, &bch->Flags))
3587 deactivate_bchannel(bch); /* locked there */
3588 ch->protocol = ISDN_P_NONE;
3590 module_put(THIS_MODULE);
3593 case CONTROL_CHANNEL:
3594 spin_lock_irqsave(&hc->lock, flags);
3595 err = channel_bctrl(bch, arg);
3596 spin_unlock_irqrestore(&hc->lock, flags);
3599 printk(KERN_WARNING "%s: unknown prim(%x)\n",
3606 * handle D-channel events
3608 * handle state change event
3611 ph_state_change(struct dchannel *dch)
3613 struct hfc_multi *hc = dch->hw;
3617 printk(KERN_WARNING "%s: ERROR given dch is NULL\n",
3623 if (hc->type == 1) {
3624 if (dch->dev.D.protocol == ISDN_P_TE_E1) {
3625 if (debug & DEBUG_HFCMULTI_STATE)
3627 "%s: E1 TE (id=%d) newstate %x\n",
3628 __func__, hc->id, dch->state);
3630 if (debug & DEBUG_HFCMULTI_STATE)
3632 "%s: E1 NT (id=%d) newstate %x\n",
3633 __func__, hc->id, dch->state);
3635 switch (dch->state) {
3637 if (hc->e1_state != 1) {
3638 for (i = 1; i <= 31; i++) {
3639 /* reset fifos on e1 activation */
3640 HFC_outb_nodebug(hc, R_FIFO, (i << 1) | 1);
3641 HFC_wait_nodebug(hc);
3642 HFC_outb_nodebug(hc,
3643 R_INC_RES_FIFO, V_RES_F);
3644 HFC_wait_nodebug(hc);
3647 test_and_set_bit(FLG_ACTIVE, &dch->Flags);
3648 _queue_data(&dch->dev.D, PH_ACTIVATE_IND,
3649 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
3653 if (hc->e1_state != 1)
3655 test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
3656 _queue_data(&dch->dev.D, PH_DEACTIVATE_IND,
3657 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
3659 hc->e1_state = dch->state;
3661 if (dch->dev.D.protocol == ISDN_P_TE_S0) {
3662 if (debug & DEBUG_HFCMULTI_STATE)
3664 "%s: S/T TE newstate %x\n",
3665 __func__, dch->state);
3666 switch (dch->state) {
3668 l1_event(dch->l1, HW_RESET_IND);
3671 l1_event(dch->l1, HW_DEACT_IND);
3675 l1_event(dch->l1, ANYSIGNAL);
3678 l1_event(dch->l1, INFO2);
3681 l1_event(dch->l1, INFO4_P8);
3685 if (debug & DEBUG_HFCMULTI_STATE)
3686 printk(KERN_DEBUG "%s: S/T NT newstate %x\n",
3687 __func__, dch->state);
3688 switch (dch->state) {
3690 if (hc->chan[ch].nt_timer == 0) {
3691 hc->chan[ch].nt_timer = -1;
3692 HFC_outb(hc, R_ST_SEL,
3694 /* undocumented: delay after R_ST_SEL */
3696 HFC_outb(hc, A_ST_WR_STATE, 4 |
3697 V_ST_LD_STA); /* G4 */
3698 udelay(6); /* wait at least 5,21us */
3699 HFC_outb(hc, A_ST_WR_STATE, 4);
3702 /* one extra count for the next event */
3703 hc->chan[ch].nt_timer =
3704 nt_t1_count[poll_timer] + 1;
3705 HFC_outb(hc, R_ST_SEL,
3707 /* undocumented: delay after R_ST_SEL */
3709 /* allow G2 -> G3 transition */
3710 HFC_outb(hc, A_ST_WR_STATE, 2 |
3715 hc->chan[ch].nt_timer = -1;
3716 test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
3717 _queue_data(&dch->dev.D, PH_DEACTIVATE_IND,
3718 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
3721 hc->chan[ch].nt_timer = -1;
3724 hc->chan[ch].nt_timer = -1;
3725 test_and_set_bit(FLG_ACTIVE, &dch->Flags);
3726 _queue_data(&dch->dev.D, PH_ACTIVATE_IND,
3727 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
3735 * called for card mode init message
3739 hfcmulti_initmode(struct dchannel *dch)
3741 struct hfc_multi *hc = dch->hw;
3742 u_char a_st_wr_state, r_e1_wr_sta;
3745 if (debug & DEBUG_HFCMULTI_INIT)
3746 printk(KERN_DEBUG "%s: entered\n", __func__);
3748 if (hc->type == 1) {
3749 hc->chan[hc->dslot].slot_tx = -1;
3750 hc->chan[hc->dslot].slot_rx = -1;
3751 hc->chan[hc->dslot].conf = -1;
3753 mode_hfcmulti(hc, hc->dslot, dch->dev.D.protocol,
3755 dch->timer.function = (void *) hfcmulti_dbusy_timer;
3756 dch->timer.data = (long) dch;
3757 init_timer(&dch->timer);
3759 for (i = 1; i <= 31; i++) {
3762 hc->chan[i].slot_tx = -1;
3763 hc->chan[i].slot_rx = -1;
3764 hc->chan[i].conf = -1;
3765 mode_hfcmulti(hc, i, ISDN_P_NONE, -1, 0, -1, 0);
3768 if (test_bit(HFC_CFG_REPORT_LOS, &hc->chan[hc->dslot].cfg)) {
3769 HFC_outb(hc, R_LOS0, 255); /* 2 ms */
3770 HFC_outb(hc, R_LOS1, 255); /* 512 ms */
3772 if (test_bit(HFC_CFG_OPTICAL, &hc->chan[hc->dslot].cfg)) {
3773 HFC_outb(hc, R_RX0, 0);
3774 hc->hw.r_tx0 = 0 | V_OUT_EN;
3776 HFC_outb(hc, R_RX0, 1);
3777 hc->hw.r_tx0 = 1 | V_OUT_EN;
3779 hc->hw.r_tx1 = V_ATX | V_NTRI;
3780 HFC_outb(hc, R_TX0, hc->hw.r_tx0);
3781 HFC_outb(hc, R_TX1, hc->hw.r_tx1);
3782 HFC_outb(hc, R_TX_FR0, 0x00);
3783 HFC_outb(hc, R_TX_FR1, 0xf8);
3785 if (test_bit(HFC_CFG_CRC4, &hc->chan[hc->dslot].cfg))
3786 HFC_outb(hc, R_TX_FR2, V_TX_MF | V_TX_E | V_NEG_E);
3788 HFC_outb(hc, R_RX_FR0, V_AUTO_RESYNC | V_AUTO_RECO | 0);
3790 if (test_bit(HFC_CFG_CRC4, &hc->chan[hc->dslot].cfg))
3791 HFC_outb(hc, R_RX_FR1, V_RX_MF | V_RX_MF_SYNC);
3793 if (dch->dev.D.protocol == ISDN_P_NT_E1) {
3794 if (debug & DEBUG_HFCMULTI_INIT)
3795 printk(KERN_DEBUG "%s: E1 port is NT-mode\n",
3797 r_e1_wr_sta = 0; /* G0 */
3798 hc->e1_getclock = 0;
3800 if (debug & DEBUG_HFCMULTI_INIT)
3801 printk(KERN_DEBUG "%s: E1 port is TE-mode\n",
3803 r_e1_wr_sta = 0; /* F0 */
3804 hc->e1_getclock = 1;
3806 if (test_bit(HFC_CHIP_RX_SYNC, &hc->chip))
3807 HFC_outb(hc, R_SYNC_OUT, V_SYNC_E1_RX);
3809 HFC_outb(hc, R_SYNC_OUT, 0);
3810 if (test_bit(HFC_CHIP_E1CLOCK_GET, &hc->chip))
3811 hc->e1_getclock = 1;
3812 if (test_bit(HFC_CHIP_E1CLOCK_PUT, &hc->chip))
3813 hc->e1_getclock = 0;
3814 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
3815 /* SLAVE (clock master) */
3816 if (debug & DEBUG_HFCMULTI_INIT)
3818 "%s: E1 port is clock master "
3819 "(clock from PCM)\n", __func__);
3820 HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC | V_PCM_SYNC);
3822 if (hc->e1_getclock) {
3823 /* MASTER (clock slave) */
3824 if (debug & DEBUG_HFCMULTI_INIT)
3826 "%s: E1 port is clock slave "
3827 "(clock to PCM)\n", __func__);
3828 HFC_outb(hc, R_SYNC_CTRL, V_SYNC_OFFS);
3830 /* MASTER (clock master) */
3831 if (debug & DEBUG_HFCMULTI_INIT)
3832 printk(KERN_DEBUG "%s: E1 port is "
3834 "(clock from QUARTZ)\n",
3836 HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC |
3837 V_PCM_SYNC | V_JATT_OFF);
3838 HFC_outb(hc, R_SYNC_OUT, 0);
3841 HFC_outb(hc, R_JATT_ATT, 0x9c); /* undoc register */
3842 HFC_outb(hc, R_PWM_MD, V_PWM0_MD);
3843 HFC_outb(hc, R_PWM0, 0x50);
3844 HFC_outb(hc, R_PWM1, 0xff);
3845 /* state machine setup */
3846 HFC_outb(hc, R_E1_WR_STA, r_e1_wr_sta | V_E1_LD_STA);
3847 udelay(6); /* wait at least 5,21us */
3848 HFC_outb(hc, R_E1_WR_STA, r_e1_wr_sta);
3849 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
3850 hc->syncronized = 0;
3851 plxsd_checksync(hc, 0);
3855 hc->chan[i].slot_tx = -1;
3856 hc->chan[i].slot_rx = -1;
3857 hc->chan[i].conf = -1;
3858 mode_hfcmulti(hc, i, dch->dev.D.protocol, -1, 0, -1, 0);
3859 dch->timer.function = (void *)hfcmulti_dbusy_timer;
3860 dch->timer.data = (long) dch;
3861 init_timer(&dch->timer);
3862 hc->chan[i - 2].slot_tx = -1;
3863 hc->chan[i - 2].slot_rx = -1;
3864 hc->chan[i - 2].conf = -1;
3865 mode_hfcmulti(hc, i - 2, ISDN_P_NONE, -1, 0, -1, 0);
3866 hc->chan[i - 1].slot_tx = -1;
3867 hc->chan[i - 1].slot_rx = -1;
3868 hc->chan[i - 1].conf = -1;
3869 mode_hfcmulti(hc, i - 1, ISDN_P_NONE, -1, 0, -1, 0);
3871 pt = hc->chan[i].port;
3872 /* select interface */
3873 HFC_outb(hc, R_ST_SEL, pt);
3874 /* undocumented: delay after R_ST_SEL */
3876 if (dch->dev.D.protocol == ISDN_P_NT_S0) {
3877 if (debug & DEBUG_HFCMULTI_INIT)
3879 "%s: ST port %d is NT-mode\n",
3882 HFC_outb(hc, A_ST_CLK_DLY, clockdelay_nt);
3883 a_st_wr_state = 1; /* G1 */
3884 hc->hw.a_st_ctrl0[pt] = V_ST_MD;
3886 if (debug & DEBUG_HFCMULTI_INIT)
3888 "%s: ST port %d is TE-mode\n",
3891 HFC_outb(hc, A_ST_CLK_DLY, clockdelay_te);
3892 a_st_wr_state = 2; /* F2 */
3893 hc->hw.a_st_ctrl0[pt] = 0;
3895 if (!test_bit(HFC_CFG_NONCAP_TX, &hc->chan[i].cfg))
3896 hc->hw.a_st_ctrl0[pt] |= V_TX_LI;
3898 HFC_outb(hc, A_ST_CTRL0, hc->hw.a_st_ctrl0[pt]);
3899 /* disable E-channel */
3900 if ((dch->dev.D.protocol == ISDN_P_NT_S0) ||
3901 test_bit(HFC_CFG_DIS_ECHANNEL, &hc->chan[i].cfg))
3902 HFC_outb(hc, A_ST_CTRL1, V_E_IGNO);
3904 HFC_outb(hc, A_ST_CTRL1, 0);
3905 /* enable B-channel receive */
3906 HFC_outb(hc, A_ST_CTRL2, V_B1_RX_EN | V_B2_RX_EN);
3907 /* state machine setup */
3908 HFC_outb(hc, A_ST_WR_STATE, a_st_wr_state | V_ST_LD_STA);
3909 udelay(6); /* wait at least 5,21us */
3910 HFC_outb(hc, A_ST_WR_STATE, a_st_wr_state);
3911 hc->hw.r_sci_msk |= 1 << pt;
3912 /* state machine interrupts */
3913 HFC_outb(hc, R_SCI_MSK, hc->hw.r_sci_msk);
3914 /* unset sync on port */
3915 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
3917 ~(1 << hc->chan[dch->slot].port);
3918 plxsd_checksync(hc, 0);
3921 if (debug & DEBUG_HFCMULTI_INIT)
3922 printk("%s: done\n", __func__);
3927 open_dchannel(struct hfc_multi *hc, struct dchannel *dch,
3928 struct channel_req *rq)
3933 if (debug & DEBUG_HW_OPEN)
3934 printk(KERN_DEBUG "%s: dev(%d) open from %p\n", __func__,
3935 dch->dev.id, __builtin_return_address(0));
3936 if (rq->protocol == ISDN_P_NONE)
3938 if ((dch->dev.D.protocol != ISDN_P_NONE) &&
3939 (dch->dev.D.protocol != rq->protocol)) {
3940 if (debug & DEBUG_HFCMULTI_MODE)
3941 printk(KERN_WARNING "%s: change protocol %x to %x\n",
3942 __func__, dch->dev.D.protocol, rq->protocol);
3944 if ((dch->dev.D.protocol == ISDN_P_TE_S0)
3945 && (rq->protocol != ISDN_P_TE_S0))
3946 l1_event(dch->l1, CLOSE_CHANNEL);
3947 if (dch->dev.D.protocol != rq->protocol) {
3948 if (rq->protocol == ISDN_P_TE_S0) {
3949 err = create_l1(dch, hfcm_l1callback);
3953 dch->dev.D.protocol = rq->protocol;
3954 spin_lock_irqsave(&hc->lock, flags);
3955 hfcmulti_initmode(dch);
3956 spin_unlock_irqrestore(&hc->lock, flags);
3959 if (((rq->protocol == ISDN_P_NT_S0) && (dch->state == 3)) ||
3960 ((rq->protocol == ISDN_P_TE_S0) && (dch->state == 7)) ||
3961 ((rq->protocol == ISDN_P_NT_E1) && (dch->state == 1)) ||
3962 ((rq->protocol == ISDN_P_TE_E1) && (dch->state == 1))) {
3963 _queue_data(&dch->dev.D, PH_ACTIVATE_IND, MISDN_ID_ANY,
3964 0, NULL, GFP_KERNEL);
3966 rq->ch = &dch->dev.D;
3967 if (!try_module_get(THIS_MODULE))
3968 printk(KERN_WARNING "%s:cannot get module\n", __func__);
3973 open_bchannel(struct hfc_multi *hc, struct dchannel *dch,
3974 struct channel_req *rq)
3976 struct bchannel *bch;
3979 if (!test_channelmap(rq->adr.channel, dch->dev.channelmap))
3981 if (rq->protocol == ISDN_P_NONE)
3984 ch = rq->adr.channel;
3986 ch = (rq->adr.channel - 1) + (dch->slot - 2);
3987 bch = hc->chan[ch].bch;
3989 printk(KERN_ERR "%s:internal error ch %d has no bch\n",
3993 if (test_and_set_bit(FLG_OPEN, &bch->Flags))
3994 return -EBUSY; /* b-channel can be only open once */
3995 bch->ch.protocol = rq->protocol;
3996 hc->chan[ch].rx_off = 0;
3998 if (!try_module_get(THIS_MODULE))
3999 printk(KERN_WARNING "%s:cannot get module\n", __func__);
4004 * device control function
4007 channel_dctrl(struct dchannel *dch, struct mISDN_ctrl_req *cq)
4012 case MISDN_CTRL_GETOP:
4016 printk(KERN_WARNING "%s: unknown Op %x\n",
4025 hfcm_dctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
4027 struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
4028 struct dchannel *dch = container_of(dev, struct dchannel, dev);
4029 struct hfc_multi *hc = dch->hw;
4030 struct channel_req *rq;
4034 if (dch->debug & DEBUG_HW)
4035 printk(KERN_DEBUG "%s: cmd:%x %p\n",
4036 __func__, cmd, arg);
4040 switch (rq->protocol) {
4043 if (hc->type == 1) {
4047 err = open_dchannel(hc, dch, rq); /* locked there */
4051 if (hc->type != 1) {
4055 err = open_dchannel(hc, dch, rq); /* locked there */
4058 spin_lock_irqsave(&hc->lock, flags);
4059 err = open_bchannel(hc, dch, rq);
4060 spin_unlock_irqrestore(&hc->lock, flags);
4064 if (debug & DEBUG_HW_OPEN)
4065 printk(KERN_DEBUG "%s: dev(%d) close from %p\n",
4066 __func__, dch->dev.id,
4067 __builtin_return_address(0));
4068 module_put(THIS_MODULE);
4070 case CONTROL_CHANNEL:
4071 spin_lock_irqsave(&hc->lock, flags);
4072 err = channel_dctrl(dch, arg);
4073 spin_unlock_irqrestore(&hc->lock, flags);
4076 if (dch->debug & DEBUG_HW)
4077 printk(KERN_DEBUG "%s: unknown command %x\n",
4085 * initialize the card
4089 * start timer irq, wait some time and check if we have interrupts.
4090 * if not, reset chip and try again.
4093 init_card(struct hfc_multi *hc)
4097 void __iomem *plx_acc;
4100 if (debug & DEBUG_HFCMULTI_INIT)
4101 printk(KERN_DEBUG "%s: entered\n", __func__);
4103 spin_lock_irqsave(&hc->lock, flags);
4104 /* set interrupts but leave global interrupt disabled */
4105 hc->hw.r_irq_ctrl = V_FIFO_IRQ;
4107 spin_unlock_irqrestore(&hc->lock, flags);
4109 if (request_irq(hc->pci_dev->irq, hfcmulti_interrupt, IRQF_SHARED,
4111 printk(KERN_WARNING "mISDN: Could not get interrupt %d.\n",
4115 hc->irq = hc->pci_dev->irq;
4117 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
4118 spin_lock_irqsave(&plx_lock, plx_flags);
4119 plx_acc = hc->plx_membase + PLX_INTCSR;
4120 writew((PLX_INTCSR_PCIINT_ENABLE | PLX_INTCSR_LINTI1_ENABLE),
4121 plx_acc); /* enable PCI & LINT1 irq */
4122 spin_unlock_irqrestore(&plx_lock, plx_flags);
4125 if (debug & DEBUG_HFCMULTI_INIT)
4126 printk(KERN_DEBUG "%s: IRQ %d count %d\n",
4127 __func__, hc->irq, hc->irqcnt);
4128 err = init_chip(hc);
4132 * Finally enable IRQ output
4133 * this is only allowed, if an IRQ routine is allready
4134 * established for this HFC, so don't do that earlier
4136 spin_lock_irqsave(&hc->lock, flags);
4138 spin_unlock_irqrestore(&hc->lock, flags);
4139 /* printk(KERN_DEBUG "no master irq set!!!\n"); */
4140 set_current_state(TASK_UNINTERRUPTIBLE);
4141 schedule_timeout((100*HZ)/1000); /* Timeout 100ms */
4142 /* turn IRQ off until chip is completely initialized */
4143 spin_lock_irqsave(&hc->lock, flags);
4145 spin_unlock_irqrestore(&hc->lock, flags);
4146 if (debug & DEBUG_HFCMULTI_INIT)
4147 printk(KERN_DEBUG "%s: IRQ %d count %d\n",
4148 __func__, hc->irq, hc->irqcnt);
4150 if (debug & DEBUG_HFCMULTI_INIT)
4151 printk(KERN_DEBUG "%s: done\n", __func__);
4155 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
4156 printk(KERN_INFO "ignoring missing interrupts\n");
4160 printk(KERN_ERR "HFC PCI: IRQ(%d) getting no interrupts during init.\n",
4166 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
4167 spin_lock_irqsave(&plx_lock, plx_flags);
4168 plx_acc = hc->plx_membase + PLX_INTCSR;
4169 writew(0x00, plx_acc); /*disable IRQs*/
4170 spin_unlock_irqrestore(&plx_lock, plx_flags);
4173 if (debug & DEBUG_HFCMULTI_INIT)
4174 printk(KERN_WARNING "%s: free irq %d\n", __func__, hc->irq);
4176 free_irq(hc->irq, hc);
4180 if (debug & DEBUG_HFCMULTI_INIT)
4181 printk(KERN_DEBUG "%s: done (err=%d)\n", __func__, err);
4186 * find pci device and set it up
4190 setup_pci(struct hfc_multi *hc, struct pci_dev *pdev,
4191 const struct pci_device_id *ent)
4193 struct hm_map *m = (struct hm_map *)ent->driver_data;
4196 "HFC-multi: card manufacturer: '%s' card name: '%s' clock: %s\n",
4197 m->vendor_name, m->card_name, m->clock2 ? "double" : "normal");
4201 test_and_set_bit(HFC_CHIP_CLOCK2, &hc->chip);
4203 if (ent->device == 0xB410) {
4204 test_and_set_bit(HFC_CHIP_B410P, &hc->chip);
4205 test_and_set_bit(HFC_CHIP_PCM_MASTER, &hc->chip);
4206 test_and_clear_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
4210 if (hc->pci_dev->irq <= 0) {
4211 printk(KERN_WARNING "HFC-multi: No IRQ for PCI card found.\n");
4214 if (pci_enable_device(hc->pci_dev)) {
4215 printk(KERN_WARNING "HFC-multi: Error enabling PCI card.\n");
4219 hc->ledstate = 0xAFFEAFFE;
4220 hc->opticalsupport = m->opticalsupport;
4222 /* set memory access methods */
4223 if (m->io_mode) /* use mode from card config */
4224 hc->io_mode = m->io_mode;
4225 switch (hc->io_mode) {
4226 case HFC_IO_MODE_PLXSD:
4227 test_and_set_bit(HFC_CHIP_PLXSD, &hc->chip);
4228 hc->slots = 128; /* required */
4230 case HFC_IO_MODE_PCIMEM:
4231 hc->HFC_outb = HFC_outb_pcimem;
4232 hc->HFC_inb = HFC_inb_pcimem;
4233 hc->HFC_inw = HFC_inw_pcimem;
4234 hc->HFC_wait = HFC_wait_pcimem;
4235 hc->read_fifo = read_fifo_pcimem;
4236 hc->write_fifo = write_fifo_pcimem;
4238 case HFC_IO_MODE_REGIO:
4239 hc->HFC_outb = HFC_outb_regio;
4240 hc->HFC_inb = HFC_inb_regio;
4241 hc->HFC_inw = HFC_inw_regio;
4242 hc->HFC_wait = HFC_wait_regio;
4243 hc->read_fifo = read_fifo_regio;
4244 hc->write_fifo = write_fifo_regio;
4247 printk(KERN_WARNING "HFC-multi: Invalid IO mode.\n");
4248 pci_disable_device(hc->pci_dev);
4251 hc->HFC_outb_nodebug = hc->HFC_outb;
4252 hc->HFC_inb_nodebug = hc->HFC_inb;
4253 hc->HFC_inw_nodebug = hc->HFC_inw;
4254 hc->HFC_wait_nodebug = hc->HFC_wait;
4255 #ifdef HFC_REGISTER_DEBUG
4256 hc->HFC_outb = HFC_outb_debug;
4257 hc->HFC_inb = HFC_inb_debug;
4258 hc->HFC_inw = HFC_inw_debug;
4259 hc->HFC_wait = HFC_wait_debug;
4262 hc->pci_membase = NULL;
4263 hc->plx_membase = NULL;
4265 switch (hc->io_mode) {
4266 case HFC_IO_MODE_PLXSD:
4267 hc->plx_origmembase = hc->pci_dev->resource[0].start;
4268 /* MEMBASE 1 is PLX PCI Bridge */
4270 if (!hc->plx_origmembase) {
4272 "HFC-multi: No IO-Memory for PCI PLX bridge found\n");
4273 pci_disable_device(hc->pci_dev);
4277 hc->plx_membase = ioremap(hc->plx_origmembase, 0x80);
4278 if (!hc->plx_membase) {
4280 "HFC-multi: failed to remap plx address space. "
4281 "(internal error)\n");
4282 pci_disable_device(hc->pci_dev);
4286 "HFC-multi: plx_membase:%#lx plx_origmembase:%#lx\n",
4287 (u_long)hc->plx_membase, hc->plx_origmembase);
4289 hc->pci_origmembase = hc->pci_dev->resource[2].start;
4290 /* MEMBASE 1 is PLX PCI Bridge */
4291 if (!hc->pci_origmembase) {
4293 "HFC-multi: No IO-Memory for PCI card found\n");
4294 pci_disable_device(hc->pci_dev);
4298 hc->pci_membase = ioremap(hc->pci_origmembase, 0x400);
4299 if (!hc->pci_membase) {
4300 printk(KERN_WARNING "HFC-multi: failed to remap io "
4301 "address space. (internal error)\n");
4302 pci_disable_device(hc->pci_dev);
4307 "card %d: defined at MEMBASE %#lx (%#lx) IRQ %d HZ %d "
4309 hc->id, (u_long)hc->pci_membase, hc->pci_origmembase,
4310 hc->pci_dev->irq, HZ, hc->leds);
4311 pci_write_config_word(hc->pci_dev, PCI_COMMAND, PCI_ENA_MEMIO);
4313 case HFC_IO_MODE_PCIMEM:
4314 hc->pci_origmembase = hc->pci_dev->resource[1].start;
4315 if (!hc->pci_origmembase) {
4317 "HFC-multi: No IO-Memory for PCI card found\n");
4318 pci_disable_device(hc->pci_dev);
4322 hc->pci_membase = ioremap(hc->pci_origmembase, 256);
4323 if (!hc->pci_membase) {
4325 "HFC-multi: failed to remap io address space. "
4326 "(internal error)\n");
4327 pci_disable_device(hc->pci_dev);
4330 printk(KERN_INFO "card %d: defined at MEMBASE %#lx (%#lx) IRQ %d "
4331 "HZ %d leds-type %d\n", hc->id, (u_long)hc->pci_membase,
4332 hc->pci_origmembase, hc->pci_dev->irq, HZ, hc->leds);
4333 pci_write_config_word(hc->pci_dev, PCI_COMMAND, PCI_ENA_MEMIO);
4335 case HFC_IO_MODE_REGIO:
4336 hc->pci_iobase = (u_int) hc->pci_dev->resource[0].start;
4337 if (!hc->pci_iobase) {
4339 "HFC-multi: No IO for PCI card found\n");
4340 pci_disable_device(hc->pci_dev);
4344 if (!request_region(hc->pci_iobase, 8, "hfcmulti")) {
4345 printk(KERN_WARNING "HFC-multi: failed to request "
4346 "address space at 0x%08lx (internal error)\n",
4348 pci_disable_device(hc->pci_dev);
4353 "%s %s: defined at IOBASE %#x IRQ %d HZ %d leds-type %d\n",
4354 m->vendor_name, m->card_name, (u_int) hc->pci_iobase,
4355 hc->pci_dev->irq, HZ, hc->leds);
4356 pci_write_config_word(hc->pci_dev, PCI_COMMAND, PCI_ENA_REGIO);
4359 printk(KERN_WARNING "HFC-multi: Invalid IO mode.\n");
4360 pci_disable_device(hc->pci_dev);
4364 pci_set_drvdata(hc->pci_dev, hc);
4366 /* At this point the needed PCI config is done */
4367 /* fifos are still not enabled */
4377 release_port(struct hfc_multi *hc, struct dchannel *dch)
4381 struct bchannel *pb;
4384 pt = hc->chan[ci].port;
4386 if (debug & DEBUG_HFCMULTI_INIT)
4387 printk(KERN_DEBUG "%s: entered for port %d\n",
4390 if (pt >= hc->ports) {
4391 printk(KERN_WARNING "%s: ERROR port out of range (%d).\n",
4396 if (debug & DEBUG_HFCMULTI_INIT)
4397 printk(KERN_DEBUG "%s: releasing port=%d\n",
4400 if (dch->dev.D.protocol == ISDN_P_TE_S0)
4401 l1_event(dch->l1, CLOSE_CHANNEL);
4403 hc->chan[ci].dch = NULL;
4405 if (hc->created[pt]) {
4406 hc->created[pt] = 0;
4407 mISDN_unregister_device(&dch->dev);
4410 spin_lock_irqsave(&hc->lock, flags);
4412 if (dch->timer.function) {
4413 del_timer(&dch->timer);
4414 dch->timer.function = NULL;
4417 if (hc->type == 1) { /* E1 */
4419 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
4420 hc->syncronized = 0;
4421 plxsd_checksync(hc, 1);
4424 for (i = 0; i <= 31; i++) {
4425 if (hc->chan[i].bch) {
4426 if (debug & DEBUG_HFCMULTI_INIT)
4428 "%s: free port %d channel %d\n",
4429 __func__, hc->chan[i].port+1, i);
4430 pb = hc->chan[i].bch;
4431 hc->chan[i].bch = NULL;
4432 spin_unlock_irqrestore(&hc->lock, flags);
4433 mISDN_freebchannel(pb);
4435 kfree(hc->chan[i].coeff);
4436 spin_lock_irqsave(&hc->lock, flags);
4441 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
4443 ~(1 << hc->chan[ci].port);
4444 plxsd_checksync(hc, 1);
4447 if (hc->chan[ci - 2].bch) {
4448 if (debug & DEBUG_HFCMULTI_INIT)
4450 "%s: free port %d channel %d\n",
4451 __func__, hc->chan[ci - 2].port+1,
4453 pb = hc->chan[ci - 2].bch;
4454 hc->chan[ci - 2].bch = NULL;
4455 spin_unlock_irqrestore(&hc->lock, flags);
4456 mISDN_freebchannel(pb);
4458 kfree(hc->chan[ci - 2].coeff);
4459 spin_lock_irqsave(&hc->lock, flags);
4461 if (hc->chan[ci - 1].bch) {
4462 if (debug & DEBUG_HFCMULTI_INIT)
4464 "%s: free port %d channel %d\n",
4465 __func__, hc->chan[ci - 1].port+1,
4467 pb = hc->chan[ci - 1].bch;
4468 hc->chan[ci - 1].bch = NULL;
4469 spin_unlock_irqrestore(&hc->lock, flags);
4470 mISDN_freebchannel(pb);
4472 kfree(hc->chan[ci - 1].coeff);
4473 spin_lock_irqsave(&hc->lock, flags);
4477 spin_unlock_irqrestore(&hc->lock, flags);
4479 if (debug & DEBUG_HFCMULTI_INIT)
4480 printk(KERN_DEBUG "%s: free port %d channel D\n", __func__, pt);
4481 mISDN_freedchannel(dch);
4484 if (debug & DEBUG_HFCMULTI_INIT)
4485 printk(KERN_DEBUG "%s: done!\n", __func__);
4489 release_card(struct hfc_multi *hc)
4494 if (debug & DEBUG_HFCMULTI_INIT)
4495 printk(KERN_WARNING "%s: release card (%d) entered\n",
4498 spin_lock_irqsave(&hc->lock, flags);
4500 spin_unlock_irqrestore(&hc->lock, flags);
4508 /* disable D-channels & B-channels */
4509 if (debug & DEBUG_HFCMULTI_INIT)
4510 printk(KERN_DEBUG "%s: disable all channels (d and b)\n",
4512 for (ch = 0; ch <= 31; ch++) {
4513 if (hc->chan[ch].dch)
4514 release_port(hc, hc->chan[ch].dch);
4517 /* release hardware & irq */
4519 if (debug & DEBUG_HFCMULTI_INIT)
4520 printk(KERN_WARNING "%s: free irq %d\n",
4522 free_irq(hc->irq, hc);
4526 release_io_hfcmulti(hc);
4528 if (debug & DEBUG_HFCMULTI_INIT)
4529 printk(KERN_WARNING "%s: remove instance from list\n",
4531 list_del(&hc->list);
4533 if (debug & DEBUG_HFCMULTI_INIT)
4534 printk(KERN_WARNING "%s: delete instance\n", __func__);
4535 if (hc == syncmaster)
4538 if (debug & DEBUG_HFCMULTI_INIT)
4539 printk(KERN_WARNING "%s: card successfully removed\n",
4544 init_e1_port(struct hfc_multi *hc, struct hm_map *m)
4546 struct dchannel *dch;
4547 struct bchannel *bch;
4549 char name[MISDN_MAX_IDLEN];
4551 dch = kzalloc(sizeof(struct dchannel), GFP_KERNEL);
4555 mISDN_initdchannel(dch, MAX_DFRAME_LEN_L1, ph_state_change);
4557 dch->dev.Dprotocols = (1 << ISDN_P_TE_E1) | (1 << ISDN_P_NT_E1);
4558 dch->dev.Bprotocols = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
4559 (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK));
4560 dch->dev.D.send = handle_dmsg;
4561 dch->dev.D.ctrl = hfcm_dctrl;
4562 dch->dev.nrbchan = (hc->dslot)?30:31;
4563 dch->slot = hc->dslot;
4564 hc->chan[hc->dslot].dch = dch;
4565 hc->chan[hc->dslot].port = 0;
4566 hc->chan[hc->dslot].nt_timer = -1;
4567 for (ch = 1; ch <= 31; ch++) {
4568 if (ch == hc->dslot) /* skip dchannel */
4570 bch = kzalloc(sizeof(struct bchannel), GFP_KERNEL);
4572 printk(KERN_ERR "%s: no memory for bchannel\n",
4577 hc->chan[ch].coeff = kzalloc(512, GFP_KERNEL);
4578 if (!hc->chan[ch].coeff) {
4579 printk(KERN_ERR "%s: no memory for coeffs\n",
4587 mISDN_initbchannel(bch, MAX_DATA_MEM);
4589 bch->ch.send = handle_bmsg;
4590 bch->ch.ctrl = hfcm_bctrl;
4592 list_add(&bch->ch.list, &dch->dev.bchannels);
4593 hc->chan[ch].bch = bch;
4594 hc->chan[ch].port = 0;
4595 set_channelmap(bch->nr, dch->dev.channelmap);
4597 /* set optical line type */
4598 if (port[Port_cnt] & 0x001) {
4599 if (!m->opticalsupport) {
4601 "This board has no optical "
4604 if (debug & DEBUG_HFCMULTI_INIT)
4606 "%s: PORT set optical "
4607 "interfacs: card(%d) "
4611 test_and_set_bit(HFC_CFG_OPTICAL,
4612 &hc->chan[hc->dslot].cfg);
4615 /* set LOS report */
4616 if (port[Port_cnt] & 0x004) {
4617 if (debug & DEBUG_HFCMULTI_INIT)
4618 printk(KERN_DEBUG "%s: PORT set "
4619 "LOS report: card(%d) port(%d)\n",
4620 __func__, HFC_cnt + 1, 1);
4621 test_and_set_bit(HFC_CFG_REPORT_LOS,
4622 &hc->chan[hc->dslot].cfg);
4624 /* set AIS report */
4625 if (port[Port_cnt] & 0x008) {
4626 if (debug & DEBUG_HFCMULTI_INIT)
4627 printk(KERN_DEBUG "%s: PORT set "
4628 "AIS report: card(%d) port(%d)\n",
4629 __func__, HFC_cnt + 1, 1);
4630 test_and_set_bit(HFC_CFG_REPORT_AIS,
4631 &hc->chan[hc->dslot].cfg);
4633 /* set SLIP report */
4634 if (port[Port_cnt] & 0x010) {
4635 if (debug & DEBUG_HFCMULTI_INIT)
4637 "%s: PORT set SLIP report: "
4638 "card(%d) port(%d)\n",
4639 __func__, HFC_cnt + 1, 1);
4640 test_and_set_bit(HFC_CFG_REPORT_SLIP,
4641 &hc->chan[hc->dslot].cfg);
4643 /* set RDI report */
4644 if (port[Port_cnt] & 0x020) {
4645 if (debug & DEBUG_HFCMULTI_INIT)
4647 "%s: PORT set RDI report: "
4648 "card(%d) port(%d)\n",
4649 __func__, HFC_cnt + 1, 1);
4650 test_and_set_bit(HFC_CFG_REPORT_RDI,
4651 &hc->chan[hc->dslot].cfg);
4653 /* set CRC-4 Mode */
4654 if (!(port[Port_cnt] & 0x100)) {
4655 if (debug & DEBUG_HFCMULTI_INIT)
4656 printk(KERN_DEBUG "%s: PORT turn on CRC4 report:"
4657 " card(%d) port(%d)\n",
4658 __func__, HFC_cnt + 1, 1);
4659 test_and_set_bit(HFC_CFG_CRC4,
4660 &hc->chan[hc->dslot].cfg);
4662 if (debug & DEBUG_HFCMULTI_INIT)
4663 printk(KERN_DEBUG "%s: PORT turn off CRC4"
4664 " report: card(%d) port(%d)\n",
4665 __func__, HFC_cnt + 1, 1);
4667 /* set forced clock */
4668 if (port[Port_cnt] & 0x0200) {
4669 if (debug & DEBUG_HFCMULTI_INIT)
4670 printk(KERN_DEBUG "%s: PORT force getting clock from "
4671 "E1: card(%d) port(%d)\n",
4672 __func__, HFC_cnt + 1, 1);
4673 test_and_set_bit(HFC_CHIP_E1CLOCK_GET, &hc->chip);
4675 if (port[Port_cnt] & 0x0400) {
4676 if (debug & DEBUG_HFCMULTI_INIT)
4677 printk(KERN_DEBUG "%s: PORT force putting clock to "
4678 "E1: card(%d) port(%d)\n",
4679 __func__, HFC_cnt + 1, 1);
4680 test_and_set_bit(HFC_CHIP_E1CLOCK_PUT, &hc->chip);
4683 if (port[Port_cnt] & 0x0800) {
4684 if (debug & DEBUG_HFCMULTI_INIT)
4685 printk(KERN_DEBUG "%s: PORT disable JATT PLL on "
4686 "E1: card(%d) port(%d)\n",
4687 __func__, HFC_cnt + 1, 1);
4688 test_and_set_bit(HFC_CHIP_RX_SYNC, &hc->chip);
4690 /* set elastic jitter buffer */
4691 if (port[Port_cnt] & 0x3000) {
4692 hc->chan[hc->dslot].jitter = (port[Port_cnt]>>12) & 0x3;
4693 if (debug & DEBUG_HFCMULTI_INIT)
4695 "%s: PORT set elastic "
4696 "buffer to %d: card(%d) port(%d)\n",
4697 __func__, hc->chan[hc->dslot].jitter,
4700 hc->chan[hc->dslot].jitter = 2; /* default */
4701 snprintf(name, MISDN_MAX_IDLEN - 1, "hfc-e1.%d", HFC_cnt + 1);
4702 ret = mISDN_register_device(&dch->dev, name);
4708 release_port(hc, dch);
4713 init_multi_port(struct hfc_multi *hc, int pt)
4715 struct dchannel *dch;
4716 struct bchannel *bch;
4718 char name[MISDN_MAX_IDLEN];
4720 dch = kzalloc(sizeof(struct dchannel), GFP_KERNEL);
4724 mISDN_initdchannel(dch, MAX_DFRAME_LEN_L1, ph_state_change);
4726 dch->dev.Dprotocols = (1 << ISDN_P_TE_S0) | (1 << ISDN_P_NT_S0);
4727 dch->dev.Bprotocols = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
4728 (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK));
4729 dch->dev.D.send = handle_dmsg;
4730 dch->dev.D.ctrl = hfcm_dctrl;
4731 dch->dev.nrbchan = 2;
4734 hc->chan[i + 2].dch = dch;
4735 hc->chan[i + 2].port = pt;
4736 hc->chan[i + 2].nt_timer = -1;
4737 for (ch = 0; ch < dch->dev.nrbchan; ch++) {
4738 bch = kzalloc(sizeof(struct bchannel), GFP_KERNEL);
4740 printk(KERN_ERR "%s: no memory for bchannel\n",
4745 hc->chan[i + ch].coeff = kzalloc(512, GFP_KERNEL);
4746 if (!hc->chan[i + ch].coeff) {
4747 printk(KERN_ERR "%s: no memory for coeffs\n",
4755 mISDN_initbchannel(bch, MAX_DATA_MEM);
4757 bch->ch.send = handle_bmsg;
4758 bch->ch.ctrl = hfcm_bctrl;
4759 bch->ch.nr = ch + 1;
4760 list_add(&bch->ch.list, &dch->dev.bchannels);
4761 hc->chan[i + ch].bch = bch;
4762 hc->chan[i + ch].port = pt;
4763 set_channelmap(bch->nr, dch->dev.channelmap);
4765 /* set master clock */
4766 if (port[Port_cnt] & 0x001) {
4767 if (debug & DEBUG_HFCMULTI_INIT)
4769 "%s: PROTOCOL set master clock: "
4770 "card(%d) port(%d)\n",
4771 __func__, HFC_cnt + 1, pt + 1);
4772 if (dch->dev.D.protocol != ISDN_P_TE_S0) {
4773 printk(KERN_ERR "Error: Master clock "
4774 "for port(%d) of card(%d) is only"
4775 " possible with TE-mode\n",
4776 pt + 1, HFC_cnt + 1);
4780 if (hc->masterclk >= 0) {
4781 printk(KERN_ERR "Error: Master clock "
4782 "for port(%d) of card(%d) already "
4783 "defined for port(%d)\n",
4784 pt + 1, HFC_cnt + 1, hc->masterclk+1);
4790 /* set transmitter line to non capacitive */
4791 if (port[Port_cnt] & 0x002) {
4792 if (debug & DEBUG_HFCMULTI_INIT)
4794 "%s: PROTOCOL set non capacitive "
4795 "transmitter: card(%d) port(%d)\n",
4796 __func__, HFC_cnt + 1, pt + 1);
4797 test_and_set_bit(HFC_CFG_NONCAP_TX,
4798 &hc->chan[i + 2].cfg);
4800 /* disable E-channel */
4801 if (port[Port_cnt] & 0x004) {
4802 if (debug & DEBUG_HFCMULTI_INIT)
4804 "%s: PROTOCOL disable E-channel: "
4805 "card(%d) port(%d)\n",
4806 __func__, HFC_cnt + 1, pt + 1);
4807 test_and_set_bit(HFC_CFG_DIS_ECHANNEL,
4808 &hc->chan[i + 2].cfg);
4810 snprintf(name, MISDN_MAX_IDLEN - 1, "hfc-%ds.%d/%d",
4811 hc->type, HFC_cnt + 1, pt + 1);
4812 ret = mISDN_register_device(&dch->dev, name);
4815 hc->created[pt] = 1;
4818 release_port(hc, dch);
4823 hfcmulti_init(struct pci_dev *pdev, const struct pci_device_id *ent)
4825 struct hm_map *m = (struct hm_map *)ent->driver_data;
4828 struct hfc_multi *hc;
4830 u_char dips = 0, pmj = 0; /* dip settings, port mode Jumpers */
4832 if (HFC_cnt >= MAX_CARDS) {
4833 printk(KERN_ERR "too many cards (max=%d).\n",
4837 if ((type[HFC_cnt] & 0xff) && (type[HFC_cnt] & 0xff) != m->type) {
4838 printk(KERN_WARNING "HFC-MULTI: Card '%s:%s' type %d found but "
4839 "type[%d] %d was supplied as module parameter\n",
4840 m->vendor_name, m->card_name, m->type, HFC_cnt,
4841 type[HFC_cnt] & 0xff);
4842 printk(KERN_WARNING "HFC-MULTI: Load module without parameters "
4843 "first, to see cards and their types.");
4846 if (debug & DEBUG_HFCMULTI_INIT)
4847 printk(KERN_DEBUG "%s: Registering %s:%s chip type %d (0x%x)\n",
4848 __func__, m->vendor_name, m->card_name, m->type,
4851 /* allocate card+fifo structure */
4852 hc = kzalloc(sizeof(struct hfc_multi), GFP_KERNEL);
4854 printk(KERN_ERR "No kmem for HFC-Multi card\n");
4857 spin_lock_init(&hc->lock);
4860 hc->ports = m->ports;
4862 hc->pcm = pcm[HFC_cnt];
4863 hc->io_mode = iomode[HFC_cnt];
4864 if (dslot[HFC_cnt] < 0) {
4866 printk(KERN_INFO "HFC-E1 card has disabled D-channel, but "
4868 } if (dslot[HFC_cnt] > 0 && dslot[HFC_cnt] < 32) {
4869 hc->dslot = dslot[HFC_cnt];
4870 printk(KERN_INFO "HFC-E1 card has alternating D-channel on "
4871 "time slot %d\n", dslot[HFC_cnt]);
4875 /* set chip specific features */
4877 if (type[HFC_cnt] & 0x100) {
4878 test_and_set_bit(HFC_CHIP_ULAW, &hc->chip);
4879 silence = 0xff; /* ulaw silence */
4881 silence = 0x2a; /* alaw silence */
4882 if (!(type[HFC_cnt] & 0x200))
4883 test_and_set_bit(HFC_CHIP_DTMF, &hc->chip);
4885 if (type[HFC_cnt] & 0x800)
4886 test_and_set_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
4887 if (type[HFC_cnt] & 0x1000) {
4888 test_and_set_bit(HFC_CHIP_PCM_MASTER, &hc->chip);
4889 test_and_clear_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
4891 if (type[HFC_cnt] & 0x4000)
4892 test_and_set_bit(HFC_CHIP_EXRAM_128, &hc->chip);
4893 if (type[HFC_cnt] & 0x8000)
4894 test_and_set_bit(HFC_CHIP_EXRAM_512, &hc->chip);
4896 if (type[HFC_cnt] & 0x10000)
4898 if (type[HFC_cnt] & 0x20000)
4900 if (type[HFC_cnt] & 0x80000) {
4901 test_and_set_bit(HFC_CHIP_WATCHDOG, &hc->chip);
4903 hc->wdbyte = V_GPIO_OUT2;
4904 printk(KERN_NOTICE "Watchdog enabled\n");
4907 /* setup pci, hc->slots may change due to PLXSD */
4908 ret_err = setup_pci(hc, pdev, ent);
4910 if (hc == syncmaster)
4916 /* crate channels */
4917 for (pt = 0; pt < hc->ports; pt++) {
4918 if (Port_cnt >= MAX_PORTS) {
4919 printk(KERN_ERR "too many ports (max=%d).\n",
4925 ret_err = init_e1_port(hc, m);
4927 ret_err = init_multi_port(hc, pt);
4928 if (debug & DEBUG_HFCMULTI_INIT)
4930 "%s: Registering D-channel, card(%d) port(%d)"
4932 __func__, HFC_cnt + 1, pt, ret_err);
4935 while (pt) { /* release already registered ports */
4937 release_port(hc, hc->chan[(pt << 2) + 2].dch);
4945 switch (m->dip_type) {
4948 * get DIP Setting for beroNet 1S/2S/4S cards
4949 * check if Port Jumper config matches
4950 * module param 'protocol'
4951 * DIP Setting: (collect GPIO 13/14/15 (R_GPIO_IN1) +
4952 * GPI 19/23 (R_GPI_IN2))
4954 dips = ((~HFC_inb(hc, R_GPIO_IN1) & 0xE0) >> 5) |
4955 ((~HFC_inb(hc, R_GPI_IN2) & 0x80) >> 3) |
4956 (~HFC_inb(hc, R_GPI_IN2) & 0x08);
4958 /* Port mode (TE/NT) jumpers */
4959 pmj = ((HFC_inb(hc, R_GPI_IN3) >> 4) & 0xf);
4961 if (test_bit(HFC_CHIP_B410P, &hc->chip))
4964 printk(KERN_INFO "%s: %s DIPs(0x%x) jumpers(0x%x)\n",
4965 m->vendor_name, m->card_name, dips, pmj);
4969 * get DIP Setting for beroNet 8S0+ cards
4971 * enable PCI auxbridge function
4973 HFC_outb(hc, R_BRG_PCM_CFG, 1 | V_PCM_CLK);
4974 /* prepare access to auxport */
4975 outw(0x4000, hc->pci_iobase + 4);
4977 * some dummy reads are required to
4978 * read valid DIP switch data
4980 dips = inb(hc->pci_iobase);
4981 dips = inb(hc->pci_iobase);
4982 dips = inb(hc->pci_iobase);
4983 dips = ~inb(hc->pci_iobase) & 0x3F;
4984 outw(0x0, hc->pci_iobase + 4);
4985 /* disable PCI auxbridge function */
4986 HFC_outb(hc, R_BRG_PCM_CFG, V_PCM_CLK);
4987 printk(KERN_INFO "%s: %s DIPs(0x%x)\n",
4988 m->vendor_name, m->card_name, dips);
4992 * get DIP Setting for beroNet E1 cards
4993 * DIP Setting: collect GPI 4/5/6/7 (R_GPI_IN0)
4995 dips = (~HFC_inb(hc, R_GPI_IN0) & 0xF0)>>4;
4996 printk(KERN_INFO "%s: %s DIPs(0x%x)\n",
4997 m->vendor_name, m->card_name, dips);
5002 spin_lock_irqsave(&HFClock, flags);
5003 list_add_tail(&hc->list, &HFClist);
5004 spin_unlock_irqrestore(&HFClock, flags);
5006 /* initialize hardware */
5007 ret_err = init_card(hc);
5009 printk(KERN_ERR "init card returns %d\n", ret_err);
5014 /* start IRQ and return */
5015 spin_lock_irqsave(&hc->lock, flags);
5017 spin_unlock_irqrestore(&hc->lock, flags);
5021 release_io_hfcmulti(hc);
5022 if (hc == syncmaster)
5028 static void __devexit hfc_remove_pci(struct pci_dev *pdev)
5030 struct hfc_multi *card = pci_get_drvdata(pdev);
5034 printk(KERN_INFO "removing hfc_multi card vendor:%x "
5035 "device:%x subvendor:%x subdevice:%x\n",
5036 pdev->vendor, pdev->device,
5037 pdev->subsystem_vendor, pdev->subsystem_device);
5040 spin_lock_irqsave(&HFClock, flags);
5042 spin_unlock_irqrestore(&HFClock, flags);
5045 printk(KERN_WARNING "%s: drvdata allready removed\n",
5050 #define VENDOR_CCD "Cologne Chip AG"
5051 #define VENDOR_BN "beroNet GmbH"
5052 #define VENDOR_DIG "Digium Inc."
5053 #define VENDOR_JH "Junghanns.NET GmbH"
5054 #define VENDOR_PRIM "PrimuX"
5056 static const struct hm_map hfcm_map[] = {
5057 /*0*/ {VENDOR_BN, "HFC-1S Card (mini PCI)", 4, 1, 1, 3, 0, DIP_4S, 0},
5058 /*1*/ {VENDOR_BN, "HFC-2S Card", 4, 2, 1, 3, 0, DIP_4S, 0},
5059 /*2*/ {VENDOR_BN, "HFC-2S Card (mini PCI)", 4, 2, 1, 3, 0, DIP_4S, 0},
5060 /*3*/ {VENDOR_BN, "HFC-4S Card", 4, 4, 1, 2, 0, DIP_4S, 0},
5061 /*4*/ {VENDOR_BN, "HFC-4S Card (mini PCI)", 4, 4, 1, 2, 0, 0, 0},
5062 /*5*/ {VENDOR_CCD, "HFC-4S Eval (old)", 4, 4, 0, 0, 0, 0, 0},
5063 /*6*/ {VENDOR_CCD, "HFC-4S IOB4ST", 4, 4, 1, 2, 0, DIP_4S, 0},
5064 /*7*/ {VENDOR_CCD, "HFC-4S", 4, 4, 1, 2, 0, 0, 0},
5065 /*8*/ {VENDOR_DIG, "HFC-4S Card", 4, 4, 0, 2, 0, 0, HFC_IO_MODE_REGIO},
5066 /*9*/ {VENDOR_CCD, "HFC-4S Swyx 4xS0 SX2 QuadBri", 4, 4, 1, 2, 0, 0, 0},
5067 /*10*/ {VENDOR_JH, "HFC-4S (junghanns 2.0)", 4, 4, 1, 2, 0, 0, 0},
5068 /*11*/ {VENDOR_PRIM, "HFC-2S Primux Card", 4, 2, 0, 0, 0, 0, 0},
5070 /*12*/ {VENDOR_BN, "HFC-8S Card", 8, 8, 1, 0, 0, 0, 0},
5071 /*13*/ {VENDOR_BN, "HFC-8S Card (+)", 8, 8, 1, 8, 0, DIP_8S,
5073 /*14*/ {VENDOR_CCD, "HFC-8S Eval (old)", 8, 8, 0, 0, 0, 0, 0},
5074 /*15*/ {VENDOR_CCD, "HFC-8S IOB4ST Recording", 8, 8, 1, 0, 0, 0, 0},
5076 /*16*/ {VENDOR_CCD, "HFC-8S IOB8ST", 8, 8, 1, 0, 0, 0, 0},
5077 /*17*/ {VENDOR_CCD, "HFC-8S", 8, 8, 1, 0, 0, 0, 0},
5078 /*18*/ {VENDOR_CCD, "HFC-8S", 8, 8, 1, 0, 0, 0, 0},
5080 /*19*/ {VENDOR_BN, "HFC-E1 Card", 1, 1, 0, 1, 0, DIP_E1, 0},
5081 /*20*/ {VENDOR_BN, "HFC-E1 Card (mini PCI)", 1, 1, 0, 1, 0, 0, 0},
5082 /*21*/ {VENDOR_BN, "HFC-E1+ Card (Dual)", 1, 1, 0, 1, 0, DIP_E1, 0},
5083 /*22*/ {VENDOR_BN, "HFC-E1 Card (Dual)", 1, 1, 0, 1, 0, DIP_E1, 0},
5085 /*23*/ {VENDOR_CCD, "HFC-E1 Eval (old)", 1, 1, 0, 0, 0, 0, 0},
5086 /*24*/ {VENDOR_CCD, "HFC-E1 IOB1E1", 1, 1, 0, 1, 0, 0, 0},
5087 /*25*/ {VENDOR_CCD, "HFC-E1", 1, 1, 0, 1, 0, 0, 0},
5089 /*26*/ {VENDOR_CCD, "HFC-4S Speech Design", 4, 4, 0, 0, 0, 0,
5091 /*27*/ {VENDOR_CCD, "HFC-E1 Speech Design", 1, 1, 0, 0, 0, 0,
5093 /*28*/ {VENDOR_CCD, "HFC-4S OpenVox", 4, 4, 1, 0, 0, 0, 0},
5094 /*29*/ {VENDOR_CCD, "HFC-2S OpenVox", 4, 2, 1, 0, 0, 0, 0},
5095 /*30*/ {VENDOR_CCD, "HFC-8S OpenVox", 8, 8, 1, 0, 0, 0, 0},
5099 #define H(x) ((unsigned long)&hfcm_map[x])
5100 static struct pci_device_id hfmultipci_ids[] __devinitdata = {
5102 /* Cards with HFC-4S Chip */
5103 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5104 PCI_SUBDEVICE_ID_CCD_BN1SM, 0, 0, H(0)}, /* BN1S mini PCI */
5105 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5106 PCI_SUBDEVICE_ID_CCD_BN2S, 0, 0, H(1)}, /* BN2S */
5107 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5108 PCI_SUBDEVICE_ID_CCD_BN2SM, 0, 0, H(2)}, /* BN2S mini PCI */
5109 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5110 PCI_SUBDEVICE_ID_CCD_BN4S, 0, 0, H(3)}, /* BN4S */
5111 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5112 PCI_SUBDEVICE_ID_CCD_BN4SM, 0, 0, H(4)}, /* BN4S mini PCI */
5113 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5114 PCI_DEVICE_ID_CCD_HFC4S, 0, 0, H(5)}, /* Old Eval */
5115 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5116 PCI_SUBDEVICE_ID_CCD_IOB4ST, 0, 0, H(6)}, /* IOB4ST */
5117 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5118 PCI_SUBDEVICE_ID_CCD_HFC4S, 0, 0, H(7)}, /* 4S */
5119 { PCI_VENDOR_ID_DIGIUM, PCI_DEVICE_ID_DIGIUM_HFC4S,
5120 PCI_VENDOR_ID_DIGIUM, PCI_DEVICE_ID_DIGIUM_HFC4S, 0, 0, H(8)},
5121 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5122 PCI_SUBDEVICE_ID_CCD_SWYX4S, 0, 0, H(9)}, /* 4S Swyx */
5123 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5124 PCI_SUBDEVICE_ID_CCD_JH4S20, 0, 0, H(10)},
5125 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5126 PCI_SUBDEVICE_ID_CCD_PMX2S, 0, 0, H(11)}, /* Primux */
5127 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5128 PCI_SUBDEVICE_ID_CCD_OV4S, 0, 0, H(28)}, /* OpenVox 4 */
5129 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5130 PCI_SUBDEVICE_ID_CCD_OV2S, 0, 0, H(29)}, /* OpenVox 2 */
5132 /* Cards with HFC-8S Chip */
5133 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5134 PCI_SUBDEVICE_ID_CCD_BN8S, 0, 0, H(12)}, /* BN8S */
5135 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5136 PCI_SUBDEVICE_ID_CCD_BN8SP, 0, 0, H(13)}, /* BN8S+ */
5137 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5138 PCI_DEVICE_ID_CCD_HFC8S, 0, 0, H(14)}, /* old Eval */
5139 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5140 PCI_SUBDEVICE_ID_CCD_IOB8STR, 0, 0, H(15)},
5141 /* IOB8ST Recording */
5142 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5143 PCI_SUBDEVICE_ID_CCD_IOB8ST, 0, 0, H(16)}, /* IOB8ST */
5144 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5145 PCI_SUBDEVICE_ID_CCD_IOB8ST_1, 0, 0, H(17)}, /* IOB8ST */
5146 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5147 PCI_SUBDEVICE_ID_CCD_HFC8S, 0, 0, H(18)}, /* 8S */
5148 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5149 PCI_SUBDEVICE_ID_CCD_OV8S, 0, 0, H(30)}, /* OpenVox 8 */
5152 /* Cards with HFC-E1 Chip */
5153 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
5154 PCI_SUBDEVICE_ID_CCD_BNE1, 0, 0, H(19)}, /* BNE1 */
5155 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
5156 PCI_SUBDEVICE_ID_CCD_BNE1M, 0, 0, H(20)}, /* BNE1 mini PCI */
5157 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
5158 PCI_SUBDEVICE_ID_CCD_BNE1DP, 0, 0, H(21)}, /* BNE1 + (Dual) */
5159 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
5160 PCI_SUBDEVICE_ID_CCD_BNE1D, 0, 0, H(22)}, /* BNE1 (Dual) */
5162 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
5163 PCI_DEVICE_ID_CCD_HFCE1, 0, 0, H(23)}, /* Old Eval */
5164 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
5165 PCI_SUBDEVICE_ID_CCD_IOB1E1, 0, 0, H(24)}, /* IOB1E1 */
5166 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
5167 PCI_SUBDEVICE_ID_CCD_HFCE1, 0, 0, H(25)}, /* E1 */
5169 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030, PCI_VENDOR_ID_CCD,
5170 PCI_SUBDEVICE_ID_CCD_SPD4S, 0, 0, H(26)}, /* PLX PCI Bridge */
5171 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030, PCI_VENDOR_ID_CCD,
5172 PCI_SUBDEVICE_ID_CCD_SPDE1, 0, 0, H(27)}, /* PLX PCI Bridge */
5173 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_ANY_ID, PCI_ANY_ID,
5175 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_ANY_ID, PCI_ANY_ID,
5177 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_ANY_ID, PCI_ANY_ID,
5183 MODULE_DEVICE_TABLE(pci, hfmultipci_ids);
5186 hfcmulti_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5188 struct hm_map *m = (struct hm_map *)ent->driver_data;
5192 if (ent->vendor == PCI_VENDOR_ID_CCD)
5193 if (ent->device == PCI_DEVICE_ID_CCD_HFC4S ||
5194 ent->device == PCI_DEVICE_ID_CCD_HFC8S ||
5195 ent->device == PCI_DEVICE_ID_CCD_HFCE1)
5197 "unknown HFC multiport controller "
5198 "(vendor:%x device:%x subvendor:%x "
5199 "subdevice:%x) Please contact the "
5200 "driver maintainer for support.\n",
5201 ent->vendor, ent->device,
5202 ent->subvendor, ent->subdevice);
5205 ret = hfcmulti_init(pdev, ent);
5209 printk(KERN_INFO "%d devices registered\n", HFC_cnt);
5213 static struct pci_driver hfcmultipci_driver = {
5214 .name = "hfc_multi",
5215 .probe = hfcmulti_probe,
5216 .remove = __devexit_p(hfc_remove_pci),
5217 .id_table = hfmultipci_ids,
5221 HFCmulti_cleanup(void)
5223 struct hfc_multi *card, *next;
5225 /* unload interrupt function symbol */
5227 symbol_put(ztdummy_extern_interrupt);
5228 if (register_interrupt)
5229 symbol_put(ztdummy_register_interrupt);
5230 if (unregister_interrupt) {
5231 if (interrupt_registered) {
5232 interrupt_registered = 0;
5233 unregister_interrupt();
5235 symbol_put(ztdummy_unregister_interrupt);
5238 list_for_each_entry_safe(card, next, &HFClist, list)
5240 /* get rid of all devices of this driver */
5241 pci_unregister_driver(&hfcmultipci_driver);
5250 printk(KERN_ERR "%s: IRQ_DEBUG IS ENABLED!\n", __func__);
5253 spin_lock_init(&HFClock);
5254 spin_lock_init(&plx_lock);
5256 if (debug & DEBUG_HFCMULTI_INIT)
5257 printk(KERN_DEBUG "%s: init entered\n", __func__);
5259 hfc_interrupt = symbol_get(ztdummy_extern_interrupt);
5260 register_interrupt = symbol_get(ztdummy_register_interrupt);
5261 unregister_interrupt = symbol_get(ztdummy_unregister_interrupt);
5262 printk(KERN_INFO "mISDN: HFC-multi driver %s\n",
5271 * wenn dieses break nochmal verschwindet,
5272 * gibt es heisse ohren :-)
5273 * "without the break you will get hot ears ???"
5295 "%s: Wrong poll value (%d).\n", __func__, poll);
5301 err = pci_register_driver(&hfcmultipci_driver);
5303 printk(KERN_ERR "error registering pci driver: %x\n", err);
5305 symbol_put(ztdummy_extern_interrupt);
5306 if (register_interrupt)
5307 symbol_put(ztdummy_register_interrupt);
5308 if (unregister_interrupt) {
5309 if (interrupt_registered) {
5310 interrupt_registered = 0;
5311 unregister_interrupt();
5313 symbol_put(ztdummy_unregister_interrupt);
5321 module_init(HFCmulti_init);
5322 module_exit(HFCmulti_cleanup);