blob: cc978e8f2c9bbfd1aa22266b1bf5ed94f5aa5ea6 [file] [log] [blame]
Karsten Keilaf69fb32008-07-27 02:00:43 +02001/*
2 * hfcmulti.c low level driver for hfc-4s/hfc-8s/hfc-e1 based cards
3 *
4 * Author Andreas Eversberg (jolly@eversberg.eu)
5 * ported to mqueue mechanism:
6 * Peter Sprenger (sprengermoving-bytes.de)
7 *
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)
12 *
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)
16 * any later version.
17 *
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.
22 *
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.
26 *
27 *
28 * Thanks to Cologne Chip AG for this great controller!
29 */
30
31/*
32 * module parameters:
33 * type:
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
41 * Bit 10 = spare
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)
44 * Bit 13 = spare
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
49 * Bit 18 = spare
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
53 * bus (PCM master)
54 *
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
64 *
65 * HFC-E1 only bits:
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
73 * mode instead.
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.
77 * (E1 only)
78 * Bit 12-13 = 0xX000 = elastic jitter buffer (1-3), Set both bits to 0
79 * for default.
80 * (all other bits are reserved and shall be 0)
81 *
82 * debug:
83 * NOTE: only one debug value must be given for all cards
84 * enable debugging (see hfc_multi.h for debug options)
85 *
86 * poll:
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.
92 *
93 * pcm:
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.
105 *
106 * dslot:
Frank Seidel44e09582009-05-22 11:04:47 +0000107 * NOTE: only one dslot value must be given for every card.
Karsten Keilaf69fb32008-07-27 02:00:43 +0200108 * 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!
115 *
116 * iomode:
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).
Gilles Espinassef77f13e2010-03-29 15:41:47 +0200120 * Some cards require specific IO mode, so it cannot be changed.
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300121 * It may be useful to set IO mode to register io (REGIO) to solve
Karsten Keilaf69fb32008-07-27 02:00:43 +0200122 * PCI bridge problems.
123 * If unsure, don't give this parameter.
124 *
125 * clockdelay_nt:
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.
130 *
131 * clockdelay_te:
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.
Andreas Eversberg3bd69ad2008-09-06 09:03:46 +0200136 *
137 * clock:
Andreas Eversberg1b36c782008-09-20 13:43:28 +0200138 * NOTE: only one clock value must be given once
Andreas Eversberg3bd69ad2008-09-06 09:03:46 +0200139 * Selects interface with clock source for mISDN and applications.
140 * Set to card number starting with 1. Set to -1 to disable.
141 * By default, the first card is used as clock source.
Karsten Keildb9bb632009-05-22 11:04:53 +0000142 *
143 * hwid:
144 * NOTE: only one hwid value must be given once
Joe Perches475be4d2012-02-19 19:52:38 -0800145 * Enable special embedded devices with XHFC controllers.
Karsten Keilaf69fb32008-07-27 02:00:43 +0200146 */
147
148/*
149 * debug register access (never use this, it will flood your system log)
150 * #define HFC_REGISTER_DEBUG
151 */
152
Karsten Keil69e656c2009-01-07 00:00:59 +0100153#define HFC_MULTI_VERSION "2.03"
Karsten Keilaf69fb32008-07-27 02:00:43 +0200154
Alexey Dobriyana6b7a402011-06-06 10:43:46 +0000155#include <linux/interrupt.h>
Karsten Keilaf69fb32008-07-27 02:00:43 +0200156#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +0900157#include <linux/slab.h>
Karsten Keilaf69fb32008-07-27 02:00:43 +0200158#include <linux/pci.h>
159#include <linux/delay.h>
160#include <linux/mISDNhw.h>
161#include <linux/mISDNdsp.h>
162
163/*
Joe Perches475be4d2012-02-19 19:52:38 -0800164 #define IRQCOUNT_DEBUG
165 #define IRQ_DEBUG
Karsten Keilaf69fb32008-07-27 02:00:43 +0200166*/
167
168#include "hfc_multi.h"
169#ifdef ECHOPREP
170#include "gaintab.h"
171#endif
172
173#define MAX_CARDS 8
174#define MAX_PORTS (8 * MAX_CARDS)
175
176static LIST_HEAD(HFClist);
177static spinlock_t HFClock; /* global hfc list lock */
178
179static void ph_state_change(struct dchannel *);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200180
181static struct hfc_multi *syncmaster;
Hannes Eder5b834352008-12-12 21:15:17 -0800182static int plxsd_master; /* if we have a master card (yet) */
Karsten Keilaf69fb32008-07-27 02:00:43 +0200183static spinlock_t plx_lock; /* may not acquire other lock inside */
Karsten Keilaf69fb32008-07-27 02:00:43 +0200184
185#define TYP_E1 1
186#define TYP_4S 4
187#define TYP_8S 8
188
189static int poll_timer = 6; /* default = 128 samples = 16ms */
190/* number of POLL_TIMER interrupts for G2 timeout (ca 1s) */
191static int nt_t1_count[] = { 3840, 1920, 960, 480, 240, 120, 60, 30 };
192#define CLKDEL_TE 0x0f /* CLKDEL in TE mode */
193#define CLKDEL_NT 0x6c /* CLKDEL in NT mode
194 (0x60 MUST be included!) */
Karsten Keilaf69fb32008-07-27 02:00:43 +0200195
196#define DIP_4S 0x1 /* DIP Switches for Beronet 1S/2S/4S cards */
197#define DIP_8S 0x2 /* DIP Switches for Beronet 8S+ cards */
198#define DIP_E1 0x3 /* DIP Switches for Beronet E1 cards */
199
200/*
201 * module stuff
202 */
203
204static uint type[MAX_CARDS];
Andreas Eversberg3bd69ad2008-09-06 09:03:46 +0200205static int pcm[MAX_CARDS];
206static int dslot[MAX_CARDS];
Karsten Keilaf69fb32008-07-27 02:00:43 +0200207static uint iomode[MAX_CARDS];
208static uint port[MAX_PORTS];
209static uint debug;
210static uint poll;
Andreas Eversberg3bd69ad2008-09-06 09:03:46 +0200211static int clock;
Karsten Keilaf69fb32008-07-27 02:00:43 +0200212static uint timer;
213static uint clockdelay_te = CLKDEL_TE;
214static uint clockdelay_nt = CLKDEL_NT;
Karsten Keildb9bb632009-05-22 11:04:53 +0000215#define HWID_NONE 0
216#define HWID_MINIP4 1
217#define HWID_MINIP8 2
218#define HWID_MINIP16 3
219static uint hwid = HWID_NONE;
Karsten Keilaf69fb32008-07-27 02:00:43 +0200220
221static int HFC_cnt, Port_cnt, PCM_cnt = 99;
222
223MODULE_AUTHOR("Andreas Eversberg");
224MODULE_LICENSE("GPL");
Karsten Keil69e656c2009-01-07 00:00:59 +0100225MODULE_VERSION(HFC_MULTI_VERSION);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200226module_param(debug, uint, S_IRUGO | S_IWUSR);
227module_param(poll, uint, S_IRUGO | S_IWUSR);
Andreas Eversberg3bd69ad2008-09-06 09:03:46 +0200228module_param(clock, int, S_IRUGO | S_IWUSR);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200229module_param(timer, uint, S_IRUGO | S_IWUSR);
230module_param(clockdelay_te, uint, S_IRUGO | S_IWUSR);
231module_param(clockdelay_nt, uint, S_IRUGO | S_IWUSR);
232module_param_array(type, uint, NULL, S_IRUGO | S_IWUSR);
Andreas Eversberg3bd69ad2008-09-06 09:03:46 +0200233module_param_array(pcm, int, NULL, S_IRUGO | S_IWUSR);
234module_param_array(dslot, int, NULL, S_IRUGO | S_IWUSR);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200235module_param_array(iomode, uint, NULL, S_IRUGO | S_IWUSR);
236module_param_array(port, uint, NULL, S_IRUGO | S_IWUSR);
Karsten Keildb9bb632009-05-22 11:04:53 +0000237module_param(hwid, uint, S_IRUGO | S_IWUSR); /* The hardware ID */
Karsten Keilaf69fb32008-07-27 02:00:43 +0200238
239#ifdef HFC_REGISTER_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -0800240#define HFC_outb(hc, reg, val) \
Karsten Keilaf69fb32008-07-27 02:00:43 +0200241 (hc->HFC_outb(hc, reg, val, __func__, __LINE__))
Joe Perches475be4d2012-02-19 19:52:38 -0800242#define HFC_outb_nodebug(hc, reg, val) \
Karsten Keilaf69fb32008-07-27 02:00:43 +0200243 (hc->HFC_outb_nodebug(hc, reg, val, __func__, __LINE__))
Joe Perches475be4d2012-02-19 19:52:38 -0800244#define HFC_inb(hc, reg) \
Karsten Keilaf69fb32008-07-27 02:00:43 +0200245 (hc->HFC_inb(hc, reg, __func__, __LINE__))
Joe Perches475be4d2012-02-19 19:52:38 -0800246#define HFC_inb_nodebug(hc, reg) \
Karsten Keilaf69fb32008-07-27 02:00:43 +0200247 (hc->HFC_inb_nodebug(hc, reg, __func__, __LINE__))
Joe Perches475be4d2012-02-19 19:52:38 -0800248#define HFC_inw(hc, reg) \
Karsten Keilaf69fb32008-07-27 02:00:43 +0200249 (hc->HFC_inw(hc, reg, __func__, __LINE__))
Joe Perches475be4d2012-02-19 19:52:38 -0800250#define HFC_inw_nodebug(hc, reg) \
Karsten Keilaf69fb32008-07-27 02:00:43 +0200251 (hc->HFC_inw_nodebug(hc, reg, __func__, __LINE__))
Joe Perches475be4d2012-02-19 19:52:38 -0800252#define HFC_wait(hc) \
Karsten Keilaf69fb32008-07-27 02:00:43 +0200253 (hc->HFC_wait(hc, __func__, __LINE__))
Joe Perches475be4d2012-02-19 19:52:38 -0800254#define HFC_wait_nodebug(hc) \
Karsten Keilaf69fb32008-07-27 02:00:43 +0200255 (hc->HFC_wait_nodebug(hc, __func__, __LINE__))
256#else
257#define HFC_outb(hc, reg, val) (hc->HFC_outb(hc, reg, val))
258#define HFC_outb_nodebug(hc, reg, val) (hc->HFC_outb_nodebug(hc, reg, val))
259#define HFC_inb(hc, reg) (hc->HFC_inb(hc, reg))
260#define HFC_inb_nodebug(hc, reg) (hc->HFC_inb_nodebug(hc, reg))
261#define HFC_inw(hc, reg) (hc->HFC_inw(hc, reg))
262#define HFC_inw_nodebug(hc, reg) (hc->HFC_inw_nodebug(hc, reg))
263#define HFC_wait(hc) (hc->HFC_wait(hc))
264#define HFC_wait_nodebug(hc) (hc->HFC_wait_nodebug(hc))
265#endif
266
Karsten Keildb9bb632009-05-22 11:04:53 +0000267#ifdef CONFIG_MISDN_HFCMULTI_8xx
268#include "hfc_multi_8xx.h"
269#endif
270
Karsten Keilaf69fb32008-07-27 02:00:43 +0200271/* HFC_IO_MODE_PCIMEM */
272static void
273#ifdef HFC_REGISTER_DEBUG
274HFC_outb_pcimem(struct hfc_multi *hc, u_char reg, u_char val,
275 const char *function, int line)
276#else
Joe Perches475be4d2012-02-19 19:52:38 -0800277 HFC_outb_pcimem(struct hfc_multi *hc, u_char reg, u_char val)
Karsten Keilaf69fb32008-07-27 02:00:43 +0200278#endif
279{
Karsten Keileac74af2009-05-22 11:04:56 +0000280 writeb(val, hc->pci_membase + reg);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200281}
282static u_char
283#ifdef HFC_REGISTER_DEBUG
284HFC_inb_pcimem(struct hfc_multi *hc, u_char reg, const char *function, int line)
285#else
Joe Perches475be4d2012-02-19 19:52:38 -0800286 HFC_inb_pcimem(struct hfc_multi *hc, u_char reg)
Karsten Keilaf69fb32008-07-27 02:00:43 +0200287#endif
288{
Karsten Keileac74af2009-05-22 11:04:56 +0000289 return readb(hc->pci_membase + reg);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200290}
291static u_short
292#ifdef HFC_REGISTER_DEBUG
293HFC_inw_pcimem(struct hfc_multi *hc, u_char reg, const char *function, int line)
294#else
Joe Perches475be4d2012-02-19 19:52:38 -0800295 HFC_inw_pcimem(struct hfc_multi *hc, u_char reg)
Karsten Keilaf69fb32008-07-27 02:00:43 +0200296#endif
297{
Karsten Keileac74af2009-05-22 11:04:56 +0000298 return readw(hc->pci_membase + reg);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200299}
300static void
301#ifdef HFC_REGISTER_DEBUG
302HFC_wait_pcimem(struct hfc_multi *hc, const char *function, int line)
303#else
Joe Perches475be4d2012-02-19 19:52:38 -0800304 HFC_wait_pcimem(struct hfc_multi *hc)
Karsten Keilaf69fb32008-07-27 02:00:43 +0200305#endif
306{
Karsten Keileac74af2009-05-22 11:04:56 +0000307 while (readb(hc->pci_membase + R_STATUS) & V_BUSY)
308 cpu_relax();
Karsten Keilaf69fb32008-07-27 02:00:43 +0200309}
310
311/* HFC_IO_MODE_REGIO */
312static void
313#ifdef HFC_REGISTER_DEBUG
314HFC_outb_regio(struct hfc_multi *hc, u_char reg, u_char val,
Joe Perches475be4d2012-02-19 19:52:38 -0800315 const char *function, int line)
Karsten Keilaf69fb32008-07-27 02:00:43 +0200316#else
Joe Perches475be4d2012-02-19 19:52:38 -0800317 HFC_outb_regio(struct hfc_multi *hc, u_char reg, u_char val)
Karsten Keilaf69fb32008-07-27 02:00:43 +0200318#endif
319{
Karsten Keileac74af2009-05-22 11:04:56 +0000320 outb(reg, hc->pci_iobase + 4);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200321 outb(val, hc->pci_iobase);
322}
323static u_char
324#ifdef HFC_REGISTER_DEBUG
325HFC_inb_regio(struct hfc_multi *hc, u_char reg, const char *function, int line)
326#else
Joe Perches475be4d2012-02-19 19:52:38 -0800327 HFC_inb_regio(struct hfc_multi *hc, u_char reg)
Karsten Keilaf69fb32008-07-27 02:00:43 +0200328#endif
329{
Karsten Keileac74af2009-05-22 11:04:56 +0000330 outb(reg, hc->pci_iobase + 4);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200331 return inb(hc->pci_iobase);
332}
333static u_short
334#ifdef HFC_REGISTER_DEBUG
335HFC_inw_regio(struct hfc_multi *hc, u_char reg, const char *function, int line)
336#else
Joe Perches475be4d2012-02-19 19:52:38 -0800337 HFC_inw_regio(struct hfc_multi *hc, u_char reg)
Karsten Keilaf69fb32008-07-27 02:00:43 +0200338#endif
339{
Karsten Keileac74af2009-05-22 11:04:56 +0000340 outb(reg, hc->pci_iobase + 4);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200341 return inw(hc->pci_iobase);
342}
343static void
344#ifdef HFC_REGISTER_DEBUG
345HFC_wait_regio(struct hfc_multi *hc, const char *function, int line)
346#else
Joe Perches475be4d2012-02-19 19:52:38 -0800347 HFC_wait_regio(struct hfc_multi *hc)
Karsten Keilaf69fb32008-07-27 02:00:43 +0200348#endif
349{
Karsten Keileac74af2009-05-22 11:04:56 +0000350 outb(R_STATUS, hc->pci_iobase + 4);
351 while (inb(hc->pci_iobase) & V_BUSY)
352 cpu_relax();
Karsten Keilaf69fb32008-07-27 02:00:43 +0200353}
354
355#ifdef HFC_REGISTER_DEBUG
356static void
357HFC_outb_debug(struct hfc_multi *hc, u_char reg, u_char val,
Joe Perches475be4d2012-02-19 19:52:38 -0800358 const char *function, int line)
Karsten Keilaf69fb32008-07-27 02:00:43 +0200359{
360 char regname[256] = "", bits[9] = "xxxxxxxx";
361 int i;
362
363 i = -1;
364 while (hfc_register_names[++i].name) {
365 if (hfc_register_names[i].reg == reg)
366 strcat(regname, hfc_register_names[i].name);
367 }
368 if (regname[0] == '\0')
369 strcpy(regname, "register");
370
Karsten Keileac74af2009-05-22 11:04:56 +0000371 bits[7] = '0' + (!!(val & 1));
372 bits[6] = '0' + (!!(val & 2));
373 bits[5] = '0' + (!!(val & 4));
374 bits[4] = '0' + (!!(val & 8));
375 bits[3] = '0' + (!!(val & 16));
376 bits[2] = '0' + (!!(val & 32));
377 bits[1] = '0' + (!!(val & 64));
378 bits[0] = '0' + (!!(val & 128));
Karsten Keilaf69fb32008-07-27 02:00:43 +0200379 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -0800380 "HFC_outb(chip %d, %02x=%s, 0x%02x=%s); in %s() line %d\n",
381 hc->id, reg, regname, val, bits, function, line);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200382 HFC_outb_nodebug(hc, reg, val);
383}
384static u_char
385HFC_inb_debug(struct hfc_multi *hc, u_char reg, const char *function, int line)
386{
387 char regname[256] = "", bits[9] = "xxxxxxxx";
388 u_char val = HFC_inb_nodebug(hc, reg);
389 int i;
390
391 i = 0;
392 while (hfc_register_names[i++].name)
393 ;
394 while (hfc_register_names[++i].name) {
395 if (hfc_register_names[i].reg == reg)
396 strcat(regname, hfc_register_names[i].name);
397 }
398 if (regname[0] == '\0')
399 strcpy(regname, "register");
400
Karsten Keileac74af2009-05-22 11:04:56 +0000401 bits[7] = '0' + (!!(val & 1));
402 bits[6] = '0' + (!!(val & 2));
403 bits[5] = '0' + (!!(val & 4));
404 bits[4] = '0' + (!!(val & 8));
405 bits[3] = '0' + (!!(val & 16));
406 bits[2] = '0' + (!!(val & 32));
407 bits[1] = '0' + (!!(val & 64));
408 bits[0] = '0' + (!!(val & 128));
Karsten Keilaf69fb32008-07-27 02:00:43 +0200409 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -0800410 "HFC_inb(chip %d, %02x=%s) = 0x%02x=%s; in %s() line %d\n",
411 hc->id, reg, regname, val, bits, function, line);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200412 return val;
413}
414static u_short
415HFC_inw_debug(struct hfc_multi *hc, u_char reg, const char *function, int line)
416{
417 char regname[256] = "";
418 u_short val = HFC_inw_nodebug(hc, reg);
419 int i;
420
421 i = 0;
422 while (hfc_register_names[i++].name)
423 ;
424 while (hfc_register_names[++i].name) {
425 if (hfc_register_names[i].reg == reg)
426 strcat(regname, hfc_register_names[i].name);
427 }
428 if (regname[0] == '\0')
429 strcpy(regname, "register");
430
431 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -0800432 "HFC_inw(chip %d, %02x=%s) = 0x%04x; in %s() line %d\n",
433 hc->id, reg, regname, val, function, line);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200434 return val;
435}
436static void
437HFC_wait_debug(struct hfc_multi *hc, const char *function, int line)
438{
439 printk(KERN_DEBUG "HFC_wait(chip %d); in %s() line %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800440 hc->id, function, line);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200441 HFC_wait_nodebug(hc);
442}
443#endif
444
445/* write fifo data (REGIO) */
Hannes Eder5b834352008-12-12 21:15:17 -0800446static void
Karsten Keilaf69fb32008-07-27 02:00:43 +0200447write_fifo_regio(struct hfc_multi *hc, u_char *data, int len)
448{
Joe Perches475be4d2012-02-19 19:52:38 -0800449 outb(A_FIFO_DATA0, (hc->pci_iobase) + 4);
450 while (len >> 2) {
Karsten Keilb3e0aee2008-08-02 16:35:53 +0200451 outl(cpu_to_le32(*(u32 *)data), hc->pci_iobase);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200452 data += 4;
453 len -= 4;
454 }
Joe Perches475be4d2012-02-19 19:52:38 -0800455 while (len >> 1) {
Karsten Keilb3e0aee2008-08-02 16:35:53 +0200456 outw(cpu_to_le16(*(u16 *)data), hc->pci_iobase);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200457 data += 2;
458 len -= 2;
459 }
460 while (len) {
461 outb(*data, hc->pci_iobase);
462 data++;
463 len--;
464 }
465}
466/* write fifo data (PCIMEM) */
Hannes Eder5b834352008-12-12 21:15:17 -0800467static void
Karsten Keilaf69fb32008-07-27 02:00:43 +0200468write_fifo_pcimem(struct hfc_multi *hc, u_char *data, int len)
469{
Joe Perches475be4d2012-02-19 19:52:38 -0800470 while (len >> 2) {
Karsten Keilb3e0aee2008-08-02 16:35:53 +0200471 writel(cpu_to_le32(*(u32 *)data),
Joe Perches475be4d2012-02-19 19:52:38 -0800472 hc->pci_membase + A_FIFO_DATA0);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200473 data += 4;
474 len -= 4;
475 }
Joe Perches475be4d2012-02-19 19:52:38 -0800476 while (len >> 1) {
Karsten Keilb3e0aee2008-08-02 16:35:53 +0200477 writew(cpu_to_le16(*(u16 *)data),
Joe Perches475be4d2012-02-19 19:52:38 -0800478 hc->pci_membase + A_FIFO_DATA0);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200479 data += 2;
480 len -= 2;
481 }
482 while (len) {
Karsten Keilb3e0aee2008-08-02 16:35:53 +0200483 writeb(*data, hc->pci_membase + A_FIFO_DATA0);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200484 data++;
485 len--;
486 }
487}
Karsten Keileac74af2009-05-22 11:04:56 +0000488
Karsten Keilaf69fb32008-07-27 02:00:43 +0200489/* read fifo data (REGIO) */
Hannes Eder5b834352008-12-12 21:15:17 -0800490static void
Karsten Keilaf69fb32008-07-27 02:00:43 +0200491read_fifo_regio(struct hfc_multi *hc, u_char *data, int len)
492{
Joe Perches475be4d2012-02-19 19:52:38 -0800493 outb(A_FIFO_DATA0, (hc->pci_iobase) + 4);
494 while (len >> 2) {
Karsten Keilb3e0aee2008-08-02 16:35:53 +0200495 *(u32 *)data = le32_to_cpu(inl(hc->pci_iobase));
Karsten Keilaf69fb32008-07-27 02:00:43 +0200496 data += 4;
497 len -= 4;
498 }
Joe Perches475be4d2012-02-19 19:52:38 -0800499 while (len >> 1) {
Karsten Keilb3e0aee2008-08-02 16:35:53 +0200500 *(u16 *)data = le16_to_cpu(inw(hc->pci_iobase));
Karsten Keilaf69fb32008-07-27 02:00:43 +0200501 data += 2;
502 len -= 2;
503 }
504 while (len) {
505 *data = inb(hc->pci_iobase);
506 data++;
507 len--;
508 }
509}
510
511/* read fifo data (PCIMEM) */
Hannes Eder5b834352008-12-12 21:15:17 -0800512static void
Karsten Keilaf69fb32008-07-27 02:00:43 +0200513read_fifo_pcimem(struct hfc_multi *hc, u_char *data, int len)
514{
Joe Perches475be4d2012-02-19 19:52:38 -0800515 while (len >> 2) {
Karsten Keilaf69fb32008-07-27 02:00:43 +0200516 *(u32 *)data =
Karsten Keilb3e0aee2008-08-02 16:35:53 +0200517 le32_to_cpu(readl(hc->pci_membase + A_FIFO_DATA0));
Karsten Keilaf69fb32008-07-27 02:00:43 +0200518 data += 4;
519 len -= 4;
520 }
Joe Perches475be4d2012-02-19 19:52:38 -0800521 while (len >> 1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +0200522 *(u16 *)data =
Karsten Keilb3e0aee2008-08-02 16:35:53 +0200523 le16_to_cpu(readw(hc->pci_membase + A_FIFO_DATA0));
Karsten Keilaf69fb32008-07-27 02:00:43 +0200524 data += 2;
525 len -= 2;
526 }
527 while (len) {
Karsten Keilb3e0aee2008-08-02 16:35:53 +0200528 *data = readb(hc->pci_membase + A_FIFO_DATA0);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200529 data++;
530 len--;
531 }
532}
533
Karsten Keilaf69fb32008-07-27 02:00:43 +0200534static void
535enable_hwirq(struct hfc_multi *hc)
536{
537 hc->hw.r_irq_ctrl |= V_GLOB_IRQ_EN;
538 HFC_outb(hc, R_IRQ_CTRL, hc->hw.r_irq_ctrl);
539}
540
541static void
542disable_hwirq(struct hfc_multi *hc)
543{
544 hc->hw.r_irq_ctrl &= ~((u_char)V_GLOB_IRQ_EN);
545 HFC_outb(hc, R_IRQ_CTRL, hc->hw.r_irq_ctrl);
546}
547
548#define NUM_EC 2
549#define MAX_TDM_CHAN 32
550
551
552inline void
553enablepcibridge(struct hfc_multi *c)
554{
555 HFC_outb(c, R_BRG_PCM_CFG, (0x0 << 6) | 0x3); /* was _io before */
556}
557
558inline void
559disablepcibridge(struct hfc_multi *c)
560{
561 HFC_outb(c, R_BRG_PCM_CFG, (0x0 << 6) | 0x2); /* was _io before */
562}
563
564inline unsigned char
565readpcibridge(struct hfc_multi *hc, unsigned char address)
566{
567 unsigned short cipv;
568 unsigned char data;
569
570 if (!hc->pci_iobase)
571 return 0;
572
573 /* slow down a PCI read access by 1 PCI clock cycle */
574 HFC_outb(hc, R_CTRL, 0x4); /*was _io before*/
575
576 if (address == 0)
577 cipv = 0x4000;
578 else
579 cipv = 0x5800;
580
581 /* select local bridge port address by writing to CIP port */
582 /* data = HFC_inb(c, cipv); * was _io before */
583 outw(cipv, hc->pci_iobase + 4);
584 data = inb(hc->pci_iobase);
585
586 /* restore R_CTRL for normal PCI read cycle speed */
587 HFC_outb(hc, R_CTRL, 0x0); /* was _io before */
588
589 return data;
590}
591
592inline void
593writepcibridge(struct hfc_multi *hc, unsigned char address, unsigned char data)
594{
595 unsigned short cipv;
596 unsigned int datav;
597
598 if (!hc->pci_iobase)
599 return;
600
601 if (address == 0)
602 cipv = 0x4000;
603 else
604 cipv = 0x5800;
605
606 /* select local bridge port address by writing to CIP port */
607 outw(cipv, hc->pci_iobase + 4);
608 /* define a 32 bit dword with 4 identical bytes for write sequence */
609 datav = data | ((__u32) data << 8) | ((__u32) data << 16) |
Joe Perches475be4d2012-02-19 19:52:38 -0800610 ((__u32) data << 24);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200611
612 /*
613 * write this 32 bit dword to the bridge data port
614 * this will initiate a write sequence of up to 4 writes to the same
615 * address on the local bus interface the number of write accesses
616 * is undefined but >=1 and depends on the next PCI transaction
617 * during write sequence on the local bus
618 */
619 outl(datav, hc->pci_iobase);
620}
621
622inline void
623cpld_set_reg(struct hfc_multi *hc, unsigned char reg)
624{
625 /* Do data pin read low byte */
626 HFC_outb(hc, R_GPIO_OUT1, reg);
627}
628
629inline void
630cpld_write_reg(struct hfc_multi *hc, unsigned char reg, unsigned char val)
631{
632 cpld_set_reg(hc, reg);
633
634 enablepcibridge(hc);
635 writepcibridge(hc, 1, val);
636 disablepcibridge(hc);
637
638 return;
639}
640
641inline unsigned char
642cpld_read_reg(struct hfc_multi *hc, unsigned char reg)
643{
644 unsigned char bytein;
645
646 cpld_set_reg(hc, reg);
647
648 /* Do data pin read low byte */
649 HFC_outb(hc, R_GPIO_OUT1, reg);
650
651 enablepcibridge(hc);
652 bytein = readpcibridge(hc, 1);
653 disablepcibridge(hc);
654
655 return bytein;
656}
657
658inline void
659vpm_write_address(struct hfc_multi *hc, unsigned short addr)
660{
661 cpld_write_reg(hc, 0, 0xff & addr);
662 cpld_write_reg(hc, 1, 0x01 & (addr >> 8));
663}
664
665inline unsigned short
666vpm_read_address(struct hfc_multi *c)
667{
668 unsigned short addr;
669 unsigned short highbit;
670
671 addr = cpld_read_reg(c, 0);
672 highbit = cpld_read_reg(c, 1);
673
674 addr = addr | (highbit << 8);
675
676 return addr & 0x1ff;
677}
678
679inline unsigned char
680vpm_in(struct hfc_multi *c, int which, unsigned short addr)
681{
682 unsigned char res;
683
684 vpm_write_address(c, addr);
685
686 if (!which)
687 cpld_set_reg(c, 2);
688 else
689 cpld_set_reg(c, 3);
690
691 enablepcibridge(c);
692 res = readpcibridge(c, 1);
693 disablepcibridge(c);
694
695 cpld_set_reg(c, 0);
696
697 return res;
698}
699
700inline void
701vpm_out(struct hfc_multi *c, int which, unsigned short addr,
Joe Perches475be4d2012-02-19 19:52:38 -0800702 unsigned char data)
Karsten Keilaf69fb32008-07-27 02:00:43 +0200703{
704 vpm_write_address(c, addr);
705
706 enablepcibridge(c);
707
708 if (!which)
709 cpld_set_reg(c, 2);
710 else
711 cpld_set_reg(c, 3);
712
713 writepcibridge(c, 1, data);
714
715 cpld_set_reg(c, 0);
716
717 disablepcibridge(c);
718
719 {
Joe Perches475be4d2012-02-19 19:52:38 -0800720 unsigned char regin;
721 regin = vpm_in(c, which, addr);
722 if (regin != data)
723 printk(KERN_DEBUG "Wrote 0x%x to register 0x%x but got back "
724 "0x%x\n", data, addr, regin);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200725 }
726
727}
728
729
Hannes Eder5b834352008-12-12 21:15:17 -0800730static void
Karsten Keilaf69fb32008-07-27 02:00:43 +0200731vpm_init(struct hfc_multi *wc)
732{
733 unsigned char reg;
734 unsigned int mask;
735 unsigned int i, x, y;
736 unsigned int ver;
737
738 for (x = 0; x < NUM_EC; x++) {
739 /* Setup GPIO's */
740 if (!x) {
741 ver = vpm_in(wc, x, 0x1a0);
742 printk(KERN_DEBUG "VPM: Chip %d: ver %02x\n", x, ver);
743 }
744
745 for (y = 0; y < 4; y++) {
746 vpm_out(wc, x, 0x1a8 + y, 0x00); /* GPIO out */
747 vpm_out(wc, x, 0x1ac + y, 0x00); /* GPIO dir */
748 vpm_out(wc, x, 0x1b0 + y, 0x00); /* GPIO sel */
749 }
750
751 /* Setup TDM path - sets fsync and tdm_clk as inputs */
752 reg = vpm_in(wc, x, 0x1a3); /* misc_con */
753 vpm_out(wc, x, 0x1a3, reg & ~2);
754
755 /* Setup Echo length (256 taps) */
756 vpm_out(wc, x, 0x022, 1);
757 vpm_out(wc, x, 0x023, 0xff);
758
759 /* Setup timeslots */
760 vpm_out(wc, x, 0x02f, 0x00);
761 mask = 0x02020202 << (x * 4);
762
763 /* Setup the tdm channel masks for all chips */
764 for (i = 0; i < 4; i++)
765 vpm_out(wc, x, 0x33 - i, (mask >> (i << 3)) & 0xff);
766
767 /* Setup convergence rate */
768 printk(KERN_DEBUG "VPM: A-law mode\n");
769 reg = 0x00 | 0x10 | 0x01;
770 vpm_out(wc, x, 0x20, reg);
771 printk(KERN_DEBUG "VPM reg 0x20 is %x\n", reg);
772 /*vpm_out(wc, x, 0x20, (0x00 | 0x08 | 0x20 | 0x10)); */
773
774 vpm_out(wc, x, 0x24, 0x02);
775 reg = vpm_in(wc, x, 0x24);
776 printk(KERN_DEBUG "NLP Thresh is set to %d (0x%x)\n", reg, reg);
777
778 /* Initialize echo cans */
779 for (i = 0; i < MAX_TDM_CHAN; i++) {
780 if (mask & (0x00000001 << i))
781 vpm_out(wc, x, i, 0x00);
782 }
783
784 /*
785 * ARM arch at least disallows a udelay of
786 * more than 2ms... it gives a fake "__bad_udelay"
787 * reference at link-time.
788 * long delays in kernel code are pretty sucky anyway
789 * for now work around it using 5 x 2ms instead of 1 x 10ms
790 */
791
792 udelay(2000);
793 udelay(2000);
794 udelay(2000);
795 udelay(2000);
796 udelay(2000);
797
798 /* Put in bypass mode */
799 for (i = 0; i < MAX_TDM_CHAN; i++) {
800 if (mask & (0x00000001 << i))
801 vpm_out(wc, x, i, 0x01);
802 }
803
804 /* Enable bypass */
805 for (i = 0; i < MAX_TDM_CHAN; i++) {
806 if (mask & (0x00000001 << i))
807 vpm_out(wc, x, 0x78 + i, 0x01);
808 }
809
810 }
811}
812
Hannes Eder047ce8f2008-12-12 21:18:32 -0800813#ifdef UNUSED
Hannes Eder5b834352008-12-12 21:15:17 -0800814static void
Karsten Keilaf69fb32008-07-27 02:00:43 +0200815vpm_check(struct hfc_multi *hctmp)
816{
817 unsigned char gpi2;
818
819 gpi2 = HFC_inb(hctmp, R_GPI_IN2);
820
821 if ((gpi2 & 0x3) != 0x3)
822 printk(KERN_DEBUG "Got interrupt 0x%x from VPM!\n", gpi2);
823}
Hannes Eder047ce8f2008-12-12 21:18:32 -0800824#endif /* UNUSED */
Karsten Keilaf69fb32008-07-27 02:00:43 +0200825
826
827/*
828 * Interface to enable/disable the HW Echocan
829 *
830 * these functions are called within a spin_lock_irqsave on
831 * the channel instance lock, so we are not disturbed by irqs
832 *
833 * we can later easily change the interface to make other
834 * things configurable, for now we configure the taps
835 *
836 */
837
Hannes Eder5b834352008-12-12 21:15:17 -0800838static void
Karsten Keilaf69fb32008-07-27 02:00:43 +0200839vpm_echocan_on(struct hfc_multi *hc, int ch, int taps)
840{
841 unsigned int timeslot;
842 unsigned int unit;
843 struct bchannel *bch = hc->chan[ch].bch;
844#ifdef TXADJ
845 int txadj = -4;
846 struct sk_buff *skb;
847#endif
848 if (hc->chan[ch].protocol != ISDN_P_B_RAW)
849 return;
850
851 if (!bch)
852 return;
853
854#ifdef TXADJ
855 skb = _alloc_mISDN_skb(PH_CONTROL_IND, HFC_VOL_CHANGE_TX,
Joe Perches475be4d2012-02-19 19:52:38 -0800856 sizeof(int), &txadj, GFP_ATOMIC);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200857 if (skb)
858 recv_Bchannel_skb(bch, skb);
859#endif
860
Joe Perches475be4d2012-02-19 19:52:38 -0800861 timeslot = ((ch / 4) * 8) + ((ch % 4) * 4) + 1;
Karsten Keilaf69fb32008-07-27 02:00:43 +0200862 unit = ch % 4;
863
864 printk(KERN_NOTICE "vpm_echocan_on called taps [%d] on timeslot %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800865 taps, timeslot);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200866
867 vpm_out(hc, unit, timeslot, 0x7e);
868}
869
Hannes Eder5b834352008-12-12 21:15:17 -0800870static void
Karsten Keilaf69fb32008-07-27 02:00:43 +0200871vpm_echocan_off(struct hfc_multi *hc, int ch)
872{
873 unsigned int timeslot;
874 unsigned int unit;
875 struct bchannel *bch = hc->chan[ch].bch;
876#ifdef TXADJ
877 int txadj = 0;
878 struct sk_buff *skb;
879#endif
880
881 if (hc->chan[ch].protocol != ISDN_P_B_RAW)
882 return;
883
884 if (!bch)
885 return;
886
887#ifdef TXADJ
888 skb = _alloc_mISDN_skb(PH_CONTROL_IND, HFC_VOL_CHANGE_TX,
Joe Perches475be4d2012-02-19 19:52:38 -0800889 sizeof(int), &txadj, GFP_ATOMIC);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200890 if (skb)
891 recv_Bchannel_skb(bch, skb);
892#endif
893
Joe Perches475be4d2012-02-19 19:52:38 -0800894 timeslot = ((ch / 4) * 8) + ((ch % 4) * 4) + 1;
Karsten Keilaf69fb32008-07-27 02:00:43 +0200895 unit = ch % 4;
896
897 printk(KERN_NOTICE "vpm_echocan_off called on timeslot %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800898 timeslot);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200899 /* FILLME */
900 vpm_out(hc, unit, timeslot, 0x01);
901}
902
903
904/*
905 * Speech Design resync feature
906 * NOTE: This is called sometimes outside interrupt handler.
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300907 * We must lock irqsave, so no other interrupt (other card) will occur!
Karsten Keilaf69fb32008-07-27 02:00:43 +0200908 * Also multiple interrupts may nest, so must lock each access (lists, card)!
909 */
910static inline void
911hfcmulti_resync(struct hfc_multi *locked, struct hfc_multi *newmaster, int rm)
912{
Hannes Ederbcf91742008-12-12 21:11:28 -0800913 struct hfc_multi *hc, *next, *pcmmaster = NULL;
Hannes Ederc31655f2008-12-12 21:20:03 -0800914 void __iomem *plx_acc_32;
915 u_int pv;
Karsten Keilaf69fb32008-07-27 02:00:43 +0200916 u_long flags;
917
918 spin_lock_irqsave(&HFClock, flags);
919 spin_lock(&plx_lock); /* must be locked inside other locks */
920
921 if (debug & DEBUG_HFCMULTI_PLXSD)
922 printk(KERN_DEBUG "%s: RESYNC(syncmaster=0x%p)\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800923 __func__, syncmaster);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200924
925 /* select new master */
926 if (newmaster) {
927 if (debug & DEBUG_HFCMULTI_PLXSD)
928 printk(KERN_DEBUG "using provided controller\n");
929 } else {
930 list_for_each_entry_safe(hc, next, &HFClist, list) {
931 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
932 if (hc->syncronized) {
933 newmaster = hc;
934 break;
935 }
936 }
937 }
938 }
939
940 /* Disable sync of all cards */
941 list_for_each_entry_safe(hc, next, &HFClist, list) {
942 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
Hannes Ederc31655f2008-12-12 21:20:03 -0800943 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
Karsten Keilaf69fb32008-07-27 02:00:43 +0200944 pv = readl(plx_acc_32);
945 pv &= ~PLX_SYNC_O_EN;
946 writel(pv, plx_acc_32);
947 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip)) {
948 pcmmaster = hc;
Karsten Keildb9bb632009-05-22 11:04:53 +0000949 if (hc->ctype == HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +0200950 if (debug & DEBUG_HFCMULTI_PLXSD)
951 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -0800952 "Schedule SYNC_I\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +0200953 hc->e1_resync |= 1; /* get SYNC_I */
954 }
955 }
956 }
957 }
958
959 if (newmaster) {
960 hc = newmaster;
961 if (debug & DEBUG_HFCMULTI_PLXSD)
962 printk(KERN_DEBUG "id=%d (0x%p) = syncronized with "
Joe Perches475be4d2012-02-19 19:52:38 -0800963 "interface.\n", hc->id, hc);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200964 /* Enable new sync master */
Hannes Ederc31655f2008-12-12 21:20:03 -0800965 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
Karsten Keilaf69fb32008-07-27 02:00:43 +0200966 pv = readl(plx_acc_32);
967 pv |= PLX_SYNC_O_EN;
968 writel(pv, plx_acc_32);
969 /* switch to jatt PLL, if not disabled by RX_SYNC */
Karsten Keildb9bb632009-05-22 11:04:53 +0000970 if (hc->ctype == HFC_TYPE_E1
Joe Perches475be4d2012-02-19 19:52:38 -0800971 && !test_bit(HFC_CHIP_RX_SYNC, &hc->chip)) {
Karsten Keilaf69fb32008-07-27 02:00:43 +0200972 if (debug & DEBUG_HFCMULTI_PLXSD)
973 printk(KERN_DEBUG "Schedule jatt PLL\n");
974 hc->e1_resync |= 2; /* switch to jatt */
975 }
976 } else {
977 if (pcmmaster) {
978 hc = pcmmaster;
979 if (debug & DEBUG_HFCMULTI_PLXSD)
980 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -0800981 "id=%d (0x%p) = PCM master syncronized "
982 "with QUARTZ\n", hc->id, hc);
Karsten Keildb9bb632009-05-22 11:04:53 +0000983 if (hc->ctype == HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +0200984 /* Use the crystal clock for the PCM
985 master card */
986 if (debug & DEBUG_HFCMULTI_PLXSD)
987 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -0800988 "Schedule QUARTZ for HFC-E1\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +0200989 hc->e1_resync |= 4; /* switch quartz */
990 } else {
991 if (debug & DEBUG_HFCMULTI_PLXSD)
992 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -0800993 "QUARTZ is automatically "
994 "enabled by HFC-%dS\n", hc->ctype);
Karsten Keilaf69fb32008-07-27 02:00:43 +0200995 }
Hannes Ederc31655f2008-12-12 21:20:03 -0800996 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
Karsten Keilaf69fb32008-07-27 02:00:43 +0200997 pv = readl(plx_acc_32);
998 pv |= PLX_SYNC_O_EN;
999 writel(pv, plx_acc_32);
1000 } else
1001 if (!rm)
1002 printk(KERN_ERR "%s no pcm master, this MUST "
Joe Perches475be4d2012-02-19 19:52:38 -08001003 "not happen!\n", __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001004 }
1005 syncmaster = newmaster;
1006
1007 spin_unlock(&plx_lock);
1008 spin_unlock_irqrestore(&HFClock, flags);
1009}
1010
1011/* This must be called AND hc must be locked irqsave!!! */
1012inline void
1013plxsd_checksync(struct hfc_multi *hc, int rm)
1014{
1015 if (hc->syncronized) {
1016 if (syncmaster == NULL) {
1017 if (debug & DEBUG_HFCMULTI_PLXSD)
Karsten Keileac74af2009-05-22 11:04:56 +00001018 printk(KERN_DEBUG "%s: GOT sync on card %d"
Joe Perches475be4d2012-02-19 19:52:38 -08001019 " (id=%d)\n", __func__, hc->id + 1,
1020 hc->id);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001021 hfcmulti_resync(hc, hc, rm);
1022 }
1023 } else {
1024 if (syncmaster == hc) {
1025 if (debug & DEBUG_HFCMULTI_PLXSD)
Karsten Keileac74af2009-05-22 11:04:56 +00001026 printk(KERN_DEBUG "%s: LOST sync on card %d"
Joe Perches475be4d2012-02-19 19:52:38 -08001027 " (id=%d)\n", __func__, hc->id + 1,
1028 hc->id);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001029 hfcmulti_resync(hc, NULL, rm);
1030 }
1031 }
1032}
1033
1034
1035/*
1036 * free hardware resources used by driver
1037 */
1038static void
1039release_io_hfcmulti(struct hfc_multi *hc)
1040{
Hannes Ederc31655f2008-12-12 21:20:03 -08001041 void __iomem *plx_acc_32;
1042 u_int pv;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001043 u_long plx_flags;
1044
1045 if (debug & DEBUG_HFCMULTI_INIT)
1046 printk(KERN_DEBUG "%s: entered\n", __func__);
1047
1048 /* soft reset also masks all interrupts */
1049 hc->hw.r_cirm |= V_SRES;
1050 HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
1051 udelay(1000);
1052 hc->hw.r_cirm &= ~V_SRES;
1053 HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
1054 udelay(1000); /* instead of 'wait' that may cause locking */
1055
1056 /* release Speech Design card, if PLX was initialized */
1057 if (test_bit(HFC_CHIP_PLXSD, &hc->chip) && hc->plx_membase) {
1058 if (debug & DEBUG_HFCMULTI_PLXSD)
1059 printk(KERN_DEBUG "%s: release PLXSD card %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001060 __func__, hc->id + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001061 spin_lock_irqsave(&plx_lock, plx_flags);
Hannes Ederc31655f2008-12-12 21:20:03 -08001062 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001063 writel(PLX_GPIOC_INIT, plx_acc_32);
1064 pv = readl(plx_acc_32);
1065 /* Termination off */
1066 pv &= ~PLX_TERM_ON;
1067 /* Disconnect the PCM */
1068 pv |= PLX_SLAVE_EN_N;
1069 pv &= ~PLX_MASTER_EN;
1070 pv &= ~PLX_SYNC_O_EN;
1071 /* Put the DSP in Reset */
1072 pv &= ~PLX_DSP_RES_N;
1073 writel(pv, plx_acc_32);
1074 if (debug & DEBUG_HFCMULTI_INIT)
Karsten Keileac74af2009-05-22 11:04:56 +00001075 printk(KERN_DEBUG "%s: PCM off: PLX_GPIO=%x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001076 __func__, pv);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001077 spin_unlock_irqrestore(&plx_lock, plx_flags);
1078 }
1079
1080 /* disable memory mapped ports / io ports */
1081 test_and_clear_bit(HFC_CHIP_PLXSD, &hc->chip); /* prevent resync */
Karsten Keildb9bb632009-05-22 11:04:53 +00001082 if (hc->pci_dev)
1083 pci_write_config_word(hc->pci_dev, PCI_COMMAND, 0);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001084 if (hc->pci_membase)
Hannes Ederc31655f2008-12-12 21:20:03 -08001085 iounmap(hc->pci_membase);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001086 if (hc->plx_membase)
Hannes Ederc31655f2008-12-12 21:20:03 -08001087 iounmap(hc->plx_membase);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001088 if (hc->pci_iobase)
1089 release_region(hc->pci_iobase, 8);
Karsten Keildb9bb632009-05-22 11:04:53 +00001090 if (hc->xhfc_membase)
1091 iounmap((void *)hc->xhfc_membase);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001092
1093 if (hc->pci_dev) {
1094 pci_disable_device(hc->pci_dev);
1095 pci_set_drvdata(hc->pci_dev, NULL);
1096 }
1097 if (debug & DEBUG_HFCMULTI_INIT)
1098 printk(KERN_DEBUG "%s: done\n", __func__);
1099}
1100
1101/*
1102 * function called to reset the HFC chip. A complete software reset of chip
1103 * and fifos is done. All configuration of the chip is done.
1104 */
1105
1106static int
1107init_chip(struct hfc_multi *hc)
1108{
1109 u_long flags, val, val2 = 0, rev;
1110 int i, err = 0;
1111 u_char r_conf_en, rval;
Hannes Ederc31655f2008-12-12 21:20:03 -08001112 void __iomem *plx_acc_32;
1113 u_int pv;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001114 u_long plx_flags, hfc_flags;
1115 int plx_count;
1116 struct hfc_multi *pos, *next, *plx_last_hc;
1117
1118 spin_lock_irqsave(&hc->lock, flags);
1119 /* reset all registers */
1120 memset(&hc->hw, 0, sizeof(struct hfcm_hw));
1121
1122 /* revision check */
1123 if (debug & DEBUG_HFCMULTI_INIT)
1124 printk(KERN_DEBUG "%s: entered\n", __func__);
Karsten Keildb9bb632009-05-22 11:04:53 +00001125 val = HFC_inb(hc, R_CHIP_ID);
Karsten Keileac74af2009-05-22 11:04:56 +00001126 if ((val >> 4) != 0x8 && (val >> 4) != 0xc && (val >> 4) != 0xe &&
1127 (val >> 1) != 0x31) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02001128 printk(KERN_INFO "HFC_multi: unknown CHIP_ID:%x\n", (u_int)val);
1129 err = -EIO;
1130 goto out;
1131 }
1132 rev = HFC_inb(hc, R_CHIP_RV);
1133 printk(KERN_INFO
Joe Perches475be4d2012-02-19 19:52:38 -08001134 "HFC_multi: detected HFC with chip ID=0x%lx revision=%ld%s\n",
1135 val, rev, (rev == 0 && (hc->ctype != HFC_TYPE_XHFC)) ?
1136 " (old FIFO handling)" : "");
Karsten Keildb9bb632009-05-22 11:04:53 +00001137 if (hc->ctype != HFC_TYPE_XHFC && rev == 0) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02001138 test_and_set_bit(HFC_CHIP_REVISION0, &hc->chip);
1139 printk(KERN_WARNING
Joe Perches475be4d2012-02-19 19:52:38 -08001140 "HFC_multi: NOTE: Your chip is revision 0, "
1141 "ask Cologne Chip for update. Newer chips "
1142 "have a better FIFO handling. Old chips "
1143 "still work but may have slightly lower "
1144 "HDLC transmit performance.\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02001145 }
1146 if (rev > 1) {
1147 printk(KERN_WARNING "HFC_multi: WARNING: This driver doesn't "
Joe Perches475be4d2012-02-19 19:52:38 -08001148 "consider chip revision = %ld. The chip / "
1149 "bridge may not work.\n", rev);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001150 }
1151
1152 /* set s-ram size */
1153 hc->Flen = 0x10;
1154 hc->Zmin = 0x80;
1155 hc->Zlen = 384;
1156 hc->DTMFbase = 0x1000;
1157 if (test_bit(HFC_CHIP_EXRAM_128, &hc->chip)) {
1158 if (debug & DEBUG_HFCMULTI_INIT)
1159 printk(KERN_DEBUG "%s: changing to 128K extenal RAM\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001160 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001161 hc->hw.r_ctrl |= V_EXT_RAM;
1162 hc->hw.r_ram_sz = 1;
1163 hc->Flen = 0x20;
1164 hc->Zmin = 0xc0;
1165 hc->Zlen = 1856;
1166 hc->DTMFbase = 0x2000;
1167 }
1168 if (test_bit(HFC_CHIP_EXRAM_512, &hc->chip)) {
1169 if (debug & DEBUG_HFCMULTI_INIT)
1170 printk(KERN_DEBUG "%s: changing to 512K extenal RAM\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001171 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001172 hc->hw.r_ctrl |= V_EXT_RAM;
1173 hc->hw.r_ram_sz = 2;
1174 hc->Flen = 0x20;
1175 hc->Zmin = 0xc0;
1176 hc->Zlen = 8000;
1177 hc->DTMFbase = 0x2000;
1178 }
Karsten Keildb9bb632009-05-22 11:04:53 +00001179 if (hc->ctype == HFC_TYPE_XHFC) {
1180 hc->Flen = 0x8;
1181 hc->Zmin = 0x0;
1182 hc->Zlen = 64;
1183 hc->DTMFbase = 0x0;
1184 }
Karsten Keilaf69fb32008-07-27 02:00:43 +02001185 hc->max_trans = poll << 1;
1186 if (hc->max_trans > hc->Zlen)
1187 hc->max_trans = hc->Zlen;
1188
1189 /* Speech Design PLX bridge */
1190 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
1191 if (debug & DEBUG_HFCMULTI_PLXSD)
1192 printk(KERN_DEBUG "%s: initializing PLXSD card %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001193 __func__, hc->id + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001194 spin_lock_irqsave(&plx_lock, plx_flags);
Hannes Ederc31655f2008-12-12 21:20:03 -08001195 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001196 writel(PLX_GPIOC_INIT, plx_acc_32);
1197 pv = readl(plx_acc_32);
1198 /* The first and the last cards are terminating the PCM bus */
1199 pv |= PLX_TERM_ON; /* hc is currently the last */
1200 /* Disconnect the PCM */
1201 pv |= PLX_SLAVE_EN_N;
1202 pv &= ~PLX_MASTER_EN;
1203 pv &= ~PLX_SYNC_O_EN;
1204 /* Put the DSP in Reset */
1205 pv &= ~PLX_DSP_RES_N;
1206 writel(pv, plx_acc_32);
1207 spin_unlock_irqrestore(&plx_lock, plx_flags);
1208 if (debug & DEBUG_HFCMULTI_INIT)
Karsten Keileac74af2009-05-22 11:04:56 +00001209 printk(KERN_DEBUG "%s: slave/term: PLX_GPIO=%x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001210 __func__, pv);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001211 /*
1212 * If we are the 3rd PLXSD card or higher, we must turn
1213 * termination of last PLXSD card off.
1214 */
1215 spin_lock_irqsave(&HFClock, hfc_flags);
1216 plx_count = 0;
1217 plx_last_hc = NULL;
1218 list_for_each_entry_safe(pos, next, &HFClist, list) {
1219 if (test_bit(HFC_CHIP_PLXSD, &pos->chip)) {
1220 plx_count++;
1221 if (pos != hc)
1222 plx_last_hc = pos;
1223 }
1224 }
1225 if (plx_count >= 3) {
1226 if (debug & DEBUG_HFCMULTI_PLXSD)
1227 printk(KERN_DEBUG "%s: card %d is between, so "
Joe Perches475be4d2012-02-19 19:52:38 -08001228 "we disable termination\n",
1229 __func__, plx_last_hc->id + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001230 spin_lock_irqsave(&plx_lock, plx_flags);
Hannes Ederc31655f2008-12-12 21:20:03 -08001231 plx_acc_32 = plx_last_hc->plx_membase + PLX_GPIOC;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001232 pv = readl(plx_acc_32);
1233 pv &= ~PLX_TERM_ON;
1234 writel(pv, plx_acc_32);
1235 spin_unlock_irqrestore(&plx_lock, plx_flags);
1236 if (debug & DEBUG_HFCMULTI_INIT)
Karsten Keileac74af2009-05-22 11:04:56 +00001237 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08001238 "%s: term off: PLX_GPIO=%x\n",
1239 __func__, pv);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001240 }
1241 spin_unlock_irqrestore(&HFClock, hfc_flags);
1242 hc->hw.r_pcm_md0 = V_F0_LEN; /* shift clock for DSP */
1243 }
1244
Karsten Keildb9bb632009-05-22 11:04:53 +00001245 if (test_bit(HFC_CHIP_EMBSD, &hc->chip))
1246 hc->hw.r_pcm_md0 = V_F0_LEN; /* shift clock for DSP */
1247
Karsten Keilaf69fb32008-07-27 02:00:43 +02001248 /* we only want the real Z2 read-pointer for revision > 0 */
1249 if (!test_bit(HFC_CHIP_REVISION0, &hc->chip))
1250 hc->hw.r_ram_sz |= V_FZ_MD;
1251
1252 /* select pcm mode */
1253 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
1254 if (debug & DEBUG_HFCMULTI_INIT)
1255 printk(KERN_DEBUG "%s: setting PCM into slave mode\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001256 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001257 } else
Joe Perches475be4d2012-02-19 19:52:38 -08001258 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip) && !plxsd_master) {
1259 if (debug & DEBUG_HFCMULTI_INIT)
1260 printk(KERN_DEBUG "%s: setting PCM into master mode\n",
1261 __func__);
1262 hc->hw.r_pcm_md0 |= V_PCM_MD;
1263 } else {
1264 if (debug & DEBUG_HFCMULTI_INIT)
1265 printk(KERN_DEBUG "%s: performing PCM auto detect\n",
1266 __func__);
1267 }
Karsten Keilaf69fb32008-07-27 02:00:43 +02001268
1269 /* soft reset */
1270 HFC_outb(hc, R_CTRL, hc->hw.r_ctrl);
Karsten Keildb9bb632009-05-22 11:04:53 +00001271 if (hc->ctype == HFC_TYPE_XHFC)
1272 HFC_outb(hc, 0x0C /* R_FIFO_THRES */,
Joe Perches475be4d2012-02-19 19:52:38 -08001273 0x11 /* 16 Bytes TX/RX */);
Karsten Keildb9bb632009-05-22 11:04:53 +00001274 else
1275 HFC_outb(hc, R_RAM_SZ, hc->hw.r_ram_sz);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001276 HFC_outb(hc, R_FIFO_MD, 0);
Karsten Keildb9bb632009-05-22 11:04:53 +00001277 if (hc->ctype == HFC_TYPE_XHFC)
1278 hc->hw.r_cirm = V_SRES | V_HFCRES | V_PCMRES | V_STRES;
1279 else
1280 hc->hw.r_cirm = V_SRES | V_HFCRES | V_PCMRES | V_STRES
1281 | V_RLD_EPR;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001282 HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
1283 udelay(100);
1284 hc->hw.r_cirm = 0;
1285 HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
1286 udelay(100);
Karsten Keildb9bb632009-05-22 11:04:53 +00001287 if (hc->ctype != HFC_TYPE_XHFC)
1288 HFC_outb(hc, R_RAM_SZ, hc->hw.r_ram_sz);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001289
1290 /* Speech Design PLX bridge pcm and sync mode */
1291 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
1292 spin_lock_irqsave(&plx_lock, plx_flags);
Hannes Ederc31655f2008-12-12 21:20:03 -08001293 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001294 pv = readl(plx_acc_32);
1295 /* Connect PCM */
1296 if (hc->hw.r_pcm_md0 & V_PCM_MD) {
1297 pv |= PLX_MASTER_EN | PLX_SLAVE_EN_N;
1298 pv |= PLX_SYNC_O_EN;
1299 if (debug & DEBUG_HFCMULTI_INIT)
Karsten Keileac74af2009-05-22 11:04:56 +00001300 printk(KERN_DEBUG "%s: master: PLX_GPIO=%x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001301 __func__, pv);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001302 } else {
1303 pv &= ~(PLX_MASTER_EN | PLX_SLAVE_EN_N);
1304 pv &= ~PLX_SYNC_O_EN;
1305 if (debug & DEBUG_HFCMULTI_INIT)
Karsten Keileac74af2009-05-22 11:04:56 +00001306 printk(KERN_DEBUG "%s: slave: PLX_GPIO=%x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001307 __func__, pv);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001308 }
1309 writel(pv, plx_acc_32);
1310 spin_unlock_irqrestore(&plx_lock, plx_flags);
1311 }
1312
1313 /* PCM setup */
1314 HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0x90);
1315 if (hc->slots == 32)
1316 HFC_outb(hc, R_PCM_MD1, 0x00);
1317 if (hc->slots == 64)
1318 HFC_outb(hc, R_PCM_MD1, 0x10);
1319 if (hc->slots == 128)
1320 HFC_outb(hc, R_PCM_MD1, 0x20);
1321 HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0xa0);
1322 if (test_bit(HFC_CHIP_PLXSD, &hc->chip))
1323 HFC_outb(hc, R_PCM_MD2, V_SYNC_SRC); /* sync via SYNC_I / O */
Karsten Keildb9bb632009-05-22 11:04:53 +00001324 else if (test_bit(HFC_CHIP_EMBSD, &hc->chip))
1325 HFC_outb(hc, R_PCM_MD2, 0x10); /* V_C2O_EN */
Karsten Keilaf69fb32008-07-27 02:00:43 +02001326 else
1327 HFC_outb(hc, R_PCM_MD2, 0x00); /* sync from interface */
1328 HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0x00);
1329 for (i = 0; i < 256; i++) {
1330 HFC_outb_nodebug(hc, R_SLOT, i);
1331 HFC_outb_nodebug(hc, A_SL_CFG, 0);
Karsten Keildb9bb632009-05-22 11:04:53 +00001332 if (hc->ctype != HFC_TYPE_XHFC)
1333 HFC_outb_nodebug(hc, A_CONF, 0);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001334 hc->slot_owner[i] = -1;
1335 }
1336
1337 /* set clock speed */
1338 if (test_bit(HFC_CHIP_CLOCK2, &hc->chip)) {
1339 if (debug & DEBUG_HFCMULTI_INIT)
1340 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08001341 "%s: setting double clock\n", __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001342 HFC_outb(hc, R_BRG_PCM_CFG, V_PCM_CLK);
1343 }
1344
Karsten Keildb9bb632009-05-22 11:04:53 +00001345 if (test_bit(HFC_CHIP_EMBSD, &hc->chip))
1346 HFC_outb(hc, 0x02 /* R_CLK_CFG */, 0x40 /* V_CLKO_OFF */);
1347
Karsten Keilaf69fb32008-07-27 02:00:43 +02001348 /* B410P GPIO */
1349 if (test_bit(HFC_CHIP_B410P, &hc->chip)) {
1350 printk(KERN_NOTICE "Setting GPIOs\n");
1351 HFC_outb(hc, R_GPIO_SEL, 0x30);
1352 HFC_outb(hc, R_GPIO_EN1, 0x3);
1353 udelay(1000);
1354 printk(KERN_NOTICE "calling vpm_init\n");
1355 vpm_init(hc);
1356 }
1357
1358 /* check if R_F0_CNT counts (8 kHz frame count) */
1359 val = HFC_inb(hc, R_F0_CNTL);
1360 val += HFC_inb(hc, R_F0_CNTH) << 8;
1361 if (debug & DEBUG_HFCMULTI_INIT)
1362 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08001363 "HFC_multi F0_CNT %ld after reset\n", val);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001364 spin_unlock_irqrestore(&hc->lock, flags);
1365 set_current_state(TASK_UNINTERRUPTIBLE);
Joe Perches475be4d2012-02-19 19:52:38 -08001366 schedule_timeout((HZ / 100) ? : 1); /* Timeout minimum 10ms */
Karsten Keilaf69fb32008-07-27 02:00:43 +02001367 spin_lock_irqsave(&hc->lock, flags);
1368 val2 = HFC_inb(hc, R_F0_CNTL);
1369 val2 += HFC_inb(hc, R_F0_CNTH) << 8;
1370 if (debug & DEBUG_HFCMULTI_INIT)
1371 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08001372 "HFC_multi F0_CNT %ld after 10 ms (1st try)\n",
1373 val2);
1374 if (val2 >= val + 8) { /* 1 ms */
Karsten Keilaf69fb32008-07-27 02:00:43 +02001375 /* it counts, so we keep the pcm mode */
1376 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip))
1377 printk(KERN_INFO "controller is PCM bus MASTER\n");
1378 else
Joe Perches475be4d2012-02-19 19:52:38 -08001379 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip))
1380 printk(KERN_INFO "controller is PCM bus SLAVE\n");
1381 else {
1382 test_and_set_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
1383 printk(KERN_INFO "controller is PCM bus SLAVE "
1384 "(auto detected)\n");
1385 }
Karsten Keilaf69fb32008-07-27 02:00:43 +02001386 } else {
1387 /* does not count */
1388 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip)) {
Joe Perches475be4d2012-02-19 19:52:38 -08001389 controller_fail:
Karsten Keilaf69fb32008-07-27 02:00:43 +02001390 printk(KERN_ERR "HFC_multi ERROR, getting no 125us "
Joe Perches475be4d2012-02-19 19:52:38 -08001391 "pulse. Seems that controller fails.\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02001392 err = -EIO;
1393 goto out;
1394 }
1395 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
1396 printk(KERN_INFO "controller is PCM bus SLAVE "
Joe Perches475be4d2012-02-19 19:52:38 -08001397 "(ignoring missing PCM clock)\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02001398 } else {
1399 /* only one pcm master */
1400 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)
Joe Perches475be4d2012-02-19 19:52:38 -08001401 && plxsd_master) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02001402 printk(KERN_ERR "HFC_multi ERROR, no clock "
Joe Perches475be4d2012-02-19 19:52:38 -08001403 "on another Speech Design card found. "
1404 "Please be sure to connect PCM cable.\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02001405 err = -EIO;
1406 goto out;
1407 }
1408 /* retry with master clock */
1409 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
1410 spin_lock_irqsave(&plx_lock, plx_flags);
Hannes Ederc31655f2008-12-12 21:20:03 -08001411 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001412 pv = readl(plx_acc_32);
1413 pv |= PLX_MASTER_EN | PLX_SLAVE_EN_N;
1414 pv |= PLX_SYNC_O_EN;
1415 writel(pv, plx_acc_32);
1416 spin_unlock_irqrestore(&plx_lock, plx_flags);
1417 if (debug & DEBUG_HFCMULTI_INIT)
Karsten Keileac74af2009-05-22 11:04:56 +00001418 printk(KERN_DEBUG "%s: master: "
Joe Perches475be4d2012-02-19 19:52:38 -08001419 "PLX_GPIO=%x\n", __func__, pv);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001420 }
1421 hc->hw.r_pcm_md0 |= V_PCM_MD;
1422 HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0x00);
1423 spin_unlock_irqrestore(&hc->lock, flags);
1424 set_current_state(TASK_UNINTERRUPTIBLE);
Joe Perches475be4d2012-02-19 19:52:38 -08001425 schedule_timeout((HZ / 100) ?: 1); /* Timeout min. 10ms */
Karsten Keilaf69fb32008-07-27 02:00:43 +02001426 spin_lock_irqsave(&hc->lock, flags);
1427 val2 = HFC_inb(hc, R_F0_CNTL);
1428 val2 += HFC_inb(hc, R_F0_CNTH) << 8;
1429 if (debug & DEBUG_HFCMULTI_INIT)
1430 printk(KERN_DEBUG "HFC_multi F0_CNT %ld after "
Joe Perches475be4d2012-02-19 19:52:38 -08001431 "10 ms (2nd try)\n", val2);
1432 if (val2 >= val + 8) { /* 1 ms */
Karsten Keilaf69fb32008-07-27 02:00:43 +02001433 test_and_set_bit(HFC_CHIP_PCM_MASTER,
Joe Perches475be4d2012-02-19 19:52:38 -08001434 &hc->chip);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001435 printk(KERN_INFO "controller is PCM bus MASTER "
Joe Perches475be4d2012-02-19 19:52:38 -08001436 "(auto detected)\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02001437 } else
1438 goto controller_fail;
1439 }
1440 }
1441
1442 /* Release the DSP Reset */
1443 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
1444 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip))
1445 plxsd_master = 1;
1446 spin_lock_irqsave(&plx_lock, plx_flags);
Hannes Ederc31655f2008-12-12 21:20:03 -08001447 plx_acc_32 = hc->plx_membase + PLX_GPIOC;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001448 pv = readl(plx_acc_32);
1449 pv |= PLX_DSP_RES_N;
1450 writel(pv, plx_acc_32);
1451 spin_unlock_irqrestore(&plx_lock, plx_flags);
1452 if (debug & DEBUG_HFCMULTI_INIT)
Karsten Keileac74af2009-05-22 11:04:56 +00001453 printk(KERN_DEBUG "%s: reset off: PLX_GPIO=%x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001454 __func__, pv);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001455 }
1456
1457 /* pcm id */
1458 if (hc->pcm)
1459 printk(KERN_INFO "controller has given PCM BUS ID %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001460 hc->pcm);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001461 else {
1462 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip)
Joe Perches475be4d2012-02-19 19:52:38 -08001463 || test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02001464 PCM_cnt++; /* SD has proprietary bridging */
1465 }
1466 hc->pcm = PCM_cnt;
1467 printk(KERN_INFO "controller has PCM BUS ID %d "
Joe Perches475be4d2012-02-19 19:52:38 -08001468 "(auto selected)\n", hc->pcm);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001469 }
1470
1471 /* set up timer */
1472 HFC_outb(hc, R_TI_WD, poll_timer);
1473 hc->hw.r_irqmsk_misc |= V_TI_IRQMSK;
1474
Karsten Keilaf69fb32008-07-27 02:00:43 +02001475 /* set E1 state machine IRQ */
Karsten Keildb9bb632009-05-22 11:04:53 +00001476 if (hc->ctype == HFC_TYPE_E1)
Karsten Keilaf69fb32008-07-27 02:00:43 +02001477 hc->hw.r_irqmsk_misc |= V_STA_IRQMSK;
1478
1479 /* set DTMF detection */
1480 if (test_bit(HFC_CHIP_DTMF, &hc->chip)) {
1481 if (debug & DEBUG_HFCMULTI_INIT)
1482 printk(KERN_DEBUG "%s: enabling DTMF detection "
Joe Perches475be4d2012-02-19 19:52:38 -08001483 "for all B-channel\n", __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001484 hc->hw.r_dtmf = V_DTMF_EN | V_DTMF_STOP;
1485 if (test_bit(HFC_CHIP_ULAW, &hc->chip))
1486 hc->hw.r_dtmf |= V_ULAW_SEL;
1487 HFC_outb(hc, R_DTMF_N, 102 - 1);
1488 hc->hw.r_irqmsk_misc |= V_DTMF_IRQMSK;
1489 }
1490
1491 /* conference engine */
1492 if (test_bit(HFC_CHIP_ULAW, &hc->chip))
1493 r_conf_en = V_CONF_EN | V_ULAW;
1494 else
1495 r_conf_en = V_CONF_EN;
Karsten Keildb9bb632009-05-22 11:04:53 +00001496 if (hc->ctype != HFC_TYPE_XHFC)
1497 HFC_outb(hc, R_CONF_EN, r_conf_en);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001498
1499 /* setting leds */
1500 switch (hc->leds) {
1501 case 1: /* HFC-E1 OEM */
1502 if (test_bit(HFC_CHIP_WATCHDOG, &hc->chip))
1503 HFC_outb(hc, R_GPIO_SEL, 0x32);
1504 else
1505 HFC_outb(hc, R_GPIO_SEL, 0x30);
1506
1507 HFC_outb(hc, R_GPIO_EN1, 0x0f);
1508 HFC_outb(hc, R_GPIO_OUT1, 0x00);
1509
1510 HFC_outb(hc, R_GPIO_EN0, V_GPIO_EN2 | V_GPIO_EN3);
1511 break;
1512
1513 case 2: /* HFC-4S OEM */
1514 case 3:
1515 HFC_outb(hc, R_GPIO_SEL, 0xf0);
1516 HFC_outb(hc, R_GPIO_EN1, 0xff);
1517 HFC_outb(hc, R_GPIO_OUT1, 0x00);
1518 break;
1519 }
1520
Karsten Keildb9bb632009-05-22 11:04:53 +00001521 if (test_bit(HFC_CHIP_EMBSD, &hc->chip)) {
1522 hc->hw.r_st_sync = 0x10; /* V_AUTO_SYNCI */
1523 HFC_outb(hc, R_ST_SYNC, hc->hw.r_st_sync);
1524 }
1525
Karsten Keilaf69fb32008-07-27 02:00:43 +02001526 /* set master clock */
1527 if (hc->masterclk >= 0) {
1528 if (debug & DEBUG_HFCMULTI_INIT)
1529 printk(KERN_DEBUG "%s: setting ST master clock "
Joe Perches475be4d2012-02-19 19:52:38 -08001530 "to port %d (0..%d)\n",
1531 __func__, hc->masterclk, hc->ports - 1);
Karsten Keildb9bb632009-05-22 11:04:53 +00001532 hc->hw.r_st_sync |= (hc->masterclk | V_AUTO_SYNC);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001533 HFC_outb(hc, R_ST_SYNC, hc->hw.r_st_sync);
1534 }
1535
Karsten Keildb9bb632009-05-22 11:04:53 +00001536
1537
Karsten Keilaf69fb32008-07-27 02:00:43 +02001538 /* setting misc irq */
1539 HFC_outb(hc, R_IRQMSK_MISC, hc->hw.r_irqmsk_misc);
1540 if (debug & DEBUG_HFCMULTI_INIT)
1541 printk(KERN_DEBUG "r_irqmsk_misc.2: 0x%x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001542 hc->hw.r_irqmsk_misc);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001543
1544 /* RAM access test */
1545 HFC_outb(hc, R_RAM_ADDR0, 0);
1546 HFC_outb(hc, R_RAM_ADDR1, 0);
1547 HFC_outb(hc, R_RAM_ADDR2, 0);
1548 for (i = 0; i < 256; i++) {
1549 HFC_outb_nodebug(hc, R_RAM_ADDR0, i);
Joe Perches475be4d2012-02-19 19:52:38 -08001550 HFC_outb_nodebug(hc, R_RAM_DATA, ((i * 3) & 0xff));
Karsten Keilaf69fb32008-07-27 02:00:43 +02001551 }
1552 for (i = 0; i < 256; i++) {
1553 HFC_outb_nodebug(hc, R_RAM_ADDR0, i);
1554 HFC_inb_nodebug(hc, R_RAM_DATA);
1555 rval = HFC_inb_nodebug(hc, R_INT_DATA);
1556 if (rval != ((i * 3) & 0xff)) {
1557 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08001558 "addr:%x val:%x should:%x\n", i, rval,
1559 (i * 3) & 0xff);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001560 err++;
1561 }
1562 }
1563 if (err) {
1564 printk(KERN_DEBUG "aborting - %d RAM access errors\n", err);
1565 err = -EIO;
1566 goto out;
1567 }
1568
1569 if (debug & DEBUG_HFCMULTI_INIT)
1570 printk(KERN_DEBUG "%s: done\n", __func__);
1571out:
1572 spin_unlock_irqrestore(&hc->lock, flags);
1573 return err;
1574}
1575
1576
1577/*
1578 * control the watchdog
1579 */
1580static void
1581hfcmulti_watchdog(struct hfc_multi *hc)
1582{
1583 hc->wdcount++;
1584
1585 if (hc->wdcount > 10) {
1586 hc->wdcount = 0;
1587 hc->wdbyte = hc->wdbyte == V_GPIO_OUT2 ?
Joe Perches475be4d2012-02-19 19:52:38 -08001588 V_GPIO_OUT3 : V_GPIO_OUT2;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001589
Joe Perches475be4d2012-02-19 19:52:38 -08001590 /* printk("Sending Watchdog Kill %x\n",hc->wdbyte); */
Karsten Keilaf69fb32008-07-27 02:00:43 +02001591 HFC_outb(hc, R_GPIO_EN0, V_GPIO_EN2 | V_GPIO_EN3);
1592 HFC_outb(hc, R_GPIO_OUT0, hc->wdbyte);
1593 }
1594}
1595
1596
1597
1598/*
1599 * output leds
1600 */
1601static void
1602hfcmulti_leds(struct hfc_multi *hc)
1603{
1604 unsigned long lled;
1605 unsigned long leddw;
1606 int i, state, active, leds;
1607 struct dchannel *dch;
1608 int led[4];
1609
1610 hc->ledcount += poll;
1611 if (hc->ledcount > 4096) {
1612 hc->ledcount -= 4096;
1613 hc->ledstate = 0xAFFEAFFE;
1614 }
1615
1616 switch (hc->leds) {
1617 case 1: /* HFC-E1 OEM */
1618 /* 2 red blinking: NT mode deactivate
1619 * 2 red steady: TE mode deactivate
1620 * left green: L1 active
1621 * left red: frame sync, but no L1
Andreas Eversbergd2fb5492012-04-24 20:52:12 +00001622 * todo right green: L2 active
Karsten Keilaf69fb32008-07-27 02:00:43 +02001623 */
Andreas Eversbergd2fb5492012-04-24 20:52:12 +00001624 dch = hc->chan[hc->dslot].dch;
1625 if (test_bit(FLG_ACTIVE, &dch->Flags)) {
1626 led[0] = 0;
1627 led[1] = 0;
1628 led[2] = 0;
1629 led[3] = 1;
1630 } else {
1631 if (dch->dev.D.protocol
Joe Perches475be4d2012-02-19 19:52:38 -08001632 != ISDN_P_NT_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02001633 led[0] = 1;
1634 led[1] = 1;
Joe Perches475be4d2012-02-19 19:52:38 -08001635 } else if (hc->ledcount >> 11) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02001636 led[0] = 1;
1637 led[1] = 1;
1638 } else {
1639 led[0] = 0;
1640 led[1] = 0;
1641 }
1642 led[2] = 0;
1643 led[3] = 0;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001644 }
1645 leds = (led[0] | (led[1]<<2) | (led[2]<<1) | (led[3]<<3))^0xF;
Joe Perches475be4d2012-02-19 19:52:38 -08001646 /* leds are inverted */
Karsten Keilaf69fb32008-07-27 02:00:43 +02001647 if (leds != (int)hc->ledstate) {
1648 HFC_outb_nodebug(hc, R_GPIO_OUT1, leds);
1649 hc->ledstate = leds;
1650 }
1651 break;
1652
1653 case 2: /* HFC-4S OEM */
1654 /* red blinking = PH_DEACTIVATE NT Mode
1655 * red steady = PH_DEACTIVATE TE Mode
1656 * green steady = PH_ACTIVATE
1657 */
1658 for (i = 0; i < 4; i++) {
1659 state = 0;
1660 active = -1;
1661 dch = hc->chan[(i << 2) | 2].dch;
1662 if (dch) {
1663 state = dch->state;
1664 if (dch->dev.D.protocol == ISDN_P_NT_S0)
1665 active = 3;
1666 else
1667 active = 7;
1668 }
1669 if (state) {
1670 if (state == active) {
1671 led[i] = 1; /* led green */
1672 } else
1673 if (dch->dev.D.protocol == ISDN_P_TE_S0)
1674 /* TE mode: led red */
1675 led[i] = 2;
1676 else
Joe Perches475be4d2012-02-19 19:52:38 -08001677 if (hc->ledcount >> 11)
Karsten Keilaf69fb32008-07-27 02:00:43 +02001678 /* led red */
1679 led[i] = 2;
1680 else
1681 /* led off */
1682 led[i] = 0;
1683 } else
1684 led[i] = 0; /* led off */
1685 }
1686 if (test_bit(HFC_CHIP_B410P, &hc->chip)) {
1687 leds = 0;
1688 for (i = 0; i < 4; i++) {
1689 if (led[i] == 1) {
1690 /*green*/
1691 leds |= (0x2 << (i * 2));
1692 } else if (led[i] == 2) {
1693 /*red*/
1694 leds |= (0x1 << (i * 2));
1695 }
1696 }
1697 if (leds != (int)hc->ledstate) {
1698 vpm_out(hc, 0, 0x1a8 + 3, leds);
1699 hc->ledstate = leds;
1700 }
1701 } else {
1702 leds = ((led[3] > 0) << 0) | ((led[1] > 0) << 1) |
Joe Perches475be4d2012-02-19 19:52:38 -08001703 ((led[0] > 0) << 2) | ((led[2] > 0) << 3) |
1704 ((led[3] & 1) << 4) | ((led[1] & 1) << 5) |
1705 ((led[0] & 1) << 6) | ((led[2] & 1) << 7);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001706 if (leds != (int)hc->ledstate) {
1707 HFC_outb_nodebug(hc, R_GPIO_EN1, leds & 0x0F);
1708 HFC_outb_nodebug(hc, R_GPIO_OUT1, leds >> 4);
1709 hc->ledstate = leds;
1710 }
1711 }
1712 break;
1713
1714 case 3: /* HFC 1S/2S Beronet */
1715 /* red blinking = PH_DEACTIVATE NT Mode
1716 * red steady = PH_DEACTIVATE TE Mode
1717 * green steady = PH_ACTIVATE
1718 */
1719 for (i = 0; i < 2; i++) {
1720 state = 0;
1721 active = -1;
1722 dch = hc->chan[(i << 2) | 2].dch;
1723 if (dch) {
1724 state = dch->state;
1725 if (dch->dev.D.protocol == ISDN_P_NT_S0)
1726 active = 3;
1727 else
1728 active = 7;
1729 }
1730 if (state) {
1731 if (state == active) {
1732 led[i] = 1; /* led green */
1733 } else
1734 if (dch->dev.D.protocol == ISDN_P_TE_S0)
1735 /* TE mode: led red */
1736 led[i] = 2;
1737 else
1738 if (hc->ledcount >> 11)
1739 /* led red */
1740 led[i] = 2;
1741 else
1742 /* led off */
1743 led[i] = 0;
1744 } else
1745 led[i] = 0; /* led off */
1746 }
1747
1748
Joe Perches475be4d2012-02-19 19:52:38 -08001749 leds = (led[0] > 0) | ((led[1] > 0) << 1) | ((led[0]&1) << 2)
1750 | ((led[1]&1) << 3);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001751 if (leds != (int)hc->ledstate) {
1752 HFC_outb_nodebug(hc, R_GPIO_EN1,
Joe Perches475be4d2012-02-19 19:52:38 -08001753 ((led[0] > 0) << 2) | ((led[1] > 0) << 3));
Karsten Keilaf69fb32008-07-27 02:00:43 +02001754 HFC_outb_nodebug(hc, R_GPIO_OUT1,
Joe Perches475be4d2012-02-19 19:52:38 -08001755 ((led[0] & 1) << 2) | ((led[1] & 1) << 3));
Karsten Keilaf69fb32008-07-27 02:00:43 +02001756 hc->ledstate = leds;
1757 }
1758 break;
1759 case 8: /* HFC 8S+ Beronet */
1760 lled = 0;
1761
1762 for (i = 0; i < 8; i++) {
1763 state = 0;
1764 active = -1;
1765 dch = hc->chan[(i << 2) | 2].dch;
1766 if (dch) {
1767 state = dch->state;
1768 if (dch->dev.D.protocol == ISDN_P_NT_S0)
1769 active = 3;
1770 else
1771 active = 7;
1772 }
1773 if (state) {
1774 if (state == active) {
1775 lled |= 0 << i;
1776 } else
1777 if (hc->ledcount >> 11)
1778 lled |= 0 << i;
1779 else
1780 lled |= 1 << i;
1781 } else
1782 lled |= 1 << i;
1783 }
1784 leddw = lled << 24 | lled << 16 | lled << 8 | lled;
1785 if (leddw != hc->ledstate) {
1786 /* HFC_outb(hc, R_BRG_PCM_CFG, 1);
Joe Perches475be4d2012-02-19 19:52:38 -08001787 HFC_outb(c, R_BRG_PCM_CFG, (0x0 << 6) | 0x3); */
Karsten Keilaf69fb32008-07-27 02:00:43 +02001788 /* was _io before */
1789 HFC_outb_nodebug(hc, R_BRG_PCM_CFG, 1 | V_PCM_CLK);
1790 outw(0x4000, hc->pci_iobase + 4);
1791 outl(leddw, hc->pci_iobase);
1792 HFC_outb_nodebug(hc, R_BRG_PCM_CFG, V_PCM_CLK);
1793 hc->ledstate = leddw;
1794 }
1795 break;
1796 }
1797}
1798/*
1799 * read dtmf coefficients
1800 */
1801
1802static void
1803hfcmulti_dtmf(struct hfc_multi *hc)
1804{
1805 s32 *coeff;
1806 u_int mantissa;
1807 int co, ch;
1808 struct bchannel *bch = NULL;
1809 u8 exponent;
1810 int dtmf = 0;
1811 int addr;
1812 u16 w_float;
1813 struct sk_buff *skb;
1814 struct mISDNhead *hh;
1815
1816 if (debug & DEBUG_HFCMULTI_DTMF)
1817 printk(KERN_DEBUG "%s: dtmf detection irq\n", __func__);
1818 for (ch = 0; ch <= 31; ch++) {
1819 /* only process enabled B-channels */
1820 bch = hc->chan[ch].bch;
1821 if (!bch)
1822 continue;
1823 if (!hc->created[hc->chan[ch].port])
1824 continue;
1825 if (!test_bit(FLG_TRANSPARENT, &bch->Flags))
1826 continue;
1827 if (debug & DEBUG_HFCMULTI_DTMF)
1828 printk(KERN_DEBUG "%s: dtmf channel %d:",
Joe Perches475be4d2012-02-19 19:52:38 -08001829 __func__, ch);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001830 coeff = &(hc->chan[ch].coeff[hc->chan[ch].coeff_count * 16]);
1831 dtmf = 1;
1832 for (co = 0; co < 8; co++) {
1833 /* read W(n-1) coefficient */
Joe Perches475be4d2012-02-19 19:52:38 -08001834 addr = hc->DTMFbase + ((co << 7) | (ch << 2));
Karsten Keilaf69fb32008-07-27 02:00:43 +02001835 HFC_outb_nodebug(hc, R_RAM_ADDR0, addr);
Joe Perches475be4d2012-02-19 19:52:38 -08001836 HFC_outb_nodebug(hc, R_RAM_ADDR1, addr >> 8);
1837 HFC_outb_nodebug(hc, R_RAM_ADDR2, (addr >> 16)
1838 | V_ADDR_INC);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001839 w_float = HFC_inb_nodebug(hc, R_RAM_DATA);
1840 w_float |= (HFC_inb_nodebug(hc, R_RAM_DATA) << 8);
1841 if (debug & DEBUG_HFCMULTI_DTMF)
1842 printk(" %04x", w_float);
1843
1844 /* decode float (see chip doc) */
1845 mantissa = w_float & 0x0fff;
1846 if (w_float & 0x8000)
1847 mantissa |= 0xfffff000;
Joe Perches475be4d2012-02-19 19:52:38 -08001848 exponent = (w_float >> 12) & 0x7;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001849 if (exponent) {
1850 mantissa ^= 0x1000;
Joe Perches475be4d2012-02-19 19:52:38 -08001851 mantissa <<= (exponent - 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001852 }
1853
1854 /* store coefficient */
Joe Perches475be4d2012-02-19 19:52:38 -08001855 coeff[co << 1] = mantissa;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001856
1857 /* read W(n) coefficient */
1858 w_float = HFC_inb_nodebug(hc, R_RAM_DATA);
1859 w_float |= (HFC_inb_nodebug(hc, R_RAM_DATA) << 8);
1860 if (debug & DEBUG_HFCMULTI_DTMF)
1861 printk(" %04x", w_float);
1862
1863 /* decode float (see chip doc) */
1864 mantissa = w_float & 0x0fff;
1865 if (w_float & 0x8000)
1866 mantissa |= 0xfffff000;
Joe Perches475be4d2012-02-19 19:52:38 -08001867 exponent = (w_float >> 12) & 0x7;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001868 if (exponent) {
1869 mantissa ^= 0x1000;
Joe Perches475be4d2012-02-19 19:52:38 -08001870 mantissa <<= (exponent - 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001871 }
1872
1873 /* store coefficient */
Joe Perches475be4d2012-02-19 19:52:38 -08001874 coeff[(co << 1) | 1] = mantissa;
Karsten Keilaf69fb32008-07-27 02:00:43 +02001875 }
1876 if (debug & DEBUG_HFCMULTI_DTMF)
Andreas Eversbergb5df5a52009-05-22 11:04:48 +00001877 printk(" DTMF ready %08x %08x %08x %08x "
Joe Perches475be4d2012-02-19 19:52:38 -08001878 "%08x %08x %08x %08x\n",
1879 coeff[0], coeff[1], coeff[2], coeff[3],
1880 coeff[4], coeff[5], coeff[6], coeff[7]);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001881 hc->chan[ch].coeff_count++;
1882 if (hc->chan[ch].coeff_count == 8) {
1883 hc->chan[ch].coeff_count = 0;
1884 skb = mI_alloc_skb(512, GFP_ATOMIC);
1885 if (!skb) {
Karsten Keileac74af2009-05-22 11:04:56 +00001886 printk(KERN_DEBUG "%s: No memory for skb\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001887 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001888 continue;
1889 }
1890 hh = mISDN_HEAD_P(skb);
1891 hh->prim = PH_CONTROL_IND;
1892 hh->id = DTMF_HFC_COEF;
1893 memcpy(skb_put(skb, 512), hc->chan[ch].coeff, 512);
1894 recv_Bchannel_skb(bch, skb);
1895 }
1896 }
1897
1898 /* restart DTMF processing */
1899 hc->dtmf = dtmf;
1900 if (dtmf)
1901 HFC_outb_nodebug(hc, R_DTMF, hc->hw.r_dtmf | V_RST_DTMF);
1902}
1903
1904
1905/*
1906 * fill fifo as much as possible
1907 */
1908
1909static void
1910hfcmulti_tx(struct hfc_multi *hc, int ch)
1911{
1912 int i, ii, temp, len = 0;
1913 int Zspace, z1, z2; /* must be int for calculation */
1914 int Fspace, f1, f2;
1915 u_char *d;
1916 int *txpending, slot_tx;
1917 struct bchannel *bch;
1918 struct dchannel *dch;
1919 struct sk_buff **sp = NULL;
1920 int *idxp;
1921
1922 bch = hc->chan[ch].bch;
1923 dch = hc->chan[ch].dch;
1924 if ((!dch) && (!bch))
1925 return;
1926
1927 txpending = &hc->chan[ch].txpending;
1928 slot_tx = hc->chan[ch].slot_tx;
1929 if (dch) {
1930 if (!test_bit(FLG_ACTIVE, &dch->Flags))
1931 return;
1932 sp = &dch->tx_skb;
1933 idxp = &dch->tx_idx;
1934 } else {
1935 if (!test_bit(FLG_ACTIVE, &bch->Flags))
1936 return;
1937 sp = &bch->tx_skb;
1938 idxp = &bch->tx_idx;
1939 }
1940 if (*sp)
1941 len = (*sp)->len;
1942
1943 if ((!len) && *txpending != 1)
1944 return; /* no data */
1945
1946 if (test_bit(HFC_CHIP_B410P, &hc->chip) &&
1947 (hc->chan[ch].protocol == ISDN_P_B_RAW) &&
1948 (hc->chan[ch].slot_rx < 0) &&
1949 (hc->chan[ch].slot_tx < 0))
1950 HFC_outb_nodebug(hc, R_FIFO, 0x20 | (ch << 1));
1951 else
1952 HFC_outb_nodebug(hc, R_FIFO, ch << 1);
1953 HFC_wait_nodebug(hc);
1954
1955 if (*txpending == 2) {
1956 /* reset fifo */
1957 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_RES_F);
1958 HFC_wait_nodebug(hc);
1959 HFC_outb(hc, A_SUBCH_CFG, 0);
1960 *txpending = 1;
1961 }
1962next_frame:
1963 if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
1964 f1 = HFC_inb_nodebug(hc, A_F1);
1965 f2 = HFC_inb_nodebug(hc, A_F2);
1966 while (f2 != (temp = HFC_inb_nodebug(hc, A_F2))) {
1967 if (debug & DEBUG_HFCMULTI_FIFO)
1968 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08001969 "%s(card %d): reread f2 because %d!=%d\n",
1970 __func__, hc->id + 1, temp, f2);
Karsten Keilaf69fb32008-07-27 02:00:43 +02001971 f2 = temp; /* repeat until F2 is equal */
1972 }
1973 Fspace = f2 - f1 - 1;
1974 if (Fspace < 0)
1975 Fspace += hc->Flen;
1976 /*
1977 * Old FIFO handling doesn't give us the current Z2 read
1978 * pointer, so we cannot send the next frame before the fifo
1979 * is empty. It makes no difference except for a slightly
1980 * lower performance.
1981 */
1982 if (test_bit(HFC_CHIP_REVISION0, &hc->chip)) {
1983 if (f1 != f2)
1984 Fspace = 0;
1985 else
1986 Fspace = 1;
1987 }
1988 /* one frame only for ST D-channels, to allow resending */
Karsten Keildb9bb632009-05-22 11:04:53 +00001989 if (hc->ctype != HFC_TYPE_E1 && dch) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02001990 if (f1 != f2)
1991 Fspace = 0;
1992 }
1993 /* F-counter full condition */
1994 if (Fspace == 0)
1995 return;
1996 }
1997 z1 = HFC_inw_nodebug(hc, A_Z1) - hc->Zmin;
1998 z2 = HFC_inw_nodebug(hc, A_Z2) - hc->Zmin;
1999 while (z2 != (temp = (HFC_inw_nodebug(hc, A_Z2) - hc->Zmin))) {
2000 if (debug & DEBUG_HFCMULTI_FIFO)
2001 printk(KERN_DEBUG "%s(card %d): reread z2 because "
Joe Perches475be4d2012-02-19 19:52:38 -08002002 "%d!=%d\n", __func__, hc->id + 1, temp, z2);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002003 z2 = temp; /* repeat unti Z2 is equal */
2004 }
Andreas Eversberg7cfa1532009-05-22 11:04:46 +00002005 hc->chan[ch].Zfill = z1 - z2;
2006 if (hc->chan[ch].Zfill < 0)
2007 hc->chan[ch].Zfill += hc->Zlen;
Karsten Keilaf69fb32008-07-27 02:00:43 +02002008 Zspace = z2 - z1;
2009 if (Zspace <= 0)
2010 Zspace += hc->Zlen;
2011 Zspace -= 4; /* keep not too full, so pointers will not overrun */
2012 /* fill transparent data only to maxinum transparent load (minus 4) */
2013 if (bch && test_bit(FLG_TRANSPARENT, &bch->Flags))
2014 Zspace = Zspace - hc->Zlen + hc->max_trans;
2015 if (Zspace <= 0) /* no space of 4 bytes */
2016 return;
2017
2018 /* if no data */
2019 if (!len) {
2020 if (z1 == z2) { /* empty */
2021 /* if done with FIFO audio data during PCM connection */
2022 if (bch && (!test_bit(FLG_HDLC, &bch->Flags)) &&
2023 *txpending && slot_tx >= 0) {
2024 if (debug & DEBUG_HFCMULTI_MODE)
2025 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002026 "%s: reconnecting PCM due to no "
2027 "more FIFO data: channel %d "
2028 "slot_tx %d\n",
2029 __func__, ch, slot_tx);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002030 /* connect slot */
Karsten Keildb9bb632009-05-22 11:04:53 +00002031 if (hc->ctype == HFC_TYPE_XHFC)
2032 HFC_outb(hc, A_CON_HDLC, 0xc0
Joe Perches475be4d2012-02-19 19:52:38 -08002033 | 0x07 << 2 | V_HDLC_TRP | V_IFF);
2034 /* Enable FIFO, no interrupt */
Karsten Keildb9bb632009-05-22 11:04:53 +00002035 else
2036 HFC_outb(hc, A_CON_HDLC, 0xc0 | 0x00 |
Joe Perches475be4d2012-02-19 19:52:38 -08002037 V_HDLC_TRP | V_IFF);
2038 HFC_outb_nodebug(hc, R_FIFO, ch << 1 | 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002039 HFC_wait_nodebug(hc);
Karsten Keildb9bb632009-05-22 11:04:53 +00002040 if (hc->ctype == HFC_TYPE_XHFC)
2041 HFC_outb(hc, A_CON_HDLC, 0xc0
Joe Perches475be4d2012-02-19 19:52:38 -08002042 | 0x07 << 2 | V_HDLC_TRP | V_IFF);
2043 /* Enable FIFO, no interrupt */
Karsten Keildb9bb632009-05-22 11:04:53 +00002044 else
2045 HFC_outb(hc, A_CON_HDLC, 0xc0 | 0x00 |
Joe Perches475be4d2012-02-19 19:52:38 -08002046 V_HDLC_TRP | V_IFF);
2047 HFC_outb_nodebug(hc, R_FIFO, ch << 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002048 HFC_wait_nodebug(hc);
2049 }
2050 *txpending = 0;
2051 }
2052 return; /* no data */
2053 }
2054
Andreas Eversberg8dd2f362008-08-02 22:51:52 +02002055 /* "fill fifo if empty" feature */
2056 if (bch && test_bit(FLG_FILLEMPTY, &bch->Flags)
Joe Perches475be4d2012-02-19 19:52:38 -08002057 && !test_bit(FLG_HDLC, &bch->Flags) && z2 == z1) {
Andreas Eversberg8dd2f362008-08-02 22:51:52 +02002058 if (debug & DEBUG_HFCMULTI_FILL)
2059 printk(KERN_DEBUG "%s: buffer empty, so we have "
Joe Perches475be4d2012-02-19 19:52:38 -08002060 "underrun\n", __func__);
Andreas Eversberg8dd2f362008-08-02 22:51:52 +02002061 /* fill buffer, to prevent future underrun */
2062 hc->write_fifo(hc, hc->silence_data, poll >> 1);
2063 Zspace -= (poll >> 1);
2064 }
2065
Karsten Keilaf69fb32008-07-27 02:00:43 +02002066 /* if audio data and connected slot */
2067 if (bch && (!test_bit(FLG_HDLC, &bch->Flags)) && (!*txpending)
Joe Perches475be4d2012-02-19 19:52:38 -08002068 && slot_tx >= 0) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02002069 if (debug & DEBUG_HFCMULTI_MODE)
2070 printk(KERN_DEBUG "%s: disconnecting PCM due to "
Joe Perches475be4d2012-02-19 19:52:38 -08002071 "FIFO data: channel %d slot_tx %d\n",
2072 __func__, ch, slot_tx);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002073 /* disconnect slot */
Karsten Keildb9bb632009-05-22 11:04:53 +00002074 if (hc->ctype == HFC_TYPE_XHFC)
2075 HFC_outb(hc, A_CON_HDLC, 0x80
Joe Perches475be4d2012-02-19 19:52:38 -08002076 | 0x07 << 2 | V_HDLC_TRP | V_IFF);
2077 /* Enable FIFO, no interrupt */
Karsten Keildb9bb632009-05-22 11:04:53 +00002078 else
2079 HFC_outb(hc, A_CON_HDLC, 0x80 | 0x00 |
Joe Perches475be4d2012-02-19 19:52:38 -08002080 V_HDLC_TRP | V_IFF);
2081 HFC_outb_nodebug(hc, R_FIFO, ch << 1 | 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002082 HFC_wait_nodebug(hc);
Karsten Keildb9bb632009-05-22 11:04:53 +00002083 if (hc->ctype == HFC_TYPE_XHFC)
2084 HFC_outb(hc, A_CON_HDLC, 0x80
Joe Perches475be4d2012-02-19 19:52:38 -08002085 | 0x07 << 2 | V_HDLC_TRP | V_IFF);
2086 /* Enable FIFO, no interrupt */
Karsten Keildb9bb632009-05-22 11:04:53 +00002087 else
2088 HFC_outb(hc, A_CON_HDLC, 0x80 | 0x00 |
Joe Perches475be4d2012-02-19 19:52:38 -08002089 V_HDLC_TRP | V_IFF);
2090 HFC_outb_nodebug(hc, R_FIFO, ch << 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002091 HFC_wait_nodebug(hc);
2092 }
2093 *txpending = 1;
2094
2095 /* show activity */
2096 hc->activity[hc->chan[ch].port] = 1;
2097
2098 /* fill fifo to what we have left */
2099 ii = len;
2100 if (dch || test_bit(FLG_HDLC, &bch->Flags))
2101 temp = 1;
2102 else
2103 temp = 0;
2104 i = *idxp;
2105 d = (*sp)->data + i;
2106 if (ii - i > Zspace)
2107 ii = Zspace + i;
2108 if (debug & DEBUG_HFCMULTI_FIFO)
2109 printk(KERN_DEBUG "%s(card %d): fifo(%d) has %d bytes space "
Joe Perches475be4d2012-02-19 19:52:38 -08002110 "left (z1=%04x, z2=%04x) sending %d of %d bytes %s\n",
2111 __func__, hc->id + 1, ch, Zspace, z1, z2, ii-i, len-i,
2112 temp ? "HDLC" : "TRANS");
Karsten Keilaf69fb32008-07-27 02:00:43 +02002113
Karsten Keilaf69fb32008-07-27 02:00:43 +02002114 /* Have to prep the audio data */
2115 hc->write_fifo(hc, d, ii - i);
Andreas Eversberg7cfa1532009-05-22 11:04:46 +00002116 hc->chan[ch].Zfill += ii - i;
Karsten Keilaf69fb32008-07-27 02:00:43 +02002117 *idxp = ii;
2118
2119 /* if not all data has been written */
2120 if (ii != len) {
2121 /* NOTE: fifo is started by the calling function */
2122 return;
2123 }
2124
2125 /* if all data has been written, terminate frame */
2126 if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
2127 /* increment f-counter */
2128 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_INC_F);
2129 HFC_wait_nodebug(hc);
2130 }
2131
2132 /* send confirm, since get_net_bframe will not do it with trans */
2133 if (bch && test_bit(FLG_TRANSPARENT, &bch->Flags))
2134 confirm_Bsend(bch);
2135
2136 /* check for next frame */
2137 dev_kfree_skb(*sp);
2138 if (bch && get_next_bframe(bch)) { /* hdlc is confirmed here */
2139 len = (*sp)->len;
2140 goto next_frame;
2141 }
2142 if (dch && get_next_dframe(dch)) {
2143 len = (*sp)->len;
2144 goto next_frame;
2145 }
2146
2147 /*
2148 * now we have no more data, so in case of transparent,
2149 * we set the last byte in fifo to 'silence' in case we will get
2150 * no more data at all. this prevents sending an undefined value.
2151 */
2152 if (bch && test_bit(FLG_TRANSPARENT, &bch->Flags))
Andreas Eversberg8dd2f362008-08-02 22:51:52 +02002153 HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, hc->silence);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002154}
2155
2156
2157/* NOTE: only called if E1 card is in active state */
2158static void
2159hfcmulti_rx(struct hfc_multi *hc, int ch)
2160{
2161 int temp;
2162 int Zsize, z1, z2 = 0; /* = 0, to make GCC happy */
2163 int f1 = 0, f2 = 0; /* = 0, to make GCC happy */
2164 int again = 0;
2165 struct bchannel *bch;
2166 struct dchannel *dch;
2167 struct sk_buff *skb, **sp = NULL;
2168 int maxlen;
2169
2170 bch = hc->chan[ch].bch;
2171 dch = hc->chan[ch].dch;
2172 if ((!dch) && (!bch))
2173 return;
2174 if (dch) {
2175 if (!test_bit(FLG_ACTIVE, &dch->Flags))
2176 return;
2177 sp = &dch->rx_skb;
2178 maxlen = dch->maxlen;
2179 } else {
2180 if (!test_bit(FLG_ACTIVE, &bch->Flags))
2181 return;
2182 sp = &bch->rx_skb;
2183 maxlen = bch->maxlen;
2184 }
2185next_frame:
2186 /* on first AND before getting next valid frame, R_FIFO must be written
2187 to. */
2188 if (test_bit(HFC_CHIP_B410P, &hc->chip) &&
2189 (hc->chan[ch].protocol == ISDN_P_B_RAW) &&
2190 (hc->chan[ch].slot_rx < 0) &&
2191 (hc->chan[ch].slot_tx < 0))
Joe Perches475be4d2012-02-19 19:52:38 -08002192 HFC_outb_nodebug(hc, R_FIFO, 0x20 | (ch << 1) | 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002193 else
Joe Perches475be4d2012-02-19 19:52:38 -08002194 HFC_outb_nodebug(hc, R_FIFO, (ch << 1) | 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002195 HFC_wait_nodebug(hc);
2196
2197 /* ignore if rx is off BUT change fifo (above) to start pending TX */
2198 if (hc->chan[ch].rx_off)
2199 return;
2200
2201 if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
2202 f1 = HFC_inb_nodebug(hc, A_F1);
2203 while (f1 != (temp = HFC_inb_nodebug(hc, A_F1))) {
2204 if (debug & DEBUG_HFCMULTI_FIFO)
2205 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002206 "%s(card %d): reread f1 because %d!=%d\n",
2207 __func__, hc->id + 1, temp, f1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002208 f1 = temp; /* repeat until F1 is equal */
2209 }
2210 f2 = HFC_inb_nodebug(hc, A_F2);
2211 }
2212 z1 = HFC_inw_nodebug(hc, A_Z1) - hc->Zmin;
2213 while (z1 != (temp = (HFC_inw_nodebug(hc, A_Z1) - hc->Zmin))) {
2214 if (debug & DEBUG_HFCMULTI_FIFO)
2215 printk(KERN_DEBUG "%s(card %d): reread z2 because "
Joe Perches475be4d2012-02-19 19:52:38 -08002216 "%d!=%d\n", __func__, hc->id + 1, temp, z2);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002217 z1 = temp; /* repeat until Z1 is equal */
2218 }
2219 z2 = HFC_inw_nodebug(hc, A_Z2) - hc->Zmin;
2220 Zsize = z1 - z2;
2221 if ((dch || test_bit(FLG_HDLC, &bch->Flags)) && f1 != f2)
2222 /* complete hdlc frame */
2223 Zsize++;
2224 if (Zsize < 0)
2225 Zsize += hc->Zlen;
2226 /* if buffer is empty */
2227 if (Zsize <= 0)
2228 return;
2229
2230 if (*sp == NULL) {
2231 *sp = mI_alloc_skb(maxlen + 3, GFP_ATOMIC);
2232 if (*sp == NULL) {
2233 printk(KERN_DEBUG "%s: No mem for rx_skb\n",
Joe Perches475be4d2012-02-19 19:52:38 -08002234 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002235 return;
2236 }
2237 }
2238 /* show activity */
2239 hc->activity[hc->chan[ch].port] = 1;
2240
2241 /* empty fifo with what we have */
2242 if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
2243 if (debug & DEBUG_HFCMULTI_FIFO)
2244 printk(KERN_DEBUG "%s(card %d): fifo(%d) reading %d "
Joe Perches475be4d2012-02-19 19:52:38 -08002245 "bytes (z1=%04x, z2=%04x) HDLC %s (f1=%d, f2=%d) "
2246 "got=%d (again %d)\n", __func__, hc->id + 1, ch,
2247 Zsize, z1, z2, (f1 == f2) ? "fragment" : "COMPLETE",
2248 f1, f2, Zsize + (*sp)->len, again);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002249 /* HDLC */
2250 if ((Zsize + (*sp)->len) > (maxlen + 3)) {
2251 if (debug & DEBUG_HFCMULTI_FIFO)
2252 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002253 "%s(card %d): hdlc-frame too large.\n",
2254 __func__, hc->id + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002255 skb_trim(*sp, 0);
2256 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_RES_F);
2257 HFC_wait_nodebug(hc);
2258 return;
2259 }
2260
2261 hc->read_fifo(hc, skb_put(*sp, Zsize), Zsize);
2262
2263 if (f1 != f2) {
2264 /* increment Z2,F2-counter */
2265 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_INC_F);
2266 HFC_wait_nodebug(hc);
2267 /* check size */
2268 if ((*sp)->len < 4) {
2269 if (debug & DEBUG_HFCMULTI_FIFO)
2270 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002271 "%s(card %d): Frame below minimum "
2272 "size\n", __func__, hc->id + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002273 skb_trim(*sp, 0);
2274 goto next_frame;
2275 }
2276 /* there is at least one complete frame, check crc */
2277 if ((*sp)->data[(*sp)->len - 1]) {
2278 if (debug & DEBUG_HFCMULTI_CRC)
2279 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002280 "%s: CRC-error\n", __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002281 skb_trim(*sp, 0);
2282 goto next_frame;
2283 }
2284 skb_trim(*sp, (*sp)->len - 3);
2285 if ((*sp)->len < MISDN_COPY_SIZE) {
2286 skb = *sp;
2287 *sp = mI_alloc_skb(skb->len, GFP_ATOMIC);
2288 if (*sp) {
2289 memcpy(skb_put(*sp, skb->len),
Joe Perches475be4d2012-02-19 19:52:38 -08002290 skb->data, skb->len);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002291 skb_trim(skb, 0);
2292 } else {
2293 printk(KERN_DEBUG "%s: No mem\n",
Joe Perches475be4d2012-02-19 19:52:38 -08002294 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002295 *sp = skb;
2296 skb = NULL;
2297 }
2298 } else {
2299 skb = NULL;
2300 }
2301 if (debug & DEBUG_HFCMULTI_FIFO) {
2302 printk(KERN_DEBUG "%s(card %d):",
Joe Perches475be4d2012-02-19 19:52:38 -08002303 __func__, hc->id + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002304 temp = 0;
2305 while (temp < (*sp)->len)
2306 printk(" %02x", (*sp)->data[temp++]);
2307 printk("\n");
2308 }
2309 if (dch)
2310 recv_Dchannel(dch);
2311 else
Andreas Eversberg7cfa1532009-05-22 11:04:46 +00002312 recv_Bchannel(bch, MISDN_ID_ANY);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002313 *sp = skb;
2314 again++;
2315 goto next_frame;
2316 }
2317 /* there is an incomplete frame */
2318 } else {
2319 /* transparent */
2320 if (Zsize > skb_tailroom(*sp))
2321 Zsize = skb_tailroom(*sp);
2322 hc->read_fifo(hc, skb_put(*sp, Zsize), Zsize);
2323 if (((*sp)->len) < MISDN_COPY_SIZE) {
2324 skb = *sp;
2325 *sp = mI_alloc_skb(skb->len, GFP_ATOMIC);
2326 if (*sp) {
2327 memcpy(skb_put(*sp, skb->len),
Joe Perches475be4d2012-02-19 19:52:38 -08002328 skb->data, skb->len);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002329 skb_trim(skb, 0);
2330 } else {
2331 printk(KERN_DEBUG "%s: No mem\n", __func__);
2332 *sp = skb;
2333 skb = NULL;
2334 }
2335 } else {
2336 skb = NULL;
2337 }
2338 if (debug & DEBUG_HFCMULTI_FIFO)
2339 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002340 "%s(card %d): fifo(%d) reading %d bytes "
2341 "(z1=%04x, z2=%04x) TRANS\n",
2342 __func__, hc->id + 1, ch, Zsize, z1, z2);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002343 /* only bch is transparent */
Andreas Eversberg7cfa1532009-05-22 11:04:46 +00002344 recv_Bchannel(bch, hc->chan[ch].Zfill);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002345 *sp = skb;
2346 }
2347}
2348
2349
2350/*
2351 * Interrupt handler
2352 */
2353static void
2354signal_state_up(struct dchannel *dch, int info, char *msg)
2355{
2356 struct sk_buff *skb;
2357 int id, data = info;
2358
2359 if (debug & DEBUG_HFCMULTI_STATE)
2360 printk(KERN_DEBUG "%s: %s\n", __func__, msg);
2361
2362 id = TEI_SAPI | (GROUP_TEI << 8); /* manager address */
2363
2364 skb = _alloc_mISDN_skb(MPH_INFORMATION_IND, id, sizeof(data), &data,
Joe Perches475be4d2012-02-19 19:52:38 -08002365 GFP_ATOMIC);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002366 if (!skb)
2367 return;
2368 recv_Dchannel_skb(dch, skb);
2369}
2370
2371static inline void
2372handle_timer_irq(struct hfc_multi *hc)
2373{
2374 int ch, temp;
2375 struct dchannel *dch;
2376 u_long flags;
2377
2378 /* process queued resync jobs */
2379 if (hc->e1_resync) {
2380 /* lock, so e1_resync gets not changed */
2381 spin_lock_irqsave(&HFClock, flags);
2382 if (hc->e1_resync & 1) {
2383 if (debug & DEBUG_HFCMULTI_PLXSD)
2384 printk(KERN_DEBUG "Enable SYNC_I\n");
2385 HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC);
2386 /* disable JATT, if RX_SYNC is set */
2387 if (test_bit(HFC_CHIP_RX_SYNC, &hc->chip))
2388 HFC_outb(hc, R_SYNC_OUT, V_SYNC_E1_RX);
2389 }
2390 if (hc->e1_resync & 2) {
2391 if (debug & DEBUG_HFCMULTI_PLXSD)
2392 printk(KERN_DEBUG "Enable jatt PLL\n");
2393 HFC_outb(hc, R_SYNC_CTRL, V_SYNC_OFFS);
2394 }
2395 if (hc->e1_resync & 4) {
2396 if (debug & DEBUG_HFCMULTI_PLXSD)
2397 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002398 "Enable QUARTZ for HFC-E1\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02002399 /* set jatt to quartz */
2400 HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC
Joe Perches475be4d2012-02-19 19:52:38 -08002401 | V_JATT_OFF);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002402 /* switch to JATT, in case it is not already */
2403 HFC_outb(hc, R_SYNC_OUT, 0);
2404 }
2405 hc->e1_resync = 0;
2406 spin_unlock_irqrestore(&HFClock, flags);
2407 }
2408
Karsten Keildb9bb632009-05-22 11:04:53 +00002409 if (hc->ctype != HFC_TYPE_E1 || hc->e1_state == 1)
Karsten Keilaf69fb32008-07-27 02:00:43 +02002410 for (ch = 0; ch <= 31; ch++) {
2411 if (hc->created[hc->chan[ch].port]) {
2412 hfcmulti_tx(hc, ch);
2413 /* fifo is started when switching to rx-fifo */
2414 hfcmulti_rx(hc, ch);
2415 if (hc->chan[ch].dch &&
2416 hc->chan[ch].nt_timer > -1) {
2417 dch = hc->chan[ch].dch;
2418 if (!(--hc->chan[ch].nt_timer)) {
2419 schedule_event(dch,
Joe Perches475be4d2012-02-19 19:52:38 -08002420 FLG_PHCHANGE);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002421 if (debug &
2422 DEBUG_HFCMULTI_STATE)
2423 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002424 "%s: nt_timer at "
2425 "state %x\n",
2426 __func__,
2427 dch->state);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002428 }
2429 }
2430 }
2431 }
Karsten Keildb9bb632009-05-22 11:04:53 +00002432 if (hc->ctype == HFC_TYPE_E1 && hc->created[0]) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02002433 dch = hc->chan[hc->dslot].dch;
2434 if (test_bit(HFC_CFG_REPORT_LOS, &hc->chan[hc->dslot].cfg)) {
2435 /* LOS */
2436 temp = HFC_inb_nodebug(hc, R_SYNC_STA) & V_SIG_LOS;
2437 if (!temp && hc->chan[hc->dslot].los)
2438 signal_state_up(dch, L1_SIGNAL_LOS_ON,
Joe Perches475be4d2012-02-19 19:52:38 -08002439 "LOS detected");
Karsten Keilaf69fb32008-07-27 02:00:43 +02002440 if (temp && !hc->chan[hc->dslot].los)
2441 signal_state_up(dch, L1_SIGNAL_LOS_OFF,
Joe Perches475be4d2012-02-19 19:52:38 -08002442 "LOS gone");
Karsten Keilaf69fb32008-07-27 02:00:43 +02002443 hc->chan[hc->dslot].los = temp;
2444 }
2445 if (test_bit(HFC_CFG_REPORT_AIS, &hc->chan[hc->dslot].cfg)) {
2446 /* AIS */
2447 temp = HFC_inb_nodebug(hc, R_SYNC_STA) & V_AIS;
2448 if (!temp && hc->chan[hc->dslot].ais)
2449 signal_state_up(dch, L1_SIGNAL_AIS_ON,
Joe Perches475be4d2012-02-19 19:52:38 -08002450 "AIS detected");
Karsten Keilaf69fb32008-07-27 02:00:43 +02002451 if (temp && !hc->chan[hc->dslot].ais)
2452 signal_state_up(dch, L1_SIGNAL_AIS_OFF,
Joe Perches475be4d2012-02-19 19:52:38 -08002453 "AIS gone");
Karsten Keilaf69fb32008-07-27 02:00:43 +02002454 hc->chan[hc->dslot].ais = temp;
2455 }
2456 if (test_bit(HFC_CFG_REPORT_SLIP, &hc->chan[hc->dslot].cfg)) {
2457 /* SLIP */
2458 temp = HFC_inb_nodebug(hc, R_SLIP) & V_FOSLIP_RX;
2459 if (!temp && hc->chan[hc->dslot].slip_rx)
2460 signal_state_up(dch, L1_SIGNAL_SLIP_RX,
Joe Perches475be4d2012-02-19 19:52:38 -08002461 " bit SLIP detected RX");
Karsten Keilaf69fb32008-07-27 02:00:43 +02002462 hc->chan[hc->dslot].slip_rx = temp;
2463 temp = HFC_inb_nodebug(hc, R_SLIP) & V_FOSLIP_TX;
2464 if (!temp && hc->chan[hc->dslot].slip_tx)
2465 signal_state_up(dch, L1_SIGNAL_SLIP_TX,
Joe Perches475be4d2012-02-19 19:52:38 -08002466 " bit SLIP detected TX");
Karsten Keilaf69fb32008-07-27 02:00:43 +02002467 hc->chan[hc->dslot].slip_tx = temp;
2468 }
2469 if (test_bit(HFC_CFG_REPORT_RDI, &hc->chan[hc->dslot].cfg)) {
2470 /* RDI */
2471 temp = HFC_inb_nodebug(hc, R_RX_SL0_0) & V_A;
2472 if (!temp && hc->chan[hc->dslot].rdi)
2473 signal_state_up(dch, L1_SIGNAL_RDI_ON,
Joe Perches475be4d2012-02-19 19:52:38 -08002474 "RDI detected");
Karsten Keilaf69fb32008-07-27 02:00:43 +02002475 if (temp && !hc->chan[hc->dslot].rdi)
2476 signal_state_up(dch, L1_SIGNAL_RDI_OFF,
Joe Perches475be4d2012-02-19 19:52:38 -08002477 "RDI gone");
Karsten Keilaf69fb32008-07-27 02:00:43 +02002478 hc->chan[hc->dslot].rdi = temp;
2479 }
2480 temp = HFC_inb_nodebug(hc, R_JATT_DIR);
2481 switch (hc->chan[hc->dslot].sync) {
2482 case 0:
2483 if ((temp & 0x60) == 0x60) {
2484 if (debug & DEBUG_HFCMULTI_SYNC)
2485 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002486 "%s: (id=%d) E1 now "
2487 "in clock sync\n",
2488 __func__, hc->id);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002489 HFC_outb(hc, R_RX_OFF,
Joe Perches475be4d2012-02-19 19:52:38 -08002490 hc->chan[hc->dslot].jitter | V_RX_INIT);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002491 HFC_outb(hc, R_TX_OFF,
Joe Perches475be4d2012-02-19 19:52:38 -08002492 hc->chan[hc->dslot].jitter | V_RX_INIT);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002493 hc->chan[hc->dslot].sync = 1;
2494 goto check_framesync;
2495 }
2496 break;
2497 case 1:
2498 if ((temp & 0x60) != 0x60) {
2499 if (debug & DEBUG_HFCMULTI_SYNC)
2500 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002501 "%s: (id=%d) E1 "
2502 "lost clock sync\n",
2503 __func__, hc->id);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002504 hc->chan[hc->dslot].sync = 0;
2505 break;
2506 }
Joe Perches475be4d2012-02-19 19:52:38 -08002507 check_framesync:
Karsten Keilaf69fb32008-07-27 02:00:43 +02002508 temp = HFC_inb_nodebug(hc, R_SYNC_STA);
2509 if (temp == 0x27) {
2510 if (debug & DEBUG_HFCMULTI_SYNC)
2511 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002512 "%s: (id=%d) E1 "
2513 "now in frame sync\n",
2514 __func__, hc->id);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002515 hc->chan[hc->dslot].sync = 2;
2516 }
2517 break;
2518 case 2:
2519 if ((temp & 0x60) != 0x60) {
2520 if (debug & DEBUG_HFCMULTI_SYNC)
2521 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002522 "%s: (id=%d) E1 lost "
2523 "clock & frame sync\n",
2524 __func__, hc->id);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002525 hc->chan[hc->dslot].sync = 0;
2526 break;
2527 }
2528 temp = HFC_inb_nodebug(hc, R_SYNC_STA);
2529 if (temp != 0x27) {
2530 if (debug & DEBUG_HFCMULTI_SYNC)
2531 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002532 "%s: (id=%d) E1 "
2533 "lost frame sync\n",
2534 __func__, hc->id);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002535 hc->chan[hc->dslot].sync = 1;
2536 }
2537 break;
2538 }
2539 }
2540
2541 if (test_bit(HFC_CHIP_WATCHDOG, &hc->chip))
2542 hfcmulti_watchdog(hc);
2543
2544 if (hc->leds)
2545 hfcmulti_leds(hc);
2546}
2547
2548static void
2549ph_state_irq(struct hfc_multi *hc, u_char r_irq_statech)
2550{
2551 struct dchannel *dch;
2552 int ch;
2553 int active;
2554 u_char st_status, temp;
2555
2556 /* state machine */
2557 for (ch = 0; ch <= 31; ch++) {
2558 if (hc->chan[ch].dch) {
2559 dch = hc->chan[ch].dch;
2560 if (r_irq_statech & 1) {
2561 HFC_outb_nodebug(hc, R_ST_SEL,
Joe Perches475be4d2012-02-19 19:52:38 -08002562 hc->chan[ch].port);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002563 /* undocumented: delay after R_ST_SEL */
2564 udelay(1);
2565 /* undocumented: status changes during read */
2566 st_status = HFC_inb_nodebug(hc, A_ST_RD_STATE);
2567 while (st_status != (temp =
Joe Perches475be4d2012-02-19 19:52:38 -08002568 HFC_inb_nodebug(hc, A_ST_RD_STATE))) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02002569 if (debug & DEBUG_HFCMULTI_STATE)
2570 printk(KERN_DEBUG "%s: reread "
Joe Perches475be4d2012-02-19 19:52:38 -08002571 "STATE because %d!=%d\n",
2572 __func__, temp,
2573 st_status);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002574 st_status = temp; /* repeat */
2575 }
2576
2577 /* Speech Design TE-sync indication */
2578 if (test_bit(HFC_CHIP_PLXSD, &hc->chip) &&
Joe Perches475be4d2012-02-19 19:52:38 -08002579 dch->dev.D.protocol == ISDN_P_TE_S0) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02002580 if (st_status & V_FR_SYNC_ST)
2581 hc->syncronized |=
Joe Perches475be4d2012-02-19 19:52:38 -08002582 (1 << hc->chan[ch].port);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002583 else
2584 hc->syncronized &=
Joe Perches475be4d2012-02-19 19:52:38 -08002585 ~(1 << hc->chan[ch].port);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002586 }
2587 dch->state = st_status & 0x0f;
2588 if (dch->dev.D.protocol == ISDN_P_NT_S0)
2589 active = 3;
2590 else
2591 active = 7;
2592 if (dch->state == active) {
2593 HFC_outb_nodebug(hc, R_FIFO,
Joe Perches475be4d2012-02-19 19:52:38 -08002594 (ch << 1) | 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002595 HFC_wait_nodebug(hc);
2596 HFC_outb_nodebug(hc,
Joe Perches475be4d2012-02-19 19:52:38 -08002597 R_INC_RES_FIFO, V_RES_F);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002598 HFC_wait_nodebug(hc);
2599 dch->tx_idx = 0;
2600 }
2601 schedule_event(dch, FLG_PHCHANGE);
2602 if (debug & DEBUG_HFCMULTI_STATE)
2603 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002604 "%s: S/T newstate %x port %d\n",
2605 __func__, dch->state,
2606 hc->chan[ch].port);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002607 }
2608 r_irq_statech >>= 1;
2609 }
2610 }
2611 if (test_bit(HFC_CHIP_PLXSD, &hc->chip))
2612 plxsd_checksync(hc, 0);
2613}
2614
2615static void
2616fifo_irq(struct hfc_multi *hc, int block)
2617{
2618 int ch, j;
2619 struct dchannel *dch;
2620 struct bchannel *bch;
2621 u_char r_irq_fifo_bl;
2622
2623 r_irq_fifo_bl = HFC_inb_nodebug(hc, R_IRQ_FIFO_BL0 + block);
2624 j = 0;
2625 while (j < 8) {
2626 ch = (block << 2) + (j >> 1);
2627 dch = hc->chan[ch].dch;
2628 bch = hc->chan[ch].bch;
2629 if (((!dch) && (!bch)) || (!hc->created[hc->chan[ch].port])) {
2630 j += 2;
2631 continue;
2632 }
2633 if (dch && (r_irq_fifo_bl & (1 << j)) &&
2634 test_bit(FLG_ACTIVE, &dch->Flags)) {
2635 hfcmulti_tx(hc, ch);
2636 /* start fifo */
2637 HFC_outb_nodebug(hc, R_FIFO, 0);
2638 HFC_wait_nodebug(hc);
2639 }
2640 if (bch && (r_irq_fifo_bl & (1 << j)) &&
2641 test_bit(FLG_ACTIVE, &bch->Flags)) {
2642 hfcmulti_tx(hc, ch);
2643 /* start fifo */
2644 HFC_outb_nodebug(hc, R_FIFO, 0);
2645 HFC_wait_nodebug(hc);
2646 }
2647 j++;
2648 if (dch && (r_irq_fifo_bl & (1 << j)) &&
2649 test_bit(FLG_ACTIVE, &dch->Flags)) {
2650 hfcmulti_rx(hc, ch);
2651 }
2652 if (bch && (r_irq_fifo_bl & (1 << j)) &&
2653 test_bit(FLG_ACTIVE, &bch->Flags)) {
2654 hfcmulti_rx(hc, ch);
2655 }
2656 j++;
2657 }
2658}
2659
2660#ifdef IRQ_DEBUG
2661int irqsem;
2662#endif
2663static irqreturn_t
2664hfcmulti_interrupt(int intno, void *dev_id)
2665{
2666#ifdef IRQCOUNT_DEBUG
2667 static int iq1 = 0, iq2 = 0, iq3 = 0, iq4 = 0,
Joe Perches475be4d2012-02-19 19:52:38 -08002668 iq5 = 0, iq6 = 0, iqcnt = 0;
Karsten Keilaf69fb32008-07-27 02:00:43 +02002669#endif
Karsten Keilaf69fb32008-07-27 02:00:43 +02002670 struct hfc_multi *hc = dev_id;
2671 struct dchannel *dch;
2672 u_char r_irq_statech, status, r_irq_misc, r_irq_oview;
2673 int i;
Hannes Ederc31655f2008-12-12 21:20:03 -08002674 void __iomem *plx_acc;
2675 u_short wval;
Karsten Keilaf69fb32008-07-27 02:00:43 +02002676 u_char e1_syncsta, temp;
2677 u_long flags;
2678
2679 if (!hc) {
2680 printk(KERN_ERR "HFC-multi: Spurious interrupt!\n");
2681 return IRQ_NONE;
2682 }
2683
2684 spin_lock(&hc->lock);
2685
2686#ifdef IRQ_DEBUG
2687 if (irqsem)
2688 printk(KERN_ERR "irq for card %d during irq from "
Joe Perches475be4d2012-02-19 19:52:38 -08002689 "card %d, this is no bug.\n", hc->id + 1, irqsem);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002690 irqsem = hc->id + 1;
2691#endif
Karsten Keildb9bb632009-05-22 11:04:53 +00002692#ifdef CONFIG_MISDN_HFCMULTI_8xx
2693 if (hc->immap->im_cpm.cp_pbdat & hc->pb_irqmsk)
2694 goto irq_notforus;
2695#endif
Karsten Keilaf69fb32008-07-27 02:00:43 +02002696 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
2697 spin_lock_irqsave(&plx_lock, flags);
Hannes Ederc31655f2008-12-12 21:20:03 -08002698 plx_acc = hc->plx_membase + PLX_INTCSR;
Karsten Keilaf69fb32008-07-27 02:00:43 +02002699 wval = readw(plx_acc);
2700 spin_unlock_irqrestore(&plx_lock, flags);
2701 if (!(wval & PLX_INTCSR_LINTI1_STATUS))
2702 goto irq_notforus;
2703 }
2704
2705 status = HFC_inb_nodebug(hc, R_STATUS);
2706 r_irq_statech = HFC_inb_nodebug(hc, R_IRQ_STATECH);
2707#ifdef IRQCOUNT_DEBUG
2708 if (r_irq_statech)
2709 iq1++;
2710 if (status & V_DTMF_STA)
2711 iq2++;
2712 if (status & V_LOST_STA)
2713 iq3++;
2714 if (status & V_EXT_IRQSTA)
2715 iq4++;
2716 if (status & V_MISC_IRQSTA)
2717 iq5++;
2718 if (status & V_FR_IRQSTA)
2719 iq6++;
2720 if (iqcnt++ > 5000) {
2721 printk(KERN_ERR "iq1:%x iq2:%x iq3:%x iq4:%x iq5:%x iq6:%x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08002722 iq1, iq2, iq3, iq4, iq5, iq6);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002723 iqcnt = 0;
2724 }
2725#endif
Andreas Eversberg3bd69ad2008-09-06 09:03:46 +02002726
Karsten Keilaf69fb32008-07-27 02:00:43 +02002727 if (!r_irq_statech &&
2728 !(status & (V_DTMF_STA | V_LOST_STA | V_EXT_IRQSTA |
Joe Perches475be4d2012-02-19 19:52:38 -08002729 V_MISC_IRQSTA | V_FR_IRQSTA))) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02002730 /* irq is not for us */
2731 goto irq_notforus;
2732 }
2733 hc->irqcnt++;
2734 if (r_irq_statech) {
Karsten Keildb9bb632009-05-22 11:04:53 +00002735 if (hc->ctype != HFC_TYPE_E1)
Karsten Keilaf69fb32008-07-27 02:00:43 +02002736 ph_state_irq(hc, r_irq_statech);
2737 }
2738 if (status & V_EXT_IRQSTA)
2739 ; /* external IRQ */
2740 if (status & V_LOST_STA) {
2741 /* LOST IRQ */
2742 HFC_outb(hc, R_INC_RES_FIFO, V_RES_LOST); /* clear irq! */
2743 }
2744 if (status & V_MISC_IRQSTA) {
2745 /* misc IRQ */
2746 r_irq_misc = HFC_inb_nodebug(hc, R_IRQ_MISC);
Andreas Eversberg9e6115f2008-09-06 09:11:03 +02002747 r_irq_misc &= hc->hw.r_irqmsk_misc; /* ignore disabled irqs */
Karsten Keilaf69fb32008-07-27 02:00:43 +02002748 if (r_irq_misc & V_STA_IRQ) {
Karsten Keildb9bb632009-05-22 11:04:53 +00002749 if (hc->ctype == HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02002750 /* state machine */
2751 dch = hc->chan[hc->dslot].dch;
2752 e1_syncsta = HFC_inb_nodebug(hc, R_SYNC_STA);
2753 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)
Joe Perches475be4d2012-02-19 19:52:38 -08002754 && hc->e1_getclock) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02002755 if (e1_syncsta & V_FR_SYNC_E1)
2756 hc->syncronized = 1;
2757 else
2758 hc->syncronized = 0;
2759 }
2760 /* undocumented: status changes during read */
2761 dch->state = HFC_inb_nodebug(hc, R_E1_RD_STA);
2762 while (dch->state != (temp =
Joe Perches475be4d2012-02-19 19:52:38 -08002763 HFC_inb_nodebug(hc, R_E1_RD_STA))) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02002764 if (debug & DEBUG_HFCMULTI_STATE)
2765 printk(KERN_DEBUG "%s: reread "
Joe Perches475be4d2012-02-19 19:52:38 -08002766 "STATE because %d!=%d\n",
2767 __func__, temp,
2768 dch->state);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002769 dch->state = temp; /* repeat */
2770 }
2771 dch->state = HFC_inb_nodebug(hc, R_E1_RD_STA)
2772 & 0x7;
2773 schedule_event(dch, FLG_PHCHANGE);
2774 if (debug & DEBUG_HFCMULTI_STATE)
2775 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002776 "%s: E1 (id=%d) newstate %x\n",
2777 __func__, hc->id, dch->state);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002778 if (test_bit(HFC_CHIP_PLXSD, &hc->chip))
2779 plxsd_checksync(hc, 0);
2780 }
2781 }
Andreas Eversberg3bd69ad2008-09-06 09:03:46 +02002782 if (r_irq_misc & V_TI_IRQ) {
2783 if (hc->iclock_on)
2784 mISDN_clock_update(hc->iclock, poll, NULL);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002785 handle_timer_irq(hc);
Andreas Eversberg3bd69ad2008-09-06 09:03:46 +02002786 }
Karsten Keilaf69fb32008-07-27 02:00:43 +02002787
Karsten Keileac74af2009-05-22 11:04:56 +00002788 if (r_irq_misc & V_DTMF_IRQ)
Karsten Keilaf69fb32008-07-27 02:00:43 +02002789 hfcmulti_dtmf(hc);
Karsten Keileac74af2009-05-22 11:04:56 +00002790
Karsten Keilaf69fb32008-07-27 02:00:43 +02002791 if (r_irq_misc & V_IRQ_PROC) {
Karsten Keil69e656c2009-01-07 00:00:59 +01002792 static int irq_proc_cnt;
2793 if (!irq_proc_cnt++)
Karsten Keileac74af2009-05-22 11:04:56 +00002794 printk(KERN_DEBUG "%s: got V_IRQ_PROC -"
Joe Perches475be4d2012-02-19 19:52:38 -08002795 " this should not happen\n", __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002796 }
2797
2798 }
2799 if (status & V_FR_IRQSTA) {
2800 /* FIFO IRQ */
2801 r_irq_oview = HFC_inb_nodebug(hc, R_IRQ_OVIEW);
2802 for (i = 0; i < 8; i++) {
2803 if (r_irq_oview & (1 << i))
2804 fifo_irq(hc, i);
2805 }
2806 }
2807
2808#ifdef IRQ_DEBUG
2809 irqsem = 0;
2810#endif
2811 spin_unlock(&hc->lock);
2812 return IRQ_HANDLED;
2813
2814irq_notforus:
2815#ifdef IRQ_DEBUG
2816 irqsem = 0;
2817#endif
2818 spin_unlock(&hc->lock);
2819 return IRQ_NONE;
2820}
2821
2822
2823/*
2824 * timer callback for D-chan busy resolution. Currently no function
2825 */
2826
2827static void
2828hfcmulti_dbusy_timer(struct hfc_multi *hc)
2829{
2830}
2831
2832
2833/*
2834 * activate/deactivate hardware for selected channels and mode
2835 *
2836 * configure B-channel with the given protocol
2837 * ch eqals to the HFC-channel (0-31)
2838 * ch is the number of channel (0-4,4-7,8-11,12-15,16-19,20-23,24-27,28-31
2839 * for S/T, 1-31 for E1)
2840 * the hdlc interrupts will be set/unset
2841 */
2842static int
2843mode_hfcmulti(struct hfc_multi *hc, int ch, int protocol, int slot_tx,
Joe Perches475be4d2012-02-19 19:52:38 -08002844 int bank_tx, int slot_rx, int bank_rx)
Karsten Keilaf69fb32008-07-27 02:00:43 +02002845{
2846 int flow_tx = 0, flow_rx = 0, routing = 0;
2847 int oslot_tx, oslot_rx;
2848 int conf;
2849
2850 if (ch < 0 || ch > 31)
Roel Kluin650b2ef2010-02-02 12:43:47 +00002851 return -EINVAL;
Karsten Keilaf69fb32008-07-27 02:00:43 +02002852 oslot_tx = hc->chan[ch].slot_tx;
2853 oslot_rx = hc->chan[ch].slot_rx;
2854 conf = hc->chan[ch].conf;
2855
2856 if (debug & DEBUG_HFCMULTI_MODE)
2857 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002858 "%s: card %d channel %d protocol %x slot old=%d new=%d "
2859 "bank new=%d (TX) slot old=%d new=%d bank new=%d (RX)\n",
2860 __func__, hc->id, ch, protocol, oslot_tx, slot_tx,
2861 bank_tx, oslot_rx, slot_rx, bank_rx);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002862
2863 if (oslot_tx >= 0 && slot_tx != oslot_tx) {
2864 /* remove from slot */
2865 if (debug & DEBUG_HFCMULTI_MODE)
2866 printk(KERN_DEBUG "%s: remove from slot %d (TX)\n",
Joe Perches475be4d2012-02-19 19:52:38 -08002867 __func__, oslot_tx);
2868 if (hc->slot_owner[oslot_tx << 1] == ch) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02002869 HFC_outb(hc, R_SLOT, oslot_tx << 1);
2870 HFC_outb(hc, A_SL_CFG, 0);
Karsten Keildb9bb632009-05-22 11:04:53 +00002871 if (hc->ctype != HFC_TYPE_XHFC)
2872 HFC_outb(hc, A_CONF, 0);
Joe Perches475be4d2012-02-19 19:52:38 -08002873 hc->slot_owner[oslot_tx << 1] = -1;
Karsten Keilaf69fb32008-07-27 02:00:43 +02002874 } else {
2875 if (debug & DEBUG_HFCMULTI_MODE)
2876 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002877 "%s: we are not owner of this tx slot "
2878 "anymore, channel %d is.\n",
2879 __func__, hc->slot_owner[oslot_tx << 1]);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002880 }
2881 }
2882
2883 if (oslot_rx >= 0 && slot_rx != oslot_rx) {
2884 /* remove from slot */
2885 if (debug & DEBUG_HFCMULTI_MODE)
2886 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002887 "%s: remove from slot %d (RX)\n",
2888 __func__, oslot_rx);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002889 if (hc->slot_owner[(oslot_rx << 1) | 1] == ch) {
2890 HFC_outb(hc, R_SLOT, (oslot_rx << 1) | V_SL_DIR);
2891 HFC_outb(hc, A_SL_CFG, 0);
2892 hc->slot_owner[(oslot_rx << 1) | 1] = -1;
2893 } else {
2894 if (debug & DEBUG_HFCMULTI_MODE)
2895 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002896 "%s: we are not owner of this rx slot "
2897 "anymore, channel %d is.\n",
2898 __func__,
2899 hc->slot_owner[(oslot_rx << 1) | 1]);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002900 }
2901 }
2902
2903 if (slot_tx < 0) {
2904 flow_tx = 0x80; /* FIFO->ST */
2905 /* disable pcm slot */
2906 hc->chan[ch].slot_tx = -1;
2907 hc->chan[ch].bank_tx = 0;
2908 } else {
2909 /* set pcm slot */
2910 if (hc->chan[ch].txpending)
2911 flow_tx = 0x80; /* FIFO->ST */
2912 else
2913 flow_tx = 0xc0; /* PCM->ST */
2914 /* put on slot */
2915 routing = bank_tx ? 0xc0 : 0x80;
2916 if (conf >= 0 || bank_tx > 1)
2917 routing = 0x40; /* loop */
2918 if (debug & DEBUG_HFCMULTI_MODE)
2919 printk(KERN_DEBUG "%s: put channel %d to slot %d bank"
Joe Perches475be4d2012-02-19 19:52:38 -08002920 " %d flow %02x routing %02x conf %d (TX)\n",
2921 __func__, ch, slot_tx, bank_tx,
2922 flow_tx, routing, conf);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002923 HFC_outb(hc, R_SLOT, slot_tx << 1);
Joe Perches475be4d2012-02-19 19:52:38 -08002924 HFC_outb(hc, A_SL_CFG, (ch << 1) | routing);
Karsten Keildb9bb632009-05-22 11:04:53 +00002925 if (hc->ctype != HFC_TYPE_XHFC)
2926 HFC_outb(hc, A_CONF,
Joe Perches475be4d2012-02-19 19:52:38 -08002927 (conf < 0) ? 0 : (conf | V_CONF_SL));
Karsten Keilaf69fb32008-07-27 02:00:43 +02002928 hc->slot_owner[slot_tx << 1] = ch;
2929 hc->chan[ch].slot_tx = slot_tx;
2930 hc->chan[ch].bank_tx = bank_tx;
2931 }
2932 if (slot_rx < 0) {
2933 /* disable pcm slot */
2934 flow_rx = 0x80; /* ST->FIFO */
2935 hc->chan[ch].slot_rx = -1;
2936 hc->chan[ch].bank_rx = 0;
2937 } else {
2938 /* set pcm slot */
2939 if (hc->chan[ch].txpending)
2940 flow_rx = 0x80; /* ST->FIFO */
2941 else
2942 flow_rx = 0xc0; /* ST->(FIFO,PCM) */
2943 /* put on slot */
Karsten Keileac74af2009-05-22 11:04:56 +00002944 routing = bank_rx ? 0x80 : 0xc0; /* reversed */
Karsten Keilaf69fb32008-07-27 02:00:43 +02002945 if (conf >= 0 || bank_rx > 1)
2946 routing = 0x40; /* loop */
2947 if (debug & DEBUG_HFCMULTI_MODE)
2948 printk(KERN_DEBUG "%s: put channel %d to slot %d bank"
Joe Perches475be4d2012-02-19 19:52:38 -08002949 " %d flow %02x routing %02x conf %d (RX)\n",
2950 __func__, ch, slot_rx, bank_rx,
2951 flow_rx, routing, conf);
2952 HFC_outb(hc, R_SLOT, (slot_rx << 1) | V_SL_DIR);
2953 HFC_outb(hc, A_SL_CFG, (ch << 1) | V_CH_DIR | routing);
2954 hc->slot_owner[(slot_rx << 1) | 1] = ch;
Karsten Keilaf69fb32008-07-27 02:00:43 +02002955 hc->chan[ch].slot_rx = slot_rx;
2956 hc->chan[ch].bank_rx = bank_rx;
2957 }
2958
2959 switch (protocol) {
2960 case (ISDN_P_NONE):
2961 /* disable TX fifo */
2962 HFC_outb(hc, R_FIFO, ch << 1);
2963 HFC_wait(hc);
2964 HFC_outb(hc, A_CON_HDLC, flow_tx | 0x00 | V_IFF);
2965 HFC_outb(hc, A_SUBCH_CFG, 0);
2966 HFC_outb(hc, A_IRQ_MSK, 0);
2967 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
2968 HFC_wait(hc);
2969 /* disable RX fifo */
Joe Perches475be4d2012-02-19 19:52:38 -08002970 HFC_outb(hc, R_FIFO, (ch << 1) | 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002971 HFC_wait(hc);
2972 HFC_outb(hc, A_CON_HDLC, flow_rx | 0x00);
2973 HFC_outb(hc, A_SUBCH_CFG, 0);
2974 HFC_outb(hc, A_IRQ_MSK, 0);
2975 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
2976 HFC_wait(hc);
Karsten Keildb9bb632009-05-22 11:04:53 +00002977 if (hc->chan[ch].bch && hc->ctype != HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02002978 hc->hw.a_st_ctrl0[hc->chan[ch].port] &=
Joe Perches475be4d2012-02-19 19:52:38 -08002979 ((ch & 0x3) == 0) ? ~V_B1_EN : ~V_B2_EN;
Karsten Keilaf69fb32008-07-27 02:00:43 +02002980 HFC_outb(hc, R_ST_SEL, hc->chan[ch].port);
2981 /* undocumented: delay after R_ST_SEL */
2982 udelay(1);
2983 HFC_outb(hc, A_ST_CTRL0,
Joe Perches475be4d2012-02-19 19:52:38 -08002984 hc->hw.a_st_ctrl0[hc->chan[ch].port]);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002985 }
2986 if (hc->chan[ch].bch) {
2987 test_and_clear_bit(FLG_HDLC, &hc->chan[ch].bch->Flags);
2988 test_and_clear_bit(FLG_TRANSPARENT,
Joe Perches475be4d2012-02-19 19:52:38 -08002989 &hc->chan[ch].bch->Flags);
Karsten Keilaf69fb32008-07-27 02:00:43 +02002990 }
2991 break;
2992 case (ISDN_P_B_RAW): /* B-channel */
2993
2994 if (test_bit(HFC_CHIP_B410P, &hc->chip) &&
2995 (hc->chan[ch].slot_rx < 0) &&
2996 (hc->chan[ch].slot_tx < 0)) {
2997
2998 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08002999 "Setting B-channel %d to echo cancelable "
3000 "state on PCM slot %d\n", ch,
3001 ((ch / 4) * 8) + ((ch % 4) * 4) + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003002 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003003 "Enabling pass through for channel\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02003004 vpm_out(hc, ch, ((ch / 4) * 8) +
Joe Perches475be4d2012-02-19 19:52:38 -08003005 ((ch % 4) * 4) + 1, 0x01);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003006 /* rx path */
3007 /* S/T -> PCM */
3008 HFC_outb(hc, R_FIFO, (ch << 1));
3009 HFC_wait(hc);
3010 HFC_outb(hc, A_CON_HDLC, 0xc0 | V_HDLC_TRP | V_IFF);
3011 HFC_outb(hc, R_SLOT, (((ch / 4) * 8) +
Joe Perches475be4d2012-02-19 19:52:38 -08003012 ((ch % 4) * 4) + 1) << 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003013 HFC_outb(hc, A_SL_CFG, 0x80 | (ch << 1));
3014
3015 /* PCM -> FIFO */
3016 HFC_outb(hc, R_FIFO, 0x20 | (ch << 1) | 1);
3017 HFC_wait(hc);
3018 HFC_outb(hc, A_CON_HDLC, 0x20 | V_HDLC_TRP | V_IFF);
3019 HFC_outb(hc, A_SUBCH_CFG, 0);
3020 HFC_outb(hc, A_IRQ_MSK, 0);
Andreas Eversberga4d729d2012-04-24 20:52:11 +00003021 if (hc->chan[ch].protocol != protocol) {
3022 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
3023 HFC_wait(hc);
3024 }
Karsten Keilaf69fb32008-07-27 02:00:43 +02003025 HFC_outb(hc, R_SLOT, ((((ch / 4) * 8) +
Joe Perches475be4d2012-02-19 19:52:38 -08003026 ((ch % 4) * 4) + 1) << 1) | 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003027 HFC_outb(hc, A_SL_CFG, 0x80 | 0x20 | (ch << 1) | 1);
3028
3029 /* tx path */
3030 /* PCM -> S/T */
3031 HFC_outb(hc, R_FIFO, (ch << 1) | 1);
3032 HFC_wait(hc);
3033 HFC_outb(hc, A_CON_HDLC, 0xc0 | V_HDLC_TRP | V_IFF);
3034 HFC_outb(hc, R_SLOT, ((((ch / 4) * 8) +
Joe Perches475be4d2012-02-19 19:52:38 -08003035 ((ch % 4) * 4)) << 1) | 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003036 HFC_outb(hc, A_SL_CFG, 0x80 | 0x40 | (ch << 1) | 1);
3037
3038 /* FIFO -> PCM */
3039 HFC_outb(hc, R_FIFO, 0x20 | (ch << 1));
3040 HFC_wait(hc);
3041 HFC_outb(hc, A_CON_HDLC, 0x20 | V_HDLC_TRP | V_IFF);
3042 HFC_outb(hc, A_SUBCH_CFG, 0);
3043 HFC_outb(hc, A_IRQ_MSK, 0);
Andreas Eversberga4d729d2012-04-24 20:52:11 +00003044 if (hc->chan[ch].protocol != protocol) {
3045 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
3046 HFC_wait(hc);
3047 }
Karsten Keilaf69fb32008-07-27 02:00:43 +02003048 /* tx silence */
Andreas Eversberg8dd2f362008-08-02 22:51:52 +02003049 HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, hc->silence);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003050 HFC_outb(hc, R_SLOT, (((ch / 4) * 8) +
Joe Perches475be4d2012-02-19 19:52:38 -08003051 ((ch % 4) * 4)) << 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003052 HFC_outb(hc, A_SL_CFG, 0x80 | 0x20 | (ch << 1));
3053 } else {
3054 /* enable TX fifo */
3055 HFC_outb(hc, R_FIFO, ch << 1);
3056 HFC_wait(hc);
Karsten Keildb9bb632009-05-22 11:04:53 +00003057 if (hc->ctype == HFC_TYPE_XHFC)
3058 HFC_outb(hc, A_CON_HDLC, flow_tx | 0x07 << 2 |
Joe Perches475be4d2012-02-19 19:52:38 -08003059 V_HDLC_TRP | V_IFF);
3060 /* Enable FIFO, no interrupt */
Karsten Keildb9bb632009-05-22 11:04:53 +00003061 else
3062 HFC_outb(hc, A_CON_HDLC, flow_tx | 0x00 |
Joe Perches475be4d2012-02-19 19:52:38 -08003063 V_HDLC_TRP | V_IFF);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003064 HFC_outb(hc, A_SUBCH_CFG, 0);
3065 HFC_outb(hc, A_IRQ_MSK, 0);
Andreas Eversberga4d729d2012-04-24 20:52:11 +00003066 if (hc->chan[ch].protocol != protocol) {
3067 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
3068 HFC_wait(hc);
3069 }
Karsten Keilaf69fb32008-07-27 02:00:43 +02003070 /* tx silence */
Andreas Eversberg8dd2f362008-08-02 22:51:52 +02003071 HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, hc->silence);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003072 /* enable RX fifo */
Joe Perches475be4d2012-02-19 19:52:38 -08003073 HFC_outb(hc, R_FIFO, (ch << 1) | 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003074 HFC_wait(hc);
Karsten Keildb9bb632009-05-22 11:04:53 +00003075 if (hc->ctype == HFC_TYPE_XHFC)
3076 HFC_outb(hc, A_CON_HDLC, flow_rx | 0x07 << 2 |
Joe Perches475be4d2012-02-19 19:52:38 -08003077 V_HDLC_TRP);
3078 /* Enable FIFO, no interrupt*/
Karsten Keildb9bb632009-05-22 11:04:53 +00003079 else
3080 HFC_outb(hc, A_CON_HDLC, flow_rx | 0x00 |
Joe Perches475be4d2012-02-19 19:52:38 -08003081 V_HDLC_TRP);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003082 HFC_outb(hc, A_SUBCH_CFG, 0);
3083 HFC_outb(hc, A_IRQ_MSK, 0);
Andreas Eversberga4d729d2012-04-24 20:52:11 +00003084 if (hc->chan[ch].protocol != protocol) {
3085 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
3086 HFC_wait(hc);
3087 }
Karsten Keilaf69fb32008-07-27 02:00:43 +02003088 }
Karsten Keildb9bb632009-05-22 11:04:53 +00003089 if (hc->ctype != HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02003090 hc->hw.a_st_ctrl0[hc->chan[ch].port] |=
Joe Perches475be4d2012-02-19 19:52:38 -08003091 ((ch & 0x3) == 0) ? V_B1_EN : V_B2_EN;
Karsten Keilaf69fb32008-07-27 02:00:43 +02003092 HFC_outb(hc, R_ST_SEL, hc->chan[ch].port);
3093 /* undocumented: delay after R_ST_SEL */
3094 udelay(1);
3095 HFC_outb(hc, A_ST_CTRL0,
Joe Perches475be4d2012-02-19 19:52:38 -08003096 hc->hw.a_st_ctrl0[hc->chan[ch].port]);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003097 }
3098 if (hc->chan[ch].bch)
3099 test_and_set_bit(FLG_TRANSPARENT,
Joe Perches475be4d2012-02-19 19:52:38 -08003100 &hc->chan[ch].bch->Flags);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003101 break;
3102 case (ISDN_P_B_HDLC): /* B-channel */
3103 case (ISDN_P_TE_S0): /* D-channel */
3104 case (ISDN_P_NT_S0):
3105 case (ISDN_P_TE_E1):
3106 case (ISDN_P_NT_E1):
3107 /* enable TX fifo */
Joe Perches475be4d2012-02-19 19:52:38 -08003108 HFC_outb(hc, R_FIFO, ch << 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003109 HFC_wait(hc);
Karsten Keildb9bb632009-05-22 11:04:53 +00003110 if (hc->ctype == HFC_TYPE_E1 || hc->chan[ch].bch) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02003111 /* E1 or B-channel */
3112 HFC_outb(hc, A_CON_HDLC, flow_tx | 0x04);
3113 HFC_outb(hc, A_SUBCH_CFG, 0);
3114 } else {
3115 /* D-Channel without HDLC fill flags */
3116 HFC_outb(hc, A_CON_HDLC, flow_tx | 0x04 | V_IFF);
3117 HFC_outb(hc, A_SUBCH_CFG, 2);
3118 }
3119 HFC_outb(hc, A_IRQ_MSK, V_IRQ);
3120 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
3121 HFC_wait(hc);
3122 /* enable RX fifo */
Joe Perches475be4d2012-02-19 19:52:38 -08003123 HFC_outb(hc, R_FIFO, (ch << 1) | 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003124 HFC_wait(hc);
3125 HFC_outb(hc, A_CON_HDLC, flow_rx | 0x04);
Karsten Keildb9bb632009-05-22 11:04:53 +00003126 if (hc->ctype == HFC_TYPE_E1 || hc->chan[ch].bch)
Karsten Keilaf69fb32008-07-27 02:00:43 +02003127 HFC_outb(hc, A_SUBCH_CFG, 0); /* full 8 bits */
3128 else
3129 HFC_outb(hc, A_SUBCH_CFG, 2); /* 2 bits dchannel */
3130 HFC_outb(hc, A_IRQ_MSK, V_IRQ);
3131 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
3132 HFC_wait(hc);
3133 if (hc->chan[ch].bch) {
3134 test_and_set_bit(FLG_HDLC, &hc->chan[ch].bch->Flags);
Karsten Keildb9bb632009-05-22 11:04:53 +00003135 if (hc->ctype != HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02003136 hc->hw.a_st_ctrl0[hc->chan[ch].port] |=
Joe Perches475be4d2012-02-19 19:52:38 -08003137 ((ch & 0x3) == 0) ? V_B1_EN : V_B2_EN;
Karsten Keilaf69fb32008-07-27 02:00:43 +02003138 HFC_outb(hc, R_ST_SEL, hc->chan[ch].port);
3139 /* undocumented: delay after R_ST_SEL */
3140 udelay(1);
3141 HFC_outb(hc, A_ST_CTRL0,
Joe Perches475be4d2012-02-19 19:52:38 -08003142 hc->hw.a_st_ctrl0[hc->chan[ch].port]);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003143 }
3144 }
3145 break;
3146 default:
3147 printk(KERN_DEBUG "%s: protocol not known %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003148 __func__, protocol);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003149 hc->chan[ch].protocol = ISDN_P_NONE;
3150 return -ENOPROTOOPT;
3151 }
3152 hc->chan[ch].protocol = protocol;
3153 return 0;
3154}
3155
3156
3157/*
3158 * connect/disconnect PCM
3159 */
3160
3161static void
3162hfcmulti_pcm(struct hfc_multi *hc, int ch, int slot_tx, int bank_tx,
Joe Perches475be4d2012-02-19 19:52:38 -08003163 int slot_rx, int bank_rx)
Karsten Keilaf69fb32008-07-27 02:00:43 +02003164{
Julia Lawall073bd902009-12-21 14:25:32 +00003165 if (slot_tx < 0 || slot_rx < 0 || bank_tx < 0 || bank_rx < 0) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02003166 /* disable PCM */
3167 mode_hfcmulti(hc, ch, hc->chan[ch].protocol, -1, 0, -1, 0);
3168 return;
3169 }
3170
3171 /* enable pcm */
3172 mode_hfcmulti(hc, ch, hc->chan[ch].protocol, slot_tx, bank_tx,
Joe Perches475be4d2012-02-19 19:52:38 -08003173 slot_rx, bank_rx);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003174}
3175
3176/*
3177 * set/disable conference
3178 */
3179
3180static void
3181hfcmulti_conf(struct hfc_multi *hc, int ch, int num)
3182{
3183 if (num >= 0 && num <= 7)
3184 hc->chan[ch].conf = num;
3185 else
3186 hc->chan[ch].conf = -1;
3187 mode_hfcmulti(hc, ch, hc->chan[ch].protocol, hc->chan[ch].slot_tx,
Joe Perches475be4d2012-02-19 19:52:38 -08003188 hc->chan[ch].bank_tx, hc->chan[ch].slot_rx,
3189 hc->chan[ch].bank_rx);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003190}
3191
3192
3193/*
3194 * set/disable sample loop
3195 */
3196
3197/* NOTE: this function is experimental and therefore disabled */
3198
3199/*
3200 * Layer 1 callback function
3201 */
3202static int
3203hfcm_l1callback(struct dchannel *dch, u_int cmd)
3204{
3205 struct hfc_multi *hc = dch->hw;
3206 u_long flags;
3207
3208 switch (cmd) {
3209 case INFO3_P8:
3210 case INFO3_P10:
3211 break;
3212 case HW_RESET_REQ:
3213 /* start activation */
3214 spin_lock_irqsave(&hc->lock, flags);
Karsten Keildb9bb632009-05-22 11:04:53 +00003215 if (hc->ctype == HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02003216 if (debug & DEBUG_HFCMULTI_MSG)
3217 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003218 "%s: HW_RESET_REQ no BRI\n",
3219 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003220 } else {
3221 HFC_outb(hc, R_ST_SEL, hc->chan[dch->slot].port);
3222 /* undocumented: delay after R_ST_SEL */
3223 udelay(1);
3224 HFC_outb(hc, A_ST_WR_STATE, V_ST_LD_STA | 3); /* F3 */
3225 udelay(6); /* wait at least 5,21us */
3226 HFC_outb(hc, A_ST_WR_STATE, 3);
Joe Perches475be4d2012-02-19 19:52:38 -08003227 HFC_outb(hc, A_ST_WR_STATE, 3 | (V_ST_ACT * 3));
3228 /* activate */
Karsten Keilaf69fb32008-07-27 02:00:43 +02003229 }
3230 spin_unlock_irqrestore(&hc->lock, flags);
3231 l1_event(dch->l1, HW_POWERUP_IND);
3232 break;
3233 case HW_DEACT_REQ:
3234 /* start deactivation */
3235 spin_lock_irqsave(&hc->lock, flags);
Karsten Keildb9bb632009-05-22 11:04:53 +00003236 if (hc->ctype == HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02003237 if (debug & DEBUG_HFCMULTI_MSG)
3238 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003239 "%s: HW_DEACT_REQ no BRI\n",
3240 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003241 } else {
3242 HFC_outb(hc, R_ST_SEL, hc->chan[dch->slot].port);
3243 /* undocumented: delay after R_ST_SEL */
3244 udelay(1);
Joe Perches475be4d2012-02-19 19:52:38 -08003245 HFC_outb(hc, A_ST_WR_STATE, V_ST_ACT * 2);
3246 /* deactivate */
Karsten Keilaf69fb32008-07-27 02:00:43 +02003247 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
3248 hc->syncronized &=
Joe Perches475be4d2012-02-19 19:52:38 -08003249 ~(1 << hc->chan[dch->slot].port);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003250 plxsd_checksync(hc, 0);
3251 }
3252 }
3253 skb_queue_purge(&dch->squeue);
3254 if (dch->tx_skb) {
3255 dev_kfree_skb(dch->tx_skb);
3256 dch->tx_skb = NULL;
3257 }
3258 dch->tx_idx = 0;
3259 if (dch->rx_skb) {
3260 dev_kfree_skb(dch->rx_skb);
3261 dch->rx_skb = NULL;
3262 }
3263 test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
3264 if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags))
3265 del_timer(&dch->timer);
3266 spin_unlock_irqrestore(&hc->lock, flags);
3267 break;
3268 case HW_POWERUP_REQ:
3269 spin_lock_irqsave(&hc->lock, flags);
Karsten Keildb9bb632009-05-22 11:04:53 +00003270 if (hc->ctype == HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02003271 if (debug & DEBUG_HFCMULTI_MSG)
3272 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003273 "%s: HW_POWERUP_REQ no BRI\n",
3274 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003275 } else {
3276 HFC_outb(hc, R_ST_SEL, hc->chan[dch->slot].port);
3277 /* undocumented: delay after R_ST_SEL */
3278 udelay(1);
3279 HFC_outb(hc, A_ST_WR_STATE, 3 | 0x10); /* activate */
3280 udelay(6); /* wait at least 5,21us */
3281 HFC_outb(hc, A_ST_WR_STATE, 3); /* activate */
3282 }
3283 spin_unlock_irqrestore(&hc->lock, flags);
3284 break;
3285 case PH_ACTIVATE_IND:
3286 test_and_set_bit(FLG_ACTIVE, &dch->Flags);
3287 _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL,
Joe Perches475be4d2012-02-19 19:52:38 -08003288 GFP_ATOMIC);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003289 break;
3290 case PH_DEACTIVATE_IND:
3291 test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
3292 _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL,
Joe Perches475be4d2012-02-19 19:52:38 -08003293 GFP_ATOMIC);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003294 break;
3295 default:
3296 if (dch->debug & DEBUG_HW)
3297 printk(KERN_DEBUG "%s: unknown command %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003298 __func__, cmd);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003299 return -1;
3300 }
3301 return 0;
3302}
3303
3304/*
3305 * Layer2 -> Layer 1 Transfer
3306 */
3307
3308static int
3309handle_dmsg(struct mISDNchannel *ch, struct sk_buff *skb)
3310{
3311 struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
3312 struct dchannel *dch = container_of(dev, struct dchannel, dev);
3313 struct hfc_multi *hc = dch->hw;
3314 struct mISDNhead *hh = mISDN_HEAD_P(skb);
3315 int ret = -EINVAL;
3316 unsigned int id;
3317 u_long flags;
3318
3319 switch (hh->prim) {
3320 case PH_DATA_REQ:
3321 if (skb->len < 1)
3322 break;
3323 spin_lock_irqsave(&hc->lock, flags);
3324 ret = dchannel_senddata(dch, skb);
3325 if (ret > 0) { /* direct TX */
3326 id = hh->id; /* skb can be freed */
3327 hfcmulti_tx(hc, dch->slot);
3328 ret = 0;
3329 /* start fifo */
3330 HFC_outb(hc, R_FIFO, 0);
3331 HFC_wait(hc);
3332 spin_unlock_irqrestore(&hc->lock, flags);
3333 queue_ch_frame(ch, PH_DATA_CNF, id, NULL);
3334 } else
3335 spin_unlock_irqrestore(&hc->lock, flags);
3336 return ret;
3337 case PH_ACTIVATE_REQ:
3338 if (dch->dev.D.protocol != ISDN_P_TE_S0) {
3339 spin_lock_irqsave(&hc->lock, flags);
3340 ret = 0;
3341 if (debug & DEBUG_HFCMULTI_MSG)
3342 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003343 "%s: PH_ACTIVATE port %d (0..%d)\n",
3344 __func__, hc->chan[dch->slot].port,
3345 hc->ports - 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003346 /* start activation */
Karsten Keildb9bb632009-05-22 11:04:53 +00003347 if (hc->ctype == HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02003348 ph_state_change(dch);
3349 if (debug & DEBUG_HFCMULTI_STATE)
3350 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003351 "%s: E1 report state %x \n",
3352 __func__, dch->state);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003353 } else {
3354 HFC_outb(hc, R_ST_SEL,
Joe Perches475be4d2012-02-19 19:52:38 -08003355 hc->chan[dch->slot].port);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003356 /* undocumented: delay after R_ST_SEL */
3357 udelay(1);
3358 HFC_outb(hc, A_ST_WR_STATE, V_ST_LD_STA | 1);
Joe Perches475be4d2012-02-19 19:52:38 -08003359 /* G1 */
Karsten Keilaf69fb32008-07-27 02:00:43 +02003360 udelay(6); /* wait at least 5,21us */
3361 HFC_outb(hc, A_ST_WR_STATE, 1);
3362 HFC_outb(hc, A_ST_WR_STATE, 1 |
Joe Perches475be4d2012-02-19 19:52:38 -08003363 (V_ST_ACT * 3)); /* activate */
Karsten Keilaf69fb32008-07-27 02:00:43 +02003364 dch->state = 1;
3365 }
3366 spin_unlock_irqrestore(&hc->lock, flags);
3367 } else
3368 ret = l1_event(dch->l1, hh->prim);
3369 break;
3370 case PH_DEACTIVATE_REQ:
3371 test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags);
3372 if (dch->dev.D.protocol != ISDN_P_TE_S0) {
3373 spin_lock_irqsave(&hc->lock, flags);
3374 if (debug & DEBUG_HFCMULTI_MSG)
3375 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003376 "%s: PH_DEACTIVATE port %d (0..%d)\n",
3377 __func__, hc->chan[dch->slot].port,
3378 hc->ports - 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003379 /* start deactivation */
Karsten Keildb9bb632009-05-22 11:04:53 +00003380 if (hc->ctype == HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02003381 if (debug & DEBUG_HFCMULTI_MSG)
3382 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003383 "%s: PH_DEACTIVATE no BRI\n",
3384 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003385 } else {
3386 HFC_outb(hc, R_ST_SEL,
Joe Perches475be4d2012-02-19 19:52:38 -08003387 hc->chan[dch->slot].port);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003388 /* undocumented: delay after R_ST_SEL */
3389 udelay(1);
3390 HFC_outb(hc, A_ST_WR_STATE, V_ST_ACT * 2);
Joe Perches475be4d2012-02-19 19:52:38 -08003391 /* deactivate */
Karsten Keilaf69fb32008-07-27 02:00:43 +02003392 dch->state = 1;
3393 }
3394 skb_queue_purge(&dch->squeue);
3395 if (dch->tx_skb) {
3396 dev_kfree_skb(dch->tx_skb);
3397 dch->tx_skb = NULL;
3398 }
3399 dch->tx_idx = 0;
3400 if (dch->rx_skb) {
3401 dev_kfree_skb(dch->rx_skb);
3402 dch->rx_skb = NULL;
3403 }
3404 test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
3405 if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags))
3406 del_timer(&dch->timer);
3407#ifdef FIXME
3408 if (test_and_clear_bit(FLG_L1_BUSY, &dch->Flags))
3409 dchannel_sched_event(&hc->dch, D_CLEARBUSY);
3410#endif
3411 ret = 0;
3412 spin_unlock_irqrestore(&hc->lock, flags);
3413 } else
3414 ret = l1_event(dch->l1, hh->prim);
3415 break;
3416 }
3417 if (!ret)
3418 dev_kfree_skb(skb);
3419 return ret;
3420}
3421
3422static void
3423deactivate_bchannel(struct bchannel *bch)
3424{
3425 struct hfc_multi *hc = bch->hw;
3426 u_long flags;
3427
3428 spin_lock_irqsave(&hc->lock, flags);
Karsten Keilfb286f02009-07-09 10:02:29 +02003429 mISDN_clear_bchannel(bch);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003430 hc->chan[bch->slot].coeff_count = 0;
Karsten Keilaf69fb32008-07-27 02:00:43 +02003431 hc->chan[bch->slot].rx_off = 0;
3432 hc->chan[bch->slot].conf = -1;
3433 mode_hfcmulti(hc, bch->slot, ISDN_P_NONE, -1, 0, -1, 0);
3434 spin_unlock_irqrestore(&hc->lock, flags);
3435}
3436
3437static int
3438handle_bmsg(struct mISDNchannel *ch, struct sk_buff *skb)
3439{
3440 struct bchannel *bch = container_of(ch, struct bchannel, ch);
3441 struct hfc_multi *hc = bch->hw;
3442 int ret = -EINVAL;
3443 struct mISDNhead *hh = mISDN_HEAD_P(skb);
3444 unsigned int id;
3445 u_long flags;
3446
3447 switch (hh->prim) {
3448 case PH_DATA_REQ:
3449 if (!skb->len)
3450 break;
3451 spin_lock_irqsave(&hc->lock, flags);
3452 ret = bchannel_senddata(bch, skb);
3453 if (ret > 0) { /* direct TX */
3454 id = hh->id; /* skb can be freed */
3455 hfcmulti_tx(hc, bch->slot);
3456 ret = 0;
3457 /* start fifo */
3458 HFC_outb_nodebug(hc, R_FIFO, 0);
3459 HFC_wait_nodebug(hc);
3460 if (!test_bit(FLG_TRANSPARENT, &bch->Flags)) {
3461 spin_unlock_irqrestore(&hc->lock, flags);
3462 queue_ch_frame(ch, PH_DATA_CNF, id, NULL);
3463 } else
3464 spin_unlock_irqrestore(&hc->lock, flags);
3465 } else
3466 spin_unlock_irqrestore(&hc->lock, flags);
3467 return ret;
3468 case PH_ACTIVATE_REQ:
3469 if (debug & DEBUG_HFCMULTI_MSG)
3470 printk(KERN_DEBUG "%s: PH_ACTIVATE ch %d (0..32)\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003471 __func__, bch->slot);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003472 spin_lock_irqsave(&hc->lock, flags);
3473 /* activate B-channel if not already activated */
3474 if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags)) {
3475 hc->chan[bch->slot].txpending = 0;
3476 ret = mode_hfcmulti(hc, bch->slot,
Joe Perches475be4d2012-02-19 19:52:38 -08003477 ch->protocol,
3478 hc->chan[bch->slot].slot_tx,
3479 hc->chan[bch->slot].bank_tx,
3480 hc->chan[bch->slot].slot_rx,
3481 hc->chan[bch->slot].bank_rx);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003482 if (!ret) {
3483 if (ch->protocol == ISDN_P_B_RAW && !hc->dtmf
Joe Perches475be4d2012-02-19 19:52:38 -08003484 && test_bit(HFC_CHIP_DTMF, &hc->chip)) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02003485 /* start decoder */
3486 hc->dtmf = 1;
3487 if (debug & DEBUG_HFCMULTI_DTMF)
3488 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003489 "%s: start dtmf decoder\n",
3490 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003491 HFC_outb(hc, R_DTMF, hc->hw.r_dtmf |
Joe Perches475be4d2012-02-19 19:52:38 -08003492 V_RST_DTMF);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003493 }
3494 }
3495 } else
3496 ret = 0;
3497 spin_unlock_irqrestore(&hc->lock, flags);
3498 if (!ret)
3499 _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 0, NULL,
Joe Perches475be4d2012-02-19 19:52:38 -08003500 GFP_KERNEL);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003501 break;
3502 case PH_CONTROL_REQ:
3503 spin_lock_irqsave(&hc->lock, flags);
3504 switch (hh->id) {
3505 case HFC_SPL_LOOP_ON: /* set sample loop */
3506 if (debug & DEBUG_HFCMULTI_MSG)
Karsten Keileac74af2009-05-22 11:04:56 +00003507 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003508 "%s: HFC_SPL_LOOP_ON (len = %d)\n",
3509 __func__, skb->len);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003510 ret = 0;
3511 break;
3512 case HFC_SPL_LOOP_OFF: /* set silence */
3513 if (debug & DEBUG_HFCMULTI_MSG)
3514 printk(KERN_DEBUG "%s: HFC_SPL_LOOP_OFF\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003515 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003516 ret = 0;
3517 break;
3518 default:
3519 printk(KERN_ERR
Joe Perches475be4d2012-02-19 19:52:38 -08003520 "%s: unknown PH_CONTROL_REQ info %x\n",
3521 __func__, hh->id);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003522 ret = -EINVAL;
3523 }
3524 spin_unlock_irqrestore(&hc->lock, flags);
3525 break;
3526 case PH_DEACTIVATE_REQ:
3527 deactivate_bchannel(bch); /* locked there */
3528 _queue_data(ch, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0, NULL,
Joe Perches475be4d2012-02-19 19:52:38 -08003529 GFP_KERNEL);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003530 ret = 0;
3531 break;
3532 }
3533 if (!ret)
3534 dev_kfree_skb(skb);
3535 return ret;
3536}
3537
3538/*
3539 * bchannel control function
3540 */
3541static int
3542channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)
3543{
3544 int ret = 0;
3545 struct dsp_features *features =
3546 (struct dsp_features *)(*((u_long *)&cq->p1));
3547 struct hfc_multi *hc = bch->hw;
3548 int slot_tx;
3549 int bank_tx;
3550 int slot_rx;
3551 int bank_rx;
3552 int num;
3553
3554 switch (cq->op) {
3555 case MISDN_CTRL_GETOP:
3556 cq->op = MISDN_CTRL_HFC_OP | MISDN_CTRL_HW_FEATURES_OP
Andreas Eversberg8dd2f362008-08-02 22:51:52 +02003557 | MISDN_CTRL_RX_OFF | MISDN_CTRL_FILL_EMPTY;
Karsten Keilaf69fb32008-07-27 02:00:43 +02003558 break;
3559 case MISDN_CTRL_RX_OFF: /* turn off / on rx stream */
3560 hc->chan[bch->slot].rx_off = !!cq->p1;
3561 if (!hc->chan[bch->slot].rx_off) {
3562 /* reset fifo on rx on */
3563 HFC_outb_nodebug(hc, R_FIFO, (bch->slot << 1) | 1);
3564 HFC_wait_nodebug(hc);
3565 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_RES_F);
3566 HFC_wait_nodebug(hc);
3567 }
3568 if (debug & DEBUG_HFCMULTI_MSG)
3569 printk(KERN_DEBUG "%s: RX_OFF request (nr=%d off=%d)\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003570 __func__, bch->nr, hc->chan[bch->slot].rx_off);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003571 break;
Andreas Eversberg8dd2f362008-08-02 22:51:52 +02003572 case MISDN_CTRL_FILL_EMPTY: /* fill fifo, if empty */
3573 test_and_set_bit(FLG_FILLEMPTY, &bch->Flags);
3574 if (debug & DEBUG_HFCMULTI_MSG)
3575 printk(KERN_DEBUG "%s: FILL_EMPTY request (nr=%d "
Joe Perches475be4d2012-02-19 19:52:38 -08003576 "off=%d)\n", __func__, bch->nr, !!cq->p1);
Andreas Eversberg8dd2f362008-08-02 22:51:52 +02003577 break;
Karsten Keilaf69fb32008-07-27 02:00:43 +02003578 case MISDN_CTRL_HW_FEATURES: /* fill features structure */
3579 if (debug & DEBUG_HFCMULTI_MSG)
3580 printk(KERN_DEBUG "%s: HW_FEATURE request\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003581 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003582 /* create confirm */
3583 features->hfc_id = hc->id;
3584 if (test_bit(HFC_CHIP_DTMF, &hc->chip))
3585 features->hfc_dtmf = 1;
Karsten Keildb9bb632009-05-22 11:04:53 +00003586 if (test_bit(HFC_CHIP_CONF, &hc->chip))
3587 features->hfc_conf = 1;
Karsten Keilaf69fb32008-07-27 02:00:43 +02003588 features->hfc_loops = 0;
3589 if (test_bit(HFC_CHIP_B410P, &hc->chip)) {
3590 features->hfc_echocanhw = 1;
3591 } else {
3592 features->pcm_id = hc->pcm;
3593 features->pcm_slots = hc->slots;
3594 features->pcm_banks = 2;
3595 }
3596 break;
3597 case MISDN_CTRL_HFC_PCM_CONN: /* connect to pcm timeslot (0..N) */
3598 slot_tx = cq->p1 & 0xff;
3599 bank_tx = cq->p1 >> 8;
3600 slot_rx = cq->p2 & 0xff;
3601 bank_rx = cq->p2 >> 8;
3602 if (debug & DEBUG_HFCMULTI_MSG)
3603 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003604 "%s: HFC_PCM_CONN slot %d bank %d (TX) "
3605 "slot %d bank %d (RX)\n",
3606 __func__, slot_tx, bank_tx,
3607 slot_rx, bank_rx);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003608 if (slot_tx < hc->slots && bank_tx <= 2 &&
3609 slot_rx < hc->slots && bank_rx <= 2)
3610 hfcmulti_pcm(hc, bch->slot,
Joe Perches475be4d2012-02-19 19:52:38 -08003611 slot_tx, bank_tx, slot_rx, bank_rx);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003612 else {
3613 printk(KERN_WARNING
Joe Perches475be4d2012-02-19 19:52:38 -08003614 "%s: HFC_PCM_CONN slot %d bank %d (TX) "
3615 "slot %d bank %d (RX) out of range\n",
3616 __func__, slot_tx, bank_tx,
3617 slot_rx, bank_rx);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003618 ret = -EINVAL;
3619 }
3620 break;
3621 case MISDN_CTRL_HFC_PCM_DISC: /* release interface from pcm timeslot */
3622 if (debug & DEBUG_HFCMULTI_MSG)
3623 printk(KERN_DEBUG "%s: HFC_PCM_DISC\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003624 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003625 hfcmulti_pcm(hc, bch->slot, -1, 0, -1, 0);
3626 break;
3627 case MISDN_CTRL_HFC_CONF_JOIN: /* join conference (0..7) */
3628 num = cq->p1 & 0xff;
3629 if (debug & DEBUG_HFCMULTI_MSG)
3630 printk(KERN_DEBUG "%s: HFC_CONF_JOIN conf %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003631 __func__, num);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003632 if (num <= 7)
3633 hfcmulti_conf(hc, bch->slot, num);
3634 else {
3635 printk(KERN_WARNING
Joe Perches475be4d2012-02-19 19:52:38 -08003636 "%s: HW_CONF_JOIN conf %d out of range\n",
3637 __func__, num);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003638 ret = -EINVAL;
3639 }
3640 break;
3641 case MISDN_CTRL_HFC_CONF_SPLIT: /* split conference */
3642 if (debug & DEBUG_HFCMULTI_MSG)
3643 printk(KERN_DEBUG "%s: HFC_CONF_SPLIT\n", __func__);
3644 hfcmulti_conf(hc, bch->slot, -1);
3645 break;
3646 case MISDN_CTRL_HFC_ECHOCAN_ON:
3647 if (debug & DEBUG_HFCMULTI_MSG)
3648 printk(KERN_DEBUG "%s: HFC_ECHOCAN_ON\n", __func__);
3649 if (test_bit(HFC_CHIP_B410P, &hc->chip))
3650 vpm_echocan_on(hc, bch->slot, cq->p1);
3651 else
3652 ret = -EINVAL;
3653 break;
3654
3655 case MISDN_CTRL_HFC_ECHOCAN_OFF:
3656 if (debug & DEBUG_HFCMULTI_MSG)
3657 printk(KERN_DEBUG "%s: HFC_ECHOCAN_OFF\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003658 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003659 if (test_bit(HFC_CHIP_B410P, &hc->chip))
3660 vpm_echocan_off(hc, bch->slot);
3661 else
3662 ret = -EINVAL;
3663 break;
3664 default:
3665 printk(KERN_WARNING "%s: unknown Op %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003666 __func__, cq->op);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003667 ret = -EINVAL;
3668 break;
3669 }
3670 return ret;
3671}
3672
3673static int
3674hfcm_bctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
3675{
3676 struct bchannel *bch = container_of(ch, struct bchannel, ch);
3677 struct hfc_multi *hc = bch->hw;
3678 int err = -EINVAL;
3679 u_long flags;
3680
3681 if (bch->debug & DEBUG_HW)
3682 printk(KERN_DEBUG "%s: cmd:%x %p\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003683 __func__, cmd, arg);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003684 switch (cmd) {
3685 case CLOSE_CHANNEL:
3686 test_and_clear_bit(FLG_OPEN, &bch->Flags);
3687 if (test_bit(FLG_ACTIVE, &bch->Flags))
3688 deactivate_bchannel(bch); /* locked there */
3689 ch->protocol = ISDN_P_NONE;
3690 ch->peer = NULL;
3691 module_put(THIS_MODULE);
3692 err = 0;
3693 break;
3694 case CONTROL_CHANNEL:
3695 spin_lock_irqsave(&hc->lock, flags);
3696 err = channel_bctrl(bch, arg);
3697 spin_unlock_irqrestore(&hc->lock, flags);
3698 break;
3699 default:
3700 printk(KERN_WARNING "%s: unknown prim(%x)\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003701 __func__, cmd);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003702 }
3703 return err;
3704}
3705
3706/*
3707 * handle D-channel events
3708 *
3709 * handle state change event
3710 */
3711static void
3712ph_state_change(struct dchannel *dch)
3713{
Julia Lawall20b78802009-01-09 12:22:53 -08003714 struct hfc_multi *hc;
Karsten Keilaf69fb32008-07-27 02:00:43 +02003715 int ch, i;
3716
3717 if (!dch) {
Karsten Keileac74af2009-05-22 11:04:56 +00003718 printk(KERN_WARNING "%s: ERROR given dch is NULL\n", __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003719 return;
3720 }
Julia Lawall20b78802009-01-09 12:22:53 -08003721 hc = dch->hw;
Karsten Keilaf69fb32008-07-27 02:00:43 +02003722 ch = dch->slot;
3723
Karsten Keildb9bb632009-05-22 11:04:53 +00003724 if (hc->ctype == HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02003725 if (dch->dev.D.protocol == ISDN_P_TE_E1) {
3726 if (debug & DEBUG_HFCMULTI_STATE)
3727 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003728 "%s: E1 TE (id=%d) newstate %x\n",
3729 __func__, hc->id, dch->state);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003730 } else {
3731 if (debug & DEBUG_HFCMULTI_STATE)
3732 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003733 "%s: E1 NT (id=%d) newstate %x\n",
3734 __func__, hc->id, dch->state);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003735 }
3736 switch (dch->state) {
3737 case (1):
3738 if (hc->e1_state != 1) {
Karsten Keileac74af2009-05-22 11:04:56 +00003739 for (i = 1; i <= 31; i++) {
3740 /* reset fifos on e1 activation */
3741 HFC_outb_nodebug(hc, R_FIFO,
Joe Perches475be4d2012-02-19 19:52:38 -08003742 (i << 1) | 1);
Karsten Keileac74af2009-05-22 11:04:56 +00003743 HFC_wait_nodebug(hc);
3744 HFC_outb_nodebug(hc, R_INC_RES_FIFO,
Joe Perches475be4d2012-02-19 19:52:38 -08003745 V_RES_F);
Karsten Keileac74af2009-05-22 11:04:56 +00003746 HFC_wait_nodebug(hc);
3747 }
Karsten Keilaf69fb32008-07-27 02:00:43 +02003748 }
3749 test_and_set_bit(FLG_ACTIVE, &dch->Flags);
3750 _queue_data(&dch->dev.D, PH_ACTIVATE_IND,
Joe Perches475be4d2012-02-19 19:52:38 -08003751 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003752 break;
3753
3754 default:
3755 if (hc->e1_state != 1)
3756 return;
3757 test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
3758 _queue_data(&dch->dev.D, PH_DEACTIVATE_IND,
Joe Perches475be4d2012-02-19 19:52:38 -08003759 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003760 }
3761 hc->e1_state = dch->state;
3762 } else {
3763 if (dch->dev.D.protocol == ISDN_P_TE_S0) {
3764 if (debug & DEBUG_HFCMULTI_STATE)
3765 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003766 "%s: S/T TE newstate %x\n",
3767 __func__, dch->state);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003768 switch (dch->state) {
3769 case (0):
3770 l1_event(dch->l1, HW_RESET_IND);
3771 break;
3772 case (3):
3773 l1_event(dch->l1, HW_DEACT_IND);
3774 break;
3775 case (5):
3776 case (8):
3777 l1_event(dch->l1, ANYSIGNAL);
3778 break;
3779 case (6):
3780 l1_event(dch->l1, INFO2);
3781 break;
3782 case (7):
3783 l1_event(dch->l1, INFO4_P8);
3784 break;
3785 }
3786 } else {
3787 if (debug & DEBUG_HFCMULTI_STATE)
3788 printk(KERN_DEBUG "%s: S/T NT newstate %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003789 __func__, dch->state);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003790 switch (dch->state) {
3791 case (2):
3792 if (hc->chan[ch].nt_timer == 0) {
3793 hc->chan[ch].nt_timer = -1;
3794 HFC_outb(hc, R_ST_SEL,
Joe Perches475be4d2012-02-19 19:52:38 -08003795 hc->chan[ch].port);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003796 /* undocumented: delay after R_ST_SEL */
3797 udelay(1);
3798 HFC_outb(hc, A_ST_WR_STATE, 4 |
Joe Perches475be4d2012-02-19 19:52:38 -08003799 V_ST_LD_STA); /* G4 */
Karsten Keilaf69fb32008-07-27 02:00:43 +02003800 udelay(6); /* wait at least 5,21us */
3801 HFC_outb(hc, A_ST_WR_STATE, 4);
3802 dch->state = 4;
3803 } else {
3804 /* one extra count for the next event */
3805 hc->chan[ch].nt_timer =
Joe Perches475be4d2012-02-19 19:52:38 -08003806 nt_t1_count[poll_timer] + 1;
Karsten Keilaf69fb32008-07-27 02:00:43 +02003807 HFC_outb(hc, R_ST_SEL,
Joe Perches475be4d2012-02-19 19:52:38 -08003808 hc->chan[ch].port);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003809 /* undocumented: delay after R_ST_SEL */
3810 udelay(1);
3811 /* allow G2 -> G3 transition */
3812 HFC_outb(hc, A_ST_WR_STATE, 2 |
Joe Perches475be4d2012-02-19 19:52:38 -08003813 V_SET_G2_G3);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003814 }
3815 break;
3816 case (1):
3817 hc->chan[ch].nt_timer = -1;
3818 test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
3819 _queue_data(&dch->dev.D, PH_DEACTIVATE_IND,
Joe Perches475be4d2012-02-19 19:52:38 -08003820 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003821 break;
3822 case (4):
3823 hc->chan[ch].nt_timer = -1;
3824 break;
3825 case (3):
3826 hc->chan[ch].nt_timer = -1;
3827 test_and_set_bit(FLG_ACTIVE, &dch->Flags);
3828 _queue_data(&dch->dev.D, PH_ACTIVATE_IND,
Joe Perches475be4d2012-02-19 19:52:38 -08003829 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003830 break;
3831 }
3832 }
3833 }
3834}
3835
3836/*
3837 * called for card mode init message
3838 */
3839
3840static void
3841hfcmulti_initmode(struct dchannel *dch)
3842{
3843 struct hfc_multi *hc = dch->hw;
3844 u_char a_st_wr_state, r_e1_wr_sta;
3845 int i, pt;
3846
3847 if (debug & DEBUG_HFCMULTI_INIT)
3848 printk(KERN_DEBUG "%s: entered\n", __func__);
3849
Karsten Keildb9bb632009-05-22 11:04:53 +00003850 if (hc->ctype == HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02003851 hc->chan[hc->dslot].slot_tx = -1;
3852 hc->chan[hc->dslot].slot_rx = -1;
3853 hc->chan[hc->dslot].conf = -1;
3854 if (hc->dslot) {
3855 mode_hfcmulti(hc, hc->dslot, dch->dev.D.protocol,
Joe Perches475be4d2012-02-19 19:52:38 -08003856 -1, 0, -1, 0);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003857 dch->timer.function = (void *) hfcmulti_dbusy_timer;
3858 dch->timer.data = (long) dch;
3859 init_timer(&dch->timer);
3860 }
3861 for (i = 1; i <= 31; i++) {
3862 if (i == hc->dslot)
3863 continue;
3864 hc->chan[i].slot_tx = -1;
3865 hc->chan[i].slot_rx = -1;
3866 hc->chan[i].conf = -1;
3867 mode_hfcmulti(hc, i, ISDN_P_NONE, -1, 0, -1, 0);
3868 }
3869 /* E1 */
3870 if (test_bit(HFC_CFG_REPORT_LOS, &hc->chan[hc->dslot].cfg)) {
3871 HFC_outb(hc, R_LOS0, 255); /* 2 ms */
3872 HFC_outb(hc, R_LOS1, 255); /* 512 ms */
3873 }
3874 if (test_bit(HFC_CFG_OPTICAL, &hc->chan[hc->dslot].cfg)) {
3875 HFC_outb(hc, R_RX0, 0);
3876 hc->hw.r_tx0 = 0 | V_OUT_EN;
3877 } else {
3878 HFC_outb(hc, R_RX0, 1);
3879 hc->hw.r_tx0 = 1 | V_OUT_EN;
3880 }
3881 hc->hw.r_tx1 = V_ATX | V_NTRI;
3882 HFC_outb(hc, R_TX0, hc->hw.r_tx0);
3883 HFC_outb(hc, R_TX1, hc->hw.r_tx1);
3884 HFC_outb(hc, R_TX_FR0, 0x00);
3885 HFC_outb(hc, R_TX_FR1, 0xf8);
3886
3887 if (test_bit(HFC_CFG_CRC4, &hc->chan[hc->dslot].cfg))
3888 HFC_outb(hc, R_TX_FR2, V_TX_MF | V_TX_E | V_NEG_E);
3889
3890 HFC_outb(hc, R_RX_FR0, V_AUTO_RESYNC | V_AUTO_RECO | 0);
3891
3892 if (test_bit(HFC_CFG_CRC4, &hc->chan[hc->dslot].cfg))
3893 HFC_outb(hc, R_RX_FR1, V_RX_MF | V_RX_MF_SYNC);
3894
3895 if (dch->dev.D.protocol == ISDN_P_NT_E1) {
3896 if (debug & DEBUG_HFCMULTI_INIT)
3897 printk(KERN_DEBUG "%s: E1 port is NT-mode\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003898 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003899 r_e1_wr_sta = 0; /* G0 */
3900 hc->e1_getclock = 0;
3901 } else {
3902 if (debug & DEBUG_HFCMULTI_INIT)
3903 printk(KERN_DEBUG "%s: E1 port is TE-mode\n",
Joe Perches475be4d2012-02-19 19:52:38 -08003904 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003905 r_e1_wr_sta = 0; /* F0 */
3906 hc->e1_getclock = 1;
3907 }
3908 if (test_bit(HFC_CHIP_RX_SYNC, &hc->chip))
3909 HFC_outb(hc, R_SYNC_OUT, V_SYNC_E1_RX);
3910 else
3911 HFC_outb(hc, R_SYNC_OUT, 0);
3912 if (test_bit(HFC_CHIP_E1CLOCK_GET, &hc->chip))
3913 hc->e1_getclock = 1;
3914 if (test_bit(HFC_CHIP_E1CLOCK_PUT, &hc->chip))
3915 hc->e1_getclock = 0;
3916 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
3917 /* SLAVE (clock master) */
3918 if (debug & DEBUG_HFCMULTI_INIT)
3919 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003920 "%s: E1 port is clock master "
3921 "(clock from PCM)\n", __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003922 HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC | V_PCM_SYNC);
3923 } else {
3924 if (hc->e1_getclock) {
3925 /* MASTER (clock slave) */
3926 if (debug & DEBUG_HFCMULTI_INIT)
3927 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003928 "%s: E1 port is clock slave "
3929 "(clock to PCM)\n", __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003930 HFC_outb(hc, R_SYNC_CTRL, V_SYNC_OFFS);
3931 } else {
3932 /* MASTER (clock master) */
3933 if (debug & DEBUG_HFCMULTI_INIT)
3934 printk(KERN_DEBUG "%s: E1 port is "
Joe Perches475be4d2012-02-19 19:52:38 -08003935 "clock master "
3936 "(clock from QUARTZ)\n",
3937 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003938 HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC |
Joe Perches475be4d2012-02-19 19:52:38 -08003939 V_PCM_SYNC | V_JATT_OFF);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003940 HFC_outb(hc, R_SYNC_OUT, 0);
3941 }
3942 }
3943 HFC_outb(hc, R_JATT_ATT, 0x9c); /* undoc register */
3944 HFC_outb(hc, R_PWM_MD, V_PWM0_MD);
3945 HFC_outb(hc, R_PWM0, 0x50);
3946 HFC_outb(hc, R_PWM1, 0xff);
3947 /* state machine setup */
3948 HFC_outb(hc, R_E1_WR_STA, r_e1_wr_sta | V_E1_LD_STA);
3949 udelay(6); /* wait at least 5,21us */
3950 HFC_outb(hc, R_E1_WR_STA, r_e1_wr_sta);
3951 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
3952 hc->syncronized = 0;
3953 plxsd_checksync(hc, 0);
3954 }
3955 } else {
3956 i = dch->slot;
3957 hc->chan[i].slot_tx = -1;
3958 hc->chan[i].slot_rx = -1;
3959 hc->chan[i].conf = -1;
3960 mode_hfcmulti(hc, i, dch->dev.D.protocol, -1, 0, -1, 0);
3961 dch->timer.function = (void *)hfcmulti_dbusy_timer;
3962 dch->timer.data = (long) dch;
3963 init_timer(&dch->timer);
3964 hc->chan[i - 2].slot_tx = -1;
3965 hc->chan[i - 2].slot_rx = -1;
3966 hc->chan[i - 2].conf = -1;
3967 mode_hfcmulti(hc, i - 2, ISDN_P_NONE, -1, 0, -1, 0);
3968 hc->chan[i - 1].slot_tx = -1;
3969 hc->chan[i - 1].slot_rx = -1;
3970 hc->chan[i - 1].conf = -1;
3971 mode_hfcmulti(hc, i - 1, ISDN_P_NONE, -1, 0, -1, 0);
3972 /* ST */
3973 pt = hc->chan[i].port;
3974 /* select interface */
3975 HFC_outb(hc, R_ST_SEL, pt);
3976 /* undocumented: delay after R_ST_SEL */
3977 udelay(1);
3978 if (dch->dev.D.protocol == ISDN_P_NT_S0) {
3979 if (debug & DEBUG_HFCMULTI_INIT)
3980 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003981 "%s: ST port %d is NT-mode\n",
3982 __func__, pt);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003983 /* clock delay */
3984 HFC_outb(hc, A_ST_CLK_DLY, clockdelay_nt);
3985 a_st_wr_state = 1; /* G1 */
3986 hc->hw.a_st_ctrl0[pt] = V_ST_MD;
3987 } else {
3988 if (debug & DEBUG_HFCMULTI_INIT)
3989 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08003990 "%s: ST port %d is TE-mode\n",
3991 __func__, pt);
Karsten Keilaf69fb32008-07-27 02:00:43 +02003992 /* clock delay */
3993 HFC_outb(hc, A_ST_CLK_DLY, clockdelay_te);
3994 a_st_wr_state = 2; /* F2 */
3995 hc->hw.a_st_ctrl0[pt] = 0;
3996 }
3997 if (!test_bit(HFC_CFG_NONCAP_TX, &hc->chan[i].cfg))
3998 hc->hw.a_st_ctrl0[pt] |= V_TX_LI;
Karsten Keildb9bb632009-05-22 11:04:53 +00003999 if (hc->ctype == HFC_TYPE_XHFC) {
4000 hc->hw.a_st_ctrl0[pt] |= 0x40 /* V_ST_PU_CTRL */;
4001 HFC_outb(hc, 0x35 /* A_ST_CTRL3 */,
Joe Perches475be4d2012-02-19 19:52:38 -08004002 0x7c << 1 /* V_ST_PULSE */);
Karsten Keildb9bb632009-05-22 11:04:53 +00004003 }
Karsten Keilaf69fb32008-07-27 02:00:43 +02004004 /* line setup */
4005 HFC_outb(hc, A_ST_CTRL0, hc->hw.a_st_ctrl0[pt]);
4006 /* disable E-channel */
4007 if ((dch->dev.D.protocol == ISDN_P_NT_S0) ||
4008 test_bit(HFC_CFG_DIS_ECHANNEL, &hc->chan[i].cfg))
4009 HFC_outb(hc, A_ST_CTRL1, V_E_IGNO);
4010 else
4011 HFC_outb(hc, A_ST_CTRL1, 0);
4012 /* enable B-channel receive */
4013 HFC_outb(hc, A_ST_CTRL2, V_B1_RX_EN | V_B2_RX_EN);
4014 /* state machine setup */
4015 HFC_outb(hc, A_ST_WR_STATE, a_st_wr_state | V_ST_LD_STA);
4016 udelay(6); /* wait at least 5,21us */
4017 HFC_outb(hc, A_ST_WR_STATE, a_st_wr_state);
4018 hc->hw.r_sci_msk |= 1 << pt;
4019 /* state machine interrupts */
4020 HFC_outb(hc, R_SCI_MSK, hc->hw.r_sci_msk);
4021 /* unset sync on port */
4022 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
4023 hc->syncronized &=
Joe Perches475be4d2012-02-19 19:52:38 -08004024 ~(1 << hc->chan[dch->slot].port);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004025 plxsd_checksync(hc, 0);
4026 }
4027 }
4028 if (debug & DEBUG_HFCMULTI_INIT)
4029 printk("%s: done\n", __func__);
4030}
4031
4032
4033static int
4034open_dchannel(struct hfc_multi *hc, struct dchannel *dch,
Joe Perches475be4d2012-02-19 19:52:38 -08004035 struct channel_req *rq)
Karsten Keilaf69fb32008-07-27 02:00:43 +02004036{
4037 int err = 0;
4038 u_long flags;
4039
4040 if (debug & DEBUG_HW_OPEN)
4041 printk(KERN_DEBUG "%s: dev(%d) open from %p\n", __func__,
Joe Perches475be4d2012-02-19 19:52:38 -08004042 dch->dev.id, __builtin_return_address(0));
Karsten Keilaf69fb32008-07-27 02:00:43 +02004043 if (rq->protocol == ISDN_P_NONE)
4044 return -EINVAL;
4045 if ((dch->dev.D.protocol != ISDN_P_NONE) &&
4046 (dch->dev.D.protocol != rq->protocol)) {
Karsten Keileac74af2009-05-22 11:04:56 +00004047 if (debug & DEBUG_HFCMULTI_MODE)
4048 printk(KERN_DEBUG "%s: change protocol %x to %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004049 __func__, dch->dev.D.protocol, rq->protocol);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004050 }
Karsten Keileac74af2009-05-22 11:04:56 +00004051 if ((dch->dev.D.protocol == ISDN_P_TE_S0) &&
4052 (rq->protocol != ISDN_P_TE_S0))
Karsten Keilaf69fb32008-07-27 02:00:43 +02004053 l1_event(dch->l1, CLOSE_CHANNEL);
4054 if (dch->dev.D.protocol != rq->protocol) {
4055 if (rq->protocol == ISDN_P_TE_S0) {
4056 err = create_l1(dch, hfcm_l1callback);
4057 if (err)
4058 return err;
4059 }
4060 dch->dev.D.protocol = rq->protocol;
4061 spin_lock_irqsave(&hc->lock, flags);
4062 hfcmulti_initmode(dch);
4063 spin_unlock_irqrestore(&hc->lock, flags);
4064 }
Andreas Eversbergd2fb5492012-04-24 20:52:12 +00004065 if (test_bit(FLG_ACTIVE, &dch->Flags))
Karsten Keilaf69fb32008-07-27 02:00:43 +02004066 _queue_data(&dch->dev.D, PH_ACTIVATE_IND, MISDN_ID_ANY,
Joe Perches475be4d2012-02-19 19:52:38 -08004067 0, NULL, GFP_KERNEL);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004068 rq->ch = &dch->dev.D;
4069 if (!try_module_get(THIS_MODULE))
4070 printk(KERN_WARNING "%s:cannot get module\n", __func__);
4071 return 0;
4072}
4073
4074static int
4075open_bchannel(struct hfc_multi *hc, struct dchannel *dch,
Joe Perches475be4d2012-02-19 19:52:38 -08004076 struct channel_req *rq)
Karsten Keilaf69fb32008-07-27 02:00:43 +02004077{
4078 struct bchannel *bch;
4079 int ch;
4080
Karsten Keilff4cc1d2008-07-30 18:26:58 +02004081 if (!test_channelmap(rq->adr.channel, dch->dev.channelmap))
Karsten Keilaf69fb32008-07-27 02:00:43 +02004082 return -EINVAL;
4083 if (rq->protocol == ISDN_P_NONE)
4084 return -EINVAL;
Karsten Keildb9bb632009-05-22 11:04:53 +00004085 if (hc->ctype == HFC_TYPE_E1)
Karsten Keilaf69fb32008-07-27 02:00:43 +02004086 ch = rq->adr.channel;
4087 else
4088 ch = (rq->adr.channel - 1) + (dch->slot - 2);
4089 bch = hc->chan[ch].bch;
4090 if (!bch) {
4091 printk(KERN_ERR "%s:internal error ch %d has no bch\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004092 __func__, ch);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004093 return -EINVAL;
4094 }
4095 if (test_and_set_bit(FLG_OPEN, &bch->Flags))
4096 return -EBUSY; /* b-channel can be only open once */
Andreas Eversberg8dd2f362008-08-02 22:51:52 +02004097 test_and_clear_bit(FLG_FILLEMPTY, &bch->Flags);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004098 bch->ch.protocol = rq->protocol;
4099 hc->chan[ch].rx_off = 0;
4100 rq->ch = &bch->ch;
4101 if (!try_module_get(THIS_MODULE))
4102 printk(KERN_WARNING "%s:cannot get module\n", __func__);
4103 return 0;
4104}
4105
4106/*
4107 * device control function
4108 */
4109static int
4110channel_dctrl(struct dchannel *dch, struct mISDN_ctrl_req *cq)
4111{
Andreas Eversberg7df3bb82009-05-22 11:04:44 +00004112 struct hfc_multi *hc = dch->hw;
Karsten Keilaf69fb32008-07-27 02:00:43 +02004113 int ret = 0;
Andreas Eversberg7df3bb82009-05-22 11:04:44 +00004114 int wd_mode, wd_cnt;
Karsten Keilaf69fb32008-07-27 02:00:43 +02004115
4116 switch (cq->op) {
4117 case MISDN_CTRL_GETOP:
Andreas Eversberg7df3bb82009-05-22 11:04:44 +00004118 cq->op = MISDN_CTRL_HFC_OP;
4119 break;
4120 case MISDN_CTRL_HFC_WD_INIT: /* init the watchdog */
4121 wd_cnt = cq->p1 & 0xf;
4122 wd_mode = !!(cq->p1 >> 4);
4123 if (debug & DEBUG_HFCMULTI_MSG)
Karsten Keileac74af2009-05-22 11:04:56 +00004124 printk(KERN_DEBUG "%s: MISDN_CTRL_HFC_WD_INIT mode %s"
Joe Perches475be4d2012-02-19 19:52:38 -08004125 ", counter 0x%x\n", __func__,
4126 wd_mode ? "AUTO" : "MANUAL", wd_cnt);
Andreas Eversberg7df3bb82009-05-22 11:04:44 +00004127 /* set the watchdog timer */
4128 HFC_outb(hc, R_TI_WD, poll_timer | (wd_cnt << 4));
4129 hc->hw.r_bert_wd_md = (wd_mode ? V_AUTO_WD_RES : 0);
4130 if (hc->ctype == HFC_TYPE_XHFC)
4131 hc->hw.r_bert_wd_md |= 0x40 /* V_WD_EN */;
4132 /* init the watchdog register and reset the counter */
4133 HFC_outb(hc, R_BERT_WD_MD, hc->hw.r_bert_wd_md | V_WD_RES);
4134 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
4135 /* enable the watchdog output for Speech-Design */
Karsten Keileac74af2009-05-22 11:04:56 +00004136 HFC_outb(hc, R_GPIO_SEL, V_GPIO_SEL7);
4137 HFC_outb(hc, R_GPIO_EN1, V_GPIO_EN15);
Andreas Eversberg7df3bb82009-05-22 11:04:44 +00004138 HFC_outb(hc, R_GPIO_OUT1, 0);
4139 HFC_outb(hc, R_GPIO_OUT1, V_GPIO_OUT15);
4140 }
4141 break;
4142 case MISDN_CTRL_HFC_WD_RESET: /* reset the watchdog counter */
4143 if (debug & DEBUG_HFCMULTI_MSG)
4144 printk(KERN_DEBUG "%s: MISDN_CTRL_HFC_WD_RESET\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004145 __func__);
Andreas Eversberg7df3bb82009-05-22 11:04:44 +00004146 HFC_outb(hc, R_BERT_WD_MD, hc->hw.r_bert_wd_md | V_WD_RES);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004147 break;
4148 default:
4149 printk(KERN_WARNING "%s: unknown Op %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004150 __func__, cq->op);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004151 ret = -EINVAL;
4152 break;
4153 }
4154 return ret;
4155}
4156
4157static int
4158hfcm_dctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
4159{
4160 struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
4161 struct dchannel *dch = container_of(dev, struct dchannel, dev);
4162 struct hfc_multi *hc = dch->hw;
4163 struct channel_req *rq;
4164 int err = 0;
4165 u_long flags;
4166
4167 if (dch->debug & DEBUG_HW)
4168 printk(KERN_DEBUG "%s: cmd:%x %p\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004169 __func__, cmd, arg);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004170 switch (cmd) {
4171 case OPEN_CHANNEL:
4172 rq = arg;
4173 switch (rq->protocol) {
4174 case ISDN_P_TE_S0:
4175 case ISDN_P_NT_S0:
Karsten Keildb9bb632009-05-22 11:04:53 +00004176 if (hc->ctype == HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02004177 err = -EINVAL;
4178 break;
4179 }
4180 err = open_dchannel(hc, dch, rq); /* locked there */
4181 break;
4182 case ISDN_P_TE_E1:
4183 case ISDN_P_NT_E1:
Karsten Keildb9bb632009-05-22 11:04:53 +00004184 if (hc->ctype != HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02004185 err = -EINVAL;
4186 break;
4187 }
4188 err = open_dchannel(hc, dch, rq); /* locked there */
4189 break;
4190 default:
4191 spin_lock_irqsave(&hc->lock, flags);
4192 err = open_bchannel(hc, dch, rq);
4193 spin_unlock_irqrestore(&hc->lock, flags);
4194 }
4195 break;
4196 case CLOSE_CHANNEL:
4197 if (debug & DEBUG_HW_OPEN)
4198 printk(KERN_DEBUG "%s: dev(%d) close from %p\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004199 __func__, dch->dev.id,
4200 __builtin_return_address(0));
Karsten Keilaf69fb32008-07-27 02:00:43 +02004201 module_put(THIS_MODULE);
4202 break;
4203 case CONTROL_CHANNEL:
4204 spin_lock_irqsave(&hc->lock, flags);
4205 err = channel_dctrl(dch, arg);
4206 spin_unlock_irqrestore(&hc->lock, flags);
4207 break;
4208 default:
4209 if (dch->debug & DEBUG_HW)
4210 printk(KERN_DEBUG "%s: unknown command %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004211 __func__, cmd);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004212 err = -EINVAL;
4213 }
4214 return err;
4215}
4216
Andreas Eversberg3bd69ad2008-09-06 09:03:46 +02004217static int
4218clockctl(void *priv, int enable)
4219{
4220 struct hfc_multi *hc = priv;
4221
4222 hc->iclock_on = enable;
4223 return 0;
4224}
4225
Karsten Keilaf69fb32008-07-27 02:00:43 +02004226/*
4227 * initialize the card
4228 */
4229
4230/*
4231 * start timer irq, wait some time and check if we have interrupts.
4232 * if not, reset chip and try again.
4233 */
4234static int
4235init_card(struct hfc_multi *hc)
4236{
4237 int err = -EIO;
4238 u_long flags;
Hannes Ederc31655f2008-12-12 21:20:03 -08004239 void __iomem *plx_acc;
Karsten Keilaf69fb32008-07-27 02:00:43 +02004240 u_long plx_flags;
4241
4242 if (debug & DEBUG_HFCMULTI_INIT)
4243 printk(KERN_DEBUG "%s: entered\n", __func__);
4244
4245 spin_lock_irqsave(&hc->lock, flags);
4246 /* set interrupts but leave global interrupt disabled */
4247 hc->hw.r_irq_ctrl = V_FIFO_IRQ;
4248 disable_hwirq(hc);
4249 spin_unlock_irqrestore(&hc->lock, flags);
4250
Karsten Keildb9bb632009-05-22 11:04:53 +00004251 if (request_irq(hc->irq, hfcmulti_interrupt, IRQF_SHARED,
Joe Perches475be4d2012-02-19 19:52:38 -08004252 "HFC-multi", hc)) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02004253 printk(KERN_WARNING "mISDN: Could not get interrupt %d.\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004254 hc->irq);
Karsten Keildb9bb632009-05-22 11:04:53 +00004255 hc->irq = 0;
Karsten Keilaf69fb32008-07-27 02:00:43 +02004256 return -EIO;
4257 }
Karsten Keilaf69fb32008-07-27 02:00:43 +02004258
4259 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
4260 spin_lock_irqsave(&plx_lock, plx_flags);
Hannes Ederc31655f2008-12-12 21:20:03 -08004261 plx_acc = hc->plx_membase + PLX_INTCSR;
Karsten Keilaf69fb32008-07-27 02:00:43 +02004262 writew((PLX_INTCSR_PCIINT_ENABLE | PLX_INTCSR_LINTI1_ENABLE),
Joe Perches475be4d2012-02-19 19:52:38 -08004263 plx_acc); /* enable PCI & LINT1 irq */
Karsten Keilaf69fb32008-07-27 02:00:43 +02004264 spin_unlock_irqrestore(&plx_lock, plx_flags);
4265 }
4266
4267 if (debug & DEBUG_HFCMULTI_INIT)
4268 printk(KERN_DEBUG "%s: IRQ %d count %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004269 __func__, hc->irq, hc->irqcnt);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004270 err = init_chip(hc);
4271 if (err)
4272 goto error;
4273 /*
4274 * Finally enable IRQ output
Uwe Kleine-König698f9312010-07-02 20:41:51 +02004275 * this is only allowed, if an IRQ routine is already
Karsten Keilaf69fb32008-07-27 02:00:43 +02004276 * established for this HFC, so don't do that earlier
4277 */
4278 spin_lock_irqsave(&hc->lock, flags);
4279 enable_hwirq(hc);
4280 spin_unlock_irqrestore(&hc->lock, flags);
4281 /* printk(KERN_DEBUG "no master irq set!!!\n"); */
4282 set_current_state(TASK_UNINTERRUPTIBLE);
Joe Perches475be4d2012-02-19 19:52:38 -08004283 schedule_timeout((100 * HZ) / 1000); /* Timeout 100ms */
Karsten Keilaf69fb32008-07-27 02:00:43 +02004284 /* turn IRQ off until chip is completely initialized */
4285 spin_lock_irqsave(&hc->lock, flags);
4286 disable_hwirq(hc);
4287 spin_unlock_irqrestore(&hc->lock, flags);
4288 if (debug & DEBUG_HFCMULTI_INIT)
4289 printk(KERN_DEBUG "%s: IRQ %d count %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004290 __func__, hc->irq, hc->irqcnt);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004291 if (hc->irqcnt) {
4292 if (debug & DEBUG_HFCMULTI_INIT)
4293 printk(KERN_DEBUG "%s: done\n", __func__);
4294
4295 return 0;
4296 }
4297 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
4298 printk(KERN_INFO "ignoring missing interrupts\n");
4299 return 0;
4300 }
4301
4302 printk(KERN_ERR "HFC PCI: IRQ(%d) getting no interrupts during init.\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004303 hc->irq);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004304
4305 err = -EIO;
4306
4307error:
4308 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
4309 spin_lock_irqsave(&plx_lock, plx_flags);
Hannes Ederc31655f2008-12-12 21:20:03 -08004310 plx_acc = hc->plx_membase + PLX_INTCSR;
Karsten Keilaf69fb32008-07-27 02:00:43 +02004311 writew(0x00, plx_acc); /*disable IRQs*/
4312 spin_unlock_irqrestore(&plx_lock, plx_flags);
4313 }
4314
4315 if (debug & DEBUG_HFCMULTI_INIT)
Karsten Keileac74af2009-05-22 11:04:56 +00004316 printk(KERN_DEBUG "%s: free irq %d\n", __func__, hc->irq);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004317 if (hc->irq) {
4318 free_irq(hc->irq, hc);
4319 hc->irq = 0;
4320 }
4321
4322 if (debug & DEBUG_HFCMULTI_INIT)
4323 printk(KERN_DEBUG "%s: done (err=%d)\n", __func__, err);
4324 return err;
4325}
4326
4327/*
4328 * find pci device and set it up
4329 */
4330
4331static int
4332setup_pci(struct hfc_multi *hc, struct pci_dev *pdev,
Joe Perches475be4d2012-02-19 19:52:38 -08004333 const struct pci_device_id *ent)
Karsten Keilaf69fb32008-07-27 02:00:43 +02004334{
4335 struct hm_map *m = (struct hm_map *)ent->driver_data;
4336
4337 printk(KERN_INFO
Joe Perches475be4d2012-02-19 19:52:38 -08004338 "HFC-multi: card manufacturer: '%s' card name: '%s' clock: %s\n",
4339 m->vendor_name, m->card_name, m->clock2 ? "double" : "normal");
Karsten Keilaf69fb32008-07-27 02:00:43 +02004340
4341 hc->pci_dev = pdev;
4342 if (m->clock2)
4343 test_and_set_bit(HFC_CHIP_CLOCK2, &hc->chip);
4344
4345 if (ent->device == 0xB410) {
4346 test_and_set_bit(HFC_CHIP_B410P, &hc->chip);
4347 test_and_set_bit(HFC_CHIP_PCM_MASTER, &hc->chip);
4348 test_and_clear_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
4349 hc->slots = 32;
4350 }
4351
4352 if (hc->pci_dev->irq <= 0) {
4353 printk(KERN_WARNING "HFC-multi: No IRQ for PCI card found.\n");
4354 return -EIO;
4355 }
4356 if (pci_enable_device(hc->pci_dev)) {
4357 printk(KERN_WARNING "HFC-multi: Error enabling PCI card.\n");
4358 return -EIO;
4359 }
4360 hc->leds = m->leds;
4361 hc->ledstate = 0xAFFEAFFE;
4362 hc->opticalsupport = m->opticalsupport;
4363
Karsten Keildb9bb632009-05-22 11:04:53 +00004364 hc->pci_iobase = 0;
4365 hc->pci_membase = NULL;
4366 hc->plx_membase = NULL;
4367
Karsten Keilaf69fb32008-07-27 02:00:43 +02004368 /* set memory access methods */
4369 if (m->io_mode) /* use mode from card config */
4370 hc->io_mode = m->io_mode;
4371 switch (hc->io_mode) {
4372 case HFC_IO_MODE_PLXSD:
4373 test_and_set_bit(HFC_CHIP_PLXSD, &hc->chip);
4374 hc->slots = 128; /* required */
Karsten Keilaf69fb32008-07-27 02:00:43 +02004375 hc->HFC_outb = HFC_outb_pcimem;
4376 hc->HFC_inb = HFC_inb_pcimem;
4377 hc->HFC_inw = HFC_inw_pcimem;
4378 hc->HFC_wait = HFC_wait_pcimem;
4379 hc->read_fifo = read_fifo_pcimem;
4380 hc->write_fifo = write_fifo_pcimem;
Karsten Keilaf69fb32008-07-27 02:00:43 +02004381 hc->plx_origmembase = hc->pci_dev->resource[0].start;
4382 /* MEMBASE 1 is PLX PCI Bridge */
4383
4384 if (!hc->plx_origmembase) {
4385 printk(KERN_WARNING
Joe Perches475be4d2012-02-19 19:52:38 -08004386 "HFC-multi: No IO-Memory for PCI PLX bridge found\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02004387 pci_disable_device(hc->pci_dev);
4388 return -EIO;
4389 }
4390
4391 hc->plx_membase = ioremap(hc->plx_origmembase, 0x80);
4392 if (!hc->plx_membase) {
4393 printk(KERN_WARNING
Joe Perches475be4d2012-02-19 19:52:38 -08004394 "HFC-multi: failed to remap plx address space. "
4395 "(internal error)\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02004396 pci_disable_device(hc->pci_dev);
4397 return -EIO;
4398 }
4399 printk(KERN_INFO
Joe Perches475be4d2012-02-19 19:52:38 -08004400 "HFC-multi: plx_membase:%#lx plx_origmembase:%#lx\n",
4401 (u_long)hc->plx_membase, hc->plx_origmembase);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004402
4403 hc->pci_origmembase = hc->pci_dev->resource[2].start;
Joe Perches475be4d2012-02-19 19:52:38 -08004404 /* MEMBASE 1 is PLX PCI Bridge */
Karsten Keilaf69fb32008-07-27 02:00:43 +02004405 if (!hc->pci_origmembase) {
4406 printk(KERN_WARNING
Joe Perches475be4d2012-02-19 19:52:38 -08004407 "HFC-multi: No IO-Memory for PCI card found\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02004408 pci_disable_device(hc->pci_dev);
4409 return -EIO;
4410 }
4411
4412 hc->pci_membase = ioremap(hc->pci_origmembase, 0x400);
4413 if (!hc->pci_membase) {
4414 printk(KERN_WARNING "HFC-multi: failed to remap io "
Joe Perches475be4d2012-02-19 19:52:38 -08004415 "address space. (internal error)\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02004416 pci_disable_device(hc->pci_dev);
4417 return -EIO;
4418 }
4419
4420 printk(KERN_INFO
Joe Perches475be4d2012-02-19 19:52:38 -08004421 "card %d: defined at MEMBASE %#lx (%#lx) IRQ %d HZ %d "
4422 "leds-type %d\n",
4423 hc->id, (u_long)hc->pci_membase, hc->pci_origmembase,
4424 hc->pci_dev->irq, HZ, hc->leds);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004425 pci_write_config_word(hc->pci_dev, PCI_COMMAND, PCI_ENA_MEMIO);
4426 break;
4427 case HFC_IO_MODE_PCIMEM:
Karsten Keildb9bb632009-05-22 11:04:53 +00004428 hc->HFC_outb = HFC_outb_pcimem;
4429 hc->HFC_inb = HFC_inb_pcimem;
4430 hc->HFC_inw = HFC_inw_pcimem;
4431 hc->HFC_wait = HFC_wait_pcimem;
4432 hc->read_fifo = read_fifo_pcimem;
4433 hc->write_fifo = write_fifo_pcimem;
Karsten Keilaf69fb32008-07-27 02:00:43 +02004434 hc->pci_origmembase = hc->pci_dev->resource[1].start;
4435 if (!hc->pci_origmembase) {
4436 printk(KERN_WARNING
Joe Perches475be4d2012-02-19 19:52:38 -08004437 "HFC-multi: No IO-Memory for PCI card found\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02004438 pci_disable_device(hc->pci_dev);
4439 return -EIO;
4440 }
4441
4442 hc->pci_membase = ioremap(hc->pci_origmembase, 256);
4443 if (!hc->pci_membase) {
4444 printk(KERN_WARNING
Joe Perches475be4d2012-02-19 19:52:38 -08004445 "HFC-multi: failed to remap io address space. "
4446 "(internal error)\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02004447 pci_disable_device(hc->pci_dev);
4448 return -EIO;
4449 }
Karsten Keildb9bb632009-05-22 11:04:53 +00004450 printk(KERN_INFO "card %d: defined at MEMBASE %#lx (%#lx) IRQ "
Joe Perches475be4d2012-02-19 19:52:38 -08004451 "%d HZ %d leds-type %d\n", hc->id, (u_long)hc->pci_membase,
4452 hc->pci_origmembase, hc->pci_dev->irq, HZ, hc->leds);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004453 pci_write_config_word(hc->pci_dev, PCI_COMMAND, PCI_ENA_MEMIO);
4454 break;
4455 case HFC_IO_MODE_REGIO:
Karsten Keildb9bb632009-05-22 11:04:53 +00004456 hc->HFC_outb = HFC_outb_regio;
4457 hc->HFC_inb = HFC_inb_regio;
4458 hc->HFC_inw = HFC_inw_regio;
4459 hc->HFC_wait = HFC_wait_regio;
4460 hc->read_fifo = read_fifo_regio;
4461 hc->write_fifo = write_fifo_regio;
Karsten Keilaf69fb32008-07-27 02:00:43 +02004462 hc->pci_iobase = (u_int) hc->pci_dev->resource[0].start;
4463 if (!hc->pci_iobase) {
4464 printk(KERN_WARNING
Joe Perches475be4d2012-02-19 19:52:38 -08004465 "HFC-multi: No IO for PCI card found\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02004466 pci_disable_device(hc->pci_dev);
4467 return -EIO;
4468 }
4469
4470 if (!request_region(hc->pci_iobase, 8, "hfcmulti")) {
4471 printk(KERN_WARNING "HFC-multi: failed to request "
Joe Perches475be4d2012-02-19 19:52:38 -08004472 "address space at 0x%08lx (internal error)\n",
4473 hc->pci_iobase);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004474 pci_disable_device(hc->pci_dev);
4475 return -EIO;
4476 }
4477
4478 printk(KERN_INFO
Joe Perches475be4d2012-02-19 19:52:38 -08004479 "%s %s: defined at IOBASE %#x IRQ %d HZ %d leds-type %d\n",
4480 m->vendor_name, m->card_name, (u_int) hc->pci_iobase,
4481 hc->pci_dev->irq, HZ, hc->leds);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004482 pci_write_config_word(hc->pci_dev, PCI_COMMAND, PCI_ENA_REGIO);
4483 break;
4484 default:
4485 printk(KERN_WARNING "HFC-multi: Invalid IO mode.\n");
4486 pci_disable_device(hc->pci_dev);
4487 return -EIO;
4488 }
4489
4490 pci_set_drvdata(hc->pci_dev, hc);
4491
4492 /* At this point the needed PCI config is done */
4493 /* fifos are still not enabled */
4494 return 0;
4495}
4496
4497
4498/*
4499 * remove port
4500 */
4501
4502static void
4503release_port(struct hfc_multi *hc, struct dchannel *dch)
4504{
4505 int pt, ci, i = 0;
4506 u_long flags;
4507 struct bchannel *pb;
4508
4509 ci = dch->slot;
4510 pt = hc->chan[ci].port;
4511
4512 if (debug & DEBUG_HFCMULTI_INIT)
4513 printk(KERN_DEBUG "%s: entered for port %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004514 __func__, pt + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004515
4516 if (pt >= hc->ports) {
4517 printk(KERN_WARNING "%s: ERROR port out of range (%d).\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004518 __func__, pt + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004519 return;
4520 }
4521
4522 if (debug & DEBUG_HFCMULTI_INIT)
4523 printk(KERN_DEBUG "%s: releasing port=%d\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004524 __func__, pt + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004525
4526 if (dch->dev.D.protocol == ISDN_P_TE_S0)
4527 l1_event(dch->l1, CLOSE_CHANNEL);
4528
4529 hc->chan[ci].dch = NULL;
4530
4531 if (hc->created[pt]) {
4532 hc->created[pt] = 0;
4533 mISDN_unregister_device(&dch->dev);
4534 }
4535
4536 spin_lock_irqsave(&hc->lock, flags);
4537
4538 if (dch->timer.function) {
4539 del_timer(&dch->timer);
4540 dch->timer.function = NULL;
4541 }
4542
Karsten Keildb9bb632009-05-22 11:04:53 +00004543 if (hc->ctype == HFC_TYPE_E1) { /* E1 */
Karsten Keilaf69fb32008-07-27 02:00:43 +02004544 /* remove sync */
4545 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
4546 hc->syncronized = 0;
4547 plxsd_checksync(hc, 1);
4548 }
4549 /* free channels */
4550 for (i = 0; i <= 31; i++) {
4551 if (hc->chan[i].bch) {
4552 if (debug & DEBUG_HFCMULTI_INIT)
4553 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08004554 "%s: free port %d channel %d\n",
4555 __func__, hc->chan[i].port + 1, i);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004556 pb = hc->chan[i].bch;
4557 hc->chan[i].bch = NULL;
4558 spin_unlock_irqrestore(&hc->lock, flags);
4559 mISDN_freebchannel(pb);
4560 kfree(pb);
4561 kfree(hc->chan[i].coeff);
4562 spin_lock_irqsave(&hc->lock, flags);
4563 }
4564 }
4565 } else {
4566 /* remove sync */
4567 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
4568 hc->syncronized &=
Joe Perches475be4d2012-02-19 19:52:38 -08004569 ~(1 << hc->chan[ci].port);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004570 plxsd_checksync(hc, 1);
4571 }
4572 /* free channels */
4573 if (hc->chan[ci - 2].bch) {
4574 if (debug & DEBUG_HFCMULTI_INIT)
4575 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08004576 "%s: free port %d channel %d\n",
4577 __func__, hc->chan[ci - 2].port + 1,
4578 ci - 2);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004579 pb = hc->chan[ci - 2].bch;
4580 hc->chan[ci - 2].bch = NULL;
4581 spin_unlock_irqrestore(&hc->lock, flags);
4582 mISDN_freebchannel(pb);
4583 kfree(pb);
4584 kfree(hc->chan[ci - 2].coeff);
4585 spin_lock_irqsave(&hc->lock, flags);
4586 }
4587 if (hc->chan[ci - 1].bch) {
4588 if (debug & DEBUG_HFCMULTI_INIT)
4589 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08004590 "%s: free port %d channel %d\n",
4591 __func__, hc->chan[ci - 1].port + 1,
4592 ci - 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004593 pb = hc->chan[ci - 1].bch;
4594 hc->chan[ci - 1].bch = NULL;
4595 spin_unlock_irqrestore(&hc->lock, flags);
4596 mISDN_freebchannel(pb);
4597 kfree(pb);
4598 kfree(hc->chan[ci - 1].coeff);
4599 spin_lock_irqsave(&hc->lock, flags);
4600 }
4601 }
4602
4603 spin_unlock_irqrestore(&hc->lock, flags);
4604
4605 if (debug & DEBUG_HFCMULTI_INIT)
4606 printk(KERN_DEBUG "%s: free port %d channel D\n", __func__, pt);
4607 mISDN_freedchannel(dch);
4608 kfree(dch);
4609
4610 if (debug & DEBUG_HFCMULTI_INIT)
4611 printk(KERN_DEBUG "%s: done!\n", __func__);
4612}
4613
4614static void
4615release_card(struct hfc_multi *hc)
4616{
4617 u_long flags;
4618 int ch;
4619
4620 if (debug & DEBUG_HFCMULTI_INIT)
Karsten Keileac74af2009-05-22 11:04:56 +00004621 printk(KERN_DEBUG "%s: release card (%d) entered\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004622 __func__, hc->id);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004623
Andreas Eversberg3bd69ad2008-09-06 09:03:46 +02004624 /* unregister clock source */
4625 if (hc->iclock)
4626 mISDN_unregister_clock(hc->iclock);
4627
4628 /* disable irq */
Karsten Keilaf69fb32008-07-27 02:00:43 +02004629 spin_lock_irqsave(&hc->lock, flags);
4630 disable_hwirq(hc);
4631 spin_unlock_irqrestore(&hc->lock, flags);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004632 udelay(1000);
4633
4634 /* dimm leds */
4635 if (hc->leds)
4636 hfcmulti_leds(hc);
4637
4638 /* disable D-channels & B-channels */
4639 if (debug & DEBUG_HFCMULTI_INIT)
4640 printk(KERN_DEBUG "%s: disable all channels (d and b)\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004641 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004642 for (ch = 0; ch <= 31; ch++) {
4643 if (hc->chan[ch].dch)
4644 release_port(hc, hc->chan[ch].dch);
4645 }
4646
4647 /* release hardware & irq */
4648 if (hc->irq) {
4649 if (debug & DEBUG_HFCMULTI_INIT)
Karsten Keileac74af2009-05-22 11:04:56 +00004650 printk(KERN_DEBUG "%s: free irq %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004651 __func__, hc->irq);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004652 free_irq(hc->irq, hc);
4653 hc->irq = 0;
4654
4655 }
4656 release_io_hfcmulti(hc);
4657
4658 if (debug & DEBUG_HFCMULTI_INIT)
Karsten Keileac74af2009-05-22 11:04:56 +00004659 printk(KERN_DEBUG "%s: remove instance from list\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004660 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004661 list_del(&hc->list);
4662
4663 if (debug & DEBUG_HFCMULTI_INIT)
Karsten Keileac74af2009-05-22 11:04:56 +00004664 printk(KERN_DEBUG "%s: delete instance\n", __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004665 if (hc == syncmaster)
4666 syncmaster = NULL;
4667 kfree(hc);
4668 if (debug & DEBUG_HFCMULTI_INIT)
Karsten Keileac74af2009-05-22 11:04:56 +00004669 printk(KERN_DEBUG "%s: card successfully removed\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004670 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004671}
4672
4673static int
4674init_e1_port(struct hfc_multi *hc, struct hm_map *m)
4675{
4676 struct dchannel *dch;
4677 struct bchannel *bch;
4678 int ch, ret = 0;
4679 char name[MISDN_MAX_IDLEN];
4680
4681 dch = kzalloc(sizeof(struct dchannel), GFP_KERNEL);
4682 if (!dch)
4683 return -ENOMEM;
4684 dch->debug = debug;
4685 mISDN_initdchannel(dch, MAX_DFRAME_LEN_L1, ph_state_change);
4686 dch->hw = hc;
4687 dch->dev.Dprotocols = (1 << ISDN_P_TE_E1) | (1 << ISDN_P_NT_E1);
4688 dch->dev.Bprotocols = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
Joe Perches475be4d2012-02-19 19:52:38 -08004689 (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK));
Karsten Keilaf69fb32008-07-27 02:00:43 +02004690 dch->dev.D.send = handle_dmsg;
4691 dch->dev.D.ctrl = hfcm_dctrl;
Karsten Keileac74af2009-05-22 11:04:56 +00004692 dch->dev.nrbchan = (hc->dslot) ? 30 : 31;
Karsten Keilaf69fb32008-07-27 02:00:43 +02004693 dch->slot = hc->dslot;
4694 hc->chan[hc->dslot].dch = dch;
4695 hc->chan[hc->dslot].port = 0;
4696 hc->chan[hc->dslot].nt_timer = -1;
4697 for (ch = 1; ch <= 31; ch++) {
4698 if (ch == hc->dslot) /* skip dchannel */
4699 continue;
4700 bch = kzalloc(sizeof(struct bchannel), GFP_KERNEL);
4701 if (!bch) {
4702 printk(KERN_ERR "%s: no memory for bchannel\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004703 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004704 ret = -ENOMEM;
4705 goto free_chan;
4706 }
4707 hc->chan[ch].coeff = kzalloc(512, GFP_KERNEL);
4708 if (!hc->chan[ch].coeff) {
4709 printk(KERN_ERR "%s: no memory for coeffs\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004710 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004711 ret = -ENOMEM;
Julia Lawall23b904f2009-02-08 17:00:49 -08004712 kfree(bch);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004713 goto free_chan;
4714 }
4715 bch->nr = ch;
4716 bch->slot = ch;
4717 bch->debug = debug;
4718 mISDN_initbchannel(bch, MAX_DATA_MEM);
4719 bch->hw = hc;
4720 bch->ch.send = handle_bmsg;
4721 bch->ch.ctrl = hfcm_bctrl;
4722 bch->ch.nr = ch;
4723 list_add(&bch->ch.list, &dch->dev.bchannels);
4724 hc->chan[ch].bch = bch;
4725 hc->chan[ch].port = 0;
Karsten Keilff4cc1d2008-07-30 18:26:58 +02004726 set_channelmap(bch->nr, dch->dev.channelmap);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004727 }
4728 /* set optical line type */
4729 if (port[Port_cnt] & 0x001) {
4730 if (!m->opticalsupport) {
4731 printk(KERN_INFO
Joe Perches475be4d2012-02-19 19:52:38 -08004732 "This board has no optical "
4733 "support\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02004734 } else {
4735 if (debug & DEBUG_HFCMULTI_INIT)
4736 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08004737 "%s: PORT set optical "
4738 "interfacs: card(%d) "
4739 "port(%d)\n",
4740 __func__,
4741 HFC_cnt + 1, 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004742 test_and_set_bit(HFC_CFG_OPTICAL,
Joe Perches475be4d2012-02-19 19:52:38 -08004743 &hc->chan[hc->dslot].cfg);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004744 }
4745 }
4746 /* set LOS report */
4747 if (port[Port_cnt] & 0x004) {
4748 if (debug & DEBUG_HFCMULTI_INIT)
4749 printk(KERN_DEBUG "%s: PORT set "
Joe Perches475be4d2012-02-19 19:52:38 -08004750 "LOS report: card(%d) port(%d)\n",
4751 __func__, HFC_cnt + 1, 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004752 test_and_set_bit(HFC_CFG_REPORT_LOS,
Joe Perches475be4d2012-02-19 19:52:38 -08004753 &hc->chan[hc->dslot].cfg);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004754 }
4755 /* set AIS report */
4756 if (port[Port_cnt] & 0x008) {
4757 if (debug & DEBUG_HFCMULTI_INIT)
4758 printk(KERN_DEBUG "%s: PORT set "
Joe Perches475be4d2012-02-19 19:52:38 -08004759 "AIS report: card(%d) port(%d)\n",
4760 __func__, HFC_cnt + 1, 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004761 test_and_set_bit(HFC_CFG_REPORT_AIS,
Joe Perches475be4d2012-02-19 19:52:38 -08004762 &hc->chan[hc->dslot].cfg);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004763 }
4764 /* set SLIP report */
4765 if (port[Port_cnt] & 0x010) {
4766 if (debug & DEBUG_HFCMULTI_INIT)
4767 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08004768 "%s: PORT set SLIP report: "
4769 "card(%d) port(%d)\n",
4770 __func__, HFC_cnt + 1, 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004771 test_and_set_bit(HFC_CFG_REPORT_SLIP,
Joe Perches475be4d2012-02-19 19:52:38 -08004772 &hc->chan[hc->dslot].cfg);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004773 }
4774 /* set RDI report */
4775 if (port[Port_cnt] & 0x020) {
4776 if (debug & DEBUG_HFCMULTI_INIT)
4777 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08004778 "%s: PORT set RDI report: "
4779 "card(%d) port(%d)\n",
4780 __func__, HFC_cnt + 1, 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004781 test_and_set_bit(HFC_CFG_REPORT_RDI,
Joe Perches475be4d2012-02-19 19:52:38 -08004782 &hc->chan[hc->dslot].cfg);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004783 }
4784 /* set CRC-4 Mode */
4785 if (!(port[Port_cnt] & 0x100)) {
4786 if (debug & DEBUG_HFCMULTI_INIT)
4787 printk(KERN_DEBUG "%s: PORT turn on CRC4 report:"
Joe Perches475be4d2012-02-19 19:52:38 -08004788 " card(%d) port(%d)\n",
4789 __func__, HFC_cnt + 1, 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004790 test_and_set_bit(HFC_CFG_CRC4,
Joe Perches475be4d2012-02-19 19:52:38 -08004791 &hc->chan[hc->dslot].cfg);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004792 } else {
4793 if (debug & DEBUG_HFCMULTI_INIT)
4794 printk(KERN_DEBUG "%s: PORT turn off CRC4"
Joe Perches475be4d2012-02-19 19:52:38 -08004795 " report: card(%d) port(%d)\n",
4796 __func__, HFC_cnt + 1, 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004797 }
4798 /* set forced clock */
4799 if (port[Port_cnt] & 0x0200) {
4800 if (debug & DEBUG_HFCMULTI_INIT)
4801 printk(KERN_DEBUG "%s: PORT force getting clock from "
Joe Perches475be4d2012-02-19 19:52:38 -08004802 "E1: card(%d) port(%d)\n",
4803 __func__, HFC_cnt + 1, 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004804 test_and_set_bit(HFC_CHIP_E1CLOCK_GET, &hc->chip);
4805 } else
Joe Perches475be4d2012-02-19 19:52:38 -08004806 if (port[Port_cnt] & 0x0400) {
4807 if (debug & DEBUG_HFCMULTI_INIT)
4808 printk(KERN_DEBUG "%s: PORT force putting clock to "
4809 "E1: card(%d) port(%d)\n",
4810 __func__, HFC_cnt + 1, 1);
4811 test_and_set_bit(HFC_CHIP_E1CLOCK_PUT, &hc->chip);
4812 }
Karsten Keilaf69fb32008-07-27 02:00:43 +02004813 /* set JATT PLL */
4814 if (port[Port_cnt] & 0x0800) {
4815 if (debug & DEBUG_HFCMULTI_INIT)
4816 printk(KERN_DEBUG "%s: PORT disable JATT PLL on "
Joe Perches475be4d2012-02-19 19:52:38 -08004817 "E1: card(%d) port(%d)\n",
4818 __func__, HFC_cnt + 1, 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004819 test_and_set_bit(HFC_CHIP_RX_SYNC, &hc->chip);
4820 }
4821 /* set elastic jitter buffer */
4822 if (port[Port_cnt] & 0x3000) {
4823 hc->chan[hc->dslot].jitter = (port[Port_cnt]>>12) & 0x3;
4824 if (debug & DEBUG_HFCMULTI_INIT)
4825 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08004826 "%s: PORT set elastic "
4827 "buffer to %d: card(%d) port(%d)\n",
4828 __func__, hc->chan[hc->dslot].jitter,
4829 HFC_cnt + 1, 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004830 } else
4831 hc->chan[hc->dslot].jitter = 2; /* default */
4832 snprintf(name, MISDN_MAX_IDLEN - 1, "hfc-e1.%d", HFC_cnt + 1);
Matthias Urlichsb36b6542008-08-16 00:09:24 +02004833 ret = mISDN_register_device(&dch->dev, &hc->pci_dev->dev, name);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004834 if (ret)
4835 goto free_chan;
4836 hc->created[0] = 1;
4837 return ret;
4838free_chan:
4839 release_port(hc, dch);
4840 return ret;
4841}
4842
4843static int
4844init_multi_port(struct hfc_multi *hc, int pt)
4845{
4846 struct dchannel *dch;
4847 struct bchannel *bch;
4848 int ch, i, ret = 0;
4849 char name[MISDN_MAX_IDLEN];
4850
4851 dch = kzalloc(sizeof(struct dchannel), GFP_KERNEL);
4852 if (!dch)
4853 return -ENOMEM;
4854 dch->debug = debug;
4855 mISDN_initdchannel(dch, MAX_DFRAME_LEN_L1, ph_state_change);
4856 dch->hw = hc;
4857 dch->dev.Dprotocols = (1 << ISDN_P_TE_S0) | (1 << ISDN_P_NT_S0);
4858 dch->dev.Bprotocols = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
Joe Perches475be4d2012-02-19 19:52:38 -08004859 (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK));
Karsten Keilaf69fb32008-07-27 02:00:43 +02004860 dch->dev.D.send = handle_dmsg;
4861 dch->dev.D.ctrl = hfcm_dctrl;
4862 dch->dev.nrbchan = 2;
4863 i = pt << 2;
4864 dch->slot = i + 2;
4865 hc->chan[i + 2].dch = dch;
4866 hc->chan[i + 2].port = pt;
4867 hc->chan[i + 2].nt_timer = -1;
4868 for (ch = 0; ch < dch->dev.nrbchan; ch++) {
4869 bch = kzalloc(sizeof(struct bchannel), GFP_KERNEL);
4870 if (!bch) {
4871 printk(KERN_ERR "%s: no memory for bchannel\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004872 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004873 ret = -ENOMEM;
4874 goto free_chan;
4875 }
4876 hc->chan[i + ch].coeff = kzalloc(512, GFP_KERNEL);
4877 if (!hc->chan[i + ch].coeff) {
4878 printk(KERN_ERR "%s: no memory for coeffs\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004879 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004880 ret = -ENOMEM;
Julia Lawall23b904f2009-02-08 17:00:49 -08004881 kfree(bch);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004882 goto free_chan;
4883 }
4884 bch->nr = ch + 1;
4885 bch->slot = i + ch;
4886 bch->debug = debug;
4887 mISDN_initbchannel(bch, MAX_DATA_MEM);
4888 bch->hw = hc;
4889 bch->ch.send = handle_bmsg;
4890 bch->ch.ctrl = hfcm_bctrl;
4891 bch->ch.nr = ch + 1;
4892 list_add(&bch->ch.list, &dch->dev.bchannels);
4893 hc->chan[i + ch].bch = bch;
4894 hc->chan[i + ch].port = pt;
Karsten Keilff4cc1d2008-07-30 18:26:58 +02004895 set_channelmap(bch->nr, dch->dev.channelmap);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004896 }
4897 /* set master clock */
4898 if (port[Port_cnt] & 0x001) {
4899 if (debug & DEBUG_HFCMULTI_INIT)
4900 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08004901 "%s: PROTOCOL set master clock: "
4902 "card(%d) port(%d)\n",
4903 __func__, HFC_cnt + 1, pt + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004904 if (dch->dev.D.protocol != ISDN_P_TE_S0) {
4905 printk(KERN_ERR "Error: Master clock "
Joe Perches475be4d2012-02-19 19:52:38 -08004906 "for port(%d) of card(%d) is only"
4907 " possible with TE-mode\n",
4908 pt + 1, HFC_cnt + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004909 ret = -EINVAL;
4910 goto free_chan;
4911 }
4912 if (hc->masterclk >= 0) {
4913 printk(KERN_ERR "Error: Master clock "
Joe Perches475be4d2012-02-19 19:52:38 -08004914 "for port(%d) of card(%d) already "
4915 "defined for port(%d)\n",
4916 pt + 1, HFC_cnt + 1, hc->masterclk + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004917 ret = -EINVAL;
4918 goto free_chan;
4919 }
4920 hc->masterclk = pt;
4921 }
4922 /* set transmitter line to non capacitive */
4923 if (port[Port_cnt] & 0x002) {
4924 if (debug & DEBUG_HFCMULTI_INIT)
4925 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08004926 "%s: PROTOCOL set non capacitive "
4927 "transmitter: card(%d) port(%d)\n",
4928 __func__, HFC_cnt + 1, pt + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004929 test_and_set_bit(HFC_CFG_NONCAP_TX,
Joe Perches475be4d2012-02-19 19:52:38 -08004930 &hc->chan[i + 2].cfg);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004931 }
4932 /* disable E-channel */
4933 if (port[Port_cnt] & 0x004) {
Karsten Keileac74af2009-05-22 11:04:56 +00004934 if (debug & DEBUG_HFCMULTI_INIT)
Karsten Keilaf69fb32008-07-27 02:00:43 +02004935 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08004936 "%s: PROTOCOL disable E-channel: "
4937 "card(%d) port(%d)\n",
4938 __func__, HFC_cnt + 1, pt + 1);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004939 test_and_set_bit(HFC_CFG_DIS_ECHANNEL,
Joe Perches475be4d2012-02-19 19:52:38 -08004940 &hc->chan[i + 2].cfg);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004941 }
Karsten Keildb9bb632009-05-22 11:04:53 +00004942 if (hc->ctype == HFC_TYPE_XHFC) {
4943 snprintf(name, MISDN_MAX_IDLEN - 1, "xhfc.%d-%d",
Joe Perches475be4d2012-02-19 19:52:38 -08004944 HFC_cnt + 1, pt + 1);
Karsten Keildb9bb632009-05-22 11:04:53 +00004945 ret = mISDN_register_device(&dch->dev, NULL, name);
4946 } else {
4947 snprintf(name, MISDN_MAX_IDLEN - 1, "hfc-%ds.%d-%d",
Joe Perches475be4d2012-02-19 19:52:38 -08004948 hc->ctype, HFC_cnt + 1, pt + 1);
Karsten Keildb9bb632009-05-22 11:04:53 +00004949 ret = mISDN_register_device(&dch->dev, &hc->pci_dev->dev, name);
4950 }
Karsten Keilaf69fb32008-07-27 02:00:43 +02004951 if (ret)
4952 goto free_chan;
4953 hc->created[pt] = 1;
4954 return ret;
4955free_chan:
4956 release_port(hc, dch);
4957 return ret;
4958}
4959
4960static int
Karsten Keildb9bb632009-05-22 11:04:53 +00004961hfcmulti_init(struct hm_map *m, struct pci_dev *pdev,
Joe Perches475be4d2012-02-19 19:52:38 -08004962 const struct pci_device_id *ent)
Karsten Keilaf69fb32008-07-27 02:00:43 +02004963{
Karsten Keilaf69fb32008-07-27 02:00:43 +02004964 int ret_err = 0;
4965 int pt;
4966 struct hfc_multi *hc;
4967 u_long flags;
4968 u_char dips = 0, pmj = 0; /* dip settings, port mode Jumpers */
Andreas Eversberg8dd2f362008-08-02 22:51:52 +02004969 int i;
Karsten Keilaf69fb32008-07-27 02:00:43 +02004970
4971 if (HFC_cnt >= MAX_CARDS) {
4972 printk(KERN_ERR "too many cards (max=%d).\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004973 MAX_CARDS);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004974 return -EINVAL;
4975 }
4976 if ((type[HFC_cnt] & 0xff) && (type[HFC_cnt] & 0xff) != m->type) {
4977 printk(KERN_WARNING "HFC-MULTI: Card '%s:%s' type %d found but "
Joe Perches475be4d2012-02-19 19:52:38 -08004978 "type[%d] %d was supplied as module parameter\n",
4979 m->vendor_name, m->card_name, m->type, HFC_cnt,
4980 type[HFC_cnt] & 0xff);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004981 printk(KERN_WARNING "HFC-MULTI: Load module without parameters "
Joe Perches475be4d2012-02-19 19:52:38 -08004982 "first, to see cards and their types.");
Karsten Keilaf69fb32008-07-27 02:00:43 +02004983 return -EINVAL;
4984 }
4985 if (debug & DEBUG_HFCMULTI_INIT)
4986 printk(KERN_DEBUG "%s: Registering %s:%s chip type %d (0x%x)\n",
Joe Perches475be4d2012-02-19 19:52:38 -08004987 __func__, m->vendor_name, m->card_name, m->type,
4988 type[HFC_cnt]);
Karsten Keilaf69fb32008-07-27 02:00:43 +02004989
4990 /* allocate card+fifo structure */
4991 hc = kzalloc(sizeof(struct hfc_multi), GFP_KERNEL);
4992 if (!hc) {
4993 printk(KERN_ERR "No kmem for HFC-Multi card\n");
4994 return -ENOMEM;
4995 }
4996 spin_lock_init(&hc->lock);
4997 hc->mtyp = m;
Karsten Keildb9bb632009-05-22 11:04:53 +00004998 hc->ctype = m->type;
Karsten Keilaf69fb32008-07-27 02:00:43 +02004999 hc->ports = m->ports;
5000 hc->id = HFC_cnt;
5001 hc->pcm = pcm[HFC_cnt];
5002 hc->io_mode = iomode[HFC_cnt];
Karsten Keildb9bb632009-05-22 11:04:53 +00005003 if (dslot[HFC_cnt] < 0 && hc->ctype == HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02005004 hc->dslot = 0;
5005 printk(KERN_INFO "HFC-E1 card has disabled D-channel, but "
Joe Perches475be4d2012-02-19 19:52:38 -08005006 "31 B-channels\n");
Karsten Keildb9bb632009-05-22 11:04:53 +00005007 }
5008 if (dslot[HFC_cnt] > 0 && dslot[HFC_cnt] < 32
5009 && hc->ctype == HFC_TYPE_E1) {
Karsten Keilaf69fb32008-07-27 02:00:43 +02005010 hc->dslot = dslot[HFC_cnt];
5011 printk(KERN_INFO "HFC-E1 card has alternating D-channel on "
Joe Perches475be4d2012-02-19 19:52:38 -08005012 "time slot %d\n", dslot[HFC_cnt]);
Karsten Keilaf69fb32008-07-27 02:00:43 +02005013 } else
5014 hc->dslot = 16;
5015
5016 /* set chip specific features */
5017 hc->masterclk = -1;
5018 if (type[HFC_cnt] & 0x100) {
5019 test_and_set_bit(HFC_CHIP_ULAW, &hc->chip);
Andreas Eversberg8dd2f362008-08-02 22:51:52 +02005020 hc->silence = 0xff; /* ulaw silence */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005021 } else
Andreas Eversberg8dd2f362008-08-02 22:51:52 +02005022 hc->silence = 0x2a; /* alaw silence */
5023 if ((poll >> 1) > sizeof(hc->silence_data)) {
5024 printk(KERN_ERR "HFCMULTI error: silence_data too small, "
Joe Perches475be4d2012-02-19 19:52:38 -08005025 "please fix\n");
Andreas Eversberg8dd2f362008-08-02 22:51:52 +02005026 return -EINVAL;
5027 }
5028 for (i = 0; i < (poll >> 1); i++)
5029 hc->silence_data[i] = hc->silence;
5030
Karsten Keildb9bb632009-05-22 11:04:53 +00005031 if (hc->ctype != HFC_TYPE_XHFC) {
5032 if (!(type[HFC_cnt] & 0x200))
5033 test_and_set_bit(HFC_CHIP_DTMF, &hc->chip);
5034 test_and_set_bit(HFC_CHIP_CONF, &hc->chip);
5035 }
Karsten Keilaf69fb32008-07-27 02:00:43 +02005036
5037 if (type[HFC_cnt] & 0x800)
5038 test_and_set_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
5039 if (type[HFC_cnt] & 0x1000) {
5040 test_and_set_bit(HFC_CHIP_PCM_MASTER, &hc->chip);
5041 test_and_clear_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
5042 }
5043 if (type[HFC_cnt] & 0x4000)
5044 test_and_set_bit(HFC_CHIP_EXRAM_128, &hc->chip);
5045 if (type[HFC_cnt] & 0x8000)
5046 test_and_set_bit(HFC_CHIP_EXRAM_512, &hc->chip);
5047 hc->slots = 32;
5048 if (type[HFC_cnt] & 0x10000)
5049 hc->slots = 64;
5050 if (type[HFC_cnt] & 0x20000)
5051 hc->slots = 128;
5052 if (type[HFC_cnt] & 0x80000) {
5053 test_and_set_bit(HFC_CHIP_WATCHDOG, &hc->chip);
5054 hc->wdcount = 0;
5055 hc->wdbyte = V_GPIO_OUT2;
5056 printk(KERN_NOTICE "Watchdog enabled\n");
5057 }
5058
Karsten Keildb9bb632009-05-22 11:04:53 +00005059 if (pdev && ent)
5060 /* setup pci, hc->slots may change due to PLXSD */
5061 ret_err = setup_pci(hc, pdev, ent);
5062 else
5063#ifdef CONFIG_MISDN_HFCMULTI_8xx
5064 ret_err = setup_embedded(hc, m);
5065#else
5066 {
5067 printk(KERN_WARNING "Embedded IO Mode not selected\n");
5068 ret_err = -EIO;
5069 }
5070#endif
Karsten Keilaf69fb32008-07-27 02:00:43 +02005071 if (ret_err) {
5072 if (hc == syncmaster)
5073 syncmaster = NULL;
5074 kfree(hc);
5075 return ret_err;
5076 }
5077
Karsten Keildb9bb632009-05-22 11:04:53 +00005078 hc->HFC_outb_nodebug = hc->HFC_outb;
5079 hc->HFC_inb_nodebug = hc->HFC_inb;
5080 hc->HFC_inw_nodebug = hc->HFC_inw;
5081 hc->HFC_wait_nodebug = hc->HFC_wait;
5082#ifdef HFC_REGISTER_DEBUG
5083 hc->HFC_outb = HFC_outb_debug;
5084 hc->HFC_inb = HFC_inb_debug;
5085 hc->HFC_inw = HFC_inw_debug;
5086 hc->HFC_wait = HFC_wait_debug;
5087#endif
5088 /* create channels */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005089 for (pt = 0; pt < hc->ports; pt++) {
5090 if (Port_cnt >= MAX_PORTS) {
5091 printk(KERN_ERR "too many ports (max=%d).\n",
Joe Perches475be4d2012-02-19 19:52:38 -08005092 MAX_PORTS);
Karsten Keilaf69fb32008-07-27 02:00:43 +02005093 ret_err = -EINVAL;
5094 goto free_card;
5095 }
Karsten Keildb9bb632009-05-22 11:04:53 +00005096 if (hc->ctype == HFC_TYPE_E1)
Karsten Keilaf69fb32008-07-27 02:00:43 +02005097 ret_err = init_e1_port(hc, m);
5098 else
5099 ret_err = init_multi_port(hc, pt);
5100 if (debug & DEBUG_HFCMULTI_INIT)
5101 printk(KERN_DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -08005102 "%s: Registering D-channel, card(%d) port(%d)"
5103 "result %d\n",
5104 __func__, HFC_cnt + 1, pt, ret_err);
Karsten Keilaf69fb32008-07-27 02:00:43 +02005105
5106 if (ret_err) {
5107 while (pt) { /* release already registered ports */
5108 pt--;
5109 release_port(hc, hc->chan[(pt << 2) + 2].dch);
5110 }
5111 goto free_card;
5112 }
5113 Port_cnt++;
5114 }
5115
5116 /* disp switches */
5117 switch (m->dip_type) {
5118 case DIP_4S:
5119 /*
Karsten Keil69e656c2009-01-07 00:00:59 +01005120 * Get DIP setting for beroNet 1S/2S/4S cards
Karsten Keilaf69fb32008-07-27 02:00:43 +02005121 * DIP Setting: (collect GPIO 13/14/15 (R_GPIO_IN1) +
5122 * GPI 19/23 (R_GPI_IN2))
5123 */
5124 dips = ((~HFC_inb(hc, R_GPIO_IN1) & 0xE0) >> 5) |
5125 ((~HFC_inb(hc, R_GPI_IN2) & 0x80) >> 3) |
5126 (~HFC_inb(hc, R_GPI_IN2) & 0x08);
5127
5128 /* Port mode (TE/NT) jumpers */
5129 pmj = ((HFC_inb(hc, R_GPI_IN3) >> 4) & 0xf);
5130
5131 if (test_bit(HFC_CHIP_B410P, &hc->chip))
5132 pmj = ~pmj & 0xf;
5133
5134 printk(KERN_INFO "%s: %s DIPs(0x%x) jumpers(0x%x)\n",
Joe Perches475be4d2012-02-19 19:52:38 -08005135 m->vendor_name, m->card_name, dips, pmj);
Karsten Keilaf69fb32008-07-27 02:00:43 +02005136 break;
5137 case DIP_8S:
5138 /*
Karsten Keil69e656c2009-01-07 00:00:59 +01005139 * Get DIP Setting for beroNet 8S0+ cards
5140 * Enable PCI auxbridge function
Karsten Keilaf69fb32008-07-27 02:00:43 +02005141 */
5142 HFC_outb(hc, R_BRG_PCM_CFG, 1 | V_PCM_CLK);
5143 /* prepare access to auxport */
5144 outw(0x4000, hc->pci_iobase + 4);
5145 /*
5146 * some dummy reads are required to
5147 * read valid DIP switch data
5148 */
5149 dips = inb(hc->pci_iobase);
5150 dips = inb(hc->pci_iobase);
5151 dips = inb(hc->pci_iobase);
5152 dips = ~inb(hc->pci_iobase) & 0x3F;
5153 outw(0x0, hc->pci_iobase + 4);
5154 /* disable PCI auxbridge function */
5155 HFC_outb(hc, R_BRG_PCM_CFG, V_PCM_CLK);
5156 printk(KERN_INFO "%s: %s DIPs(0x%x)\n",
Joe Perches475be4d2012-02-19 19:52:38 -08005157 m->vendor_name, m->card_name, dips);
Karsten Keilaf69fb32008-07-27 02:00:43 +02005158 break;
5159 case DIP_E1:
5160 /*
5161 * get DIP Setting for beroNet E1 cards
5162 * DIP Setting: collect GPI 4/5/6/7 (R_GPI_IN0)
5163 */
Joe Perches475be4d2012-02-19 19:52:38 -08005164 dips = (~HFC_inb(hc, R_GPI_IN0) & 0xF0) >> 4;
Karsten Keilaf69fb32008-07-27 02:00:43 +02005165 printk(KERN_INFO "%s: %s DIPs(0x%x)\n",
Joe Perches475be4d2012-02-19 19:52:38 -08005166 m->vendor_name, m->card_name, dips);
Karsten Keilaf69fb32008-07-27 02:00:43 +02005167 break;
5168 }
5169
5170 /* add to list */
5171 spin_lock_irqsave(&HFClock, flags);
5172 list_add_tail(&hc->list, &HFClist);
5173 spin_unlock_irqrestore(&HFClock, flags);
5174
Andreas Eversberg3bd69ad2008-09-06 09:03:46 +02005175 /* use as clock source */
5176 if (clock == HFC_cnt + 1)
5177 hc->iclock = mISDN_register_clock("HFCMulti", 0, clockctl, hc);
5178
Karsten Keilaf69fb32008-07-27 02:00:43 +02005179 /* initialize hardware */
Karsten Keildb9bb632009-05-22 11:04:53 +00005180 hc->irq = (m->irq) ? : hc->pci_dev->irq;
Karsten Keilaf69fb32008-07-27 02:00:43 +02005181 ret_err = init_card(hc);
5182 if (ret_err) {
5183 printk(KERN_ERR "init card returns %d\n", ret_err);
5184 release_card(hc);
5185 return ret_err;
5186 }
5187
5188 /* start IRQ and return */
5189 spin_lock_irqsave(&hc->lock, flags);
5190 enable_hwirq(hc);
5191 spin_unlock_irqrestore(&hc->lock, flags);
5192 return 0;
5193
5194free_card:
5195 release_io_hfcmulti(hc);
5196 if (hc == syncmaster)
5197 syncmaster = NULL;
5198 kfree(hc);
5199 return ret_err;
5200}
5201
5202static void __devexit hfc_remove_pci(struct pci_dev *pdev)
5203{
5204 struct hfc_multi *card = pci_get_drvdata(pdev);
5205 u_long flags;
5206
5207 if (debug)
5208 printk(KERN_INFO "removing hfc_multi card vendor:%x "
Joe Perches475be4d2012-02-19 19:52:38 -08005209 "device:%x subvendor:%x subdevice:%x\n",
5210 pdev->vendor, pdev->device,
5211 pdev->subsystem_vendor, pdev->subsystem_device);
Karsten Keilaf69fb32008-07-27 02:00:43 +02005212
5213 if (card) {
5214 spin_lock_irqsave(&HFClock, flags);
5215 release_card(card);
5216 spin_unlock_irqrestore(&HFClock, flags);
5217 } else {
5218 if (debug)
Uwe Kleine-König698f9312010-07-02 20:41:51 +02005219 printk(KERN_DEBUG "%s: drvdata already removed\n",
Joe Perches475be4d2012-02-19 19:52:38 -08005220 __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02005221 }
5222}
5223
5224#define VENDOR_CCD "Cologne Chip AG"
5225#define VENDOR_BN "beroNet GmbH"
5226#define VENDOR_DIG "Digium Inc."
5227#define VENDOR_JH "Junghanns.NET GmbH"
5228#define VENDOR_PRIM "PrimuX"
5229
5230static const struct hm_map hfcm_map[] = {
Joe Perches475be4d2012-02-19 19:52:38 -08005231 /*0*/ {VENDOR_BN, "HFC-1S Card (mini PCI)", 4, 1, 1, 3, 0, DIP_4S, 0, 0},
5232 /*1*/ {VENDOR_BN, "HFC-2S Card", 4, 2, 1, 3, 0, DIP_4S, 0, 0},
5233 /*2*/ {VENDOR_BN, "HFC-2S Card (mini PCI)", 4, 2, 1, 3, 0, DIP_4S, 0, 0},
5234 /*3*/ {VENDOR_BN, "HFC-4S Card", 4, 4, 1, 2, 0, DIP_4S, 0, 0},
5235 /*4*/ {VENDOR_BN, "HFC-4S Card (mini PCI)", 4, 4, 1, 2, 0, 0, 0, 0},
5236 /*5*/ {VENDOR_CCD, "HFC-4S Eval (old)", 4, 4, 0, 0, 0, 0, 0, 0},
5237 /*6*/ {VENDOR_CCD, "HFC-4S IOB4ST", 4, 4, 1, 2, 0, DIP_4S, 0, 0},
5238 /*7*/ {VENDOR_CCD, "HFC-4S", 4, 4, 1, 2, 0, 0, 0, 0},
5239 /*8*/ {VENDOR_DIG, "HFC-4S Card", 4, 4, 0, 2, 0, 0, HFC_IO_MODE_REGIO, 0},
5240 /*9*/ {VENDOR_CCD, "HFC-4S Swyx 4xS0 SX2 QuadBri", 4, 4, 1, 2, 0, 0, 0, 0},
5241 /*10*/ {VENDOR_JH, "HFC-4S (junghanns 2.0)", 4, 4, 1, 2, 0, 0, 0, 0},
5242 /*11*/ {VENDOR_PRIM, "HFC-2S Primux Card", 4, 2, 0, 0, 0, 0, 0, 0},
Karsten Keilaf69fb32008-07-27 02:00:43 +02005243
Joe Perches475be4d2012-02-19 19:52:38 -08005244 /*12*/ {VENDOR_BN, "HFC-8S Card", 8, 8, 1, 0, 0, 0, 0, 0},
5245 /*13*/ {VENDOR_BN, "HFC-8S Card (+)", 8, 8, 1, 8, 0, DIP_8S,
5246 HFC_IO_MODE_REGIO, 0},
5247 /*14*/ {VENDOR_CCD, "HFC-8S Eval (old)", 8, 8, 0, 0, 0, 0, 0, 0},
5248 /*15*/ {VENDOR_CCD, "HFC-8S IOB4ST Recording", 8, 8, 1, 0, 0, 0, 0, 0},
Karsten Keilaf69fb32008-07-27 02:00:43 +02005249
Joe Perches475be4d2012-02-19 19:52:38 -08005250 /*16*/ {VENDOR_CCD, "HFC-8S IOB8ST", 8, 8, 1, 0, 0, 0, 0, 0},
5251 /*17*/ {VENDOR_CCD, "HFC-8S", 8, 8, 1, 0, 0, 0, 0, 0},
5252 /*18*/ {VENDOR_CCD, "HFC-8S", 8, 8, 1, 0, 0, 0, 0, 0},
Karsten Keilaf69fb32008-07-27 02:00:43 +02005253
Joe Perches475be4d2012-02-19 19:52:38 -08005254 /*19*/ {VENDOR_BN, "HFC-E1 Card", 1, 1, 0, 1, 0, DIP_E1, 0, 0},
5255 /*20*/ {VENDOR_BN, "HFC-E1 Card (mini PCI)", 1, 1, 0, 1, 0, 0, 0, 0},
5256 /*21*/ {VENDOR_BN, "HFC-E1+ Card (Dual)", 1, 1, 0, 1, 0, DIP_E1, 0, 0},
5257 /*22*/ {VENDOR_BN, "HFC-E1 Card (Dual)", 1, 1, 0, 1, 0, DIP_E1, 0, 0},
Karsten Keilaf69fb32008-07-27 02:00:43 +02005258
Joe Perches475be4d2012-02-19 19:52:38 -08005259 /*23*/ {VENDOR_CCD, "HFC-E1 Eval (old)", 1, 1, 0, 0, 0, 0, 0, 0},
5260 /*24*/ {VENDOR_CCD, "HFC-E1 IOB1E1", 1, 1, 0, 1, 0, 0, 0, 0},
5261 /*25*/ {VENDOR_CCD, "HFC-E1", 1, 1, 0, 1, 0, 0, 0, 0},
Karsten Keilaf69fb32008-07-27 02:00:43 +02005262
Joe Perches475be4d2012-02-19 19:52:38 -08005263 /*26*/ {VENDOR_CCD, "HFC-4S Speech Design", 4, 4, 0, 0, 0, 0,
5264 HFC_IO_MODE_PLXSD, 0},
5265 /*27*/ {VENDOR_CCD, "HFC-E1 Speech Design", 1, 1, 0, 0, 0, 0,
5266 HFC_IO_MODE_PLXSD, 0},
5267 /*28*/ {VENDOR_CCD, "HFC-4S OpenVox", 4, 4, 1, 0, 0, 0, 0, 0},
5268 /*29*/ {VENDOR_CCD, "HFC-2S OpenVox", 4, 2, 1, 0, 0, 0, 0, 0},
5269 /*30*/ {VENDOR_CCD, "HFC-8S OpenVox", 8, 8, 1, 0, 0, 0, 0, 0},
5270 /*31*/ {VENDOR_CCD, "XHFC-4S Speech Design", 5, 4, 0, 0, 0, 0,
5271 HFC_IO_MODE_EMBSD, XHFC_IRQ},
5272 /*32*/ {VENDOR_JH, "HFC-8S (junghanns)", 8, 8, 1, 0, 0, 0, 0, 0},
5273 /*33*/ {VENDOR_BN, "HFC-2S Beronet Card PCIe", 4, 2, 1, 3, 0, DIP_4S, 0, 0},
5274 /*34*/ {VENDOR_BN, "HFC-4S Beronet Card PCIe", 4, 4, 1, 2, 0, DIP_4S, 0, 0},
Karsten Keilaf69fb32008-07-27 02:00:43 +02005275};
5276
5277#undef H
5278#define H(x) ((unsigned long)&hfcm_map[x])
5279static struct pci_device_id hfmultipci_ids[] __devinitdata = {
5280
5281 /* Cards with HFC-4S Chip */
5282 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005283 PCI_SUBDEVICE_ID_CCD_BN1SM, 0, 0, H(0)}, /* BN1S mini PCI */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005284 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005285 PCI_SUBDEVICE_ID_CCD_BN2S, 0, 0, H(1)}, /* BN2S */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005286 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005287 PCI_SUBDEVICE_ID_CCD_BN2SM, 0, 0, H(2)}, /* BN2S mini PCI */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005288 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005289 PCI_SUBDEVICE_ID_CCD_BN4S, 0, 0, H(3)}, /* BN4S */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005290 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005291 PCI_SUBDEVICE_ID_CCD_BN4SM, 0, 0, H(4)}, /* BN4S mini PCI */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005292 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005293 PCI_DEVICE_ID_CCD_HFC4S, 0, 0, H(5)}, /* Old Eval */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005294 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005295 PCI_SUBDEVICE_ID_CCD_IOB4ST, 0, 0, H(6)}, /* IOB4ST */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005296 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005297 PCI_SUBDEVICE_ID_CCD_HFC4S, 0, 0, H(7)}, /* 4S */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005298 { PCI_VENDOR_ID_DIGIUM, PCI_DEVICE_ID_DIGIUM_HFC4S,
Joe Perches475be4d2012-02-19 19:52:38 -08005299 PCI_VENDOR_ID_DIGIUM, PCI_DEVICE_ID_DIGIUM_HFC4S, 0, 0, H(8)},
Karsten Keilaf69fb32008-07-27 02:00:43 +02005300 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005301 PCI_SUBDEVICE_ID_CCD_SWYX4S, 0, 0, H(9)}, /* 4S Swyx */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005302 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005303 PCI_SUBDEVICE_ID_CCD_JH4S20, 0, 0, H(10)},
Karsten Keilaf69fb32008-07-27 02:00:43 +02005304 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005305 PCI_SUBDEVICE_ID_CCD_PMX2S, 0, 0, H(11)}, /* Primux */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005306 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005307 PCI_SUBDEVICE_ID_CCD_OV4S, 0, 0, H(28)}, /* OpenVox 4 */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005308 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005309 PCI_SUBDEVICE_ID_CCD_OV2S, 0, 0, H(29)}, /* OpenVox 2 */
Lars Ellenbergd00561a2010-03-15 19:09:28 -07005310 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005311 0xb761, 0, 0, H(33)}, /* BN2S PCIe */
Lars Ellenbergd00561a2010-03-15 19:09:28 -07005312 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005313 0xb762, 0, 0, H(34)}, /* BN4S PCIe */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005314
5315 /* Cards with HFC-8S Chip */
5316 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005317 PCI_SUBDEVICE_ID_CCD_BN8S, 0, 0, H(12)}, /* BN8S */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005318 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005319 PCI_SUBDEVICE_ID_CCD_BN8SP, 0, 0, H(13)}, /* BN8S+ */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005320 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005321 PCI_DEVICE_ID_CCD_HFC8S, 0, 0, H(14)}, /* old Eval */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005322 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005323 PCI_SUBDEVICE_ID_CCD_IOB8STR, 0, 0, H(15)}, /* IOB8ST Recording */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005324 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005325 PCI_SUBDEVICE_ID_CCD_IOB8ST, 0, 0, H(16)}, /* IOB8ST */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005326 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005327 PCI_SUBDEVICE_ID_CCD_IOB8ST_1, 0, 0, H(17)}, /* IOB8ST */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005328 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005329 PCI_SUBDEVICE_ID_CCD_HFC8S, 0, 0, H(18)}, /* 8S */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005330 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005331 PCI_SUBDEVICE_ID_CCD_OV8S, 0, 0, H(30)}, /* OpenVox 8 */
Andreas Eversberg7245a2f2009-05-22 11:04:55 +00005332 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005333 PCI_SUBDEVICE_ID_CCD_JH8S, 0, 0, H(32)}, /* Junganns 8S */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005334
5335
5336 /* Cards with HFC-E1 Chip */
5337 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005338 PCI_SUBDEVICE_ID_CCD_BNE1, 0, 0, H(19)}, /* BNE1 */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005339 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005340 PCI_SUBDEVICE_ID_CCD_BNE1M, 0, 0, H(20)}, /* BNE1 mini PCI */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005341 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005342 PCI_SUBDEVICE_ID_CCD_BNE1DP, 0, 0, H(21)}, /* BNE1 + (Dual) */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005343 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005344 PCI_SUBDEVICE_ID_CCD_BNE1D, 0, 0, H(22)}, /* BNE1 (Dual) */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005345
5346 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005347 PCI_DEVICE_ID_CCD_HFCE1, 0, 0, H(23)}, /* Old Eval */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005348 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005349 PCI_SUBDEVICE_ID_CCD_IOB1E1, 0, 0, H(24)}, /* IOB1E1 */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005350 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005351 PCI_SUBDEVICE_ID_CCD_HFCE1, 0, 0, H(25)}, /* E1 */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005352
5353 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005354 PCI_SUBDEVICE_ID_CCD_SPD4S, 0, 0, H(26)}, /* PLX PCI Bridge */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005355 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005356 PCI_SUBDEVICE_ID_CCD_SPDE1, 0, 0, H(27)}, /* PLX PCI Bridge */
Andreas Eversbergdaebafe2009-05-25 00:56:56 -07005357
5358 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
Joe Perches475be4d2012-02-19 19:52:38 -08005359 PCI_SUBDEVICE_ID_CCD_JHSE1, 0, 0, H(25)}, /* Junghanns E1 */
Andreas Eversbergdaebafe2009-05-25 00:56:56 -07005360
Peter Huewe9db9f272010-07-15 09:05:38 +00005361 { PCI_VDEVICE(CCD, PCI_DEVICE_ID_CCD_HFC4S), 0 },
5362 { PCI_VDEVICE(CCD, PCI_DEVICE_ID_CCD_HFC8S), 0 },
5363 { PCI_VDEVICE(CCD, PCI_DEVICE_ID_CCD_HFCE1), 0 },
Karsten Keilaf69fb32008-07-27 02:00:43 +02005364 {0, }
5365};
5366#undef H
5367
5368MODULE_DEVICE_TABLE(pci, hfmultipci_ids);
5369
5370static int
5371hfcmulti_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5372{
5373 struct hm_map *m = (struct hm_map *)ent->driver_data;
5374 int ret;
5375
Karsten Keil69e656c2009-01-07 00:00:59 +01005376 if (m == NULL && ent->vendor == PCI_VENDOR_ID_CCD && (
Joe Perches475be4d2012-02-19 19:52:38 -08005377 ent->device == PCI_DEVICE_ID_CCD_HFC4S ||
5378 ent->device == PCI_DEVICE_ID_CCD_HFC8S ||
5379 ent->device == PCI_DEVICE_ID_CCD_HFCE1)) {
Karsten Keil69e656c2009-01-07 00:00:59 +01005380 printk(KERN_ERR
Joe Perches475be4d2012-02-19 19:52:38 -08005381 "Unknown HFC multiport controller (vendor:%04x device:%04x "
5382 "subvendor:%04x subdevice:%04x)\n", pdev->vendor,
5383 pdev->device, pdev->subsystem_vendor,
5384 pdev->subsystem_device);
Karsten Keil69e656c2009-01-07 00:00:59 +01005385 printk(KERN_ERR
Joe Perches475be4d2012-02-19 19:52:38 -08005386 "Please contact the driver maintainer for support.\n");
Karsten Keilaf69fb32008-07-27 02:00:43 +02005387 return -ENODEV;
5388 }
Karsten Keildb9bb632009-05-22 11:04:53 +00005389 ret = hfcmulti_init(m, pdev, ent);
Karsten Keilaf69fb32008-07-27 02:00:43 +02005390 if (ret)
5391 return ret;
5392 HFC_cnt++;
5393 printk(KERN_INFO "%d devices registered\n", HFC_cnt);
5394 return 0;
5395}
5396
5397static struct pci_driver hfcmultipci_driver = {
5398 .name = "hfc_multi",
5399 .probe = hfcmulti_probe,
5400 .remove = __devexit_p(hfc_remove_pci),
5401 .id_table = hfmultipci_ids,
5402};
5403
5404static void __exit
5405HFCmulti_cleanup(void)
5406{
5407 struct hfc_multi *card, *next;
5408
Karsten Keil69e656c2009-01-07 00:00:59 +01005409 /* get rid of all devices of this driver */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005410 list_for_each_entry_safe(card, next, &HFClist, list)
5411 release_card(card);
Karsten Keilaf69fb32008-07-27 02:00:43 +02005412 pci_unregister_driver(&hfcmultipci_driver);
5413}
5414
5415static int __init
5416HFCmulti_init(void)
5417{
5418 int err;
Karsten Keildb9bb632009-05-22 11:04:53 +00005419 int i, xhfc = 0;
5420 struct hm_map m;
Karsten Keilaf69fb32008-07-27 02:00:43 +02005421
Karsten Keil69e656c2009-01-07 00:00:59 +01005422 printk(KERN_INFO "mISDN: HFC-multi driver %s\n", HFC_MULTI_VERSION);
5423
Karsten Keilaf69fb32008-07-27 02:00:43 +02005424#ifdef IRQ_DEBUG
Karsten Keil69e656c2009-01-07 00:00:59 +01005425 printk(KERN_DEBUG "%s: IRQ_DEBUG IS ENABLED!\n", __func__);
Karsten Keilaf69fb32008-07-27 02:00:43 +02005426#endif
5427
5428 spin_lock_init(&HFClock);
5429 spin_lock_init(&plx_lock);
5430
5431 if (debug & DEBUG_HFCMULTI_INIT)
5432 printk(KERN_DEBUG "%s: init entered\n", __func__);
5433
Karsten Keilaf69fb32008-07-27 02:00:43 +02005434 switch (poll) {
5435 case 0:
5436 poll_timer = 6;
5437 poll = 128;
5438 break;
Karsten Keilaf69fb32008-07-27 02:00:43 +02005439 case 8:
5440 poll_timer = 2;
5441 break;
5442 case 16:
5443 poll_timer = 3;
5444 break;
5445 case 32:
5446 poll_timer = 4;
5447 break;
5448 case 64:
5449 poll_timer = 5;
5450 break;
5451 case 128:
5452 poll_timer = 6;
5453 break;
5454 case 256:
5455 poll_timer = 7;
5456 break;
5457 default:
5458 printk(KERN_ERR
Joe Perches475be4d2012-02-19 19:52:38 -08005459 "%s: Wrong poll value (%d).\n", __func__, poll);
Karsten Keilaf69fb32008-07-27 02:00:43 +02005460 err = -EINVAL;
5461 return err;
5462
5463 }
5464
Andreas Eversberg3bd69ad2008-09-06 09:03:46 +02005465 if (!clock)
5466 clock = 1;
5467
Karsten Keildb9bb632009-05-22 11:04:53 +00005468 /* Register the embedded devices.
5469 * This should be done before the PCI cards registration */
5470 switch (hwid) {
5471 case HWID_MINIP4:
5472 xhfc = 1;
5473 m = hfcm_map[31];
5474 break;
5475 case HWID_MINIP8:
5476 xhfc = 2;
5477 m = hfcm_map[31];
5478 break;
5479 case HWID_MINIP16:
5480 xhfc = 4;
5481 m = hfcm_map[31];
5482 break;
5483 default:
5484 xhfc = 0;
5485 }
5486
5487 for (i = 0; i < xhfc; ++i) {
5488 err = hfcmulti_init(&m, NULL, NULL);
5489 if (err) {
5490 printk(KERN_ERR "error registering embedded driver: "
Joe Perches475be4d2012-02-19 19:52:38 -08005491 "%x\n", err);
Roel Kluin2c554e12009-11-15 21:18:13 -08005492 return err;
Karsten Keildb9bb632009-05-22 11:04:53 +00005493 }
5494 HFC_cnt++;
5495 printk(KERN_INFO "%d devices registered\n", HFC_cnt);
5496 }
5497
5498 /* Register the PCI cards */
Karsten Keilaf69fb32008-07-27 02:00:43 +02005499 err = pci_register_driver(&hfcmultipci_driver);
5500 if (err < 0) {
5501 printk(KERN_ERR "error registering pci driver: %x\n", err);
Karsten Keilaf69fb32008-07-27 02:00:43 +02005502 return err;
5503 }
Karsten Keildb9bb632009-05-22 11:04:53 +00005504
Karsten Keilaf69fb32008-07-27 02:00:43 +02005505 return 0;
5506}
5507
5508
5509module_init(HFCmulti_init);
5510module_exit(HFCmulti_cleanup);