~ubuntu-branches/ubuntu/quantal/zaptel/quantal

« back to all changes in this revision

Viewing changes to kernel/ds1x1f.c

  • Committer: Bazaar Package Importer
  • Author(s): Tzafrir Cohen
  • Date: 2008-08-28 22:58:23 UTC
  • mfrom: (11.1.11 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080828225823-r8bdunirm8hmc76m
Tags: 1:1.4.11~dfsg-2
* Patch xpp_fxs_power: Fixed an issue with hook detection of the Astribank
  FXS module.
* Don't fail init.d script if fxotune fails. This may happen if running it
  when Asterisk is already running.
* Bump standards version to 3.8.0.0 .
* Ignore false lintian warning ("m-a a-i" has "a a").
* Patch xpp_fxo_cid_always: do always pass PCM if that's what the user
  asked.
* Patch vzaphfc_proc_root_dir: fix vzaphfc on 2.6.26.
* Patch wcte12xp_flags: Proper time for irq save flags.
* Patch headers_2627: Fix location of semaphore.h for 2.6.27 .
* Patch xpp_fxs_dtmf_leak: Don't play DTMFs to the wrong channel.
* Patch wctdm_fix_alarm: Fix sending channel alarms.
* Patch device_class_2626: Fix building 2.6.26 (Closes: #493397).
* Using dh_lintian for lintian overrides, hence requiring debhelper 6.0.7.
* Lintian: we know we have direct changes. Too bad we're half-upstream :-(
* Fix doc-base section names. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=======================================================================
 
2
//            T1/E1 PCI card with failover  DS1x1F card Driver
 
3
//
 
4
//                   Ver: 2.14   Date: 17.Jan.2007
 
5
//
 
6
//                      based of work by:
 
7
//               Mark Spencer <markster@digium.com>
 
8
//            Matthew Fredrickson <creslin@digium.com>
 
9
//             William Meadows <wmeadows@digium.com>
 
10
//
 
11
//                  Copyright (c)2006,2007 TCDG Corp.
 
12
//                      All rights reserved.
 
13
//                      
 
14
//                      http://www.tc-dg.net
 
15
//
 
16
// This program is free software; you can redistribute it and/or modify
 
17
// it under the terms of the GNU General Public License as published by
 
18
// the Free Software Foundation; either version 2 of the License, or
 
19
// (at your option) any later version.
 
20
// 
 
21
// This program is distributed in the hope that it will be useful,
 
22
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
23
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
24
// GNU General Public License for more details.
 
25
// 
 
26
// You should have received a copy of the GNU General Public License
 
27
// along with this program; if not, write to the Free Software
 
28
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 
29
//
 
30
//=======================================================================
 
31
 
 
32
 
 
33
#include <linux/interrupt.h>
 
34
#include <linux/pci.h>
 
35
#include <linux/delay.h>
 
36
#include <linux/spinlock.h>
 
37
 
 
38
#ifdef STANDALONE_ZAPATA
 
39
#include "zaptel.h"
 
40
#else
 
41
#include <linux/zaptel.h>
 
42
#endif
 
43
 
 
44
 
 
45
#define WC_MAX_CARDS            32
 
46
#define NUM_REGS                0xa9
 
47
#define NUM_PCI                 12
 
48
 
 
49
#define OFS_FALC                0x0000          // pci address space offset for FALC registers  256 * 32 bit words (only 8 LSB used) 
 
50
#define OFS_TDM_WR              0x0800          // pci address space offset for TDM media shift register buffers  8 * 32 bit words   
 
51
#define OFS_TDM_RD              0x0900          // pci address space offset for TDM media shift register buffers  8 * 32 bit words   
 
52
#define OFS_CTRL                0x1000          // pci address space offset for card control register             1 * 32 bit         
 
53
#define OFS_CLK                 0x1004          // pci address space offset for card clock / h.100 register       1 * 32 bit         
 
54
 
 
55
 
 
56
#define FLAG_STARTED            0x01
 
57
#define FLAG_NMF                0x02
 
58
#define FLAG_SENDINGYELLOW      0x04
 
59
 
 
60
#define MODE_SW                 -1              // mode controlled by DIP switch
 
61
#define MODE_T1                 0x01            // T1 mode                      bit.0 = T1
 
62
#define MODE_E1                 0x02            // E1 mode                      bit.1 = E1
 
63
#define MODE_UE1                0x82            // unchannelized E1             bit.7 = unchannelized
 
64
#define MODE_J1                 0x41            // J1 mode                      bit.6 = j1mode
 
65
 
 
66
 
 
67
#define DS1_SET_REL              7              // new MAINT commands for controlling the bypass relay and monitoring, hot-standby
 
68
#define DS1_CLR_REL              8
 
69
#define DS1_SET_RXMON            9
 
70
#define DS1_CLR_RXMON           10
 
71
#define DS1_SET_TXEN            11
 
72
#define DS1_CLR_TXEN            12
 
73
 
 
74
 
 
75
 
 
76
//======================================= Control register  bit definitions ================================
 
77
 
 
78
#define CTRL_LOFF               0x0000          // All LED off
 
79
#define CTRL_LGRN               0x0001          // Green LED control bit
 
80
#define CTRL_LRED               0x0002          // Red LED control bit
 
81
#define CTRL_REL                0x0004          // bypass relay  L = bypass  H = normal operation
 
82
#define CTRL_TEST               0x0008          // relay presence test bit  L = normal operation  H= presence test
 
83
#define CTRL_FRST               0x0010          // Falc reset bit  L = normal operation H = Falc Reset
 
84
#define CTRL_INTA               0x0100          // Interrupt acknowledge bit  writing a '1' resets IRQ and IRM
 
85
#define CTRL_IRQ                0x0100          // Interrupt request bit
 
86
#define CTRL_IRM                0x0400          // Interrupt missed bit  = previous interrupt has not yet been serviced when new one was triggered 
 
87
#define CTRL_RELI               0x0800          // relay presence bit  H = no relay  L = relay present  (valid only when CTRL_TEST = H)
 
88
#define CTRL_SW1                0x1000          // DIP switch #1
 
89
#define CTRL_SW2                0x2000          // DIP switch #2
 
90
#define CTRL_SW3                0x4000          // DIP switch #3
 
91
#define CTRL_SW4                0x8000          // DIP switch #4
 
92
 
 
93
//==================================== FALC-56 PEF-2256 register definitions ===============================
 
94
 
 
95
#define FR_XFIFO        0x00
 
96
#define FR_RFIFO        0x00
 
97
#define FR_CMDR         0x02
 
98
#define FR_MODE         0x03
 
99
#define FR_RAH1         0x04
 
100
#define FR_RAH2         0x05
 
101
#define FR_RAL1         0x06
 
102
#define FR_RAL2         0x07
 
103
#define FR_IPC          0x08
 
104
#define FR_CCR1         0x09
 
105
#define FR_CCR2         0x0a
 
106
#define FR_RTR1         0x0c
 
107
#define FR_RTR2         0x0d
 
108
#define FR_RTR3         0x0e
 
109
#define FR_RTR4         0x0f
 
110
#define FR_TTR1         0x10
 
111
#define FR_TTR2         0x11
 
112
#define FR_TTR3         0x12
 
113
#define FR_TTR4         0x13
 
114
#define FR_IMR0         0x14
 
115
#define FR_IMR1         0x15
 
116
#define FR_IMR2         0x16
 
117
#define FR_IMR3         0x17
 
118
#define FR_IMR4         0x18
 
119
#define FR_IMR5         0x19
 
120
#define FR_IERR         0x1b
 
121
#define FR_FMR0         0x1c
 
122
#define FR_FMR1         0x1d
 
123
#define FR_FMR2         0x1e
 
124
#define FR_LOOP         0x1f
 
125
#define FR_FMR4         0x20
 
126
#define FR_FMR5         0x21
 
127
#define FR_XSW          0x20
 
128
#define FR_XSP          0x21
 
129
#define FR_XC0          0x22
 
130
#define FR_XC1          0x23
 
131
#define FR_RC0          0x24
 
132
#define FR_RC1          0x25
 
133
#define FR_XPM0         0x26
 
134
#define FR_XPM1         0x27
 
135
#define FR_XPM2         0x28
 
136
#define FR_TSWM         0x29
 
137
#define FR_IDLE         0x2b
 
138
#define FR_XSA4         0x2c
 
139
#define FR_XSA5         0x2d
 
140
#define FR_XSA6         0x2e
 
141
#define FR_XSA7         0x2f
 
142
#define FR_XSA8         0x30
 
143
#define FR_FMR3         0x31
 
144
#define FR_CCB1         0x2f
 
145
#define FR_CCB2         0x30
 
146
#define FR_CCB3         0x31
 
147
#define FR_ICB1         0x32
 
148
#define FR_ICB2         0x33
 
149
#define FR_ICB3         0x34
 
150
#define FR_ICB4         0x35
 
151
#define FR_LIM0         0x36
 
152
#define FR_LIM1         0x37
 
153
#define FR_PCD          0x38
 
154
#define FR_PCR          0x39
 
155
#define FR_LIM2         0x3a
 
156
#define FR_LCR1         0x3b
 
157
#define FR_LCR2         0x3c
 
158
#define FR_LCR3         0x3d
 
159
#define FR_SIC1         0x3e
 
160
#define FR_SIC2         0x3f
 
161
#define FR_SIC3         0x40
 
162
#define FR_CMR1         0x44
 
163
#define FR_CMR2         0x45
 
164
#define FR_GCR          0x46
 
165
#define FR_ESM          0x47
 
166
#define FR_RBD          0x49
 
167
#define FR_VSTR         0x4a
 
168
#define FR_RES          0x4b
 
169
#define FR_FRS0         0x4c
 
170
#define FR_FRS1         0x4d
 
171
#define FR_RSW          0x4e
 
172
#define FR_RSP          0x4f
 
173
#define FR_FECL         0x50
 
174
#define FR_FECH         0x51
 
175
#define FR_CVCL         0x52
 
176
#define FR_CVCH         0x53
 
177
#define FR_CEC1L        0x54
 
178
#define FR_CEC1H        0x55
 
179
#define FR_EBCL         0x56
 
180
#define FR_EBCH         0x57
 
181
#define FR_CEC2L        0x58
 
182
#define FR_CEC2H        0x59
 
183
#define FR_CEC3L        0x5a
 
184
#define FR_CEC3H        0x5b
 
185
#define FR_RSA4         0x5c
 
186
#define FR_RSA5         0x5d
 
187
#define FR_RSA6         0x5e
 
188
#define FR_RSA7         0x5f
 
189
#define FR_RSA8         0x60
 
190
#define FR_DEC          0x60
 
191
#define FR_RSA6S        0x61
 
192
#define FR_RSP1         0x62
 
193
#define FR_RSP2         0x63
 
194
#define FR_SIS          0x64
 
195
#define FR_RSIS         0x65
 
196
#define FR_RBCL         0x66
 
197
#define FR_RBCH         0x67
 
198
#define FR_ISR0         0x68
 
199
#define FR_ISR1         0x69
 
200
#define FR_ISR2         0x6a
 
201
#define FR_ISR3         0x6b
 
202
#define FR_ISR4         0x6c
 
203
#define FR_ISR5         0x6d
 
204
#define FR_GIS          0x6e
 
205
#define FR_XS1          0x70
 
206
#define FR_XS2          0x71
 
207
#define FR_XS3          0x72
 
208
#define FR_XS4          0x73
 
209
#define FR_XS5          0x74
 
210
#define FR_XS6          0x75
 
211
#define FR_XS7          0x76
 
212
#define FR_XS8          0x77
 
213
#define FR_XS9          0x78
 
214
#define FR_XS10         0x79
 
215
#define FR_XS11         0x7a
 
216
#define FR_XS12         0x7b
 
217
#define FR_XS13         0x7c
 
218
#define FR_XS14         0x7d
 
219
#define FR_XS15         0x7e
 
220
#define FR_XS16         0x7f
 
221
#define FR_RS1          0x70
 
222
#define FR_RS2          0x71
 
223
#define FR_RS3          0x72
 
224
#define FR_RS4          0x73
 
225
#define FR_RS5          0x74
 
226
#define FR_RS6          0x75
 
227
#define FR_RS7          0x76
 
228
#define FR_RS8          0x77
 
229
#define FR_RS9          0x78
 
230
#define FR_RS10         0x79
 
231
#define FR_RS11         0x7a
 
232
#define FR_RS12         0x7b
 
233
#define FR_RS13         0x7c
 
234
#define FR_RS14         0x7d
 
235
#define FR_RS15         0x7e
 
236
#define FR_RS16         0x7f
 
237
#define FR_PC1          0x80
 
238
#define FR_PC2          0x81
 
239
#define FR_PC3          0x82
 
240
#define FR_PC4          0x83
 
241
#define FR_PC5          0x84
 
242
#define FR_GPC1         0x85
 
243
#define FR_PC6          0x86
 
244
#define FR_CMDR2        0x87
 
245
#define FR_CMDR3        0x88
 
246
#define FR_CMDR4        0x89
 
247
#define FR_CCR3         0x8b
 
248
#define FR_CCR4         0x8c
 
249
#define FR_CCR5         0x8d
 
250
#define FR_MODE2        0x8e
 
251
#define FR_MODE3        0x8f
 
252
#define FR_RBC2         0x90
 
253
#define FR_RBC3         0x91
 
254
#define FR_GCM1         0x92
 
255
#define FR_GCM2         0x93
 
256
#define FR_GCM3         0x94
 
257
#define FR_GCM4         0x95
 
258
#define FR_GCM5         0x96
 
259
#define FR_GCM6         0x97
 
260
#define FR_GCM7         0x98
 
261
#define FR_GCM8         0x99
 
262
#define FR_SIS2         0x98
 
263
#define FR_RSIS2        0x99
 
264
#define FR_SIS3         0x9a
 
265
#define FR_RSIS3        0x9b
 
266
#define FR_XFIFO2       0x9c
 
267
#define FR_RFIFO2       0x9c
 
268
#define FR_XFIFO3       0x9e
 
269
#define FR_RFIFO3       0x9e
 
270
#define FR_TSEO         0xa0
 
271
#define FR_TSBS1        0xa1
 
272
#define FR_TSBS2        0xa2
 
273
#define FR_TSBS3        0xa3
 
274
#define FR_TSS2         0xa4
 
275
#define FR_TSS3         0xa5
 
276
#define FR_TPC0         0xa8
 
277
#define FR_WID          0xec
 
278
 
 
279
//========================================================================================================
 
280
 
 
281
struct t4_regs {
 
282
        unsigned int  pci[NUM_PCI];
 
283
        unsigned char regs[NUM_REGS];
 
284
};
 
285
 
 
286
 
 
287
#define WCT4_GET_REGS   _IOW (ZT_CODE, 60, struct t4_regs)
 
288
 
 
289
 
 
290
 
 
291
static int clrtab[] = {0x80,0x40,0x20,0x10,0x8,0x4,0x2,0x1};
 
292
 
 
293
static char name[]  = {"ds1x1f"};
 
294
 
 
295
struct t1 {
 
296
        struct pci_dev *dev;
 
297
        spinlock_t lock;
 
298
        int spantype;   
 
299
        int spanflags;                                          // Span flags
 
300
        unsigned char txsigs[16];                               // Copy of tx sig registers 
 
301
        int num;
 
302
        int alarmcount;                                         // How much red alarm we've seen
 
303
        int alarmdebounce;
 
304
        char *variety;
 
305
 
 
306
        unsigned int intcount;
 
307
        int          prescaler;                                 // interrupt divider
 
308
 
 
309
        int usecount;
 
310
        int blinktimer;
 
311
        int alarmtimer;
 
312
        int loopupcnt;
 
313
        int loopdowncnt;
 
314
        unsigned char     ledtestreg;
 
315
        
 
316
        void *            cnaddr;                               // PCI and driver related parameters
 
317
        void *            ioaddr;
 
318
        unsigned long     iostart;
 
319
        unsigned long     iolen;
 
320
        unsigned long     cnstart;
 
321
        unsigned long     cnlen;
 
322
        struct resource * cres;
 
323
        struct resource * ires;
 
324
 
 
325
        unsigned char txchunkptr;                               // pointer for rd/wr audiosamples
 
326
        unsigned char rxchunkptr;
 
327
 
 
328
        unsigned char ec_chunk1[32][ZT_CHUNKSIZE];              // echocanceller memory buffers
 
329
        unsigned char ec_chunk2[32][ZT_CHUNKSIZE];
 
330
        
 
331
        struct zt_span span;                                    // Span
 
332
        struct zt_chan chans[32];                               // Channels 
 
333
};
 
334
 
 
335
                                                                
 
336
                                                                // module paramter variables
 
337
static int debug         =  0;                                  // defines debug modes 0,1,2
 
338
static int cardmode      = -1;                                  // forces card into T1, E1, J1, UE1 mode , -1 = use DIP switches
 
339
static int alarmdebounce =  0;
 
340
static int loopback      =  0;
 
341
static int frames        = -1;                                  // sets the size of the cards framebuffer 1-8 frames (preferred are 1,2,4,8)
 
342
static int extclk        = -1;                                  // controls the clock synchronization via H.100 bus connector
 
343
static int monitor       =  0;                                  // monitor = 3 puts the card in a Hi-Z mode and enabling it to monitor T1/E1 traffic
 
344
 
 
345
static struct t1 *cards[WC_MAX_CARDS];
 
346
 
 
347
 
 
348
static inline void start_alarm(struct t1 *wc)
 
349
{
 
350
        wc->blinktimer = 0;
 
351
}
 
352
 
 
353
 
 
354
static int ds1_open(struct zt_chan *chan)
 
355
{
 
356
        struct t1 *wc = chan->pvt;
 
357
        
 
358
        wc->usecount++;
 
359
 
 
360
        try_module_get(THIS_MODULE);
 
361
 
 
362
        return 0;
 
363
}
 
364
 
 
365
//-------------------------------------------------------------------------------------------------------------------------------------------
 
366
static inline unsigned int led_write_reg(struct t1 *wc, unsigned int val)               // write to the cards 32 bit control register
 
367
{
 
368
        unsigned int x;
 
369
 
 
370
        x = (ioread32(wc->ioaddr + OFS_CTRL) & 0xfc) | (val & 0x03);                    // combine LED content with all other register data
 
371
 
 
372
        iowrite32(x, wc->ioaddr + OFS_CTRL);                                            // write back register content
 
373
 
 
374
        return x;
 
375
}
 
376
 
 
377
//-------------------------------------------------------------------------------------------------------------------------------------------
 
378
static inline unsigned int ctrl_set_reg(struct t1 *wc, unsigned int val)                // set bits in control register
 
379
{
 
380
        unsigned x;
 
381
 
 
382
        x = (ioread32(wc->ioaddr + OFS_CTRL) & 0xff) | val;                             // OR newcontent with all other register data
 
383
 
 
384
        iowrite32(x, wc->ioaddr + OFS_CTRL);                                            // write back register content
 
385
 
 
386
        return x;
 
387
}
 
388
 
 
389
//-------------------------------------------------------------------------------------------------------------------------------------------
 
390
static inline unsigned int ctrl_clr_reg(struct t1 *wc, unsigned int val)                // clear bits in control register
 
391
{
 
392
        unsigned x;
 
393
 
 
394
        x = (ioread32(wc->ioaddr + OFS_CTRL) & 0xff) & (val ^ 0xff);                    // OR newcontent with all other register data
 
395
 
 
396
        iowrite32(x, wc->ioaddr + OFS_CTRL);                                            // write back register content
 
397
 
 
398
        return x;
 
399
}
 
400
 
 
401
//-------------------------------------------------------------------------------------------------------------------------------------------
 
402
static inline unsigned int ctrl_write_reg(struct t1 *wc, unsigned int val)              // write to the cards 32 bit control register
 
403
{
 
404
        iowrite32(val, wc->ioaddr + OFS_CTRL);                                          // write back register content
 
405
 
 
406
        return val;
 
407
}
 
408
 
 
409
 
 
410
//-------------------------------------------------------------------------------------------------------------------------------------------
 
411
static inline unsigned int ctrl_read_reg(struct t1 *wc)                                 // read control register
 
412
{
 
413
        return (ioread32(wc->ioaddr + OFS_CTRL));                                       // return content of control register
 
414
}
 
415
 
 
416
 
 
417
//-------------------------------------------------------------------------------------------------------------------------------------------
 
418
static inline unsigned int clk_write_reg(struct t1 *wc, unsigned int val)               // write to the cards 32 bit clock/ h.100 bus register
 
419
{
 
420
        iowrite32(val, wc->ioaddr + OFS_CLK);                                           // write back register content
 
421
 
 
422
        return val;
 
423
}
 
424
 
 
425
 
 
426
//-------------------------------------------------------------------------------------------------------------------------------------------
 
427
static inline unsigned int clk_read_reg(struct t1 *wc)                                  // read clock / h.100 bus register
 
428
{
 
429
        return (ioread32(wc->ioaddr + OFS_CLK));                                        // return content of control register
 
430
}
 
431
 
 
432
 
 
433
//-------------------------------------------------------------------------------------------------------------------------------------------
 
434
static inline unsigned int __t1_framer_in(struct t1 *wc, const unsigned int reg)        // read a Falc framer register
 
435
{
 
436
        int loc = ((reg & 0x00ff) << 2) + OFS_FALC;                                     // FALC registers are on doubleword boundaries
 
437
 
 
438
        return ((ioread32(wc->ioaddr + loc)) & 0xff);                                   // return only the 8 lsb
 
439
}
 
440
 
 
441
 
 
442
 
 
443
static inline unsigned int t1_framer_in(struct t1 *wc, const unsigned int addr)         // spinlock wrapper
 
444
{
 
445
        unsigned long flags;
 
446
        unsigned int  ret;
 
447
 
 
448
        spin_lock_irqsave(&wc->lock, flags);
 
449
 
 
450
        ret = __t1_framer_in(wc, addr);
 
451
 
 
452
        spin_unlock_irqrestore(&wc->lock, flags);
 
453
 
 
454
        return ret;
 
455
}
 
456
 
 
457
 
 
458
static inline void __t1_framer_out(struct t1 *wc, const unsigned int reg, const unsigned int val)       // write to Falc framer register        
 
459
{
 
460
        int loc = ((reg & 0x00ff) << 2) + OFS_FALC;                                     // FALC registers are on doubleword boundaries
 
461
        int ret;
 
462
 
 
463
        iowrite32(val, wc->ioaddr + loc);                                               // write to register
 
464
 
 
465
        ret = (ioread32(wc->ioaddr + loc)) & 0xff;                                      // for debugging read back register content
 
466
        
 
467
        if (debug > 1)                                  
 
468
        {
 
469
                if (ret == val)                                                         // check if write was successful
 
470
                        printk("Wrote: %02x to Adr: %02x \n", val, reg);                                // and print on the console
 
471
                else
 
472
                        printk("Wrote: %02x to Adr: %02x but read back: %02x !!!\n", val, reg, ret);    // print results on the console
 
473
        }
 
474
}
 
475
 
 
476
 
 
477
static inline void t1_framer_out(struct t1 *wc, const unsigned int addr, const unsigned int value)      // spinlock wrapper
 
478
{
 
479
        unsigned long flags;
 
480
 
 
481
        spin_lock_irqsave(&wc->lock, flags);
 
482
 
 
483
        __t1_framer_out(wc, addr, value);
 
484
 
 
485
        spin_unlock_irqrestore(&wc->lock, flags);
 
486
}
 
487
 
 
488
//-------------------------------------------------------------------------------------------------------------------------------------------
 
489
static void ds1_release(struct t1 *wc)
 
490
{
 
491
        zt_unregister(&wc->span);
 
492
 
 
493
        kfree(wc);
 
494
 
 
495
        printk("Freed a DS1x1F card\n");
 
496
}
 
497
 
 
498
 
 
499
static int ds1_close(struct zt_chan *chan)
 
500
{
 
501
        struct t1 *wc = chan->pvt;
 
502
        wc->usecount--;
 
503
        
 
504
        module_put(THIS_MODULE);
 
505
        
 
506
        if (!wc->usecount)                                              // If we're dead, release us now 
 
507
                ds1_release(wc);
 
508
 
 
509
        return 0;
 
510
}
 
511
 
 
512
//----------------------------------------------------------------------------------------------------------------------------------------
 
513
//                                                      HARDWARE INTERRUPT CONTROL Enable / Disable
 
514
 
 
515
static void ds1_enable_interrupts(struct t1 *wc)                                // enable 8 kHz TDM interrupts from the pci card
 
516
{
 
517
        iowrite32(0x00000001, wc->cnaddr + 0x1ec);                              // enable internal interrupt
 
518
 
 
519
        ctrl_set_reg(wc, CTRL_INTA);                                            // clear interrupt status bit
 
520
 
 
521
        if (debug) 
 
522
                printk("Enabled interrupts!\n");
 
523
}
 
524
 
 
525
static void ds1_disable_interrupts(struct t1 *wc)                               // disable all interrupts from the card
 
526
{
 
527
        ctrl_set_reg(wc, CTRL_INTA);                                            // clear interrupt status bit
 
528
 
 
529
        iowrite32(0x00000000, wc->cnaddr + 0x1ec);                              // disable internal interrupt
 
530
 
 
531
        if (debug) 
 
532
                printk("Disabled interrupts!\n");
 
533
}
 
534
 
 
535
//----------------------------------------------------------------------------------------------------------------------------------------
 
536
static void __ds1_set_clear(struct t1 *wc)                                      // SELECT CLEAR CHANNEL MODE - FOR T1 ONLY
 
537
{
 
538
        int i;
 
539
        unsigned short val;
 
540
        
 
541
        val = 0;
 
542
        for (i=0; i<8; i++)                                                     // go through channel 0-7
 
543
        {
 
544
                if (wc->span.chans[i   ].flags & ZT_FLAG_CLEAR)                 // check if this channel is marked Clear channel 
 
545
                        val |= clrtab[i];       
 
546
        }       
 
547
        __t1_framer_out(wc, FR_CCB1, val);                                      // write register CCB1
 
548
        
 
549
        val = 0;
 
550
        for (i=0; i<8; i++)                                                     // go through channel 8-15
 
551
        {
 
552
                if (wc->span.chans[i+ 8].flags & ZT_FLAG_CLEAR)                 // check if this channel is marked Clear channel 
 
553
                        val |= clrtab[i];       
 
554
        }       
 
555
        __t1_framer_out(wc, FR_CCB2, val);                                      // write register CCB2
 
556
        
 
557
        val = 0;
 
558
        for (i=0; i<8; i++)                                                     // go through channel 16-23
 
559
        {
 
560
                if (wc->span.chans[i+16].flags & ZT_FLAG_CLEAR)                 // check if this channel is marked Clear channel 
 
561
                        val |= clrtab[i];       
 
562
        }       
 
563
        __t1_framer_out(wc, FR_CCB3, val);                                      // write register CCB3 
 
564
        
 
565
 
 
566
 
 
567
}
 
568
 
 
569
//----------------------------------------------------------------------------------------------------------------------------------------
 
570
static int ds1_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long data)
 
571
{
 
572
        struct t4_regs regs;
 
573
        int x;
 
574
        struct t1 *wc;
 
575
 
 
576
        wc = chan->pvt;
 
577
        
 
578
        switch(cmd) 
 
579
        {
 
580
                case WCT4_GET_REGS:
 
581
                        for (x=0; x<NUM_PCI; x++)
 
582
                                regs.pci[x] = (ioread32(wc->ioaddr + (x << 2)));
 
583
 
 
584
                        for (x=0; x<NUM_REGS; x++)
 
585
                                regs.regs[x] = t1_framer_in(wc, x);
 
586
 
 
587
                        if (copy_to_user((struct t4_regs *)data, &regs, sizeof(regs)))
 
588
                                return -EFAULT;
 
589
                        break;
 
590
 
 
591
                case DS1_SET_REL:                                                               // Turn on failover relay - normal operation
 
592
                        ctrl_set_reg (wc, CTRL_REL);
 
593
                        break;
 
594
 
 
595
                case DS1_CLR_REL:                                                               // turn off failover relay - bypass
 
596
                        ctrl_clr_reg (wc, CTRL_REL);
 
597
                        break;
 
598
 
 
599
                case DS1_SET_RXMON:                                                             // Enable receiver Hi-Z monitor mode
 
600
                        __t1_framer_out(wc, FR_LIM2,__t1_framer_in(wc, FR_LIM2) & 0xFD);        // LIM2: turn off AS1
 
601
                        break;
 
602
                        
 
603
                case DS1_CLR_RXMON:                                                             // Set receiver to normal 100 Ohm impedance
 
604
                        __t1_framer_out(wc, FR_LIM2,__t1_framer_in(wc, FR_LIM2) | 0x02);        // LIM2: turn on AS1
 
605
                        break;
 
606
 
 
607
                case DS1_SET_TXEN:                                                              // Enable transmitter - normal operation        
 
608
                        __t1_framer_out(wc, FR_LIM2,__t1_framer_in(wc, FR_XPM2) & 0xBF);        // XPM2: turn on line drivers
 
609
                        break;
 
610
                        
 
611
                case DS1_CLR_TXEN:                                                              // Disable transmitter - set to Hi-Z
 
612
                        __t1_framer_out(wc, FR_LIM2,__t1_framer_in(wc, FR_XPM2) | 0x40);        // XPM2: turn off line drivers
 
613
                        break;
 
614
 
 
615
                        
 
616
                        
 
617
                default:
 
618
                        return -ENOTTY;
 
619
        }
 
620
        return 0;
 
621
}
 
622
 
 
623
 
 
624
static int ds1_maint(struct zt_span *span, int cmd)
 
625
{
 
626
        struct t1 *wc = span->pvt;
 
627
 
 
628
        if (wc->spantype == MODE_E1) 
 
629
        {
 
630
                switch(cmd) 
 
631
                {
 
632
                        case ZT_MAINT_NONE:
 
633
                                printk("XXX Turn off local and remote loops E1 XXX\n");
 
634
                                break;
 
635
 
 
636
                        case ZT_MAINT_LOCALLOOP:
 
637
                                printk("XXX Turn on local loopback E1 XXX\n");
 
638
                                break;
 
639
 
 
640
                        case ZT_MAINT_REMOTELOOP:
 
641
                                printk("XXX Turn on remote loopback E1 XXX\n");
 
642
                                break;
 
643
 
 
644
                        case ZT_MAINT_LOOPUP:
 
645
                                printk("XXX Send loopup code E1 XXX\n");
 
646
                                break;
 
647
 
 
648
                        case ZT_MAINT_LOOPDOWN:
 
649
                                printk("XXX Send loopdown code E1 XXX\n");
 
650
                                break;
 
651
 
 
652
                        case ZT_MAINT_LOOPSTOP:
 
653
                                printk("XXX Stop sending loop codes E1 XXX\n");
 
654
                                break;
 
655
 
 
656
                        case DS1_SET_REL:
 
657
                                ctrl_set_reg (wc, CTRL_REL);
 
658
                                printk("XXX Turn off E1 bypass XXX\n");
 
659
                                break;
 
660
 
 
661
                        case DS1_CLR_REL:
 
662
                                ctrl_clr_reg (wc, CTRL_REL);
 
663
                                printk("XXX Turn on E1 bypass XXX\n");
 
664
                                break;
 
665
 
 
666
                        default:
 
667
                                printk("DS1x1F: Unknown E1 maintainance command: %d\n", cmd);
 
668
                                break;
 
669
                }
 
670
        } 
 
671
        else 
 
672
        {
 
673
                switch(cmd) 
 
674
                {
 
675
                    case ZT_MAINT_NONE:
 
676
                                printk("XXX Turn off local and remote loops T1 XXX\n");
 
677
                                break;
 
678
 
 
679
                    case ZT_MAINT_LOCALLOOP:
 
680
                                printk("XXX Turn on local loop and no remote loop XXX\n");
 
681
                                break;
 
682
 
 
683
                    case ZT_MAINT_REMOTELOOP:
 
684
                                printk("XXX Turn on remote loopup XXX\n");
 
685
                                break;
 
686
 
 
687
                    case ZT_MAINT_LOOPUP:
 
688
                                t1_framer_out(wc, FR_FMR5, 0x50);       /* FMR5: Nothing but RBS mode */
 
689
                                break;
 
690
 
 
691
                    case ZT_MAINT_LOOPDOWN:
 
692
                                t1_framer_out(wc, FR_FMR5, 0x60);       /* FMR5: Nothing but RBS mode */
 
693
                                break;
 
694
 
 
695
                    case ZT_MAINT_LOOPSTOP:
 
696
                                t1_framer_out(wc, FR_FMR5, 0x40);       /* FMR5: Nothing but RBS mode */
 
697
                                break;
 
698
 
 
699
                    case DS1_SET_REL:
 
700
                                ctrl_set_reg (wc, CTRL_REL);
 
701
                                printk("XXX Turn off T1 bypass XXX\n");
 
702
                                break;
 
703
 
 
704
                    case DS1_CLR_REL:
 
705
                                ctrl_clr_reg (wc, CTRL_REL);
 
706
                                printk("XXX Turn on T1 bypass XXX\n");
 
707
                                break;
 
708
 
 
709
                    default:
 
710
                                printk("DS1x1F: Unknown T1 maintainance command: %d\n", cmd);
 
711
                                break;
 
712
                   }
 
713
        }
 
714
        return 0;
 
715
}
 
716
 
 
717
 
 
718
static int ds1_rbsbits(struct zt_chan *chan, int bits)
 
719
{
 
720
        u_char m,c;
 
721
        int n,b;
 
722
        struct t1 *wc = chan->pvt;
 
723
        unsigned long flags;
 
724
        
 
725
        if(debug > 2) 
 
726
                printk("Setting CAS signalling bits to: %d for ch: %s\n", bits, chan->name);
 
727
 
 
728
        spin_lock_irqsave(&wc->lock, flags);    
 
729
 
 
730
        if (wc->spantype == MODE_E1)                            // E1 CAS (R2) signalling
 
731
        {                                                       
 
732
                if (chan->chanpos == 16)                        // channel 16 is the signalling channel even for CAS    
 
733
                {
 
734
                        spin_unlock_irqrestore(&wc->lock, flags);
 
735
                        return 0;                               // so leave it alone    
 
736
                }
 
737
 
 
738
                n = chan->chanpos - 1;
 
739
 
 
740
                if (chan->chanpos > 15)                         // move everything above channel 16 one down
 
741
                        n--;
 
742
 
 
743
                b  = (n % 15);
 
744
                c  = wc->txsigs[b];
 
745
                m  = (n / 15) << 2;                             // we have to write one nibble with new bits
 
746
                c &= (0xf << m);                                // while keeping the other nibble as is
 
747
                c |= (bits & 0xf) << (4 - m);           
 
748
 
 
749
                wc->txsigs[b] = c;
 
750
 
 
751
                __t1_framer_out(wc,FR_XS2 + b,c);               // In E1 mode XS1 is not used for CAS signalling
 
752
 
 
753
        } 
 
754
        else                                                    // T1 or J1 CAS mode
 
755
        {
 
756
                if (wc->span.lineconfig & ZT_CONFIG_D4)         // Old D4 framin selected       
 
757
                {
 
758
                        n  = chan->chanpos - 1;
 
759
                        b  = (n/4);
 
760
                        c  = wc->txsigs[b];
 
761
                        m  = ((3 - (n % 4)) << 1);              // D4 only uses 2 CAS bits per channel
 
762
                        c &= ~(0x3 << m);                       // do the nibble thing
 
763
                        c |= ((bits >> 2) & 0x3) << m; 
 
764
                        wc->txsigs[b] = c;
 
765
                                                                // output them to the chip */
 
766
                        __t1_framer_out(wc,FR_XS1 + b ,c);      // since there are only 2 bits per channel
 
767
                        __t1_framer_out(wc,FR_XS6 + b ,c);      // write them into the CAS registers twice
 
768
                } 
 
769
                else
 
770
                { 
 
771
                        if (wc->span.lineconfig & ZT_CONFIG_ESF) // ESF = CAS 4 bits per channel
 
772
                        {
 
773
                                n  = chan->chanpos - 1;
 
774
                                b  = (n/2);
 
775
                                c  = wc->txsigs[b];
 
776
                                m  = ((n % 2) << 2);            // do the nibble thing
 
777
                                c &= (0xf << m);                
 
778
                                c |= (bits & 0xf) << (4 - m); 
 
779
                                wc->txsigs[b] = c;
 
780
                                                                // output them to the chip 
 
781
                                __t1_framer_out(wc,FR_XS1 + b,c); // write only once 
 
782
                        } 
 
783
                }
 
784
        }
 
785
 
 
786
        spin_unlock_irqrestore(&wc->lock, flags);
 
787
 
 
788
        if (debug > 2)
 
789
                printk("Finished setting CAS signalling bits\n");
 
790
 
 
791
        return 0;
 
792
}
 
793
 
 
794
 
 
795
static void __t1_check_sigbits(struct t1 *wc)                                           // read the current CAS bits from framerchip
 
796
{
 
797
        int a,i,rxs;
 
798
 
 
799
        if (!(wc->span.flags & ZT_FLAG_RUNNING))
 
800
                return;
 
801
 
 
802
        if (wc->spantype == MODE_E1)                                                    // E1 CAS mode selected
 
803
        {
 
804
                for (i = 0; i < 15; i++)                                                // do this in 16 steps
 
805
                {
 
806
                        a = __t1_framer_in(wc, FR_RS2 + i);                             // RS1 is not used for CAS bits
 
807
                        rxs = (a & 0xf);                                        
 
808
 
 
809
                        if (!(wc->span.chans[i+16].sig & ZT_SIG_CLEAR))                 // get lower nibble = channel+16
 
810
                        {
 
811
                                if (wc->span.chans[i+16].rxsig != rxs)
 
812
                                        zt_rbsbits(&wc->span.chans[i+16], rxs);
 
813
                        }
 
814
 
 
815
                        rxs = (a >> 4) & 0xf;                                           // get upper nibble = channel +0
 
816
 
 
817
                        if (!(wc->span.chans[i].sig & ZT_SIG_CLEAR)) 
 
818
                        {
 
819
                                if (wc->span.chans[i].rxsig != rxs)
 
820
                                        zt_rbsbits(&wc->span.chans[i], rxs);
 
821
                        }
 
822
                }
 
823
        } 
 
824
        else                                                                            // T1 or J1 mode selected
 
825
        {
 
826
                if (wc->span.lineconfig & ZT_CONFIG_D4)                                 // D4 framing selected
 
827
                {                                                                       // D4 uses only 2 CAS bits per channel
 
828
                        for (i = 0; i < 24; i+=4)                                       // do it in 6 steps
 
829
                        {
 
830
                                a = __t1_framer_in(wc, FR_RS1 + (i>>2));
 
831
                                
 
832
                                rxs = (a & 0x3) << 2;                                   // get bits.0 and .1 = channel +3
 
833
                                if (!(wc->span.chans[i+3].sig & ZT_SIG_CLEAR)) 
 
834
                                {
 
835
                                        if (wc->span.chans[i+3].rxsig != rxs)
 
836
                                                zt_rbsbits(&wc->span.chans[i+3], rxs);
 
837
                                }
 
838
        
 
839
                                rxs = (a & 0xc);                                        // get bits.2 and .3 = channel +2       
 
840
                                if (!(wc->span.chans[i+2].sig & ZT_SIG_CLEAR)) 
 
841
                                {
 
842
                                        if (wc->span.chans[i+2].rxsig != rxs)
 
843
                                                zt_rbsbits(&wc->span.chans[i+2], rxs);
 
844
                                }
 
845
        
 
846
                                rxs = (a >> 2) & 0xc;                                   // get bits.4 and .5 = channel +1
 
847
                                if (!(wc->span.chans[i+1].sig & ZT_SIG_CLEAR)) 
 
848
                                {
 
849
                                        if (wc->span.chans[i+1].rxsig != rxs)
 
850
                                                zt_rbsbits(&wc->span.chans[i+1], rxs);
 
851
                                }
 
852
        
 
853
                                rxs = (a >> 4) & 0xc;                                   // get bits.6 and .7 = channel +0
 
854
                                if (!(wc->span.chans[i].sig & ZT_SIG_CLEAR)) 
 
855
                                {
 
856
                                        if (wc->span.chans[i].rxsig != rxs)
 
857
                                                zt_rbsbits(&wc->span.chans[i], rxs);
 
858
                                }
 
859
                        }
 
860
                }
 
861
                else                                                                    // ESF framing uses 4 CAS bits per channel
 
862
                {
 
863
                        for (i = 0; i < 24; i+=2)                                       // do this in 12 steps 
 
864
                        {
 
865
                                a = __t1_framer_in(wc, FR_RS1 + (i>>1));        
 
866
                
 
867
                                rxs = (a & 0xf);                                        // get lower nibble = channel +1 
 
868
                                if (!(wc->span.chans[i+1].sig & ZT_SIG_CLEAR)) 
 
869
                                {
 
870
                                        if (wc->span.chans[i+1].rxsig != rxs)
 
871
                                                zt_rbsbits(&wc->span.chans[i+1], rxs);
 
872
                                }
 
873
                
 
874
                                rxs = (a >> 4) & 0xf;                                   // get upper nibble = channel +0
 
875
                                if (!(wc->span.chans[i].sig & ZT_SIG_CLEAR)) 
 
876
                                {
 
877
                                        if (wc->span.chans[i].rxsig != rxs)
 
878
                                                zt_rbsbits(&wc->span.chans[i], rxs);
 
879
                                }
 
880
                        }
 
881
                }
 
882
        }       
 
883
}
 
884
 
 
885
 
 
886
static void t4_serial_setup(struct t1 *wc)
 
887
{
 
888
        unsigned int RC,XC;
 
889
 
 
890
        switch (wc->spantype)
 
891
        {
 
892
                case MODE_E1:                   // E1 mode
 
893
                        printk("DS1x1F: Setting global parameters for E1 \n");
 
894
                        break;
 
895
 
 
896
                case MODE_UE1:                  // NEW - Unframed E1 mode
 
897
                        printk("DS1x1F: Setting global parameters for Unchannelized E1 \n");
 
898
                        break;
 
899
 
 
900
                case MODE_J1:                   // J1 mode
 
901
                        printk("DS1x1F: Setting global parameters for J1 \n");
 
902
                        break;
 
903
 
 
904
                default:                        // All others default to T1
 
905
                        printk("DS1x1F: Setting global parameters for T1 \n");
 
906
                        break;
 
907
        }
 
908
 
 
909
 
 
910
        RC = 0x000;                             // Rt = 4 x 125 ns cycle
 
911
        XC = 0x004;                             // Xt = 0 x 125 nS cycles
 
912
 
 
913
        t1_framer_out(wc, FR_GPC1, 0xe0);       // GPC1: Multiplex mode enabled, FSC is output, active low, RCLK from channel 0
 
914
        t1_framer_out(wc, FR_IPC,  0x05);       // IPC: Interrupt push/pull active low 
 
915
 
 
916
        t1_framer_out(wc, FR_GCM1, 0x66);       
 
917
        t1_framer_out(wc, FR_GCM2, 0x0e);
 
918
        t1_framer_out(wc, FR_GCM3, 0x3f);
 
919
        t1_framer_out(wc, FR_GCM4, 0x0f);
 
920
        t1_framer_out(wc, FR_GCM5, 0x04);
 
921
        t1_framer_out(wc, FR_GCM6, 0x3c);
 
922
        t1_framer_out(wc, FR_GCM7, 0x9c);
 
923
        t1_framer_out(wc, FR_GCM8, 0x90);
 
924
 
 
925
        t1_framer_out(wc, FR_GCR,  0x40);               // GCR: Interrupt on Activation/Deactivation of AIX, LOS 
 
926
        t1_framer_out(wc, FR_SIC1, 0x82);               // SIC1: 2.048 Mhz clock/bus, double buffer receive / transmit, byte interleaved
 
927
        t1_framer_out(wc, FR_SIC2, 0x00);               // SIC2: No FFS, no center receive eliastic buffer, phase 0
 
928
        t1_framer_out(wc, FR_SIC3, 0x08);               // SIC3: Edges for capture tx latches with rising edge / rx changes with falling edge
 
929
        t1_framer_out(wc, FR_CMR1, 0x30);               // CMR1: RCLK is at 8.192 Mhz dejittered
 
930
        t1_framer_out(wc, FR_CMR2, 0x25);               // CMR2: sync and clock for tx and rx provided by FALC
 
931
 
 
932
        t1_framer_out(wc, FR_XC0,  0x00 | ((XC >> 8) & 0x07));          // XC0: Normal operation of Sa-bits
 
933
        t1_framer_out(wc, FR_XC1,  XC & 0xff);                          // XC1: tx offset
 
934
 
 
935
        t1_framer_out(wc, FR_RC0,  0x00 | ((RC >> 8) & 0x07));          // RC0: rx offset
 
936
        t1_framer_out(wc, FR_RC1,  RC & 0xff);                          // RC1:
 
937
 
 
938
                                                        // ------------- Configure ports ---------------
 
939
        t1_framer_out(wc, FR_PC1,  0x10);               // PC1: FMR/SPYX output/input on RPA/XPA
 
940
        t1_framer_out(wc, FR_PC2,  0x65);               // PC2: unused
 
941
        t1_framer_out(wc, FR_PC3,  0x65);               // PC3: unused
 
942
        t1_framer_out(wc, FR_PC4,  0x35);               // PC4: unused
 
943
        t1_framer_out(wc, FR_PC5,  0x33);               // PC5: XMFS active low, SCLKR is input, RCLK is output
 
944
        t1_framer_out(wc, FR_PC6,  0x01);               // PC6: CLK1 is Tx Clock output, CLK2 is 2.048 Mhz from DCO-R
 
945
 
 
946
        t1_framer_out(wc, FR_LCR1, 0x00);               // Clear LCR1
 
947
 
 
948
        printk("DS1x1F: Successfully initialized card\n");
 
949
}
 
950
 
 
951
 
 
952
static void __t1_configure_t1(struct t1 *wc, int lineconfig, int txlevel)
 
953
{
 
954
        char *mode, *frame, *lcode;
 
955
        char as1;
 
956
        char xlt;
 
957
        
 
958
        __t1_framer_out(wc, FR_FMR1, 0xbc);             // FMR1: Mode 1, T1 mode, CRC on for ESF, 2.048 Mhz system data rate, no XAIS
 
959
 
 
960
        switch (monitor)                                // module parameter monitor 
 
961
        {
 
962
                case 1:                                 
 
963
                        as1 = 0x00;                     // Tx = normal / Rx = Hi-Z
 
964
                        xlt = 0x00;
 
965
                        break;
 
966
                        
 
967
                case 2:
 
968
                        as1 = 0x02;                     // Tx = Hi-Z  / Rx = 100 Ohm
 
969
                        xlt = 0x40;
 
970
                        break;                          
 
971
                        
 
972
                case 3:
 
973
                        as1 = 0x00;                     // Tx = Hi-Z  / Rx = Hi-Z
 
974
                        xlt = 0x40;
 
975
                        break;
 
976
                        
 
977
                default:                                // Tx = normal / Rx = 100 Ohm
 
978
                        as1 = 0x02;
 
979
                        xlt = 0x00;
 
980
                        break;
 
981
        }
 
982
        
 
983
                                                        /* Configure line interface */
 
984
        if (lineconfig & ZT_CONFIG_AMI) 
 
985
        {
 
986
                lcode = "AMI";
 
987
                __t1_framer_out(wc, FR_FMR0, 0xa0);
 
988
        } 
 
989
        else 
 
990
        {
 
991
                lcode = "B8ZS";
 
992
                __t1_framer_out(wc, FR_FMR0, 0xf0);
 
993
        }
 
994
 
 
995
        if (!(lineconfig & ZT_CONFIG_D4) && !(lineconfig & ZT_CONFIG_ESF))      // support for F4  4 frame format
 
996
        {
 
997
                frame = "F4";
 
998
                if (loopback)
 
999
                        __t1_framer_out(wc, FR_FMR2, 0x26);
 
1000
                else
 
1001
                        __t1_framer_out(wc, FR_FMR2, 0x22);
 
1002
 
 
1003
                if (wc->spantype == MODE_J1)
 
1004
                        __t1_framer_out(wc, FR_FMR4, 0x1d);
 
1005
                else
 
1006
                        __t1_framer_out(wc, FR_FMR4, 0x0d);
 
1007
        } 
 
1008
 
 
1009
        if (!(lineconfig & ZT_CONFIG_D4) && (lineconfig & ZT_CONFIG_ESF))       // standard ESF 24 frame format 
 
1010
        {
 
1011
                frame  = "ESF";
 
1012
 
 
1013
                if (loopback)
 
1014
                        __t1_framer_out(wc, FR_FMR2, 0xe6);
 
1015
                else
 
1016
                        __t1_framer_out(wc, FR_FMR2, 0xe2);
 
1017
        
 
1018
                if (wc->spantype == MODE_J1)
 
1019
                        __t1_framer_out(wc, FR_FMR4, 0x1e);
 
1020
                else
 
1021
                        __t1_framer_out(wc, FR_FMR4, 0x0e);
 
1022
        }
 
1023
 
 
1024
        if ((lineconfig & ZT_CONFIG_D4) && !(lineconfig & ZT_CONFIG_ESF))       // standard D4  12 frame format
 
1025
        {
 
1026
                frame = "D4";
 
1027
                if (loopback)
 
1028
                        __t1_framer_out(wc, FR_FMR2, 0x26);
 
1029
                else
 
1030
                        __t1_framer_out(wc, FR_FMR2, 0x22);
 
1031
 
 
1032
                if (wc->spantype == MODE_J1)
 
1033
                        __t1_framer_out(wc, FR_FMR4, 0x1c);
 
1034
                else
 
1035
                        __t1_framer_out(wc, FR_FMR4, 0x0c);
 
1036
        }
 
1037
 
 
1038
        if ((lineconfig & ZT_CONFIG_D4) && (lineconfig & ZT_CONFIG_ESF))        // support for SLC96 framing mode used in TR-08 circuits
 
1039
        {
 
1040
                frame = "SLC96";
 
1041
                if (loopback)
 
1042
                        __t1_framer_out(wc, FR_FMR2, 0x26);
 
1043
                else
 
1044
                        __t1_framer_out(wc, FR_FMR2, 0x22);
 
1045
 
 
1046
                if (wc->spantype == MODE_J1)
 
1047
                        __t1_framer_out(wc, FR_FMR4, 0x1f);
 
1048
                else
 
1049
                        __t1_framer_out(wc, FR_FMR4, 0x0f);
 
1050
        } 
 
1051
 
 
1052
 
 
1053
        __t1_framer_out(wc, FR_FMR5, 0x40);             // FMR5: Enable RBS mode */
 
1054
 
 
1055
        __t1_framer_out(wc, FR_LIM1, 0xf8);             // LIM1: Clear data in case of LOS, Set receiver threshold (0.5V), No remote loop, no DRS
 
1056
        __t1_framer_out(wc, FR_LIM0, 0x08);             // LIM0: Enable auto long haul mode, no local loop (must be set after LIM1)
 
1057
 
 
1058
        __t1_framer_out(wc, FR_CMDR, 0x50);             // CMDR: Reset the receiver and transmitter line interface
 
1059
        __t1_framer_out(wc, FR_CMDR, 0x00);             // CMDR: Reset the receiver and transmitter line interface 
 
1060
 
 
1061
        __t1_framer_out(wc, FR_PCD,  0x0a);             // PCD: LOS after 176 consecutive "zeros" 
 
1062
        __t1_framer_out(wc, FR_PCR,  0x15);             // PCR: 22 "ones" clear LOS 
 
1063
 
 
1064
        if (wc->spantype == MODE_J1)
 
1065
        {
 
1066
                mode = "J1";
 
1067
                __t1_framer_out(wc, FR_RC0, 0x80);              // J1 overide
 
1068
        }
 
1069
        else
 
1070
        {
 
1071
                mode = "T1";
 
1072
        }
 
1073
                
 
1074
        switch (txlevel)                                        // Set Tx pulse mask + Rx line build out  
 
1075
        {
 
1076
                case 7:
 
1077
                        __t1_framer_out(wc, FR_LIM2, 0xe1 | as1);       // LIM2: LBO=3, RST=50%, LOS1=1
 
1078
                        __t1_framer_out(wc, FR_XPM0, 0x07);             // XPM0 
 
1079
                        __t1_framer_out(wc, FR_XPM1, 0x01);             // XPM1 
 
1080
                        __t1_framer_out(wc, FR_XPM2, 0x00 | xlt);       // XPM2 
 
1081
                        break;
 
1082
        
 
1083
                case 6:
 
1084
                        __t1_framer_out(wc, FR_LIM2, 0xa1 | as1);       // LIM2: LBO=2, RST=50%, LOS1=1      
 
1085
                        __t1_framer_out(wc, FR_XPM0, 0x8c);             // XPM0
 
1086
                        __t1_framer_out(wc, FR_XPM1, 0x11);             // XPM1 
 
1087
                        __t1_framer_out(wc, FR_XPM2, 0x01 | xlt);       // XPM2
 
1088
                        break;
 
1089
        
 
1090
                case 5:
 
1091
                        __t1_framer_out(wc, FR_LIM2, 0x61 | as1);       // LIM2: LBO=1, RST=50%, LOS1=1
 
1092
                        __t1_framer_out(wc, FR_XPM0, 0x8c);             // XPM0
 
1093
                        __t1_framer_out(wc, FR_XPM1, 0x01);             // XPM1
 
1094
                        __t1_framer_out(wc, FR_XPM2, 0x00 | xlt);       // XPM2
 
1095
                        break;
 
1096
        
 
1097
                default:
 
1098
                        __t1_framer_out(wc, FR_LIM2, 0x21 | as1);       // LIM2: LBO=0, RST=50%, LOS1=1
 
1099
                        __t1_framer_out(wc, FR_XPM0, 0xd7);             // XPM0
 
1100
                        __t1_framer_out(wc, FR_XPM1, 0x22);             // XPM1
 
1101
                        __t1_framer_out(wc, FR_XPM2, 0x01 | xlt);       // XPM2
 
1102
                        break;
 
1103
        }
 
1104
 
 
1105
 
 
1106
        printk("DS1x1F: Configured Mode: %s Framing: %s Linecode: %s\n", mode, frame, lcode);
 
1107
}
 
1108
 
 
1109
 
 
1110
static void __t1_configure_e1(struct t1 *wc, int lineconfig)
 
1111
{
 
1112
        unsigned int  fmr2, fmr1;
 
1113
        unsigned int  cas = 0;
 
1114
        char         *crc4 = "";
 
1115
        char         *frame, *lcode;
 
1116
        char          as1;
 
1117
        char          xlt;
 
1118
        
 
1119
        fmr1 = 0x44;                                    /* FMR1: E1 mode, Automatic force resync, PCM30 mode, 2.048 Mhz backplane, no XAIS */
 
1120
        fmr2 = 0x03;                                    /* FMR2: Auto transmit remote alarm, auto loss of multiframe recovery, no payload loopback */
 
1121
 
 
1122
        switch (monitor)                                // module parameter monitor 
 
1123
        {
 
1124
                case 1:                                 
 
1125
                        as1 = 0x00;                     // Tx = normal / Rx = Hi-Z
 
1126
                        xlt = 0x00;
 
1127
                        break;
 
1128
                        
 
1129
                case 2:
 
1130
                        as1 = 0x02;                     // Tx = Hi-Z  / Rx = 100 Ohm
 
1131
                        xlt = 0x40;
 
1132
                        break;                          
 
1133
                        
 
1134
                case 3:
 
1135
                        as1 = 0x00;                     // Tx = Hi-Z  / Rx = Hi-Z
 
1136
                        xlt = 0x40;
 
1137
                        break;
 
1138
                        
 
1139
                default:                                // Tx = normal / Rx = 100 Ohm
 
1140
                        as1 = 0x02;
 
1141
                        xlt = 0x00;
 
1142
                        break;
 
1143
        }
 
1144
 
 
1145
        
 
1146
        if (wc->spantype == MODE_UE1)
 
1147
                fmr2 |= 0x30;
 
1148
 
 
1149
        if (loopback)
 
1150
                fmr2 |= 0x4;
 
1151
 
 
1152
        if (lineconfig & ZT_CONFIG_CRC4) 
 
1153
        {
 
1154
                fmr1 |=   0x08;                         /* CRC4 transmit */
 
1155
                fmr2 |=   0xc0;                         /* CRC4 receive */
 
1156
                crc4  = "/CRC4";
 
1157
        }
 
1158
 
 
1159
        __t1_framer_out(wc, FR_FMR1, fmr1);
 
1160
        __t1_framer_out(wc, FR_FMR2, fmr2);
 
1161
 
 
1162
 
 
1163
        if (lineconfig & ZT_CONFIG_AMI)                 /* Configure line interface */
 
1164
        {
 
1165
                lcode = "AMI";
 
1166
                __t1_framer_out(wc, FR_FMR0, 0xa0);
 
1167
        } 
 
1168
        else 
 
1169
        {
 
1170
                lcode = "HDB3";
 
1171
                __t1_framer_out(wc, FR_FMR0, 0xf0);
 
1172
        }
 
1173
 
 
1174
        if (lineconfig & ZT_CONFIG_CCS) 
 
1175
        {
 
1176
                frame = "CCS";
 
1177
        } 
 
1178
        else 
 
1179
        {
 
1180
                frame = "CAS";
 
1181
                cas   =  0x40;
 
1182
        }
 
1183
 
 
1184
        if (wc->spantype == MODE_UE1)
 
1185
                __t1_framer_out(wc, FR_LOOP, 0x40);
 
1186
 
 
1187
        __t1_framer_out(wc, FR_LIM1, 0xf0);                     // LIM1: Clear data in case of LOS, Set receiver threshold (0.5V), No remote loop, no DRS
 
1188
        __t1_framer_out(wc, FR_LIM0, 0x08);                     // LIM0: Enable auto long haul mode, no local loop (must be after LIM1)
 
1189
 
 
1190
        __t1_framer_out(wc, FR_CMDR, 0x50);                     // CMDR: Reset the receiver and transmitter line interface
 
1191
        __t1_framer_out(wc, FR_CMDR, 0x00);                     // CMDR: Reset the receiver and transmitter line interface
 
1192
 
 
1193
                                                                // Condition receive line interface for E1 after reset
 
1194
        __t1_framer_out(wc, 0xbb, 0x17);
 
1195
        __t1_framer_out(wc, 0xbc, 0x55);
 
1196
        __t1_framer_out(wc, 0xbb, 0x97);
 
1197
        __t1_framer_out(wc, 0xbb, 0x11);
 
1198
        __t1_framer_out(wc, 0xbc, 0xaa);
 
1199
        __t1_framer_out(wc, 0xbb, 0x91);
 
1200
        __t1_framer_out(wc, 0xbb, 0x12);
 
1201
        __t1_framer_out(wc, 0xbc, 0x55);
 
1202
        __t1_framer_out(wc, 0xbb, 0x92);
 
1203
        __t1_framer_out(wc, 0xbb, 0x0c);
 
1204
        __t1_framer_out(wc, 0xbb, 0x00);
 
1205
        __t1_framer_out(wc, 0xbb, 0x8c);
 
1206
        
 
1207
        __t1_framer_out(wc, FR_LIM2, 0x20 | as1);               // LIM2: 50% peak amplitude is a "1"
 
1208
        __t1_framer_out(wc, FR_PCD,  0x0a);                     // PCD: LOS after 176 consecutive "zeros"
 
1209
        __t1_framer_out(wc, FR_PCR,  0x15);                     // PCR: 22 "ones" clear LOS
 
1210
        
 
1211
        __t1_framer_out(wc, FR_XSW,  0x9f);                     // XSW: Spare bits all to 1 
 
1212
 
 
1213
        if (wc->spantype == MODE_UE1)
 
1214
                __t1_framer_out(wc, FR_XSP, 0x3c      );
 
1215
        else
 
1216
                __t1_framer_out(wc, FR_XSP, 0x1c | cas);        // XSP: E-bit set when async. AXS auto, XSIF to 1
 
1217
                
 
1218
                                                                // Generate pulse mask for E1
 
1219
        __t1_framer_out(wc, FR_XPM0, 0x54);                     // XPM0
 
1220
        __t1_framer_out(wc, FR_XPM1, 0x02);                     // XPM1
 
1221
        __t1_framer_out(wc, FR_XPM2, 0x00 | xlt);               // XPM2
 
1222
 
 
1223
        if (wc->spantype == MODE_UE1)
 
1224
                printk("DS1x1F: Configured Mode: E1-Unchannelized Framing: %s Linecode: %s\n", frame, lcode);
 
1225
        else
 
1226
                printk("DS1x1F: Configured Mode: E1%s Framing: %s Linecode: %s\n", crc4, frame, lcode);
 
1227
 
 
1228
}
 
1229
//-----------------------------------------------------------------------------------------------------------------------------------------
 
1230
 
 
1231
 
 
1232
static void ds1_framer_start(struct t1 *wc, struct zt_span *span)
 
1233
{
 
1234
        int alreadyrunning = wc->span.flags & ZT_FLAG_RUNNING;
 
1235
        unsigned long flags;
 
1236
 
 
1237
        spin_lock_irqsave(&wc->lock, flags);
 
1238
 
 
1239
        if (wc->spantype & MODE_E1) 
 
1240
        {                                               // configure in E1/ UE1 mode
 
1241
                __t1_configure_e1(wc, span->lineconfig);
 
1242
        } 
 
1243
        else 
 
1244
        {                                               // configure in T1 / J1 mode
 
1245
                __t1_configure_t1(wc, span->lineconfig, span->txlevel);
 
1246
                __ds1_set_clear(wc);
 
1247
        }
 
1248
        
 
1249
        if (!alreadyrunning) 
 
1250
                wc->span.flags |= ZT_FLAG_RUNNING;
 
1251
 
 
1252
        spin_unlock_irqrestore(&wc->lock, flags);
 
1253
}
 
1254
 
 
1255
 
 
1256
static int ds1_startup(struct zt_span *span)
 
1257
{
 
1258
        struct t1 *wc = span->pvt;
 
1259
 
 
1260
        int alreadyrunning = span->flags & ZT_FLAG_RUNNING;
 
1261
                                                        // initialize the start value for the entire chunk of last ec buffer 
 
1262
                                                        // Reset framer with proper parameters and start 
 
1263
        ds1_framer_start(wc, span);
 
1264
        printk("Calling startup (flags is %d)\n", span->flags);
 
1265
 
 
1266
        ctrl_write_reg(wc, CTRL_REL  | CTRL_LRED);      // now enable the relay
 
1267
 
 
1268
 
 
1269
        if (!alreadyrunning) 
 
1270
        {                                               // Only if we're not already going
 
1271
                ds1_enable_interrupts(wc);
 
1272
                span->flags |= ZT_FLAG_RUNNING;
 
1273
        }
 
1274
        return 0;
 
1275
}
 
1276
 
 
1277
 
 
1278
static int ds1_shutdown(struct zt_span *span)
 
1279
{
 
1280
        struct t1 *wc = span->pvt;
 
1281
        unsigned long flags;
 
1282
 
 
1283
        spin_lock_irqsave(&wc->lock, flags);
 
1284
 
 
1285
        __t1_framer_out(wc, FR_GCR, 0x41);              // GCR: Interrupt on Activation/Deactivation of AIX, LOS
 
1286
 
 
1287
        ds1_disable_interrupts(wc);
 
1288
 
 
1289
        ctrl_write_reg(wc, CTRL_LRED);                  // turn off relay and turn on RED LED only
 
1290
 
 
1291
        span->flags &= ~ZT_FLAG_RUNNING;
 
1292
        spin_unlock_irqrestore(&wc->lock, flags);
 
1293
        return 0;
 
1294
}
 
1295
 
 
1296
 
 
1297
static int ds1_chanconfig(struct zt_chan *chan, int sigtype)
 
1298
{
 
1299
        struct t1 *wc = chan->pvt;
 
1300
        unsigned long flags;
 
1301
        int alreadyrunning = chan->span->flags & ZT_FLAG_RUNNING;
 
1302
 
 
1303
        spin_lock_irqsave(&wc->lock, flags);
 
1304
 
 
1305
        if (alreadyrunning && (wc->spantype != MODE_E1))
 
1306
                __ds1_set_clear(wc);
 
1307
 
 
1308
        spin_unlock_irqrestore(&wc->lock, flags);
 
1309
        return 0;
 
1310
}
 
1311
 
 
1312
 
 
1313
static int ds1_spanconfig(struct zt_span *span, struct zt_lineconfig *lc)
 
1314
{
 
1315
        span->lineconfig = lc->lineconfig;
 
1316
        span->txlevel    = lc->lbo;
 
1317
        span->rxlevel    = 0;
 
1318
                                                        /* Do we want to SYNC on receive or not */
 
1319
                                                        /* If already running, apply changes immediately */
 
1320
        if (span->flags & ZT_FLAG_RUNNING)
 
1321
                return ds1_startup(span);
 
1322
 
 
1323
        return 0;
 
1324
}
 
1325
 
 
1326
 
 
1327
static int ds1_software_init(struct t1 *wc)
 
1328
{
 
1329
        int x;                                          /* Find position */
 
1330
 
 
1331
        for (x = 0; x < WC_MAX_CARDS; x++) 
 
1332
        {
 
1333
                if (!cards[x]) 
 
1334
                {
 
1335
                        cards[x] = wc;
 
1336
                        break;
 
1337
                }
 
1338
        }
 
1339
 
 
1340
        if (x >= WC_MAX_CARDS)
 
1341
                return -1;
 
1342
 
 
1343
        t4_serial_setup(wc);
 
1344
        wc->num = x;
 
1345
 
 
1346
        sprintf(wc->span.name, "WCT1/%d"                , wc->num);
 
1347
        sprintf(wc->span.desc, "%s Card %d", wc->variety, wc->num);
 
1348
 
 
1349
        wc->span.spanconfig = ds1_spanconfig;
 
1350
        wc->span.chanconfig = ds1_chanconfig;
 
1351
        wc->span.startup    = ds1_startup;
 
1352
        wc->span.shutdown   = ds1_shutdown;
 
1353
        wc->span.rbsbits    = ds1_rbsbits;
 
1354
        wc->span.maint      = ds1_maint;
 
1355
        wc->span.open       = ds1_open;
 
1356
        wc->span.close      = ds1_close;
 
1357
 
 
1358
        switch (wc->spantype)
 
1359
        {
 
1360
                case MODE_UE1:
 
1361
                        wc->span.channels = 32;
 
1362
                        break;
 
1363
 
 
1364
                case MODE_E1:
 
1365
                        wc->span.channels = 31;
 
1366
                        break;
 
1367
 
 
1368
                default:
 
1369
                        wc->span.channels = 24;
 
1370
                        break;
 
1371
        }
 
1372
 
 
1373
        wc->span.chans      = wc->chans;
 
1374
        wc->span.flags      = ZT_FLAG_RBS;
 
1375
        wc->span.linecompat = ZT_CONFIG_AMI | ZT_CONFIG_B8ZS | ZT_CONFIG_D4 | ZT_CONFIG_ESF;
 
1376
        wc->span.ioctl      = ds1_ioctl;
 
1377
        wc->span.pvt        = wc;
 
1378
 
 
1379
        if (wc->spantype & MODE_E1)
 
1380
                wc->span.deflaw = ZT_LAW_ALAW;
 
1381
        else
 
1382
                wc->span.deflaw = ZT_LAW_MULAW;
 
1383
 
 
1384
        init_waitqueue_head(&wc->span.maintq);
 
1385
 
 
1386
        for (x=0;x<wc->span.channels;x++) 
 
1387
        {
 
1388
                sprintf(wc->chans[x].name, "WCT1/%d/%d", wc->num, x + 1);
 
1389
                wc->chans[x].sigcap = ZT_SIG_EM | ZT_SIG_CLEAR | ZT_SIG_EM_E1 | 
 
1390
                                      ZT_SIG_FXSLS | ZT_SIG_FXSGS | 
 
1391
                                      ZT_SIG_FXSKS | ZT_SIG_FXOLS | ZT_SIG_DACS_RBS |
 
1392
                                      ZT_SIG_FXOGS | ZT_SIG_FXOKS | ZT_SIG_CAS | ZT_SIG_SF;
 
1393
                wc->chans[x].pvt = wc;
 
1394
                wc->chans[x].chanpos = x + 1;
 
1395
        }
 
1396
 
 
1397
        if (zt_register(&wc->span, 0)) 
 
1398
        {
 
1399
                printk("Unable to register span with zaptel\n");
 
1400
                return -1;
 
1401
        }
 
1402
        return 0;
 
1403
}
 
1404
 
 
1405
 
 
1406
static inline void __handle_leds(struct t1 *wc)
 
1407
{
 
1408
        int oldreg;
 
1409
 
 
1410
        wc->blinktimer++;
 
1411
 
 
1412
        if (wc->blinktimer >= 4000) 
 
1413
                wc->blinktimer = 0;
 
1414
 
 
1415
        oldreg = wc->ledtestreg;
 
1416
 
 
1417
        if (wc->span.alarms & ZT_ALARM_RED)                             // RED alarm active 
 
1418
        {                                                               // LOS  = loss of signal
 
1419
                if (wc->blinktimer < 50) 
 
1420
                        wc->ledtestreg = CTRL_LRED;
 
1421
                else
 
1422
                        wc->ledtestreg = CTRL_LOFF;
 
1423
        
 
1424
                if (wc->blinktimer >= 200)                              // very fast flickering
 
1425
                        wc->blinktimer = 0;
 
1426
                                        
 
1427
        } 
 
1428
        else 
 
1429
        {
 
1430
                if (wc->span.alarms & ZT_ALARM_YELLOW)                  // YELLOW ALARM = RED LED flashing
 
1431
                {                                                       // other side can't see our signal
 
1432
                        if (wc->blinktimer < 250) 
 
1433
                                wc->ledtestreg = CTRL_LRED;
 
1434
                        else
 
1435
                                wc->ledtestreg = CTRL_LOFF;
 
1436
        
 
1437
                        if (wc->blinktimer >= 500)                      // flashing
 
1438
                                wc->blinktimer = 0;
 
1439
                } 
 
1440
                else                                                            
 
1441
                {
 
1442
                        if (wc->span.alarms & ZT_ALARM_BLUE)            // BLUE ALARM 
 
1443
                        {                                               // T1 failure in front of a repeater down the line
 
1444
                                if (wc->blinktimer < 250) 
 
1445
                                        wc->ledtestreg = CTRL_LGRN;     // GREEN LED flashing
 
1446
                                else
 
1447
                                        wc->ledtestreg = CTRL_LOFF;
 
1448
        
 
1449
                                if (wc->blinktimer >= 500)              // flashing
 
1450
                                        wc->blinktimer = 0;
 
1451
                        } 
 
1452
                        else    
 
1453
                        {                                               // NO ALARM
 
1454
                                if (wc->blinktimer < 150)               // slow winking green led heartbeat
 
1455
                                        wc->ledtestreg = CTRL_LOFF;
 
1456
                                else
 
1457
                                        wc->ledtestreg = CTRL_LGRN;     // GREEN LED on most of the time
 
1458
                        }
 
1459
                }
 
1460
        }
 
1461
 
 
1462
        if (oldreg != wc->ledtestreg)                                   // only when some bits have changed
 
1463
                led_write_reg(wc, wc->ledtestreg);                      // write LED bits 0,1
 
1464
}
 
1465
 
 
1466
 
 
1467
//====================================== SEND MEDIA DATA =====================================
 
1468
static void ds1_media(struct t1 *wc)
 
1469
{
 
1470
        int x,y,ty,ry,shift;
 
1471
        unsigned int tx,rx;
 
1472
        char frm;
 
1473
 
 
1474
        frm = (clk_read_reg(wc) & 0x07) + 1;                                     // see how many frames are to be read by card
 
1475
 
 
1476
        ty = wc->txchunkptr;
 
1477
        ry = wc->rxchunkptr;
 
1478
 
 
1479
 
 
1480
        for (y = 0; y < frm; y++)
 
1481
        {
 
1482
                int reg = y * 32;
 
1483
 
 
1484
                if (ty >= ZT_CHUNKSIZE)
 
1485
                {
 
1486
                        ty = 0;
 
1487
                        zt_transmit(&wc->span);
 
1488
                }
 
1489
 
 
1490
                rx = ioread32(wc->ioaddr + OFS_TDM_RD + 0 + reg);                       // read in first 4 channels     
 
1491
                tx = 0xff;                                                              // FALC-56 uses TS0 for sync purposes only
 
1492
 
 
1493
                for (x=1; x<=wc->span.channels; x++)
 
1494
                {
 
1495
                        if ((x % 4) == 0)
 
1496
                        {
 
1497
                                iowrite32(tx, wc->ioaddr + OFS_TDM_WR + x - 4 + reg);   // write 4 bytes (channels)  of pcm data
 
1498
                                tx = 0;
 
1499
                                rx = ioread32(wc->ioaddr + OFS_TDM_RD + x     + reg);
 
1500
                        }
 
1501
 
 
1502
                        shift = ((x % 4) << 3);
 
1503
                        tx |= (wc->chans[x-1].writechunk[ty] & 0xff) << shift;
 
1504
                               wc->chans[x-1].readchunk [ry] =  (rx  >> shift) & 0xff;
 
1505
                }
 
1506
 
 
1507
                iowrite32(tx, wc->ioaddr + OFS_TDM_WR + (x & 0xfc) + reg);             // write 4 bytes (channels)  of pcm data
 
1508
 
 
1509
                ty++;
 
1510
                ry++;
 
1511
 
 
1512
                if (ry >= ZT_CHUNKSIZE)
 
1513
                {
 
1514
                        ry = 0;
 
1515
 
 
1516
                        for (x=0; x<wc->span.channels; x++)                             // handle echocanceller memory fill
 
1517
                        {
 
1518
                              zt_ec_chunk(&wc->chans[x], wc->chans[x].readchunk,  wc->ec_chunk2[x]);
 
1519
 
 
1520
                              memcpy(wc->ec_chunk2[x],   wc->ec_chunk1[x]       , ZT_CHUNKSIZE);
 
1521
                              memcpy(wc->ec_chunk1[x],   wc->chans[x].writechunk, ZT_CHUNKSIZE);
 
1522
                        }
 
1523
 
 
1524
                        zt_receive(&wc->span);
 
1525
                }
 
1526
        }
 
1527
        
 
1528
        wc->txchunkptr = ty;
 
1529
        wc->rxchunkptr = ry;
 
1530
}
 
1531
 
 
1532
 
 
1533
 
 
1534
//===============================================================================================================================================================================
 
1535
 
 
1536
 
 
1537
static void __t1_check_alarms(struct t1 *wc)
 
1538
{
 
1539
        unsigned char c,d;
 
1540
        int alarms;
 
1541
        int x,j;
 
1542
 
 
1543
        if (!(wc->span.flags & ZT_FLAG_RUNNING))
 
1544
                return;
 
1545
 
 
1546
        c = __t1_framer_in(wc, FR_FRS0);
 
1547
        d = __t1_framer_in(wc, FR_FRS1);
 
1548
 
 
1549
        /* Assume no alarms */
 
1550
        alarms = 0;
 
1551
 
 
1552
        /* And consider only carrier alarms */
 
1553
        wc->span.alarms &= (ZT_ALARM_RED | ZT_ALARM_BLUE | ZT_ALARM_NOTOPEN);
 
1554
 
 
1555
        if (wc->spantype & MODE_E1) 
 
1556
        {
 
1557
                if (c & 0x04) 
 
1558
                {                               /* No multiframe found, force RAI high after 400ms only if we haven't found a multiframe since last loss of frame */
 
1559
                        if (!(wc->spanflags & FLAG_NMF)) 
 
1560
                        {
 
1561
                                __t1_framer_out(wc, FR_FMR4, 0x9f | 0x20);              /* FMR4: Force RAI High */
 
1562
                                wc->spanflags |= FLAG_NMF;
 
1563
                                printk("NMF workaround on!\n");
 
1564
                        }
 
1565
 
 
1566
                        __t1_framer_out(wc, FR_FMR2, 0xc3);                     /* Reset to CRC4 mode */
 
1567
                        __t1_framer_out(wc, FR_FMR0, 0xf2);                     /* Force Resync */
 
1568
                        __t1_framer_out(wc, FR_FMR0, 0xf0);                     /* Force Resync */
 
1569
                } 
 
1570
                else 
 
1571
                {
 
1572
                        if (!(c & 0x02)) 
 
1573
                        {
 
1574
                                if ((wc->spanflags & FLAG_NMF)) 
 
1575
                                {
 
1576
                                        __t1_framer_out(wc, FR_FMR4, 0x9f);     /* FMR4: Clear forced RAI */
 
1577
                                        wc->spanflags &= ~FLAG_NMF;
 
1578
                                        printk("NMF workaround off!\n");
 
1579
                                }
 
1580
                        }
 
1581
                }
 
1582
        } 
 
1583
        else 
 
1584
        {                                                                       /* Detect loopup code if we're not sending one */
 
1585
                if ((!wc->span.mainttimer) && (d & 0x08)) 
 
1586
                {
 
1587
                        if ((wc->loopupcnt++ > 80)  && (wc->span.maintstat != ZT_MAINT_REMOTELOOP))     // Loop-up code detected 
 
1588
                        {
 
1589
                                __t1_framer_out(wc, FR_LIM0, 0x08);                                     // LIM0: Disable any local loop
 
1590
                                __t1_framer_out(wc, FR_LIM1, 0xf6);                                     // LIM1: Enable remote loop
 
1591
 
 
1592
                                wc->span.maintstat = ZT_MAINT_REMOTELOOP;                               // maintainance status = REMOTELOOP
 
1593
                        }
 
1594
                } 
 
1595
                else
 
1596
                        wc->loopupcnt = 0;
 
1597
                
 
1598
                                                                                /* Same for loopdown code */
 
1599
                if ((!wc->span.mainttimer) && (d & 0x10)) 
 
1600
                {                                                               /* Loop-down code detected */
 
1601
                        if ((wc->loopdowncnt++ > 80)  && (wc->span.maintstat == ZT_MAINT_REMOTELOOP)) 
 
1602
                        {
 
1603
                                __t1_framer_out(wc, FR_LIM0, 0x08);             /* LIM0: Disable any local loop */
 
1604
                                __t1_framer_out(wc, FR_LIM1, 0xf0);             /* LIM1: Disable remote loop */
 
1605
                                wc->span.maintstat = ZT_MAINT_NONE;
 
1606
                        }
 
1607
                } 
 
1608
                else
 
1609
                        wc->loopdowncnt = 0;
 
1610
        }
 
1611
 
 
1612
        if (wc->span.lineconfig & ZT_CONFIG_NOTOPEN) 
 
1613
        {
 
1614
                for (x=0,j=0;x < wc->span.channels;x++)
 
1615
                {
 
1616
                        if ((wc->span.chans[x].flags & ZT_FLAG_OPEN) || (wc->span.chans[x].flags & ZT_FLAG_NETDEV))
 
1617
                                j++;
 
1618
                }
 
1619
 
 
1620
                if (!j)
 
1621
                        alarms |= ZT_ALARM_NOTOPEN;
 
1622
        }
 
1623
 
 
1624
        if (c & 0xa0) 
 
1625
        {
 
1626
                if (wc->alarmcount >= alarmdebounce) 
 
1627
                {
 
1628
                        if (!(wc->spantype & 0x80))
 
1629
                                alarms |= ZT_ALARM_RED;
 
1630
                } 
 
1631
                else
 
1632
                        wc->alarmcount++;
 
1633
        } 
 
1634
        else
 
1635
                wc->alarmcount = 0;
 
1636
 
 
1637
        if (c & 0x4)
 
1638
                alarms |= ZT_ALARM_BLUE;
 
1639
 
 
1640
                                                                                /* Keep track of recovering */
 
1641
        if ((!alarms) && wc->span.alarms) 
 
1642
                wc->alarmtimer = ZT_ALARMSETTLE_TIME;
 
1643
 
 
1644
        if (wc->alarmtimer)
 
1645
                alarms |= ZT_ALARM_RECOVER;
 
1646
 
 
1647
                                                                                /* If receiving alarms, go into Yellow alarm state */
 
1648
        if (alarms && !(wc->spanflags & FLAG_SENDINGYELLOW)) 
 
1649
        {
 
1650
                unsigned char fmr4;
 
1651
                printk("DS1x1F: Setting yellow alarm\n");
 
1652
                                                                                /* We manually do yellow alarm to handle RECOVER and NOTOPEN, otherwise it's auto anyway */
 
1653
                fmr4 = __t1_framer_in(wc, FR_FMR4);
 
1654
                __t1_framer_out(wc, FR_FMR4, fmr4 | 0x20);
 
1655
 
 
1656
                wc->spanflags |= FLAG_SENDINGYELLOW;
 
1657
        } 
 
1658
        else 
 
1659
        {
 
1660
                if ((!alarms) && (wc->spanflags & FLAG_SENDINGYELLOW)) 
 
1661
                {
 
1662
                        unsigned char fmr4;
 
1663
                        printk("DS1x1F: Clearing yellow alarm\n");
 
1664
                                                                                // We manually do yellow alarm to handle RECOVER 
 
1665
                        fmr4 = __t1_framer_in(wc, FR_FMR4);
 
1666
                        __t1_framer_out(wc, FR_FMR4, fmr4 & ~0x20);
 
1667
 
 
1668
                        wc->spanflags &= ~FLAG_SENDINGYELLOW;
 
1669
                }
 
1670
        }
 
1671
                                                                                // Re-check the timing source when we enter/leave alarm, not withstanding yellow alarm
 
1672
        if ((c & 0x10) && !(wc->spantype & 0x80))
 
1673
                alarms |= ZT_ALARM_YELLOW;
 
1674
 
 
1675
        if (wc->span.mainttimer || wc->span.maintstat) 
 
1676
                alarms |= ZT_ALARM_LOOPBACK;
 
1677
 
 
1678
        wc->span.alarms = alarms;
 
1679
        zt_alarm_notify(&wc->span);
 
1680
}
 
1681
 
 
1682
 
 
1683
static void __ds1_do_counters(struct t1 *wc)
 
1684
{
 
1685
        if (wc->alarmtimer) 
 
1686
        {
 
1687
                if (!--wc->alarmtimer) 
 
1688
                {
 
1689
                        wc->span.alarms &= ~(ZT_ALARM_RECOVER);
 
1690
                        zt_alarm_notify(&wc->span);
 
1691
                }
 
1692
        }
 
1693
}
 
1694
 
 
1695
///--------------------------------------------------------------------------------------------------------------------------------
 
1696
ZAP_IRQ_HANDLER(ds1_interrupt)
 
1697
{
 
1698
        struct t1 *wc = dev_id;
 
1699
        unsigned long flags;
 
1700
        unsigned int x;
 
1701
        int y;
 
1702
        
 
1703
        x = ctrl_read_reg(wc);                                                          // read statusregister
 
1704
 
 
1705
        if (!(x & CTRL_IRQ))
 
1706
                return IRQ_NONE;
 
1707
 
 
1708
        ctrl_set_reg(wc, CTRL_INTA);                                                    // clear the interrupt flag
 
1709
 
 
1710
        if (!wc->intcount && debug)
 
1711
                printk("DS1x1F: Got interrupt\n");
 
1712
 
 
1713
        if (x & CTRL_IRM)                                                               // we missed at least one interrupt
 
1714
                printk("DS1x1F: Missed an Interrupt !!!\n");
 
1715
        
 
1716
        ds1_media(wc);                                                                  // handle media / audio- buffers
 
1717
 
 
1718
        x = clk_read_reg(wc) & 0x07;                                                    // get the current frame buffer setting
 
1719
 
 
1720
        spin_lock_irqsave(&wc->lock, flags);
 
1721
        
 
1722
        y = wc->prescaler - 1;
 
1723
 
 
1724
        if (y < 1)
 
1725
        {
 
1726
                y = 8 / (x + 1);
 
1727
 
 
1728
                __handle_leds(wc);
 
1729
                                                                                        // Count down timers
 
1730
                __ds1_do_counters(wc);                                                  
 
1731
 
 
1732
                wc->intcount++;
 
1733
 
 
1734
                x = wc->intcount & 0x0f;                                                                // Do some things that we don't have to do very often
 
1735
 
 
1736
                switch(x) 
 
1737
                {
 
1738
                        case 0:
 
1739
                        case 1:
 
1740
                                break;
 
1741
                        case 2:
 
1742
                                __t1_check_sigbits(wc);
 
1743
                                break;
 
1744
                        case 4:                                                                 // Check alarms 1/4 as frequently
 
1745
                                if (!(wc->intcount & 0x30))
 
1746
                                        __t1_check_alarms(wc);
 
1747
                        break;
 
1748
                }
 
1749
        }
 
1750
        wc->prescaler = y;
 
1751
        
 
1752
        spin_unlock_irqrestore(&wc->lock, flags);
 
1753
 
 
1754
        return IRQ_RETVAL(1);
 
1755
}
 
1756
 
 
1757
static int memory_test(struct t1 *wc, int pattern)
 
1758
{
 
1759
        int ret = 0;
 
1760
        int x, y;
 
1761
 
 
1762
        for (x=0; x<31; x++)                                                    // clear out tx tdm memory to FF                
 
1763
        {
 
1764
                iowrite32 (pattern, wc->ioaddr + OFS_TDM_WR + (8 * x)    );
 
1765
                
 
1766
                y = ioread32(       wc->ioaddr + OFS_TDM_WR + (8 * x)    );
 
1767
 
 
1768
                if (y != pattern)
 
1769
                {
 
1770
                        ret = 1;
 
1771
                        if (debug)
 
1772
                                printk("DS1x1F: TDM tx memory failure %08x / %08x @ %02x     LSB\n", pattern, y, x);
 
1773
                }
 
1774
                else
 
1775
                        if (debug)
 
1776
                                printk("DS1x1F: TDM tx memory OK      %08x / %08x @ %02x     LSB\n", pattern, y, x);
 
1777
        
 
1778
                iowrite32 (pattern, wc->ioaddr + OFS_TDM_RD + (8 * x));
 
1779
                
 
1780
                y = ioread32(       wc->ioaddr + OFS_TDM_RD + (8 * x));
 
1781
 
 
1782
                if (y != pattern)
 
1783
                {
 
1784
                        ret = 1;
 
1785
                        if (debug)
 
1786
                                printk("DS1x1F: TDM rx memory failure %08x / %08x @ %02x MSB\n", pattern, y, x);
 
1787
                }
 
1788
                else
 
1789
                        if (debug)
 
1790
                                printk("DS1x1F: TDM rx memory OK      %08x / %08x @ %02x MSB\n", pattern, y, x);
 
1791
 
 
1792
 
 
1793
        }
 
1794
        return (ret);
 
1795
}
 
1796
 
 
1797
 
 
1798
//--------------------------------------------------------------------------------------------------------------------------------------
 
1799
static int ds1_hardware_init(struct t1 *wc)
 
1800
{
 
1801
        unsigned int vstr, wid;
 
1802
        unsigned int x;
 
1803
 
 
1804
        if (frames < 1)                                                         // setting frames = 0 autoadjust to current ZT_CHUNKSIZE
 
1805
                frames = ZT_CHUNKSIZE;
 
1806
 
 
1807
        if (frames > 8)                                                         // maximum framebuffer size is 8 frames
 
1808
                frames = 8;
 
1809
        
 
1810
        if (extclk == -1)                                                       // extclk not specified by parameter
 
1811
        {       
 
1812
                x = ctrl_read_reg(wc);                                          // read DIP switch
 
1813
                extclk = (x >> 14) & 0x03;                                      // SW 3-4 => clock selection    
 
1814
        }       
 
1815
        
 
1816
        switch (extclk)                                                         // external / H.100 bus clocking options
 
1817
        {
 
1818
                case 1:                                                         // clock derived from H.100 bus if available
 
1819
                        x = 0x30 | (frames - 1);
 
1820
                        break;
 
1821
 
 
1822
                case 2:                                                         // this card is bus clock master
 
1823
                        x = 0x20 | (frames - 1);
 
1824
                        break;
 
1825
 
 
1826
                default:                                                        // all other cases - internally clocked / no clk output
 
1827
                        x =         frames - 1;         
 
1828
                        break;
 
1829
        }
 
1830
 
 
1831
        clk_write_reg (wc, x);                                                  // no loopback
 
1832
 
 
1833
        mdelay(10);                                                             // wait for 10 msec. for FDET settle time
 
1834
 
 
1835
        x = clk_read_reg(wc);
 
1836
        
 
1837
        switch (x & 0x30)
 
1838
        {
 
1839
                case 0x20:
 
1840
                        printk("DS1x1F: Clocking: Busmaster  Framebuffer: %d frames\n",(x & 0x07) + 1);
 
1841
                        break;
 
1842
        
 
1843
                case 0x30:
 
1844
                        if (x & 0x00010000)
 
1845
                                printk("DS1x1F: Clocking:  External (   clock present on bus) Framebuffer: %d frames\n",(x & 0x07) + 1);
 
1846
                        else
 
1847
                                printk("DS1x1F: Clocking: (External) no clock present on bus  Framebuffer: %d frames\n",(x & 0x07) + 1);
 
1848
                        break;
 
1849
        
 
1850
                default:
 
1851
                        printk("DS1x1F: Clocking: Internal  Framebuffer: %d frames\n",(x & 0x07) + 1);
 
1852
                        break;
 
1853
        }
 
1854
 
 
1855
        ctrl_write_reg(wc, CTRL_INTA | CTRL_TEST | CTRL_FRST);
 
1856
 
 
1857
        mdelay(10);                                                             // wait for 10 msec.
 
1858
 
 
1859
        x = ctrl_read_reg(wc);                                                  // read in the controlregister
 
1860
 
 
1861
        ctrl_write_reg(wc, CTRL_LRED);
 
1862
 
 
1863
        mdelay(1);                                                              // wait for 1 msec.
 
1864
 
 
1865
        if (cardmode != -1) 
 
1866
                wc->spantype = cardmode;                                        // read in spanmode paramter 
 
1867
        else 
 
1868
                switch (x & 0x3000)                                             // check if SW-1 and SW-2
 
1869
                {
 
1870
                        case 0x0000:
 
1871
                                wc->spantype = MODE_T1;                         // OFF - OFF = T1
 
1872
                                break;
 
1873
 
 
1874
                        case 0x1000:
 
1875
                                wc->spantype = MODE_J1;                         // OFF - ON  = J1
 
1876
                                break;
 
1877
 
 
1878
                        case 0x2000:
 
1879
                                wc->spantype = MODE_UE1;                        // ON - OFF  = unchannelized E1
 
1880
                                break;
 
1881
 
 
1882
                        case 0x3000:
 
1883
                                wc->spantype = MODE_E1;                         // ON - ON   =  E1
 
1884
                                break;                          
 
1885
                }
 
1886
 
 
1887
        if (x & CTRL_RELI)
 
1888
                printk("DS1x1  Board Ver: %01x.%01x SW=%01x-%01x-%01x-%01x  [%x]\n",(x>>28),((x>>20)&0xf),((x>>15)&1),((x>>14)&1),((x>>13)&1),((x>>12)&1),x);      
 
1889
        else
 
1890
                printk("DS1x1F Board Ver: %01x.%01x SW=%01x-%01x-%01x-%01x  [%x]\n",(x>>28),((x>>20)&0xf),((x>>15)&1),((x>>14)&1),((x>>13)&1),((x>>12)&1),x);     
 
1891
 
 
1892
        vstr = t1_framer_in(wc ,FR_VSTR);                                       // identify FALC framer chip version
 
1893
        wid  = t1_framer_in(wc ,FR_WID );
 
1894
 
 
1895
        if (vstr == 0x05)
 
1896
        {
 
1897
                if (wid & 0xc0)
 
1898
                        printk("FALC PEF-2256 Ver: 2.2 detected\n");
 
1899
                else
 
1900
                        printk("FALC PEF-2256 Ver: 2.1 detected\n");
 
1901
        }
 
1902
        else
 
1903
        {
 
1904
                if ((wid & 0x03) == 0x03)
 
1905
                        printk("!!! WARNING !!! Old FALC PEB-2256 Ver: 1.2 detected\n");
 
1906
                else
 
1907
                        printk("!!! WARNING !!! FALC Version unknown: VSTR: %02x WID: %02x\n", vstr, wid);
 
1908
        }
 
1909
 
 
1910
        ds1_disable_interrupts(wc);
 
1911
 
 
1912
        x = 0;
 
1913
 
 
1914
        if (memory_test (wc, 0x5555aaaa)) x = 1;
 
1915
        if (memory_test (wc, 0x01234567)) x = 1;
 
1916
        if (memory_test (wc, 0xaaaa5555)) x = 1;
 
1917
        if (memory_test (wc, 0x76543210)) x = 1;
 
1918
 
 
1919
        if (x)
 
1920
                printk("DS1x1F: Card TDM memory test failed !!!\n");
 
1921
        else
 
1922
                printk("DS1x1F: Card TDM memory test completed.\n");
 
1923
 
 
1924
        ds1_enable_interrupts(wc);
 
1925
 
 
1926
        start_alarm(wc);
 
1927
        return 0;
 
1928
 
 
1929
}
 
1930
 
 
1931
 
 
1932
static int __devinit ds1_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
1933
{
 
1934
        struct   t1   *wc;
 
1935
        unsigned long end;
 
1936
 
 
1937
        
 
1938
        if (pci_enable_device(pdev)) 
 
1939
        { 
 
1940
                printk (KERN_ALERT "DS1x1F: PCI enable failed\n");
 
1941
                pci_disable_device (pdev);
 
1942
                return (-EIO);
 
1943
        } 
 
1944
        else 
 
1945
        {
 
1946
                wc = kmalloc(sizeof(struct t1), GFP_KERNEL);
 
1947
 
 
1948
                printk("Trying to init an DS1x1F\n");
 
1949
 
 
1950
                if (wc) 
 
1951
                {
 
1952
                        memset(wc, 0x0, sizeof(struct t1));                                     // initialize structure with 0x00
 
1953
                        spin_lock_init(&wc->lock);
 
1954
 
 
1955
                        wc->cnstart = pci_resource_start(pdev, 0);                             // read the assigned memory resources for region 0
 
1956
                        end         = pci_resource_end  (pdev, 0);
 
1957
                        wc->cnlen   = end - wc->cnstart + 1;
 
1958
                        wc->cres    = request_mem_region(wc->cnstart,wc->cnlen,name);
 
1959
                        wc->cnaddr  = ioremap_nocache   (wc->cnstart,wc->cnlen     );
 
1960
        
 
1961
                        if(debug)
 
1962
                                printk (KERN_INFO "Config resources = [0x%lx-0x%lx] (%ld) \n", wc->cnstart, end, wc->cnlen);
 
1963
 
 
1964
                        wc->iostart = pci_resource_start(pdev, 2);                             // read the assigned memory resources for region 2
 
1965
                        end         = pci_resource_end  (pdev, 2);
 
1966
                        wc->iolen   = end - wc->iostart + 1;
 
1967
                        wc->ires    = request_mem_region(wc->iostart,wc->iolen,name);
 
1968
                        wc->ioaddr  = ioremap_nocache   (wc->iostart,wc->iolen     );
 
1969
 
 
1970
                        if(debug)
 
1971
                                printk (KERN_INFO "I/O resources    = [0x%lx-0x%lx] (%ld) \n", wc->iostart, end, wc->iolen);
 
1972
 
 
1973
                        wc->dev    = pdev;
 
1974
                        
 
1975
                        pci_set_drvdata(pdev, wc);                                              // keep track of our device - i.e. for later removal
 
1976
 
 
1977
                        if (request_irq(pdev->irq, ds1_interrupt, ZAP_IRQ_SHARED_DISABLED, "ds1x1f", wc))
 
1978
                        {
 
1979
                                printk("DS1x1F: Unable to request IRQ %d\n", pdev->irq);
 
1980
                                kfree(wc);
 
1981
                                return -EIO;
 
1982
                        }
 
1983
 
 
1984
                        ds1_hardware_init(wc);                                                  // Initialize hardware
 
1985
 
 
1986
                        wc->variety = "DS1x1F T1/E1-card";                                      // We now know which version of card we have 
 
1987
                        ds1_software_init(wc);                                                  // Misc. software stuff
 
1988
 
 
1989
                        printk("Found an: %s\n", wc->variety);
 
1990
                        return (0);
 
1991
                } 
 
1992
                else
 
1993
                {
 
1994
                        printk (KERN_ALERT "DS1x1F: failed to allocate memory\n");
 
1995
                        return (-ENOMEM);
 
1996
                }
 
1997
        }
 
1998
        return (0);
 
1999
}
 
2000
 
 
2001
 
 
2002
static void __devexit ds1_remove(struct pci_dev *pdev)
 
2003
{
 
2004
        struct t1 *wc = pci_get_drvdata(pdev);
 
2005
 
 
2006
        if (wc) 
 
2007
        {
 
2008
 
 
2009
                ds1_disable_interrupts(wc);                     // In case hardware is still there 
 
2010
                free_irq(pdev->irq, wc);                        // release the interrupt resource
 
2011
                mdelay(10);
 
2012
 
 
2013
                zt_unregister(&wc->span);
 
2014
 
 
2015
                if (debug) 
 
2016
                        printk (KERN_ALERT "DS1x1F: resetting relay / falc / red led on\n");
 
2017
 
 
2018
                ctrl_write_reg(wc, CTRL_FRST | CTRL_LRED);      // reset FALC, relay= off, Red LED = on
 
2019
 
 
2020
                if (wc->ioaddr  != NULL)                        // unmap io space
 
2021
                        iounmap (wc->ioaddr);
 
2022
 
 
2023
                if (wc->cnaddr  != NULL)                        // unmap control space
 
2024
                        iounmap (wc->cnaddr);
 
2025
 
 
2026
                release_mem_region(wc->iostart, wc->iolen);     // release io memory region
 
2027
                release_mem_region(wc->cnstart, wc->cnlen);     // release control memory region
 
2028
 
 
2029
                kfree(wc);
 
2030
 
 
2031
                printk (KERN_ALERT "DS1x1F: disable pci device\n");
 
2032
                pci_disable_device (pdev);
 
2033
        }
 
2034
        else
 
2035
                printk (KERN_ALERT "DS1x1F: WARNING Removal Failed !!!\n");
 
2036
 
 
2037
}
 
2038
 
 
2039
 
 
2040
static struct pci_device_id  ds1_ids[] = { { PCI_DEVICE( 0x2321, 0x011f) }, { 0, }, };
 
2041
 
 
2042
 
 
2043
MODULE_DEVICE_TABLE(pci,ds1_ids);
 
2044
 
 
2045
 
 
2046
static struct pci_driver ds1_driver = {
 
2047
        name:     "ds1x1f",
 
2048
        probe:    ds1_probe,
 
2049
        remove:   __devexit_p(ds1_remove),
 
2050
        suspend:  NULL,
 
2051
        resume:   NULL,
 
2052
        id_table: ds1_ids,
 
2053
};
 
2054
 
 
2055
 
 
2056
static int __init ds1_init(void)
 
2057
{
 
2058
        int res;
 
2059
        res = zap_pci_module(&ds1_driver);
 
2060
 
 
2061
        if (res)
 
2062
                return -ENODEV;
 
2063
 
 
2064
        return 0;
 
2065
}
 
2066
 
 
2067
 
 
2068
static void __exit ds1_cleanup(void)
 
2069
{
 
2070
        pci_unregister_driver(&ds1_driver);
 
2071
}
 
2072
 
 
2073
 
 
2074
 
 
2075
module_param(alarmdebounce,  int, 0600);
 
2076
module_param(loopback,       int, 0600);
 
2077
module_param(cardmode,       int, 0600);
 
2078
module_param(frames,         int, 0600);
 
2079
module_param(debug,          int, 0600);
 
2080
module_param(extclk,         int, 0600);
 
2081
module_param(monitor,        int, 0600);
 
2082
 
 
2083
MODULE_DESCRIPTION("TC-DG ds1x1f Zaptel Driver");
 
2084
MODULE_AUTHOR("TCDG Corp. <tech@tc-dg.net");
 
2085
MODULE_LICENSE("GPL");
 
2086
 
 
2087
module_init(ds1_init);
 
2088
module_exit(ds1_cleanup);
 
2089