1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152#ifndef _ECHOAUDIO_H_
153#define _ECHOAUDIO_H_
154
155
156#define TRUE 1
157#define FALSE 0
158
159#include "echoaudio_dsp.h"
160
161
162
163
164
165
166
167
168
169
170
171
172#define VENDOR_ID 0x1057
173#define DEVICE_ID_56301 0x1801
174#define DEVICE_ID_56361 0x3410
175#define SUBVENDOR_ID 0xECC0
176
177
178
179
180
181#define DARLA20 0x0010
182#define GINA20 0x0020
183#define LAYLA20 0x0030
184#define DARLA24 0x0040
185#define GINA24 0x0050
186#define LAYLA24 0x0060
187#define MONA 0x0070
188#define MIA 0x0080
189#define INDIGO 0x0090
190#define INDIGO_IO 0x00a0
191#define INDIGO_DJ 0x00b0
192#define DC8 0x00c0
193#define INDIGO_IOX 0x00d0
194#define INDIGO_DJX 0x00e0
195#define ECHO3G 0x0100
196
197
198
199
200
201
202
203
204
205
206
207#define ECHO_MAXAUDIOINPUTS 32
208#define ECHO_MAXAUDIOOUTPUTS 32
209#define ECHO_MAXAUDIOPIPES 32
210
211#define E3G_MAX_OUTPUTS 16
212#define ECHO_MAXMIDIJACKS 1
213#define ECHO_MIDI_QUEUE_SZ 512
214#define ECHO_MTC_QUEUE_SZ 32
215
216
217
218
219
220#define MIDI_ACTIVITY_TIMEOUT_USEC 200000
221
222
223
224
225
226
227
228
229
230
231
232#define ECHO_CLOCK_INTERNAL 0
233#define ECHO_CLOCK_WORD 1
234#define ECHO_CLOCK_SUPER 2
235#define ECHO_CLOCK_SPDIF 3
236#define ECHO_CLOCK_ADAT 4
237#define ECHO_CLOCK_ESYNC 5
238#define ECHO_CLOCK_ESYNC96 6
239#define ECHO_CLOCK_MTC 7
240#define ECHO_CLOCK_NUMBER 8
241#define ECHO_CLOCKS 0xffff
242
243
244
245
246
247#define ECHO_CLOCK_BIT_INTERNAL (1 << ECHO_CLOCK_INTERNAL)
248#define ECHO_CLOCK_BIT_WORD (1 << ECHO_CLOCK_WORD)
249#define ECHO_CLOCK_BIT_SUPER (1 << ECHO_CLOCK_SUPER)
250#define ECHO_CLOCK_BIT_SPDIF (1 << ECHO_CLOCK_SPDIF)
251#define ECHO_CLOCK_BIT_ADAT (1 << ECHO_CLOCK_ADAT)
252#define ECHO_CLOCK_BIT_ESYNC (1 << ECHO_CLOCK_ESYNC)
253#define ECHO_CLOCK_BIT_ESYNC96 (1 << ECHO_CLOCK_ESYNC96)
254#define ECHO_CLOCK_BIT_MTC (1<<ECHO_CLOCK_MTC)
255
256
257
258
259
260
261
262
263
264
265
266#define DIGITAL_MODE_NONE 0xFF
267#define DIGITAL_MODE_SPDIF_RCA 0
268#define DIGITAL_MODE_SPDIF_OPTICAL 1
269#define DIGITAL_MODE_ADAT 2
270#define DIGITAL_MODE_SPDIF_CDROM 3
271#define DIGITAL_MODES 4
272
273
274
275
276#define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA (1 << DIGITAL_MODE_SPDIF_RCA)
277#define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL (1 << DIGITAL_MODE_SPDIF_OPTICAL)
278#define ECHOCAPS_HAS_DIGITAL_MODE_ADAT (1 << DIGITAL_MODE_ADAT)
279#define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_CDROM (1 << DIGITAL_MODE_SPDIF_CDROM)
280
281
282#define EXT_3GBOX_NC 0x01
283#define EXT_3GBOX_NOT_SET 0x02
284
285
286#define ECHOGAIN_MUTED (-128)
287#define ECHOGAIN_MINOUT (-128)
288#define ECHOGAIN_MAXOUT (6)
289#define ECHOGAIN_MININP (-50)
290#define ECHOGAIN_MAXINP (50)
291
292#define PIPE_STATE_STOPPED 0
293#define PIPE_STATE_PAUSED 1
294#define PIPE_STATE_STARTED 2
295#define PIPE_STATE_PENDING 3
296
297
298
299#ifdef CONFIG_SND_DEBUG
300#define DE_INIT(x) snd_printk x
301#else
302#define DE_INIT(x)
303#endif
304
305
306#ifdef CONFIG_SND_DEBUG
307#define DE_HWP(x) snd_printk x
308#else
309#define DE_HWP(x)
310#endif
311
312
313#ifdef CONFIG_SND_DEBUG
314#define DE_ACT(x) snd_printk x
315#else
316#define DE_ACT(x)
317#endif
318
319
320#ifdef CONFIG_SND_DEBUG
321#define DE_MID(x) snd_printk x
322#else
323#define DE_MID(x)
324#endif
325
326
327struct audiopipe {
328 volatile u32 *dma_counter;
329
330
331
332 u32 last_counter;
333
334
335 u32 position;
336
337
338
339 short index;
340
341
342 short interleave;
343 struct snd_dma_buffer sgpage;
344 struct snd_pcm_hardware hw;
345 struct snd_pcm_hw_constraint_list constr;
346 short sglist_head;
347 char state;
348};
349
350
351struct audioformat {
352 u8 interleave;
353
354
355 u8 bits_per_sample;
356 char mono_to_stereo;
357
358
359 char data_are_bigendian;
360};
361
362
363struct echoaudio {
364 spinlock_t lock;
365 struct snd_pcm_substream *substream[DSP_MAXPIPES];
366 int last_period[DSP_MAXPIPES];
367 struct mutex mode_mutex;
368 u16 num_digital_modes, digital_mode_list[6];
369 u16 num_clock_sources, clock_source_list[10];
370 atomic_t opencount;
371 struct snd_kcontrol *clock_src_ctl;
372 struct snd_pcm *analog_pcm, *digital_pcm;
373 struct snd_card *card;
374 const char *card_name;
375 struct pci_dev *pci;
376 unsigned long dsp_registers_phys;
377 struct resource *iores;
378 struct snd_dma_buffer commpage_dma_buf;
379 int irq;
380#ifdef ECHOCARD_HAS_MIDI
381 struct snd_rawmidi *rmidi;
382 struct snd_rawmidi_substream *midi_in, *midi_out;
383#endif
384 struct timer_list timer;
385 char tinuse;
386 char midi_full;
387 char can_set_rate;
388 char rate_set;
389
390
391 struct comm_page *comm_page;
392
393
394 u32 pipe_alloc_mask;
395 u32 pipe_cyclic_mask;
396
397
398 u32 sample_rate;
399 u8 digital_mode;
400
401
402 u8 spdif_status;
403 u8 clock_state;
404 u8 input_clock;
405
406
407 u8 output_clock;
408 char meters_enabled;
409 char asic_loaded;
410 char bad_board;
411 char professional_spdif;
412 char non_audio_spdif;
413 char digital_in_automute;
414 char has_phantom_power;
415 char hasnt_input_nominal_level;
416 char phantom_power;
417 char has_midi;
418 char midi_input_enabled;
419
420#ifdef ECHOCARD_ECHO3G
421
422 char px_digital_out, px_analog_in, px_digital_in, px_num;
423 char bx_digital_out, bx_analog_in, bx_digital_in, bx_num;
424#endif
425
426 char nominal_level[ECHO_MAXAUDIOPIPES];
427
428 s8 input_gain[ECHO_MAXAUDIOINPUTS];
429
430 s8 output_gain[ECHO_MAXAUDIOOUTPUTS];
431
432 s8 monitor_gain[ECHO_MAXAUDIOOUTPUTS][ECHO_MAXAUDIOINPUTS];
433
434 s8 vmixer_gain[ECHO_MAXAUDIOOUTPUTS][ECHO_MAXAUDIOOUTPUTS];
435
436
437 u16 digital_modes;
438
439 u16 input_clock_types;
440 u16 output_clock_types;
441
442 u16 device_id, subdevice_id;
443 u16 *dsp_code;
444
445 short dsp_code_to_load;
446 short asic_code;
447 u32 comm_page_phys;
448
449 volatile u32 __iomem *dsp_registers;
450 u32 active_mask;
451
452#ifdef CONFIG_PM
453 const struct firmware *fw_cache[8];
454#endif
455
456#ifdef ECHOCARD_HAS_MIDI
457 u16 mtc_state;
458 u8 midi_buffer[MIDI_IN_BUFFER_SIZE];
459#endif
460};
461
462
463static int init_dsp_comm_page(struct echoaudio *chip);
464static int init_line_levels(struct echoaudio *chip);
465static int free_pipes(struct echoaudio *chip, struct audiopipe *pipe);
466static int load_firmware(struct echoaudio *chip);
467static int wait_handshake(struct echoaudio *chip);
468static int send_vector(struct echoaudio *chip, u32 command);
469static int get_firmware(const struct firmware **fw_entry,
470 struct echoaudio *chip, const short fw_index);
471static void free_firmware(const struct firmware *fw_entry);
472
473#ifdef ECHOCARD_HAS_MIDI
474static int enable_midi_input(struct echoaudio *chip, char enable);
475static void snd_echo_midi_output_trigger(
476 struct snd_rawmidi_substream *substream, int up);
477static int midi_service_irq(struct echoaudio *chip);
478static int __devinit snd_echo_midi_create(struct snd_card *card,
479 struct echoaudio *chip);
480#endif
481
482
483static inline void clear_handshake(struct echoaudio *chip)
484{
485 chip->comm_page->handshake = 0;
486}
487
488static inline u32 get_dsp_register(struct echoaudio *chip, u32 index)
489{
490 return readl(&chip->dsp_registers[index]);
491}
492
493static inline void set_dsp_register(struct echoaudio *chip, u32 index,
494 u32 value)
495{
496 writel(value, &chip->dsp_registers[index]);
497}
498
499
500
501
502
503
504
505static inline int px_digital_out(const struct echoaudio *chip)
506{
507 return PX_DIGITAL_OUT;
508}
509
510static inline int px_analog_in(const struct echoaudio *chip)
511{
512 return PX_ANALOG_IN;
513}
514
515static inline int px_digital_in(const struct echoaudio *chip)
516{
517 return PX_DIGITAL_IN;
518}
519
520static inline int px_num(const struct echoaudio *chip)
521{
522 return PX_NUM;
523}
524
525static inline int bx_digital_out(const struct echoaudio *chip)
526{
527 return BX_DIGITAL_OUT;
528}
529
530static inline int bx_analog_in(const struct echoaudio *chip)
531{
532 return BX_ANALOG_IN;
533}
534
535static inline int bx_digital_in(const struct echoaudio *chip)
536{
537 return BX_DIGITAL_IN;
538}
539
540static inline int bx_num(const struct echoaudio *chip)
541{
542 return BX_NUM;
543}
544
545static inline int num_pipes_out(const struct echoaudio *chip)
546{
547 return px_analog_in(chip);
548}
549
550static inline int num_pipes_in(const struct echoaudio *chip)
551{
552 return px_num(chip) - px_analog_in(chip);
553}
554
555static inline int num_busses_out(const struct echoaudio *chip)
556{
557 return bx_analog_in(chip);
558}
559
560static inline int num_busses_in(const struct echoaudio *chip)
561{
562 return bx_num(chip) - bx_analog_in(chip);
563}
564
565static inline int num_analog_busses_out(const struct echoaudio *chip)
566{
567 return bx_digital_out(chip);
568}
569
570static inline int num_analog_busses_in(const struct echoaudio *chip)
571{
572 return bx_digital_in(chip) - bx_analog_in(chip);
573}
574
575static inline int num_digital_busses_out(const struct echoaudio *chip)
576{
577 return num_busses_out(chip) - num_analog_busses_out(chip);
578}
579
580static inline int num_digital_busses_in(const struct echoaudio *chip)
581{
582 return num_busses_in(chip) - num_analog_busses_in(chip);
583}
584
585
586
587static inline int monitor_index(const struct echoaudio *chip, int out, int in)
588{
589 return out * num_busses_in(chip) + in;
590}
591
592
593#ifndef pci_device
594#define pci_device(chip) (&chip->pci->dev)
595#endif
596
597
598#endif
599