xref: /openbmc/linux/drivers/isdn/mISDN/dsp.h (revision bc138ec4ac58bb83e2d9d5c12328d5452294c1f0)
1960366cfSKarsten Keil /*
2960366cfSKarsten Keil  * Audio support data for ISDN4Linux.
3960366cfSKarsten Keil  *
4960366cfSKarsten Keil  * Copyright 2002/2003 by Andreas Eversberg (jolly@eversberg.eu)
5960366cfSKarsten Keil  *
6960366cfSKarsten Keil  * This software may be used and distributed according to the terms
7960366cfSKarsten Keil  * of the GNU General Public License, incorporated herein by reference.
8960366cfSKarsten Keil  *
9960366cfSKarsten Keil  */
10960366cfSKarsten Keil 
11960366cfSKarsten Keil #define DEBUG_DSP_CTRL		0x0001
12960366cfSKarsten Keil #define DEBUG_DSP_CORE		0x0002
13960366cfSKarsten Keil #define DEBUG_DSP_DTMF		0x0004
14960366cfSKarsten Keil #define DEBUG_DSP_CMX		0x0010
15960366cfSKarsten Keil #define DEBUG_DSP_TONE		0x0020
16960366cfSKarsten Keil #define DEBUG_DSP_BLOWFISH	0x0040
17960366cfSKarsten Keil #define DEBUG_DSP_DELAY		0x0100
18190f71d9SAndreas Eversberg #define DEBUG_DSP_CLOCK		0x0200
19960366cfSKarsten Keil #define DEBUG_DSP_DTMFCOEFF	0x8000 /* heavy output */
20960366cfSKarsten Keil 
21960366cfSKarsten Keil /* options may be:
22960366cfSKarsten Keil  *
23960366cfSKarsten Keil  * bit 0 = use ulaw instead of alaw
24960366cfSKarsten Keil  * bit 1 = enable hfc hardware accelleration for all channels
25960366cfSKarsten Keil  *
26960366cfSKarsten Keil  */
27960366cfSKarsten Keil #define DSP_OPT_ULAW		(1<<0)
28960366cfSKarsten Keil #define DSP_OPT_NOHARDWARE	(1<<1)
29960366cfSKarsten Keil 
30960366cfSKarsten Keil #include <linux/timer.h>
31960366cfSKarsten Keil #include <linux/workqueue.h>
32960366cfSKarsten Keil 
33960366cfSKarsten Keil #include "dsp_ecdis.h"
34960366cfSKarsten Keil 
35960366cfSKarsten Keil extern int dsp_options;
36960366cfSKarsten Keil extern int dsp_debug;
37960366cfSKarsten Keil extern int dsp_poll;
38960366cfSKarsten Keil extern int dsp_tics;
39960366cfSKarsten Keil extern spinlock_t dsp_lock;
40960366cfSKarsten Keil extern struct work_struct dsp_workq;
41960366cfSKarsten Keil extern u32 dsp_poll_diff; /* calculated fix-comma corrected poll value */
42960366cfSKarsten Keil 
43960366cfSKarsten Keil /***************
44960366cfSKarsten Keil  * audio stuff *
45960366cfSKarsten Keil  ***************/
46960366cfSKarsten Keil 
47960366cfSKarsten Keil extern s32 dsp_audio_alaw_to_s32[256];
48960366cfSKarsten Keil extern s32 dsp_audio_ulaw_to_s32[256];
49960366cfSKarsten Keil extern s32 *dsp_audio_law_to_s32;
50960366cfSKarsten Keil extern u8 dsp_audio_s16_to_law[65536];
51960366cfSKarsten Keil extern u8 dsp_audio_alaw_to_ulaw[256];
52960366cfSKarsten Keil extern u8 dsp_audio_mix_law[65536];
53960366cfSKarsten Keil extern u8 dsp_audio_seven2law[128];
54960366cfSKarsten Keil extern u8 dsp_audio_law2seven[256];
55960366cfSKarsten Keil extern void dsp_audio_generate_law_tables(void);
56960366cfSKarsten Keil extern void dsp_audio_generate_s2law_table(void);
57960366cfSKarsten Keil extern void dsp_audio_generate_seven(void);
58960366cfSKarsten Keil extern void dsp_audio_generate_mix_table(void);
59960366cfSKarsten Keil extern void dsp_audio_generate_ulaw_samples(void);
60960366cfSKarsten Keil extern void dsp_audio_generate_volume_changes(void);
61960366cfSKarsten Keil extern u8 dsp_silence;
62960366cfSKarsten Keil 
63960366cfSKarsten Keil 
64960366cfSKarsten Keil /*************
65960366cfSKarsten Keil  * cmx stuff *
66960366cfSKarsten Keil  *************/
67960366cfSKarsten Keil 
68960366cfSKarsten Keil #define MAX_POLL	256	/* maximum number of send-chunks */
69960366cfSKarsten Keil 
70960366cfSKarsten Keil #define CMX_BUFF_SIZE	0x8000	/* must be 2**n (0x1000 about 1/2 second) */
71960366cfSKarsten Keil #define CMX_BUFF_HALF	0x4000	/* CMX_BUFF_SIZE / 2 */
72960366cfSKarsten Keil #define CMX_BUFF_MASK	0x7fff	/* CMX_BUFF_SIZE - 1 */
73960366cfSKarsten Keil 
74960366cfSKarsten Keil /* how many seconds will we check the lowest delay until the jitter buffer
75960366cfSKarsten Keil    is reduced by that delay */
76960366cfSKarsten Keil #define MAX_SECONDS_JITTER_CHECK 5
77960366cfSKarsten Keil 
78960366cfSKarsten Keil extern struct timer_list dsp_spl_tl;
79960366cfSKarsten Keil extern u32 dsp_spl_jiffies;
80960366cfSKarsten Keil 
81960366cfSKarsten Keil /* the structure of conferences:
82960366cfSKarsten Keil  *
83960366cfSKarsten Keil  * each conference has a unique number, given by user space.
84960366cfSKarsten Keil  * the conferences are linked in a chain.
85960366cfSKarsten Keil  * each conference has members linked in a chain.
86960366cfSKarsten Keil  * each dsplayer points to a member, each member points to a dsplayer.
87960366cfSKarsten Keil  */
88960366cfSKarsten Keil 
89960366cfSKarsten Keil /* all members within a conference (this is linked 1:1 with the dsp) */
90960366cfSKarsten Keil struct dsp;
91960366cfSKarsten Keil struct dsp_conf_member {
92960366cfSKarsten Keil 	struct list_head	list;
93960366cfSKarsten Keil 	struct dsp		*dsp;
94960366cfSKarsten Keil };
95960366cfSKarsten Keil 
96960366cfSKarsten Keil /* the list of all conferences */
97960366cfSKarsten Keil struct dsp_conf {
98960366cfSKarsten Keil 	struct list_head	list;
99960366cfSKarsten Keil 	u32			id;
100960366cfSKarsten Keil 				/* all cmx stacks with the same ID are
101960366cfSKarsten Keil 				 connected */
102960366cfSKarsten Keil 	struct list_head	mlist;
103960366cfSKarsten Keil 	int			software; /* conf is processed by software */
104960366cfSKarsten Keil 	int			hardware; /* conf is processed by hardware */
105960366cfSKarsten Keil 				/* note: if both unset, has only one member */
106960366cfSKarsten Keil };
107960366cfSKarsten Keil 
108960366cfSKarsten Keil 
109960366cfSKarsten Keil /**************
110960366cfSKarsten Keil  * DTMF stuff *
111960366cfSKarsten Keil  **************/
112960366cfSKarsten Keil 
113960366cfSKarsten Keil #define DSP_DTMF_NPOINTS 102
114960366cfSKarsten Keil 
115a5355c27SAndreas Eversberg #define ECHOCAN_BUFF_SIZE 0x400 /* must be 2**n */
116a5355c27SAndreas Eversberg #define ECHOCAN_BUFF_MASK 0x3ff /* -1 */
117960366cfSKarsten Keil 
118960366cfSKarsten Keil struct dsp_dtmf {
119960366cfSKarsten Keil 	int		treshold; /* above this is dtmf (square of) */
120960366cfSKarsten Keil 	int		software; /* dtmf uses software decoding */
121960366cfSKarsten Keil 	int		hardware; /* dtmf uses hardware decoding */
122960366cfSKarsten Keil 	int		size; /* number of bytes in buffer */
123960366cfSKarsten Keil 	signed short	buffer[DSP_DTMF_NPOINTS];
124960366cfSKarsten Keil 		/* buffers one full dtmf frame */
125960366cfSKarsten Keil 	u8		lastwhat, lastdigit;
126960366cfSKarsten Keil 	int		count;
127b5df5a5cSAndreas Eversberg 	u8		digits[16]; /* dtmf result */
128960366cfSKarsten Keil };
129960366cfSKarsten Keil 
130960366cfSKarsten Keil 
131960366cfSKarsten Keil /******************
132960366cfSKarsten Keil  * pipeline stuff *
133960366cfSKarsten Keil  ******************/
134960366cfSKarsten Keil struct dsp_pipeline {
135960366cfSKarsten Keil 	rwlock_t  lock;
136960366cfSKarsten Keil 	struct list_head list;
137960366cfSKarsten Keil 	int inuse;
138960366cfSKarsten Keil };
139960366cfSKarsten Keil 
140960366cfSKarsten Keil /***************
141960366cfSKarsten Keil  * tones stuff *
142960366cfSKarsten Keil  ***************/
143960366cfSKarsten Keil 
144960366cfSKarsten Keil struct dsp_tone {
145960366cfSKarsten Keil 	int		software; /* tones are generated by software */
146960366cfSKarsten Keil 	int		hardware; /* tones are generated by hardware */
147960366cfSKarsten Keil 	int		tone;
148960366cfSKarsten Keil 	void		*pattern;
149960366cfSKarsten Keil 	int		count;
150960366cfSKarsten Keil 	int		index;
151960366cfSKarsten Keil 	struct timer_list tl;
152960366cfSKarsten Keil };
153960366cfSKarsten Keil 
154*bc138ec4SAndreas Eversberg /***************
155*bc138ec4SAndreas Eversberg  * echo stuff *
156*bc138ec4SAndreas Eversberg  ***************/
157*bc138ec4SAndreas Eversberg 
158*bc138ec4SAndreas Eversberg struct dsp_echo {
159*bc138ec4SAndreas Eversberg 	int		software; /* echo is generated by software */
160*bc138ec4SAndreas Eversberg 	int		hardware; /* echo is generated by hardware */
161*bc138ec4SAndreas Eversberg };
162*bc138ec4SAndreas Eversberg 
163960366cfSKarsten Keil /*****************
164960366cfSKarsten Keil  * general stuff *
165960366cfSKarsten Keil  *****************/
166960366cfSKarsten Keil 
167960366cfSKarsten Keil struct dsp {
168960366cfSKarsten Keil 	struct list_head list;
169960366cfSKarsten Keil 	struct mISDNchannel	ch;
170960366cfSKarsten Keil 	struct mISDNchannel	*up;
171960366cfSKarsten Keil 	unsigned char	name[64];
172960366cfSKarsten Keil 	int		b_active;
173*bc138ec4SAndreas Eversberg 	struct dsp_echo	echo;
174960366cfSKarsten Keil 	int		rx_disabled; /* what the user wants */
175960366cfSKarsten Keil 	int		rx_is_off; /* what the card is */
176960366cfSKarsten Keil 	int		tx_mix;
177960366cfSKarsten Keil 	struct dsp_tone	tone;
178960366cfSKarsten Keil 	struct dsp_dtmf	dtmf;
179960366cfSKarsten Keil 	int		tx_volume, rx_volume;
180960366cfSKarsten Keil 
181960366cfSKarsten Keil 	/* queue for sending frames */
182960366cfSKarsten Keil 	struct work_struct	workq;
183960366cfSKarsten Keil 	struct sk_buff_head	sendq;
184960366cfSKarsten Keil 	int		hdlc;	/* if mode is hdlc */
185960366cfSKarsten Keil 	int		data_pending;	/* currently an unconfirmed frame */
186960366cfSKarsten Keil 
187960366cfSKarsten Keil 	/* conference stuff */
188960366cfSKarsten Keil 	u32		conf_id;
189960366cfSKarsten Keil 	struct dsp_conf	*conf;
190960366cfSKarsten Keil 	struct dsp_conf_member
191960366cfSKarsten Keil 			*member;
192960366cfSKarsten Keil 
193960366cfSKarsten Keil 	/* buffer stuff */
194960366cfSKarsten Keil 	int		rx_W; /* current write pos for data without timestamp */
195960366cfSKarsten Keil 	int		rx_R; /* current read pos for transmit clock */
196960366cfSKarsten Keil 	int		rx_init; /* if set, pointers will be adjusted first */
197960366cfSKarsten Keil 	int		tx_W; /* current write pos for transmit data */
198960366cfSKarsten Keil 	int		tx_R; /* current read pos for transmit clock */
199960366cfSKarsten Keil 	int		rx_delay[MAX_SECONDS_JITTER_CHECK];
200960366cfSKarsten Keil 	int		tx_delay[MAX_SECONDS_JITTER_CHECK];
201960366cfSKarsten Keil 	u8		tx_buff[CMX_BUFF_SIZE];
202960366cfSKarsten Keil 	u8		rx_buff[CMX_BUFF_SIZE];
203960366cfSKarsten Keil 	int		last_tx; /* if set, we transmitted last poll interval */
204960366cfSKarsten Keil 	int		cmx_delay; /* initial delay of buffers,
205960366cfSKarsten Keil 				or 0 for dynamic jitter buffer */
206960366cfSKarsten Keil 	int		tx_dejitter; /* if set, dejitter tx buffer */
207960366cfSKarsten Keil 	int		tx_data; /* enables tx-data of CMX to upper layer */
208960366cfSKarsten Keil 
209960366cfSKarsten Keil 	/* hardware stuff */
210960366cfSKarsten Keil 	struct dsp_features features;
211960366cfSKarsten Keil 	int		features_rx_off; /* set if rx_off is featured */
2128dd2f36fSAndreas Eversberg 	int		features_fill_empty; /* set if fill_empty is featured */
213960366cfSKarsten Keil 	int		pcm_slot_rx; /* current PCM slot (or -1) */
214960366cfSKarsten Keil 	int		pcm_bank_rx;
215960366cfSKarsten Keil 	int		pcm_slot_tx;
216960366cfSKarsten Keil 	int		pcm_bank_tx;
217960366cfSKarsten Keil 	int		hfc_conf; /* unique id of current conference (or -1) */
218960366cfSKarsten Keil 
219960366cfSKarsten Keil 	/* encryption stuff */
220960366cfSKarsten Keil 	int		bf_enable;
221960366cfSKarsten Keil 	u32		bf_p[18];
222960366cfSKarsten Keil 	u32		bf_s[1024];
223960366cfSKarsten Keil 	int		bf_crypt_pos;
224960366cfSKarsten Keil 	u8		bf_data_in[9];
225960366cfSKarsten Keil 	u8		bf_crypt_out[9];
226960366cfSKarsten Keil 	int		bf_decrypt_in_pos;
227960366cfSKarsten Keil 	int		bf_decrypt_out_pos;
228960366cfSKarsten Keil 	u8		bf_crypt_inring[16];
229960366cfSKarsten Keil 	u8		bf_data_out[9];
230960366cfSKarsten Keil 	int		bf_sync;
231960366cfSKarsten Keil 
232960366cfSKarsten Keil 	struct dsp_pipeline
233960366cfSKarsten Keil 			pipeline;
234960366cfSKarsten Keil };
235960366cfSKarsten Keil 
236960366cfSKarsten Keil /* functions */
237960366cfSKarsten Keil 
238960366cfSKarsten Keil extern void dsp_change_volume(struct sk_buff *skb, int volume);
239960366cfSKarsten Keil 
240960366cfSKarsten Keil extern struct list_head dsp_ilist;
241960366cfSKarsten Keil extern struct list_head conf_ilist;
242960366cfSKarsten Keil extern void dsp_cmx_debug(struct dsp *dsp);
243960366cfSKarsten Keil extern void dsp_cmx_hardware(struct dsp_conf *conf, struct dsp *dsp);
244960366cfSKarsten Keil extern int dsp_cmx_conf(struct dsp *dsp, u32 conf_id);
245960366cfSKarsten Keil extern void dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb);
246960366cfSKarsten Keil extern void dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb);
247960366cfSKarsten Keil extern void dsp_cmx_send(void *arg);
248960366cfSKarsten Keil extern void dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb);
249960366cfSKarsten Keil extern int dsp_cmx_del_conf_member(struct dsp *dsp);
250960366cfSKarsten Keil extern int dsp_cmx_del_conf(struct dsp_conf *conf);
251960366cfSKarsten Keil 
252960366cfSKarsten Keil extern void dsp_dtmf_goertzel_init(struct dsp *dsp);
253960366cfSKarsten Keil extern void dsp_dtmf_hardware(struct dsp *dsp);
254960366cfSKarsten Keil extern u8 *dsp_dtmf_goertzel_decode(struct dsp *dsp, u8 *data, int len,
255960366cfSKarsten Keil 		int fmt);
256960366cfSKarsten Keil 
257960366cfSKarsten Keil extern int dsp_tone(struct dsp *dsp, int tone);
258960366cfSKarsten Keil extern void dsp_tone_copy(struct dsp *dsp, u8 *data, int len);
259960366cfSKarsten Keil extern void dsp_tone_timeout(void *arg);
260960366cfSKarsten Keil 
261960366cfSKarsten Keil extern void dsp_bf_encrypt(struct dsp *dsp, u8 *data, int len);
262960366cfSKarsten Keil extern void dsp_bf_decrypt(struct dsp *dsp, u8 *data, int len);
263960366cfSKarsten Keil extern int dsp_bf_init(struct dsp *dsp, const u8 *key, unsigned int keylen);
264960366cfSKarsten Keil extern void dsp_bf_cleanup(struct dsp *dsp);
265960366cfSKarsten Keil 
266960366cfSKarsten Keil extern int  dsp_pipeline_module_init(void);
267960366cfSKarsten Keil extern void dsp_pipeline_module_exit(void);
268960366cfSKarsten Keil extern int  dsp_pipeline_init(struct dsp_pipeline *pipeline);
269960366cfSKarsten Keil extern void dsp_pipeline_destroy(struct dsp_pipeline *pipeline);
270960366cfSKarsten Keil extern int  dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg);
271960366cfSKarsten Keil extern void dsp_pipeline_process_tx(struct dsp_pipeline *pipeline, u8 *data,
272960366cfSKarsten Keil 		int len);
273960366cfSKarsten Keil extern void dsp_pipeline_process_rx(struct dsp_pipeline *pipeline, u8 *data,
2747cfa153dSAndreas Eversberg 		int len, unsigned int txlen);
275960366cfSKarsten Keil 
276