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#if PAGE_SIZE < 4096
32#error PAGE_SIZE is < 4k
33#endif
34
35static int restore_dsp_rettings(struct echoaudio *chip);
36
37
38
39
40
41
42static int wait_handshake(struct echoaudio *chip)
43{
44 int i;
45
46
47 for (i = 0; i < HANDSHAKE_TIMEOUT; i++) {
48
49 barrier();
50 if (chip->comm_page->handshake) {
51 return 0;
52 }
53 udelay(1);
54 }
55
56 snd_printk(KERN_ERR "wait_handshake(): Timeout waiting for DSP\n");
57 return -EBUSY;
58}
59
60
61
62
63
64
65
66static int send_vector(struct echoaudio *chip, u32 command)
67{
68 int i;
69
70 wmb();
71
72
73 for (i = 0; i < VECTOR_BUSY_TIMEOUT; i++) {
74 if (!(get_dsp_register(chip, CHI32_VECTOR_REG) &
75 CHI32_VECTOR_BUSY)) {
76 set_dsp_register(chip, CHI32_VECTOR_REG, command);
77
78 return 0;
79 }
80 udelay(1);
81 }
82
83 DE_ACT((KERN_ERR "timeout on send_vector\n"));
84 return -EBUSY;
85}
86
87
88
89
90
91static int write_dsp(struct echoaudio *chip, u32 data)
92{
93 u32 status, i;
94
95 for (i = 0; i < 10000000; i++) {
96 status = get_dsp_register(chip, CHI32_STATUS_REG);
97 if ((status & CHI32_STATUS_HOST_WRITE_EMPTY) != 0) {
98 set_dsp_register(chip, CHI32_DATA_REG, data);
99 wmb();
100 return 0;
101 }
102 udelay(1);
103 cond_resched();
104 }
105
106 chip->bad_board = TRUE;
107 DE_ACT((KERN_ERR "write_dsp: Set bad_board to TRUE\n"));
108 return -EIO;
109}
110
111
112
113
114
115static int read_dsp(struct echoaudio *chip, u32 *data)
116{
117 u32 status, i;
118
119 for (i = 0; i < READ_DSP_TIMEOUT; i++) {
120 status = get_dsp_register(chip, CHI32_STATUS_REG);
121 if ((status & CHI32_STATUS_HOST_READ_FULL) != 0) {
122 *data = get_dsp_register(chip, CHI32_DATA_REG);
123 return 0;
124 }
125 udelay(1);
126 cond_resched();
127 }
128
129 chip->bad_board = TRUE;
130 DE_INIT((KERN_ERR "read_dsp: Set bad_board to TRUE\n"));
131 return -EIO;
132}
133
134
135
136
137
138
139
140
141
142
143
144
145static int read_sn(struct echoaudio *chip)
146{
147 int i;
148 u32 sn[6];
149
150 for (i = 0; i < 5; i++) {
151 if (read_dsp(chip, &sn[i])) {
152 snd_printk(KERN_ERR "Failed to read serial number\n");
153 return -EIO;
154 }
155 }
156 DE_INIT(("Read serial number %08x %08x %08x %08x %08x\n",
157 sn[0], sn[1], sn[2], sn[3], sn[4]));
158 return 0;
159}
160
161
162
163#ifndef ECHOCARD_HAS_ASIC
164
165static inline int check_asic_status(struct echoaudio *chip)
166{
167 chip->asic_loaded = TRUE;
168 return 0;
169}
170
171#endif
172
173
174
175#ifdef ECHOCARD_HAS_ASIC
176
177
178static int load_asic_generic(struct echoaudio *chip, u32 cmd, short asic)
179{
180 const struct firmware *fw;
181 int err;
182 u32 i, size;
183 u8 *code;
184
185 err = get_firmware(&fw, chip, asic);
186 if (err < 0) {
187 snd_printk(KERN_WARNING "Firmware not found !\n");
188 return err;
189 }
190
191 code = (u8 *)fw->data;
192 size = fw->size;
193
194
195 if (write_dsp(chip, cmd) < 0)
196 goto la_error;
197
198
199 if (write_dsp(chip, size) < 0)
200 goto la_error;
201
202 for (i = 0; i < size; i++) {
203 if (write_dsp(chip, code[i]) < 0)
204 goto la_error;
205 }
206
207 DE_INIT(("ASIC loaded\n"));
208 free_firmware(fw);
209 return 0;
210
211la_error:
212 DE_INIT(("failed on write_dsp\n"));
213 free_firmware(fw);
214 return -EIO;
215}
216
217#endif
218
219
220
221#ifdef DSP_56361
222
223
224
225
226static int install_resident_loader(struct echoaudio *chip)
227{
228 u32 address;
229 int index, words, i;
230 u16 *code;
231 u32 status;
232 const struct firmware *fw;
233
234
235
236 if (chip->device_id != DEVICE_ID_56361)
237 return 0;
238
239
240
241 status = get_dsp_register(chip, CHI32_STATUS_REG);
242 if (status & CHI32_STATUS_REG_HF5) {
243 DE_INIT(("Resident loader already installed; status is 0x%x\n",
244 status));
245 return 0;
246 }
247
248 i = get_firmware(&fw, chip, FW_361_LOADER);
249 if (i < 0) {
250 snd_printk(KERN_WARNING "Firmware not found !\n");
251 return i;
252 }
253
254
255
256
257
258
259
260
261
262
263 set_dsp_register(chip, CHI32_CONTROL_REG,
264 get_dsp_register(chip, CHI32_CONTROL_REG) | 0x900);
265
266 code = (u16 *)fw->data;
267
268
269
270
271 index = code[0];
272
273
274 index += 3;
275
276
277 words = code[index++];
278
279
280 address = ((u32)code[index] << 16) + code[index + 1];
281 index += 2;
282
283
284 if (write_dsp(chip, words)) {
285 DE_INIT(("install_resident_loader: Failed to write word count!\n"));
286 goto irl_error;
287 }
288
289 if (write_dsp(chip, address)) {
290 DE_INIT(("install_resident_loader: Failed to write DSP address!\n"));
291 goto irl_error;
292 }
293
294 for (i = 0; i < words; i++) {
295 u32 data;
296
297 data = ((u32)code[index] << 16) + code[index + 1];
298 if (write_dsp(chip, data)) {
299 DE_INIT(("install_resident_loader: Failed to write DSP code\n"));
300 goto irl_error;
301 }
302 index += 2;
303 }
304
305
306 for (i = 0; i < 200; i++) {
307 udelay(50);
308 status = get_dsp_register(chip, CHI32_STATUS_REG);
309 if (status & CHI32_STATUS_REG_HF5)
310 break;
311 }
312
313 if (i == 200) {
314 DE_INIT(("Resident loader failed to set HF5\n"));
315 goto irl_error;
316 }
317
318 DE_INIT(("Resident loader successfully installed\n"));
319 free_firmware(fw);
320 return 0;
321
322irl_error:
323 free_firmware(fw);
324 return -EIO;
325}
326
327#endif
328
329
330static int load_dsp(struct echoaudio *chip, u16 *code)
331{
332 u32 address, data;
333 int index, words, i;
334
335 if (chip->dsp_code == code) {
336 DE_INIT(("DSP is already loaded!\n"));
337 return 0;
338 }
339 chip->bad_board = TRUE;
340 chip->dsp_code = NULL;
341 chip->asic_loaded = FALSE;
342
343 DE_INIT(("load_dsp: Set bad_board to TRUE\n"));
344
345
346#ifdef DSP_56361
347 if ((i = install_resident_loader(chip)) < 0)
348 return i;
349#endif
350
351
352 if (send_vector(chip, DSP_VC_RESET) < 0) {
353 DE_INIT(("LoadDsp: send_vector DSP_VC_RESET failed, Critical Failure\n"));
354 return -EIO;
355 }
356
357 udelay(10);
358
359
360 for (i = 0; i < 1000; i++) {
361 if (get_dsp_register(chip, CHI32_STATUS_REG) &
362 CHI32_STATUS_REG_HF3)
363 break;
364 udelay(10);
365 }
366
367 if (i == 1000) {
368 DE_INIT(("load_dsp: Timeout waiting for CHI32_STATUS_REG_HF3\n"));
369 return -EIO;
370 }
371
372
373 set_dsp_register(chip, CHI32_CONTROL_REG,
374 get_dsp_register(chip, CHI32_CONTROL_REG) | 0x900);
375
376
377
378 index = code[0];
379 for (;;) {
380 int block_type, mem_type;
381
382
383 index++;
384
385
386 block_type = code[index];
387 if (block_type == 4)
388 break;
389
390 index++;
391
392
393 mem_type = code[index++];
394
395
396 words = code[index++];
397 if (words == 0)
398 break;
399
400
401 address = ((u32)code[index] << 16) + code[index + 1];
402 index += 2;
403
404 if (write_dsp(chip, words) < 0) {
405 DE_INIT(("load_dsp: failed to write number of DSP words\n"));
406 return -EIO;
407 }
408 if (write_dsp(chip, address) < 0) {
409 DE_INIT(("load_dsp: failed to write DSP address\n"));
410 return -EIO;
411 }
412 if (write_dsp(chip, mem_type) < 0) {
413 DE_INIT(("load_dsp: failed to write DSP memory type\n"));
414 return -EIO;
415 }
416
417 for (i = 0; i < words; i++, index+=2) {
418 data = ((u32)code[index] << 16) + code[index + 1];
419 if (write_dsp(chip, data) < 0) {
420 DE_INIT(("load_dsp: failed to write DSP data\n"));
421 return -EIO;
422 }
423 }
424 }
425
426 if (write_dsp(chip, 0) < 0) {
427 DE_INIT(("load_dsp: Failed to write final zero\n"));
428 return -EIO;
429 }
430 udelay(10);
431
432 for (i = 0; i < 5000; i++) {
433
434 if (get_dsp_register(chip, CHI32_STATUS_REG) &
435 CHI32_STATUS_REG_HF4) {
436 set_dsp_register(chip, CHI32_CONTROL_REG,
437 get_dsp_register(chip, CHI32_CONTROL_REG) & ~0x1b00);
438
439 if (write_dsp(chip, DSP_FNC_SET_COMMPAGE_ADDR) < 0) {
440 DE_INIT(("load_dsp: Failed to write DSP_FNC_SET_COMMPAGE_ADDR\n"));
441 return -EIO;
442 }
443
444 if (write_dsp(chip, chip->comm_page_phys) < 0) {
445 DE_INIT(("load_dsp: Failed to write comm page address\n"));
446 return -EIO;
447 }
448
449
450
451
452
453 if (read_sn(chip) < 0) {
454 DE_INIT(("load_dsp: Failed to read serial number\n"));
455 return -EIO;
456 }
457
458 chip->dsp_code = code;
459 chip->bad_board = FALSE;
460 DE_INIT(("load_dsp: OK!\n"));
461 return 0;
462 }
463 udelay(100);
464 }
465
466 DE_INIT(("load_dsp: DSP load timed out waiting for HF4\n"));
467 return -EIO;
468}
469
470
471
472
473static int load_firmware(struct echoaudio *chip)
474{
475 const struct firmware *fw;
476 int box_type, err;
477
478 if (snd_BUG_ON(!chip->comm_page))
479 return -EPERM;
480
481
482 if (chip->dsp_code) {
483 if ((box_type = check_asic_status(chip)) >= 0)
484 return box_type;
485
486 chip->dsp_code = NULL;
487 }
488
489 err = get_firmware(&fw, chip, chip->dsp_code_to_load);
490 if (err < 0)
491 return err;
492 err = load_dsp(chip, (u16 *)fw->data);
493 free_firmware(fw);
494 if (err < 0)
495 return err;
496
497 if ((box_type = load_asic(chip)) < 0)
498 return box_type;
499
500 return box_type;
501}
502
503
504
505
506
507
508
509#if defined(ECHOCARD_HAS_INPUT_NOMINAL_LEVEL) || \
510 defined(ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL)
511
512
513static int set_nominal_level(struct echoaudio *chip, u16 index, char consumer)
514{
515 if (snd_BUG_ON(index >= num_busses_out(chip) + num_busses_in(chip)))
516 return -EINVAL;
517
518
519 if (wait_handshake(chip))
520 return -EIO;
521
522 chip->nominal_level[index] = consumer;
523
524 if (consumer)
525 chip->comm_page->nominal_level_mask |= cpu_to_le32(1 << index);
526 else
527 chip->comm_page->nominal_level_mask &= ~cpu_to_le32(1 << index);
528
529 return 0;
530}
531
532#endif
533
534
535
536
537static int set_output_gain(struct echoaudio *chip, u16 channel, s8 gain)
538{
539 if (snd_BUG_ON(channel >= num_busses_out(chip)))
540 return -EINVAL;
541
542 if (wait_handshake(chip))
543 return -EIO;
544
545
546 chip->output_gain[channel] = gain;
547 chip->comm_page->line_out_level[channel] = gain;
548 return 0;
549}
550
551
552
553#ifdef ECHOCARD_HAS_MONITOR
554
555static int set_monitor_gain(struct echoaudio *chip, u16 output, u16 input,
556 s8 gain)
557{
558 if (snd_BUG_ON(output >= num_busses_out(chip) ||
559 input >= num_busses_in(chip)))
560 return -EINVAL;
561
562 if (wait_handshake(chip))
563 return -EIO;
564
565 chip->monitor_gain[output][input] = gain;
566 chip->comm_page->monitors[monitor_index(chip, output, input)] = gain;
567 return 0;
568}
569#endif
570
571
572
573static int update_output_line_level(struct echoaudio *chip)
574{
575 if (wait_handshake(chip))
576 return -EIO;
577 clear_handshake(chip);
578 return send_vector(chip, DSP_VC_UPDATE_OUTVOL);
579}
580
581
582
583
584static int update_input_line_level(struct echoaudio *chip)
585{
586 if (wait_handshake(chip))
587 return -EIO;
588 clear_handshake(chip);
589 return send_vector(chip, DSP_VC_UPDATE_INGAIN);
590}
591
592
593
594
595
596static void set_meters_on(struct echoaudio *chip, char on)
597{
598 if (on && !chip->meters_enabled) {
599 send_vector(chip, DSP_VC_METERS_ON);
600 chip->meters_enabled = 1;
601 } else if (!on && chip->meters_enabled) {
602 send_vector(chip, DSP_VC_METERS_OFF);
603 chip->meters_enabled = 0;
604 memset((s8 *)chip->comm_page->vu_meter, ECHOGAIN_MUTED,
605 DSP_MAXPIPES);
606 memset((s8 *)chip->comm_page->peak_meter, ECHOGAIN_MUTED,
607 DSP_MAXPIPES);
608 }
609}
610
611
612
613
614
615
616
617
618
619
620
621static void get_audio_meters(struct echoaudio *chip, long *meters)
622{
623 int i, m, n;
624
625 m = 0;
626 n = 0;
627 for (i = 0; i < num_busses_out(chip); i++, m++) {
628 meters[n++] = chip->comm_page->vu_meter[m];
629 meters[n++] = chip->comm_page->peak_meter[m];
630 }
631 for (; n < 32; n++)
632 meters[n] = 0;
633
634#ifdef ECHOCARD_ECHO3G
635 m = E3G_MAX_OUTPUTS;
636#endif
637
638 for (i = 0; i < num_busses_in(chip); i++, m++) {
639 meters[n++] = chip->comm_page->vu_meter[m];
640 meters[n++] = chip->comm_page->peak_meter[m];
641 }
642 for (; n < 64; n++)
643 meters[n] = 0;
644
645#ifdef ECHOCARD_HAS_VMIXER
646 for (i = 0; i < num_pipes_out(chip); i++, m++) {
647 meters[n++] = chip->comm_page->vu_meter[m];
648 meters[n++] = chip->comm_page->peak_meter[m];
649 }
650#endif
651 for (; n < 96; n++)
652 meters[n] = 0;
653}
654
655
656
657static int restore_dsp_rettings(struct echoaudio *chip)
658{
659 int i, o, err;
660 DE_INIT(("restore_dsp_settings\n"));
661
662 if ((err = check_asic_status(chip)) < 0)
663 return err;
664
665
666 chip->comm_page->gd_clock_state = GD_CLOCK_UNDEF;
667 chip->comm_page->gd_spdif_status = GD_SPDIF_STATUS_UNDEF;
668 chip->comm_page->handshake = 0xffffffff;
669
670
671 for (i = 0; i < num_busses_out(chip); i++) {
672 err = set_output_gain(chip, i, chip->output_gain[i]);
673 if (err < 0)
674 return err;
675 }
676
677#ifdef ECHOCARD_HAS_VMIXER
678 for (i = 0; i < num_pipes_out(chip); i++)
679 for (o = 0; o < num_busses_out(chip); o++) {
680 err = set_vmixer_gain(chip, o, i,
681 chip->vmixer_gain[o][i]);
682 if (err < 0)
683 return err;
684 }
685 if (update_vmixer_level(chip) < 0)
686 return -EIO;
687#endif
688
689#ifdef ECHOCARD_HAS_MONITOR
690 for (o = 0; o < num_busses_out(chip); o++)
691 for (i = 0; i < num_busses_in(chip); i++) {
692 err = set_monitor_gain(chip, o, i,
693 chip->monitor_gain[o][i]);
694 if (err < 0)
695 return err;
696 }
697#endif
698
699#ifdef ECHOCARD_HAS_INPUT_GAIN
700 for (i = 0; i < num_busses_in(chip); i++) {
701 err = set_input_gain(chip, i, chip->input_gain[i]);
702 if (err < 0)
703 return err;
704 }
705#endif
706
707 err = update_output_line_level(chip);
708 if (err < 0)
709 return err;
710
711 err = update_input_line_level(chip);
712 if (err < 0)
713 return err;
714
715 err = set_sample_rate(chip, chip->sample_rate);
716 if (err < 0)
717 return err;
718
719 if (chip->meters_enabled) {
720 err = send_vector(chip, DSP_VC_METERS_ON);
721 if (err < 0)
722 return err;
723 }
724
725#ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
726 if (set_digital_mode(chip, chip->digital_mode) < 0)
727 return -EIO;
728#endif
729
730#ifdef ECHOCARD_HAS_DIGITAL_IO
731 if (set_professional_spdif(chip, chip->professional_spdif) < 0)
732 return -EIO;
733#endif
734
735#ifdef ECHOCARD_HAS_PHANTOM_POWER
736 if (set_phantom_power(chip, chip->phantom_power) < 0)
737 return -EIO;
738#endif
739
740#ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
741
742 if (set_input_clock(chip, chip->input_clock) < 0)
743 return -EIO;
744#endif
745
746#ifdef ECHOCARD_HAS_OUTPUT_CLOCK_SWITCH
747 if (set_output_clock(chip, chip->output_clock) < 0)
748 return -EIO;
749#endif
750
751 if (wait_handshake(chip) < 0)
752 return -EIO;
753 clear_handshake(chip);
754 if (send_vector(chip, DSP_VC_UPDATE_FLAGS) < 0)
755 return -EIO;
756
757 DE_INIT(("restore_dsp_rettings done\n"));
758 return 0;
759}
760
761
762
763
764
765
766
767
768
769
770static void set_audio_format(struct echoaudio *chip, u16 pipe_index,
771 const struct audioformat *format)
772{
773 u16 dsp_format;
774
775 dsp_format = DSP_AUDIOFORM_SS_16LE;
776
777
778 if (format->interleave > 2) {
779 switch (format->bits_per_sample) {
780 case 16:
781 dsp_format = DSP_AUDIOFORM_SUPER_INTERLEAVE_16LE;
782 break;
783 case 24:
784 dsp_format = DSP_AUDIOFORM_SUPER_INTERLEAVE_24LE;
785 break;
786 case 32:
787 dsp_format = DSP_AUDIOFORM_SUPER_INTERLEAVE_32LE;
788 break;
789 }
790 dsp_format |= format->interleave;
791 } else if (format->data_are_bigendian) {
792
793 switch (format->interleave) {
794 case 1:
795 dsp_format = DSP_AUDIOFORM_MM_32BE;
796 break;
797#ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
798 case 2:
799 dsp_format = DSP_AUDIOFORM_SS_32BE;
800 break;
801#endif
802 }
803 } else if (format->interleave == 1 &&
804 format->bits_per_sample == 32 && !format->mono_to_stereo) {
805
806 dsp_format = DSP_AUDIOFORM_MM_32LE;
807 } else {
808
809 switch (format->bits_per_sample) {
810 case 8:
811 if (format->interleave == 2)
812 dsp_format = DSP_AUDIOFORM_SS_8;
813 else
814 dsp_format = DSP_AUDIOFORM_MS_8;
815 break;
816 default:
817 case 16:
818 if (format->interleave == 2)
819 dsp_format = DSP_AUDIOFORM_SS_16LE;
820 else
821 dsp_format = DSP_AUDIOFORM_MS_16LE;
822 break;
823 case 24:
824 if (format->interleave == 2)
825 dsp_format = DSP_AUDIOFORM_SS_24LE;
826 else
827 dsp_format = DSP_AUDIOFORM_MS_24LE;
828 break;
829 case 32:
830 if (format->interleave == 2)
831 dsp_format = DSP_AUDIOFORM_SS_32LE;
832 else
833 dsp_format = DSP_AUDIOFORM_MS_32LE;
834 break;
835 }
836 }
837 DE_ACT(("set_audio_format[%d] = %x\n", pipe_index, dsp_format));
838 chip->comm_page->audio_format[pipe_index] = cpu_to_le16(dsp_format);
839}
840
841
842
843
844
845
846
847static int start_transport(struct echoaudio *chip, u32 channel_mask,
848 u32 cyclic_mask)
849{
850 DE_ACT(("start_transport %x\n", channel_mask));
851
852 if (wait_handshake(chip))
853 return -EIO;
854
855 chip->comm_page->cmd_start |= cpu_to_le32(channel_mask);
856
857 if (chip->comm_page->cmd_start) {
858 clear_handshake(chip);
859 send_vector(chip, DSP_VC_START_TRANSFER);
860 if (wait_handshake(chip))
861 return -EIO;
862
863 chip->active_mask |= channel_mask;
864 chip->comm_page->cmd_start = 0;
865 return 0;
866 }
867
868 DE_ACT(("start_transport: No pipes to start!\n"));
869 return -EINVAL;
870}
871
872
873
874static int pause_transport(struct echoaudio *chip, u32 channel_mask)
875{
876 DE_ACT(("pause_transport %x\n", channel_mask));
877
878 if (wait_handshake(chip))
879 return -EIO;
880
881 chip->comm_page->cmd_stop |= cpu_to_le32(channel_mask);
882 chip->comm_page->cmd_reset = 0;
883 if (chip->comm_page->cmd_stop) {
884 clear_handshake(chip);
885 send_vector(chip, DSP_VC_STOP_TRANSFER);
886 if (wait_handshake(chip))
887 return -EIO;
888
889 chip->active_mask &= ~channel_mask;
890 chip->comm_page->cmd_stop = 0;
891 chip->comm_page->cmd_reset = 0;
892 return 0;
893 }
894
895 DE_ACT(("pause_transport: No pipes to stop!\n"));
896 return 0;
897}
898
899
900
901static int stop_transport(struct echoaudio *chip, u32 channel_mask)
902{
903 DE_ACT(("stop_transport %x\n", channel_mask));
904
905 if (wait_handshake(chip))
906 return -EIO;
907
908 chip->comm_page->cmd_stop |= cpu_to_le32(channel_mask);
909 chip->comm_page->cmd_reset |= cpu_to_le32(channel_mask);
910 if (chip->comm_page->cmd_reset) {
911 clear_handshake(chip);
912 send_vector(chip, DSP_VC_STOP_TRANSFER);
913 if (wait_handshake(chip))
914 return -EIO;
915
916 chip->active_mask &= ~channel_mask;
917 chip->comm_page->cmd_stop = 0;
918 chip->comm_page->cmd_reset = 0;
919 return 0;
920 }
921
922 DE_ACT(("stop_transport: No pipes to stop!\n"));
923 return 0;
924}
925
926
927
928static inline int is_pipe_allocated(struct echoaudio *chip, u16 pipe_index)
929{
930 return (chip->pipe_alloc_mask & (1 << pipe_index));
931}
932
933
934
935
936
937static int rest_in_peace(struct echoaudio *chip)
938{
939 DE_ACT(("rest_in_peace() open=%x\n", chip->pipe_alloc_mask));
940
941
942 stop_transport(chip, chip->active_mask);
943
944 set_meters_on(chip, FALSE);
945
946#ifdef ECHOCARD_HAS_MIDI
947 enable_midi_input(chip, FALSE);
948#endif
949
950
951 if (chip->dsp_code) {
952
953 chip->dsp_code = NULL;
954
955 return send_vector(chip, DSP_VC_GO_COMATOSE);
956 }
957 return 0;
958}
959
960
961
962
963static int init_dsp_comm_page(struct echoaudio *chip)
964{
965
966 if (offsetof(struct comm_page, midi_output) != 0xbe0) {
967 DE_INIT(("init_dsp_comm_page() - Invalid struct comm_page structure\n"));
968 return -EPERM;
969 }
970
971
972 chip->card_name = ECHOCARD_NAME;
973 chip->bad_board = TRUE;
974 chip->dsp_code = NULL;
975 chip->asic_loaded = FALSE;
976 memset(chip->comm_page, 0, sizeof(struct comm_page));
977
978
979 chip->comm_page->comm_size =
980 cpu_to_le32(sizeof(struct comm_page));
981 chip->comm_page->handshake = 0xffffffff;
982 chip->comm_page->midi_out_free_count =
983 cpu_to_le32(DSP_MIDI_OUT_FIFO_SIZE);
984 chip->comm_page->sample_rate = cpu_to_le32(44100);
985
986
987 memset(chip->comm_page->monitors, ECHOGAIN_MUTED, MONITOR_ARRAY_SIZE);
988 memset(chip->comm_page->vmixer, ECHOGAIN_MUTED, VMIXER_ARRAY_SIZE);
989
990 return 0;
991}
992
993
994
995
996
997
998
999static int init_line_levels(struct echoaudio *chip)
1000{
1001 DE_INIT(("init_line_levels\n"));
1002 memset(chip->output_gain, ECHOGAIN_MUTED, sizeof(chip->output_gain));
1003 memset(chip->input_gain, ECHOGAIN_MUTED, sizeof(chip->input_gain));
1004 memset(chip->monitor_gain, ECHOGAIN_MUTED, sizeof(chip->monitor_gain));
1005 memset(chip->vmixer_gain, ECHOGAIN_MUTED, sizeof(chip->vmixer_gain));
1006 chip->input_clock = ECHO_CLOCK_INTERNAL;
1007 chip->output_clock = ECHO_CLOCK_WORD;
1008 chip->sample_rate = 44100;
1009 return restore_dsp_rettings(chip);
1010}
1011
1012
1013
1014
1015
1016
1017static int service_irq(struct echoaudio *chip)
1018{
1019 int st;
1020
1021
1022 if (get_dsp_register(chip, CHI32_STATUS_REG) & CHI32_STATUS_IRQ) {
1023 st = 0;
1024#ifdef ECHOCARD_HAS_MIDI
1025
1026 if (chip->comm_page->midi_input[0])
1027 st = midi_service_irq(chip);
1028#endif
1029
1030 chip->comm_page->midi_input[0] = 0;
1031 send_vector(chip, DSP_VC_ACK_INT);
1032 return st;
1033 }
1034 return -1;
1035}
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046static int allocate_pipes(struct echoaudio *chip, struct audiopipe *pipe,
1047 int pipe_index, int interleave)
1048{
1049 int i;
1050 u32 channel_mask;
1051 char is_cyclic;
1052
1053 DE_ACT(("allocate_pipes: ch=%d int=%d\n", pipe_index, interleave));
1054
1055 if (chip->bad_board)
1056 return -EIO;
1057
1058 is_cyclic = 1;
1059
1060 for (channel_mask = i = 0; i < interleave; i++)
1061 channel_mask |= 1 << (pipe_index + i);
1062 if (chip->pipe_alloc_mask & channel_mask) {
1063 DE_ACT(("allocate_pipes: channel already open\n"));
1064 return -EAGAIN;
1065 }
1066
1067 chip->comm_page->position[pipe_index] = 0;
1068 chip->pipe_alloc_mask |= channel_mask;
1069 if (is_cyclic)
1070 chip->pipe_cyclic_mask |= channel_mask;
1071 pipe->index = pipe_index;
1072 pipe->interleave = interleave;
1073 pipe->state = PIPE_STATE_STOPPED;
1074
1075
1076
1077
1078 pipe->dma_counter = &chip->comm_page->position[pipe_index];
1079 *pipe->dma_counter = 0;
1080 DE_ACT(("allocate_pipes: ok\n"));
1081 return pipe_index;
1082}
1083
1084
1085
1086static int free_pipes(struct echoaudio *chip, struct audiopipe *pipe)
1087{
1088 u32 channel_mask;
1089 int i;
1090
1091 DE_ACT(("free_pipes: Pipe %d\n", pipe->index));
1092 if (snd_BUG_ON(!is_pipe_allocated(chip, pipe->index)))
1093 return -EINVAL;
1094 if (snd_BUG_ON(pipe->state != PIPE_STATE_STOPPED))
1095 return -EINVAL;
1096
1097 for (channel_mask = i = 0; i < pipe->interleave; i++)
1098 channel_mask |= 1 << (pipe->index + i);
1099
1100 chip->pipe_alloc_mask &= ~channel_mask;
1101 chip->pipe_cyclic_mask &= ~channel_mask;
1102 return 0;
1103}
1104
1105
1106
1107
1108
1109
1110
1111static int sglist_init(struct echoaudio *chip, struct audiopipe *pipe)
1112{
1113 pipe->sglist_head = 0;
1114 memset(pipe->sgpage.area, 0, PAGE_SIZE);
1115 chip->comm_page->sglist_addr[pipe->index].addr =
1116 cpu_to_le32(pipe->sgpage.addr);
1117 return 0;
1118}
1119
1120
1121
1122static int sglist_add_mapping(struct echoaudio *chip, struct audiopipe *pipe,
1123 dma_addr_t address, size_t length)
1124{
1125 int head = pipe->sglist_head;
1126 struct sg_entry *list = (struct sg_entry *)pipe->sgpage.area;
1127
1128 if (head < MAX_SGLIST_ENTRIES - 1) {
1129 list[head].addr = cpu_to_le32(address);
1130 list[head].size = cpu_to_le32(length);
1131 pipe->sglist_head++;
1132 } else {
1133 DE_ACT(("SGlist: too many fragments\n"));
1134 return -ENOMEM;
1135 }
1136 return 0;
1137}
1138
1139
1140
1141static inline int sglist_add_irq(struct echoaudio *chip, struct audiopipe *pipe)
1142{
1143 return sglist_add_mapping(chip, pipe, 0, 0);
1144}
1145
1146
1147
1148static inline int sglist_wrap(struct echoaudio *chip, struct audiopipe *pipe)
1149{
1150 return sglist_add_mapping(chip, pipe, pipe->sgpage.addr, 0);
1151}
1152