Debian Codegraph @

drivers/dahdi/wctdm24xxp/wctdm24xxp.h

raw symbols SCIP
1 /*
2 * Wildcard TDM2400P TDM FXS/FXO Interface Driver for DAHDI Telephony interface
3 *
4 * Written by Mark Spencer <[email protected]>
5 * Support for TDM800P and VPM150M by Matthew Fredrickson <[email protected]>
6 *
7 * Copyright (C) 2005-2010 Digium, Inc.
8 *
9 * All rights reserved.
10 *
11 */
12
13 /*
14 * See http://www.asterisk.org for more information about
15 * the Asterisk project. Please do not directly contact
16 * any of the maintainers of this project for assistance;
17 * the project provides a web site, mailing lists and IRC
18 * channels for your use.
19 *
20 * This program is free software, distributed under the terms of
21 * the GNU General Public License Version 2 as published by the
22 * Free Software Foundation. See the LICENSE file included with
23 * this program for more details.
24 */
25
26 #ifndef _WCTDM24XXP_H
27 #define _WCTDM24XXP_H
28
29 #include <dahdi/kernel.h>
30
31 #include <linux/version.h>
32 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
33 #include <linux/semaphore.h>
34 #else
35 #include <asm/semaphore.h>
36 #endif
37
38 #include "voicebus/voicebus.h"
39
40 #define NUM_FXO_REGS 60
41
42 #define WC_MAX_IFACES 128
43
44 /*!
45 * \brief Default ringer debounce (in ms)
46 */
47 #define DEFAULT_RING_DEBOUNCE 1024
48 #define POLARITY_DEBOUNCE 64 /* Polarity debounce (in ms) */
49
50 #define OHT_TIMER 6000 /* How long after RING to retain OHT */
51
52 #define FLAG_EXPRESS (1 << 0)
53
54 #define EFRAME_SIZE 108L
55 #define EFRAME_GAP 20L
56 #define SFRAME_SIZE ((EFRAME_SIZE * DAHDI_CHUNKSIZE) + (EFRAME_GAP * (DAHDI_CHUNKSIZE - 1)))
57
58 #define MAX_ALARMS 10
59
60 #define MINPEGTIME 10 * 8 /* 30 ms peak to peak gets us no more than 100 Hz */
61 #define PEGTIME 50 * 8 /* 50ms peak to peak gets us rings of 10 Hz or more */
62 #define PEGCOUNT 5 /* 5 cycles of pegging means RING */
63
64 #define SDI_CLK (0x00010000)
65 #define SDI_DOUT (0x00020000)
66 #define SDI_DREAD (0x00040000)
67 #define SDI_DIN (0x00080000)
68
69 #define __CMD_RD (1 << 20) /* Read Operation */
70 #define __CMD_WR (1 << 21) /* Write Operation */
71 #define __CMD_FIN (1 << 22) /* Has finished receive */
72 #define __CMD_TX (1 << 23) /* Has been transmitted */
73
74 #define CMD_WR(a,b) (((a) << 8) | (b) | __CMD_WR)
75 #define CMD_RD(a) (((a) << 8) | __CMD_RD)
76
77 #if 0
78 #define CMD_BYTE(card,bit,altcs) (((((card) & 0x3) * 3 + (bit)) * 7) \
79 + ((card) >> 2) + (altcs) + ((altcs) ? -21 : 0))
80 #endif
81 #define NUM_MODULES 24
82 #define NUM_SLOTS 6
83 #define MAX_SPANS 9
84
85 #define NUM_CAL_REGS 12
86
87 #define QRV_DEBOUNCETIME 20
88
89 #define VPM150M_HPI_CONTROL 0x00
90 #define VPM150M_HPI_ADDRESS 0x02
91 #define VPM150M_HPI_DATA 0x03
92
93 #define VPM_SUPPORT
94 #define VPM150M_SUPPORT
95
96 #ifdef VPM150M_SUPPORT
97 #include "voicebus/GpakCust.h"
98 #endif
99
100 #include "voicebus/vpmoct.h"
101
102 struct calregs {
103 unsigned char vals[NUM_CAL_REGS];
104 };
105
106 enum battery_state {
107 BATTERY_UNKNOWN = 0,
108 BATTERY_DEBOUNCING_PRESENT,
109 BATTERY_DEBOUNCING_PRESENT_FROM_LOST_ALARM,
110 BATTERY_DEBOUNCING_PRESENT_ALARM,
111 BATTERY_PRESENT,
112 BATTERY_DEBOUNCING_LOST,
113 BATTERY_DEBOUNCING_LOST_FROM_PRESENT_ALARM,
114 BATTERY_DEBOUNCING_LOST_ALARM,
115 BATTERY_LOST,
116 };
117
118 enum ring_detector_state {
119 RINGOFF = 0,
120 DEBOUNCING_RINGING_POSITIVE,
121 DEBOUNCING_RINGING_NEGATIVE,
122 RINGING,
123 DEBOUNCING_RINGOFF,
124 };
125
126 enum polarity_state {
127 UNKNOWN_POLARITY = 0,
128 POLARITY_DEBOUNCE_POSITIVE,
129 POLARITY_POSITIVE,
130 POLARITY_DEBOUNCE_NEGATIVE,
131 POLARITY_NEGATIVE,
132 };
133
134 struct wctdm_cmd {
135 struct list_head node;
136 struct completion *complete;
137 u32 cmd;
138 u8 ident;
139 };
140
141 /**
142 * struct wctdm_span -
143 * @span: dahdi_span to register.
144 * @timing_priority: What the priority of this span is relative to the other
145 * spans.
146 * @spanno: Which span on the card this is.
147 *
148 * NOTE: spanno would normally be taken care of by dahdi_span.offset, but
149 * appears to have meaning in xhfc.c, and that needs to be audited before
150 * changing. !!!TODO!!!
151 *
152 */
153 struct wctdm_span {
154 struct dahdi_span span;
155 int timing_priority;
156 int spanno;
157 struct wctdm *wc;
158 struct b400m_span *bspan;
159 };
160
161 struct wctdm_chan {
162 struct dahdi_chan chan;
163 struct dahdi_echocan_state ec;
164 int timeslot;
165 unsigned int hwpreec_enabled:1;
166 };
167
168 struct fxo {
169 enum ring_detector_state ring_state:4;
170 enum battery_state battery_state:4;
171 enum polarity_state polarity_state:4;
172 u8 ring_polarity_change_count:4;
173 u8 hook_ring_shadow;
174 s8 line_voltage_status;
175 int offhook;
176 int neonmwi_state;
177 int neonmwi_last_voltage;
178 unsigned int neonmwi_debounce;
179 unsigned int neonmwi_offcounter;
180 unsigned long display_fxovoltage;
181 unsigned long ringdebounce_timer;
182 unsigned long battdebounce_timer;
183 unsigned long poldebounce_timer;
184 };
185
186 struct fxs {
187 u8 oht_active:1;
188 u8 off_hook:1;
189 int idletxhookstate; /* IDLE changing hook state */
190 /* lasttxhook reflects the last value written to the proslic's reg
191 * 64 (LINEFEED_CONTROL) in bits 0-2. Bit 4 indicates if the last
192 * write is pending i.e. it is in process of being written to the
193 * register
194 * NOTE: in order for this value to actually be written to the
195 * proslic, the appropriate matching value must be written into the
196 * sethook variable so that it gets queued and handled by the
197 * voicebus ISR.
198 */
199 int lasttxhook;
200 u8 linefeed_control_shadow;
201 u8 hook_state_shadow;
202 int palarms;
203 struct dahdi_vmwi_info vmwisetting;
204 int vmwi_active_messages;
205 int vmwi_linereverse;
206 int reversepolarity; /* polarity reversal */
207 struct calregs calregs;
208 unsigned long check_alarm;
209 unsigned long check_proslic;
210 unsigned long oppending_timeout;
211 unsigned long ohttimer;
212 };
213
214 struct qrv {
215 #define RADMODE_INVERTCOR 1
216 #define RADMODE_IGNORECOR 2
217 #define RADMODE_EXTTONE 4
218 #define RADMODE_EXTINVERT 8
219 #define RADMODE_IGNORECT 16
220 #define RADMODE_PREEMP 32
221 #define RADMODE_DEEMP 64
222 char hook;
223 unsigned short debouncetime;
224 unsigned short debtime;
225 int radmode;
226 signed short rxgain;
227 signed short txgain;
228 u8 isrshadow[3];
229 };
230
231 enum module_type {
232 NONE = 0,
233 FXS,
234 FXO,
235 FXSINIT,
236 QRV,
237 BRI,
238 };
239
240 struct wctdm_module {
241 union modtypes {
242 struct fxo fxo;
243 struct fxs fxs;
244 struct qrv qrv;
245 struct b400m *bri;
246 } mod;
247
248 /* Protected by wctdm.reglock */
249 struct list_head pending_cmds;
250 struct list_head active_cmds;
251 u8 offsets[3];
252 u8 subaddr;
253 u8 card;
254
255 enum module_type type;
256 int sethook; /* pending hook state command */
257 int dacssrc;
258 };
259
260 struct wctdm {
261 const struct wctdm_desc *desc;
262 const char *board_name;
263
264 spinlock_t frame_list_lock;
265 struct list_head frame_list;
266
267 unsigned long framecount;
268 unsigned char txident;
269 unsigned char rxident;
270
271 u8 ctlreg;
272 u8 tdm410leds;
273
274 int mods_per_board; /* maximum number of modules for this board */
275 int digi_mods; /* number of digital modules present */
276 int avchannels; /* active "voice" (voice, B and D) channels */
277
278 spinlock_t reglock; /* held when accessing anything affecting the module array */
279 wait_queue_head_t regq;
280 struct list_head free_isr_commands;
281
282 struct wctdm_module mods[NUM_MODULES];
283
284 struct vpmadt032 *vpmadt032;
285 struct vpmoct *vpmoct;
286 struct voicebus vb;
287 struct wctdm_span *aspan; /* pointer to the spans[] holding the analog span */
288 struct wctdm_span *spans[MAX_SPANS];
289 struct wctdm_chan *chans[NUM_MODULES];
290 #ifdef CONFIG_VOICEBUS_ECREFERENCE
291 struct dahdi_fifo *ec_reference[NUM_MODULES];
292 #endif
293
294 /* Only care about digital spans here */
295 /* int span_timing_prio[MAX_SPANS - 1]; */
296 struct semaphore syncsem;
297 int oldsync;
298
299 int not_ready; /* 0 when the entire card is ready to go */
300 unsigned long checkflag; /* Internal state flags and task bits */
301 int companding;
302 struct dahdi_device *ddev;
303 };
304
305 static inline bool is_initialized(struct wctdm *wc)
306 {
307 WARN_ON(wc->not_ready < 0);
308 return (wc->not_ready == 0);
309 }
310
311 /* Atomic flag bits for checkflag field */
312 #define WCTDM_CHECK_TIMING 0
313
314 int wctdm_getreg(struct wctdm *wc, struct wctdm_module *const mod, int addr);
315 int wctdm_setreg(struct wctdm *wc, struct wctdm_module *const mod,
316 int addr, int val);
317
318 int wctdm_wait_for_ready(struct wctdm *wc);
319
320 extern struct semaphore ifacelock;
321 extern struct wctdm *ifaces[WC_MAX_IFACES];
322
323 #endif