0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #if PAGE_SIZE < 4096
0032 #error PAGE_SIZE is < 4k
0033 #endif
0034
0035 static int restore_dsp_rettings(struct echoaudio *chip);
0036
0037
0038
0039
0040
0041
0042 static int wait_handshake(struct echoaudio *chip)
0043 {
0044 int i;
0045
0046
0047 for (i = 0; i < HANDSHAKE_TIMEOUT; i++) {
0048
0049 barrier();
0050 if (chip->comm_page->handshake) {
0051 return 0;
0052 }
0053 udelay(1);
0054 }
0055
0056 dev_err(chip->card->dev, "wait_handshake(): Timeout waiting for DSP\n");
0057 return -EBUSY;
0058 }
0059
0060
0061
0062
0063
0064
0065
0066 static int send_vector(struct echoaudio *chip, u32 command)
0067 {
0068 int i;
0069
0070 wmb();
0071
0072
0073 for (i = 0; i < VECTOR_BUSY_TIMEOUT; i++) {
0074 if (!(get_dsp_register(chip, CHI32_VECTOR_REG) &
0075 CHI32_VECTOR_BUSY)) {
0076 set_dsp_register(chip, CHI32_VECTOR_REG, command);
0077
0078 return 0;
0079 }
0080 udelay(1);
0081 }
0082
0083 dev_err(chip->card->dev, "timeout on send_vector\n");
0084 return -EBUSY;
0085 }
0086
0087
0088
0089
0090
0091 static int write_dsp(struct echoaudio *chip, u32 data)
0092 {
0093 u32 status, i;
0094
0095 for (i = 0; i < 10000000; i++) {
0096 status = get_dsp_register(chip, CHI32_STATUS_REG);
0097 if ((status & CHI32_STATUS_HOST_WRITE_EMPTY) != 0) {
0098 set_dsp_register(chip, CHI32_DATA_REG, data);
0099 wmb();
0100 return 0;
0101 }
0102 udelay(1);
0103 cond_resched();
0104 }
0105
0106 chip->bad_board = true;
0107 dev_dbg(chip->card->dev, "write_dsp: Set bad_board to true\n");
0108 return -EIO;
0109 }
0110
0111
0112
0113
0114
0115 static int read_dsp(struct echoaudio *chip, u32 *data)
0116 {
0117 u32 status, i;
0118
0119 for (i = 0; i < READ_DSP_TIMEOUT; i++) {
0120 status = get_dsp_register(chip, CHI32_STATUS_REG);
0121 if ((status & CHI32_STATUS_HOST_READ_FULL) != 0) {
0122 *data = get_dsp_register(chip, CHI32_DATA_REG);
0123 return 0;
0124 }
0125 udelay(1);
0126 cond_resched();
0127 }
0128
0129 chip->bad_board = true;
0130 dev_err(chip->card->dev, "read_dsp: Set bad_board to true\n");
0131 return -EIO;
0132 }
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145 static int read_sn(struct echoaudio *chip)
0146 {
0147 int i;
0148 u32 sn[6];
0149
0150 for (i = 0; i < 5; i++) {
0151 if (read_dsp(chip, &sn[i])) {
0152 dev_err(chip->card->dev,
0153 "Failed to read serial number\n");
0154 return -EIO;
0155 }
0156 }
0157 dev_dbg(chip->card->dev,
0158 "Read serial number %08x %08x %08x %08x %08x\n",
0159 sn[0], sn[1], sn[2], sn[3], sn[4]);
0160 return 0;
0161 }
0162
0163
0164
0165 #ifndef ECHOCARD_HAS_ASIC
0166
0167 static inline int check_asic_status(struct echoaudio *chip)
0168 {
0169 chip->asic_loaded = true;
0170 return 0;
0171 }
0172
0173 #endif
0174
0175
0176
0177 #ifdef ECHOCARD_HAS_ASIC
0178
0179
0180 static int load_asic_generic(struct echoaudio *chip, u32 cmd, short asic)
0181 {
0182 const struct firmware *fw;
0183 int err;
0184 u32 i, size;
0185 u8 *code;
0186
0187 err = get_firmware(&fw, chip, asic);
0188 if (err < 0) {
0189 dev_warn(chip->card->dev, "Firmware not found !\n");
0190 return err;
0191 }
0192
0193 code = (u8 *)fw->data;
0194 size = fw->size;
0195
0196
0197 if (write_dsp(chip, cmd) < 0)
0198 goto la_error;
0199
0200
0201 if (write_dsp(chip, size) < 0)
0202 goto la_error;
0203
0204 for (i = 0; i < size; i++) {
0205 if (write_dsp(chip, code[i]) < 0)
0206 goto la_error;
0207 }
0208
0209 free_firmware(fw, chip);
0210 return 0;
0211
0212 la_error:
0213 dev_err(chip->card->dev, "failed on write_dsp\n");
0214 free_firmware(fw, chip);
0215 return -EIO;
0216 }
0217
0218 #endif
0219
0220
0221
0222 #ifdef DSP_56361
0223
0224
0225
0226
0227 static int install_resident_loader(struct echoaudio *chip)
0228 {
0229 u32 address;
0230 int index, words, i;
0231 u16 *code;
0232 u32 status;
0233 const struct firmware *fw;
0234
0235
0236
0237 if (chip->device_id != DEVICE_ID_56361)
0238 return 0;
0239
0240
0241
0242 status = get_dsp_register(chip, CHI32_STATUS_REG);
0243 if (status & CHI32_STATUS_REG_HF5) {
0244 dev_dbg(chip->card->dev,
0245 "Resident loader already installed; status is 0x%x\n",
0246 status);
0247 return 0;
0248 }
0249
0250 i = get_firmware(&fw, chip, FW_361_LOADER);
0251 if (i < 0) {
0252 dev_warn(chip->card->dev, "Firmware not found !\n");
0253 return i;
0254 }
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265 set_dsp_register(chip, CHI32_CONTROL_REG,
0266 get_dsp_register(chip, CHI32_CONTROL_REG) | 0x900);
0267
0268 code = (u16 *)fw->data;
0269
0270
0271
0272
0273 index = code[0];
0274
0275
0276 index += 3;
0277
0278
0279 words = code[index++];
0280
0281
0282 address = ((u32)code[index] << 16) + code[index + 1];
0283 index += 2;
0284
0285
0286 if (write_dsp(chip, words)) {
0287 dev_err(chip->card->dev,
0288 "install_resident_loader: Failed to write word count!\n");
0289 goto irl_error;
0290 }
0291
0292 if (write_dsp(chip, address)) {
0293 dev_err(chip->card->dev,
0294 "install_resident_loader: Failed to write DSP address!\n");
0295 goto irl_error;
0296 }
0297
0298 for (i = 0; i < words; i++) {
0299 u32 data;
0300
0301 data = ((u32)code[index] << 16) + code[index + 1];
0302 if (write_dsp(chip, data)) {
0303 dev_err(chip->card->dev,
0304 "install_resident_loader: Failed to write DSP code\n");
0305 goto irl_error;
0306 }
0307 index += 2;
0308 }
0309
0310
0311 for (i = 0; i < 200; i++) {
0312 udelay(50);
0313 status = get_dsp_register(chip, CHI32_STATUS_REG);
0314 if (status & CHI32_STATUS_REG_HF5)
0315 break;
0316 }
0317
0318 if (i == 200) {
0319 dev_err(chip->card->dev, "Resident loader failed to set HF5\n");
0320 goto irl_error;
0321 }
0322
0323 dev_dbg(chip->card->dev, "Resident loader successfully installed\n");
0324 free_firmware(fw, chip);
0325 return 0;
0326
0327 irl_error:
0328 free_firmware(fw, chip);
0329 return -EIO;
0330 }
0331
0332 #endif
0333
0334
0335 static int load_dsp(struct echoaudio *chip, u16 *code)
0336 {
0337 u32 address, data;
0338 int index, words, i;
0339
0340 if (chip->dsp_code == code) {
0341 dev_warn(chip->card->dev, "DSP is already loaded!\n");
0342 return 0;
0343 }
0344 chip->bad_board = true;
0345 chip->dsp_code = NULL;
0346 chip->asic_loaded = false;
0347
0348 dev_dbg(chip->card->dev, "load_dsp: Set bad_board to true\n");
0349
0350
0351 #ifdef DSP_56361
0352 i = install_resident_loader(chip);
0353 if (i < 0)
0354 return i;
0355 #endif
0356
0357
0358 if (send_vector(chip, DSP_VC_RESET) < 0) {
0359 dev_err(chip->card->dev,
0360 "LoadDsp: send_vector DSP_VC_RESET failed, Critical Failure\n");
0361 return -EIO;
0362 }
0363
0364 udelay(10);
0365
0366
0367 for (i = 0; i < 1000; i++) {
0368 if (get_dsp_register(chip, CHI32_STATUS_REG) &
0369 CHI32_STATUS_REG_HF3)
0370 break;
0371 udelay(10);
0372 }
0373
0374 if (i == 1000) {
0375 dev_err(chip->card->dev,
0376 "load_dsp: Timeout waiting for CHI32_STATUS_REG_HF3\n");
0377 return -EIO;
0378 }
0379
0380
0381 set_dsp_register(chip, CHI32_CONTROL_REG,
0382 get_dsp_register(chip, CHI32_CONTROL_REG) | 0x900);
0383
0384
0385
0386 index = code[0];
0387 for (;;) {
0388 int block_type, mem_type;
0389
0390
0391 index++;
0392
0393
0394 block_type = code[index];
0395 if (block_type == 4)
0396 break;
0397
0398 index++;
0399
0400
0401 mem_type = code[index++];
0402
0403
0404 words = code[index++];
0405 if (words == 0)
0406 break;
0407
0408
0409 address = ((u32)code[index] << 16) + code[index + 1];
0410 index += 2;
0411
0412 if (write_dsp(chip, words) < 0) {
0413 dev_err(chip->card->dev,
0414 "load_dsp: failed to write number of DSP words\n");
0415 return -EIO;
0416 }
0417 if (write_dsp(chip, address) < 0) {
0418 dev_err(chip->card->dev,
0419 "load_dsp: failed to write DSP address\n");
0420 return -EIO;
0421 }
0422 if (write_dsp(chip, mem_type) < 0) {
0423 dev_err(chip->card->dev,
0424 "load_dsp: failed to write DSP memory type\n");
0425 return -EIO;
0426 }
0427
0428 for (i = 0; i < words; i++, index+=2) {
0429 data = ((u32)code[index] << 16) + code[index + 1];
0430 if (write_dsp(chip, data) < 0) {
0431 dev_err(chip->card->dev,
0432 "load_dsp: failed to write DSP data\n");
0433 return -EIO;
0434 }
0435 }
0436 }
0437
0438 if (write_dsp(chip, 0) < 0) {
0439 dev_err(chip->card->dev,
0440 "load_dsp: Failed to write final zero\n");
0441 return -EIO;
0442 }
0443 udelay(10);
0444
0445 for (i = 0; i < 5000; i++) {
0446
0447 if (get_dsp_register(chip, CHI32_STATUS_REG) &
0448 CHI32_STATUS_REG_HF4) {
0449 set_dsp_register(chip, CHI32_CONTROL_REG,
0450 get_dsp_register(chip, CHI32_CONTROL_REG) & ~0x1b00);
0451
0452 if (write_dsp(chip, DSP_FNC_SET_COMMPAGE_ADDR) < 0) {
0453 dev_err(chip->card->dev,
0454 "load_dsp: Failed to write DSP_FNC_SET_COMMPAGE_ADDR\n");
0455 return -EIO;
0456 }
0457
0458 if (write_dsp(chip, chip->comm_page_phys) < 0) {
0459 dev_err(chip->card->dev,
0460 "load_dsp: Failed to write comm page address\n");
0461 return -EIO;
0462 }
0463
0464
0465
0466
0467
0468 if (read_sn(chip) < 0) {
0469 dev_err(chip->card->dev,
0470 "load_dsp: Failed to read serial number\n");
0471 return -EIO;
0472 }
0473
0474 chip->dsp_code = code;
0475 chip->bad_board = false;
0476 return 0;
0477 }
0478 udelay(100);
0479 }
0480
0481 dev_err(chip->card->dev,
0482 "load_dsp: DSP load timed out waiting for HF4\n");
0483 return -EIO;
0484 }
0485
0486
0487
0488
0489 static int load_firmware(struct echoaudio *chip)
0490 {
0491 const struct firmware *fw;
0492 int box_type, err;
0493
0494 if (snd_BUG_ON(!chip->comm_page))
0495 return -EPERM;
0496
0497
0498 if (chip->dsp_code) {
0499 box_type = check_asic_status(chip);
0500 if (box_type >= 0)
0501 return box_type;
0502
0503 chip->dsp_code = NULL;
0504 }
0505
0506 err = get_firmware(&fw, chip, chip->dsp_code_to_load);
0507 if (err < 0)
0508 return err;
0509 err = load_dsp(chip, (u16 *)fw->data);
0510 free_firmware(fw, chip);
0511 if (err < 0)
0512 return err;
0513
0514 box_type = load_asic(chip);
0515 if (box_type < 0)
0516 return box_type;
0517
0518 return box_type;
0519 }
0520
0521
0522
0523
0524
0525
0526
0527 #if defined(ECHOCARD_HAS_INPUT_NOMINAL_LEVEL) || \
0528 defined(ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL)
0529
0530
0531 static int set_nominal_level(struct echoaudio *chip, u16 index, char consumer)
0532 {
0533 if (snd_BUG_ON(index >= num_busses_out(chip) + num_busses_in(chip)))
0534 return -EINVAL;
0535
0536
0537 if (wait_handshake(chip))
0538 return -EIO;
0539
0540 chip->nominal_level[index] = consumer;
0541
0542 if (consumer)
0543 chip->comm_page->nominal_level_mask |= cpu_to_le32(1 << index);
0544 else
0545 chip->comm_page->nominal_level_mask &= ~cpu_to_le32(1 << index);
0546
0547 return 0;
0548 }
0549
0550 #endif
0551
0552
0553
0554
0555 static int set_output_gain(struct echoaudio *chip, u16 channel, s8 gain)
0556 {
0557 if (snd_BUG_ON(channel >= num_busses_out(chip)))
0558 return -EINVAL;
0559
0560 if (wait_handshake(chip))
0561 return -EIO;
0562
0563
0564 chip->output_gain[channel] = gain;
0565 chip->comm_page->line_out_level[channel] = gain;
0566 return 0;
0567 }
0568
0569
0570
0571 #ifdef ECHOCARD_HAS_MONITOR
0572
0573 static int set_monitor_gain(struct echoaudio *chip, u16 output, u16 input,
0574 s8 gain)
0575 {
0576 if (snd_BUG_ON(output >= num_busses_out(chip) ||
0577 input >= num_busses_in(chip)))
0578 return -EINVAL;
0579
0580 if (wait_handshake(chip))
0581 return -EIO;
0582
0583 chip->monitor_gain[output][input] = gain;
0584 chip->comm_page->monitors[monitor_index(chip, output, input)] = gain;
0585 return 0;
0586 }
0587 #endif
0588
0589
0590
0591 static int update_output_line_level(struct echoaudio *chip)
0592 {
0593 if (wait_handshake(chip))
0594 return -EIO;
0595 clear_handshake(chip);
0596 return send_vector(chip, DSP_VC_UPDATE_OUTVOL);
0597 }
0598
0599
0600
0601
0602 static int update_input_line_level(struct echoaudio *chip)
0603 {
0604 if (wait_handshake(chip))
0605 return -EIO;
0606 clear_handshake(chip);
0607 return send_vector(chip, DSP_VC_UPDATE_INGAIN);
0608 }
0609
0610
0611
0612
0613
0614 static void set_meters_on(struct echoaudio *chip, char on)
0615 {
0616 if (on && !chip->meters_enabled) {
0617 send_vector(chip, DSP_VC_METERS_ON);
0618 chip->meters_enabled = 1;
0619 } else if (!on && chip->meters_enabled) {
0620 send_vector(chip, DSP_VC_METERS_OFF);
0621 chip->meters_enabled = 0;
0622 memset((s8 *)chip->comm_page->vu_meter, ECHOGAIN_MUTED,
0623 DSP_MAXPIPES);
0624 memset((s8 *)chip->comm_page->peak_meter, ECHOGAIN_MUTED,
0625 DSP_MAXPIPES);
0626 }
0627 }
0628
0629
0630
0631
0632
0633
0634
0635
0636
0637
0638
0639 static void get_audio_meters(struct echoaudio *chip, long *meters)
0640 {
0641 unsigned int i, m, n;
0642
0643 for (i = 0 ; i < 96; i++)
0644 meters[i] = 0;
0645
0646 for (m = 0, n = 0, i = 0; i < num_busses_out(chip); i++, m++) {
0647 meters[n++] = chip->comm_page->vu_meter[m];
0648 meters[n++] = chip->comm_page->peak_meter[m];
0649 }
0650
0651 #ifdef ECHOCARD_ECHO3G
0652 m = E3G_MAX_OUTPUTS;
0653 #endif
0654
0655 for (n = 32, i = 0; i < num_busses_in(chip); i++, m++) {
0656 meters[n++] = chip->comm_page->vu_meter[m];
0657 meters[n++] = chip->comm_page->peak_meter[m];
0658 }
0659 #ifdef ECHOCARD_HAS_VMIXER
0660 for (n = 64, i = 0; i < num_pipes_out(chip); i++, m++) {
0661 meters[n++] = chip->comm_page->vu_meter[m];
0662 meters[n++] = chip->comm_page->peak_meter[m];
0663 }
0664 #endif
0665 }
0666
0667
0668
0669 static int restore_dsp_rettings(struct echoaudio *chip)
0670 {
0671 int i, o, err;
0672
0673 err = check_asic_status(chip);
0674 if (err < 0)
0675 return err;
0676
0677
0678 chip->comm_page->gd_clock_state = GD_CLOCK_UNDEF;
0679 chip->comm_page->gd_spdif_status = GD_SPDIF_STATUS_UNDEF;
0680 chip->comm_page->handshake = cpu_to_le32(0xffffffff);
0681
0682
0683 for (i = 0; i < num_busses_out(chip); i++) {
0684 err = set_output_gain(chip, i, chip->output_gain[i]);
0685 if (err < 0)
0686 return err;
0687 }
0688
0689 #ifdef ECHOCARD_HAS_VMIXER
0690 for (i = 0; i < num_pipes_out(chip); i++)
0691 for (o = 0; o < num_busses_out(chip); o++) {
0692 err = set_vmixer_gain(chip, o, i,
0693 chip->vmixer_gain[o][i]);
0694 if (err < 0)
0695 return err;
0696 }
0697 if (update_vmixer_level(chip) < 0)
0698 return -EIO;
0699 #endif
0700
0701 #ifdef ECHOCARD_HAS_MONITOR
0702 for (o = 0; o < num_busses_out(chip); o++)
0703 for (i = 0; i < num_busses_in(chip); i++) {
0704 err = set_monitor_gain(chip, o, i,
0705 chip->monitor_gain[o][i]);
0706 if (err < 0)
0707 return err;
0708 }
0709 #endif
0710
0711 #ifdef ECHOCARD_HAS_INPUT_GAIN
0712 for (i = 0; i < num_busses_in(chip); i++) {
0713 err = set_input_gain(chip, i, chip->input_gain[i]);
0714 if (err < 0)
0715 return err;
0716 }
0717 #endif
0718
0719 err = update_output_line_level(chip);
0720 if (err < 0)
0721 return err;
0722
0723 err = update_input_line_level(chip);
0724 if (err < 0)
0725 return err;
0726
0727 err = set_sample_rate(chip, chip->sample_rate);
0728 if (err < 0)
0729 return err;
0730
0731 if (chip->meters_enabled) {
0732 err = send_vector(chip, DSP_VC_METERS_ON);
0733 if (err < 0)
0734 return err;
0735 }
0736
0737 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
0738 if (set_digital_mode(chip, chip->digital_mode) < 0)
0739 return -EIO;
0740 #endif
0741
0742 #ifdef ECHOCARD_HAS_DIGITAL_IO
0743 if (set_professional_spdif(chip, chip->professional_spdif) < 0)
0744 return -EIO;
0745 #endif
0746
0747 #ifdef ECHOCARD_HAS_PHANTOM_POWER
0748 if (set_phantom_power(chip, chip->phantom_power) < 0)
0749 return -EIO;
0750 #endif
0751
0752 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
0753
0754 if (set_input_clock(chip, chip->input_clock) < 0)
0755 return -EIO;
0756 #endif
0757
0758 #ifdef ECHOCARD_HAS_OUTPUT_CLOCK_SWITCH
0759 if (set_output_clock(chip, chip->output_clock) < 0)
0760 return -EIO;
0761 #endif
0762
0763 if (wait_handshake(chip) < 0)
0764 return -EIO;
0765 clear_handshake(chip);
0766 if (send_vector(chip, DSP_VC_UPDATE_FLAGS) < 0)
0767 return -EIO;
0768
0769 return 0;
0770 }
0771
0772
0773
0774
0775
0776
0777
0778
0779
0780
0781 static void set_audio_format(struct echoaudio *chip, u16 pipe_index,
0782 const struct audioformat *format)
0783 {
0784 u16 dsp_format;
0785
0786 dsp_format = DSP_AUDIOFORM_SS_16LE;
0787
0788
0789 if (format->interleave > 2) {
0790 switch (format->bits_per_sample) {
0791 case 16:
0792 dsp_format = DSP_AUDIOFORM_SUPER_INTERLEAVE_16LE;
0793 break;
0794 case 24:
0795 dsp_format = DSP_AUDIOFORM_SUPER_INTERLEAVE_24LE;
0796 break;
0797 case 32:
0798 dsp_format = DSP_AUDIOFORM_SUPER_INTERLEAVE_32LE;
0799 break;
0800 }
0801 dsp_format |= format->interleave;
0802 } else if (format->data_are_bigendian) {
0803
0804 switch (format->interleave) {
0805 case 1:
0806 dsp_format = DSP_AUDIOFORM_MM_32BE;
0807 break;
0808 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
0809 case 2:
0810 dsp_format = DSP_AUDIOFORM_SS_32BE;
0811 break;
0812 #endif
0813 }
0814 } else if (format->interleave == 1 &&
0815 format->bits_per_sample == 32 && !format->mono_to_stereo) {
0816
0817 dsp_format = DSP_AUDIOFORM_MM_32LE;
0818 } else {
0819
0820 switch (format->bits_per_sample) {
0821 case 8:
0822 if (format->interleave == 2)
0823 dsp_format = DSP_AUDIOFORM_SS_8;
0824 else
0825 dsp_format = DSP_AUDIOFORM_MS_8;
0826 break;
0827 default:
0828 case 16:
0829 if (format->interleave == 2)
0830 dsp_format = DSP_AUDIOFORM_SS_16LE;
0831 else
0832 dsp_format = DSP_AUDIOFORM_MS_16LE;
0833 break;
0834 case 24:
0835 if (format->interleave == 2)
0836 dsp_format = DSP_AUDIOFORM_SS_24LE;
0837 else
0838 dsp_format = DSP_AUDIOFORM_MS_24LE;
0839 break;
0840 case 32:
0841 if (format->interleave == 2)
0842 dsp_format = DSP_AUDIOFORM_SS_32LE;
0843 else
0844 dsp_format = DSP_AUDIOFORM_MS_32LE;
0845 break;
0846 }
0847 }
0848 dev_dbg(chip->card->dev,
0849 "set_audio_format[%d] = %x\n", pipe_index, dsp_format);
0850 chip->comm_page->audio_format[pipe_index] = cpu_to_le16(dsp_format);
0851 }
0852
0853
0854
0855
0856
0857
0858
0859 static int start_transport(struct echoaudio *chip, u32 channel_mask,
0860 u32 cyclic_mask)
0861 {
0862
0863 if (wait_handshake(chip))
0864 return -EIO;
0865
0866 chip->comm_page->cmd_start |= cpu_to_le32(channel_mask);
0867
0868 if (chip->comm_page->cmd_start) {
0869 clear_handshake(chip);
0870 send_vector(chip, DSP_VC_START_TRANSFER);
0871 if (wait_handshake(chip))
0872 return -EIO;
0873
0874 chip->active_mask |= channel_mask;
0875 chip->comm_page->cmd_start = 0;
0876 return 0;
0877 }
0878
0879 dev_err(chip->card->dev, "start_transport: No pipes to start!\n");
0880 return -EINVAL;
0881 }
0882
0883
0884
0885 static int pause_transport(struct echoaudio *chip, u32 channel_mask)
0886 {
0887
0888 if (wait_handshake(chip))
0889 return -EIO;
0890
0891 chip->comm_page->cmd_stop |= cpu_to_le32(channel_mask);
0892 chip->comm_page->cmd_reset = 0;
0893 if (chip->comm_page->cmd_stop) {
0894 clear_handshake(chip);
0895 send_vector(chip, DSP_VC_STOP_TRANSFER);
0896 if (wait_handshake(chip))
0897 return -EIO;
0898
0899 chip->active_mask &= ~channel_mask;
0900 chip->comm_page->cmd_stop = 0;
0901 chip->comm_page->cmd_reset = 0;
0902 return 0;
0903 }
0904
0905 dev_dbg(chip->card->dev, "pause_transport: No pipes to stop!\n");
0906 return 0;
0907 }
0908
0909
0910
0911 static int stop_transport(struct echoaudio *chip, u32 channel_mask)
0912 {
0913
0914 if (wait_handshake(chip))
0915 return -EIO;
0916
0917 chip->comm_page->cmd_stop |= cpu_to_le32(channel_mask);
0918 chip->comm_page->cmd_reset |= cpu_to_le32(channel_mask);
0919 if (chip->comm_page->cmd_reset) {
0920 clear_handshake(chip);
0921 send_vector(chip, DSP_VC_STOP_TRANSFER);
0922 if (wait_handshake(chip))
0923 return -EIO;
0924
0925 chip->active_mask &= ~channel_mask;
0926 chip->comm_page->cmd_stop = 0;
0927 chip->comm_page->cmd_reset = 0;
0928 return 0;
0929 }
0930
0931 dev_dbg(chip->card->dev, "stop_transport: No pipes to stop!\n");
0932 return 0;
0933 }
0934
0935
0936
0937 static inline int is_pipe_allocated(struct echoaudio *chip, u16 pipe_index)
0938 {
0939 return (chip->pipe_alloc_mask & (1 << pipe_index));
0940 }
0941
0942
0943
0944
0945
0946 static int rest_in_peace(struct echoaudio *chip)
0947 {
0948
0949
0950 stop_transport(chip, chip->active_mask);
0951
0952 set_meters_on(chip, false);
0953
0954 #ifdef ECHOCARD_HAS_MIDI
0955 enable_midi_input(chip, false);
0956 #endif
0957
0958
0959 if (chip->dsp_code) {
0960
0961 chip->dsp_code = NULL;
0962
0963 return send_vector(chip, DSP_VC_GO_COMATOSE);
0964 }
0965 return 0;
0966 }
0967
0968
0969
0970
0971 static int init_dsp_comm_page(struct echoaudio *chip)
0972 {
0973
0974 if (offsetof(struct comm_page, midi_output) != 0xbe0) {
0975 dev_err(chip->card->dev,
0976 "init_dsp_comm_page() - Invalid struct comm_page structure\n");
0977 return -EPERM;
0978 }
0979
0980
0981 chip->card_name = ECHOCARD_NAME;
0982 chip->bad_board = true;
0983 chip->dsp_code = NULL;
0984 chip->asic_loaded = false;
0985 memset(chip->comm_page, 0, sizeof(struct comm_page));
0986
0987
0988 chip->comm_page->comm_size =
0989 cpu_to_le32(sizeof(struct comm_page));
0990 chip->comm_page->handshake = cpu_to_le32(0xffffffff);
0991 chip->comm_page->midi_out_free_count =
0992 cpu_to_le32(DSP_MIDI_OUT_FIFO_SIZE);
0993 chip->comm_page->sample_rate = cpu_to_le32(44100);
0994
0995
0996 memset(chip->comm_page->monitors, ECHOGAIN_MUTED, MONITOR_ARRAY_SIZE);
0997 memset(chip->comm_page->vmixer, ECHOGAIN_MUTED, VMIXER_ARRAY_SIZE);
0998
0999 return 0;
1000 }
1001
1002
1003
1004
1005
1006
1007
1008 static int init_line_levels(struct echoaudio *chip)
1009 {
1010 memset(chip->output_gain, ECHOGAIN_MUTED, sizeof(chip->output_gain));
1011 memset(chip->input_gain, ECHOGAIN_MUTED, sizeof(chip->input_gain));
1012 memset(chip->monitor_gain, ECHOGAIN_MUTED, sizeof(chip->monitor_gain));
1013 memset(chip->vmixer_gain, ECHOGAIN_MUTED, sizeof(chip->vmixer_gain));
1014 chip->input_clock = ECHO_CLOCK_INTERNAL;
1015 chip->output_clock = ECHO_CLOCK_WORD;
1016 chip->sample_rate = 44100;
1017 return restore_dsp_rettings(chip);
1018 }
1019
1020
1021
1022
1023
1024
1025 static int service_irq(struct echoaudio *chip)
1026 {
1027 int st;
1028
1029
1030 if (get_dsp_register(chip, CHI32_STATUS_REG) & CHI32_STATUS_IRQ) {
1031 st = 0;
1032 #ifdef ECHOCARD_HAS_MIDI
1033
1034 if (chip->comm_page->midi_input[0])
1035 st = midi_service_irq(chip);
1036 #endif
1037
1038 chip->comm_page->midi_input[0] = 0;
1039 send_vector(chip, DSP_VC_ACK_INT);
1040 return st;
1041 }
1042 return -1;
1043 }
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054 static int allocate_pipes(struct echoaudio *chip, struct audiopipe *pipe,
1055 int pipe_index, int interleave)
1056 {
1057 int i;
1058 u32 channel_mask;
1059
1060 dev_dbg(chip->card->dev,
1061 "allocate_pipes: ch=%d int=%d\n", pipe_index, interleave);
1062
1063 if (chip->bad_board)
1064 return -EIO;
1065
1066 for (channel_mask = i = 0; i < interleave; i++)
1067 channel_mask |= 1 << (pipe_index + i);
1068 if (chip->pipe_alloc_mask & channel_mask) {
1069 dev_err(chip->card->dev,
1070 "allocate_pipes: channel already open\n");
1071 return -EAGAIN;
1072 }
1073
1074 chip->comm_page->position[pipe_index] = 0;
1075 chip->pipe_alloc_mask |= channel_mask;
1076
1077 chip->pipe_cyclic_mask |= channel_mask;
1078 pipe->index = pipe_index;
1079 pipe->interleave = interleave;
1080 pipe->state = PIPE_STATE_STOPPED;
1081
1082
1083
1084
1085 pipe->dma_counter = (__le32 *)&chip->comm_page->position[pipe_index];
1086 *pipe->dma_counter = 0;
1087 return pipe_index;
1088 }
1089
1090
1091
1092 static int free_pipes(struct echoaudio *chip, struct audiopipe *pipe)
1093 {
1094 u32 channel_mask;
1095 int i;
1096
1097 if (snd_BUG_ON(!is_pipe_allocated(chip, pipe->index)))
1098 return -EINVAL;
1099 if (snd_BUG_ON(pipe->state != PIPE_STATE_STOPPED))
1100 return -EINVAL;
1101
1102 for (channel_mask = i = 0; i < pipe->interleave; i++)
1103 channel_mask |= 1 << (pipe->index + i);
1104
1105 chip->pipe_alloc_mask &= ~channel_mask;
1106 chip->pipe_cyclic_mask &= ~channel_mask;
1107 return 0;
1108 }
1109
1110
1111
1112
1113
1114
1115
1116 static int sglist_init(struct echoaudio *chip, struct audiopipe *pipe)
1117 {
1118 pipe->sglist_head = 0;
1119 memset(pipe->sgpage.area, 0, PAGE_SIZE);
1120 chip->comm_page->sglist_addr[pipe->index].addr =
1121 cpu_to_le32(pipe->sgpage.addr);
1122 return 0;
1123 }
1124
1125
1126
1127 static int sglist_add_mapping(struct echoaudio *chip, struct audiopipe *pipe,
1128 dma_addr_t address, size_t length)
1129 {
1130 int head = pipe->sglist_head;
1131 struct sg_entry *list = (struct sg_entry *)pipe->sgpage.area;
1132
1133 if (head < MAX_SGLIST_ENTRIES - 1) {
1134 list[head].addr = cpu_to_le32(address);
1135 list[head].size = cpu_to_le32(length);
1136 pipe->sglist_head++;
1137 } else {
1138 dev_err(chip->card->dev, "SGlist: too many fragments\n");
1139 return -ENOMEM;
1140 }
1141 return 0;
1142 }
1143
1144
1145
1146 static inline int sglist_add_irq(struct echoaudio *chip, struct audiopipe *pipe)
1147 {
1148 return sglist_add_mapping(chip, pipe, 0, 0);
1149 }
1150
1151
1152
1153 static inline int sglist_wrap(struct echoaudio *chip, struct audiopipe *pipe)
1154 {
1155 return sglist_add_mapping(chip, pipe, pipe->sgpage.addr, 0);
1156 }