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