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