Lines Matching +full:ec +full:- +full:codec

1 // SPDX-License-Identifier: GPL-2.0-or-later
11 * ---
23 #include <linux/dma-mapping.h>
57 dev_dbg(trident->card->dev, "Trident voice %i:\n", voice);
60 dev_dbg(trident->card->dev, "LBA: 0x%x\n", val);
62 dev_dbg(trident->card->dev, "GVSel: %i\n", val >> 31);
63 dev_dbg(trident->card->dev, "Pan: 0x%x\n", (val >> 24) & 0x7f);
64 dev_dbg(trident->card->dev, "Vol: 0x%x\n", (val >> 16) & 0xff);
65 dev_dbg(trident->card->dev, "CTRL: 0x%x\n", (val >> 12) & 0x0f);
66 dev_dbg(trident->card->dev, "EC: 0x%x\n", val & 0x0fff);
67 if (trident->device != TRIDENT_DEVICE_ID_NX) {
69 dev_dbg(trident->card->dev, "CSO: 0x%x\n", val >> 16);
70 dev_dbg(trident->card->dev, "Alpha: 0x%x\n", (val >> 4) & 0x0fff);
71 dev_dbg(trident->card->dev, "FMS: 0x%x\n", val & 0x0f);
73 dev_dbg(trident->card->dev, "ESO: 0x%x\n", val >> 16);
74 dev_dbg(trident->card->dev, "Delta: 0x%x\n", val & 0xffff);
79 dev_dbg(trident->card->dev, "CSO: 0x%x\n", val & 0x00ffffff);
82 dev_dbg(trident->card->dev, "Delta: 0x%x\n", tmp);
83 dev_dbg(trident->card->dev, "ESO: 0x%x\n", val & 0x00ffffff);
85 dev_dbg(trident->card->dev, "Alpha: 0x%x\n", val >> 20);
86 dev_dbg(trident->card->dev, "FMS: 0x%x\n", (val >> 16) & 0x0f);
88 dev_dbg(trident->card->dev, "FMC: 0x%x\n", (val >> 14) & 3);
89 dev_dbg(trident->card->dev, "RVol: 0x%x\n", (val >> 7) & 0x7f);
90 dev_dbg(trident->card->dev, "CVol: 0x%x\n", val & 0x7f);
94 /*---------------------------------------------------------------------------
98 CODEC (AC97).
100 Parameters: ac97 - ac97 codec structure
101 reg - CODEC register index, from AC97 Hal.
105 ---------------------------------------------------------------------------*/
110 struct snd_trident *trident = ac97->private_data;
112 guard(spinlock_irqsave)(&trident->reg_lock);
113 if (trident->device == TRIDENT_DEVICE_ID_DX) {
120 } while (--count);
121 } else if (trident->device == TRIDENT_DEVICE_ID_NX) {
123 treg = ac97->num == 0 ? NX_ACR2_AC97_R_PRIMARY : NX_ACR3_AC97_R_SECONDARY;
129 } while (--count);
130 } else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
132 if (ac97->num == 1)
139 } while (--count);
142 if (count == 0 && !trident->ac97_detect) {
143 dev_err(trident->card->dev,
144 "ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n",
152 /*---------------------------------------------------------------------------
157 CODEC (AC97).
159 Parameters: ac97 - ac97 codec structure
160 reg - CODEC register index, from AC97 Hal.
161 data - Lower 16 bits are the data to write to CODEC.
165 ---------------------------------------------------------------------------*/
171 struct snd_trident *trident = ac97->private_data;
175 guard(spinlock_irqsave)(&trident->reg_lock);
176 if (trident->device == TRIDENT_DEVICE_ID_DX) {
179 /* read AC-97 write register status */
183 } while (--count);
186 } else if (trident->device == TRIDENT_DEVICE_ID_NX) {
189 /* read AC-97 write register status */
193 } while (--count);
195 data |= (NX_AC97_BUSY_WRITE | (ac97->num << 8) | (reg & 0x000000ff));
196 } else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
199 /* read AC-97 write register status */
203 } while (--count);
206 if (ac97->num == 1)
218 /*---------------------------------------------------------------------------
226 Parameters: trident - pointer to target device class for 4DWave.
228 ---------------------------------------------------------------------------*/
237 if (trident->device == TRIDENT_DEVICE_ID_SI7018)
242 /*---------------------------------------------------------------------------
251 trident - pointer to target device class for 4DWave.
255 ---------------------------------------------------------------------------*/
267 /*---------------------------------------------------------------------------
274 Parameters : voice - Voice number 0 thru n.
275 trident - pointer to target device class for 4DWave.
279 ---------------------------------------------------------------------------*/
291 /*---------------------------------------------------------------------------
298 Parameters : voice - Voice number 0 thru n.
299 trident - pointer to target device class for 4DWave.
303 ---------------------------------------------------------------------------*/
315 /*---------------------------------------------------------------------------
318 Description: Allocate hardware channel in Bank B (32-63).
320 Parameters : trident - pointer to target device class for 4DWave.
322 Return Value: hardware channel - 32-63 or -1 when no channel is available
324 ---------------------------------------------------------------------------*/
330 if (trident->ChanPCMcnt >= trident->ChanPCM)
331 return -1;
332 for (idx = 31; idx >= 0; idx--) {
333 if (!(trident->ChanMap[T4D_BANK_B] & (1 << idx))) {
334 trident->ChanMap[T4D_BANK_B] |= 1 << idx;
335 trident->ChanPCMcnt++;
339 return -1;
342 /*---------------------------------------------------------------------------
345 Description: Free hardware channel in Bank B (32-63)
347 Parameters : trident - pointer to target device class for 4DWave.
348 channel - hardware channel number 0-63
352 ---------------------------------------------------------------------------*/
359 if (trident->ChanMap[T4D_BANK_B] & (1 << channel)) {
360 trident->ChanMap[T4D_BANK_B] &= ~(1 << channel);
361 trident->ChanPCMcnt--;
365 /*---------------------------------------------------------------------------
368 Description: Allocate hardware channel in Bank A (0-31).
370 Parameters : trident - pointer to target device class for 4DWave.
372 Return Value: hardware channel - 0-31 or -1 when no channel is available
374 ---------------------------------------------------------------------------*/
380 for (idx = 31; idx >= 0; idx--) {
381 if (!(trident->ChanMap[T4D_BANK_A] & (1 << idx))) {
382 trident->ChanMap[T4D_BANK_A] |= 1 << idx;
383 trident->synth.ChanSynthCount++;
387 return -1;
390 /*---------------------------------------------------------------------------
393 Description: Free hardware channel in Bank B (0-31).
395 Parameters : trident - pointer to target device class for 4DWave.
396 channel - hardware channel number 0-63
400 ---------------------------------------------------------------------------*/
407 if (trident->ChanMap[T4D_BANK_A] & (1 << channel)) {
408 trident->ChanMap[T4D_BANK_A] &= ~(1 << channel);
409 trident->synth.ChanSynthCount--;
413 /*---------------------------------------------------------------------------
419 Parameters: trident - pointer to target device class for 4DWave.
420 voice - synthesizer voice structure
423 ---------------------------------------------------------------------------*/
431 regs[1] = voice->LBA;
432 regs[4] = (voice->GVSel << 31) |
433 ((voice->Pan & 0x0000007f) << 24) |
434 ((voice->CTRL & 0x0000000f) << 12);
435 FmcRvolCvol = ((voice->FMC & 3) << 14) |
436 ((voice->RVol & 0x7f) << 7) |
437 (voice->CVol & 0x7f);
439 switch (trident->device) {
441 regs[4] |= voice->number > 31 ?
442 (voice->Vol & 0x000003ff) :
443 ((voice->Vol & 0x00003fc) << (16-2)) |
444 (voice->EC & 0x00000fff);
445 regs[0] = (voice->CSO << 16) | ((voice->Alpha & 0x00000fff) << 4) |
446 (voice->FMS & 0x0000000f);
447 regs[2] = (voice->ESO << 16) | (voice->Delta & 0x0ffff);
448 regs[3] = (voice->Attribute << 16) | FmcRvolCvol;
451 regs[4] |= ((voice->Vol & 0x000003fc) << (16-2)) |
452 (voice->EC & 0x00000fff);
453 regs[0] = (voice->CSO << 16) | ((voice->Alpha & 0x00000fff) << 4) |
454 (voice->FMS & 0x0000000f);
455 regs[2] = (voice->ESO << 16) | (voice->Delta & 0x0ffff);
459 regs[4] |= ((voice->Vol & 0x000003fc) << (16-2)) |
460 (voice->EC & 0x00000fff);
461 regs[0] = (voice->Delta << 24) | (voice->CSO & 0x00ffffff);
462 regs[2] = ((voice->Delta << 16) & 0xff000000) |
463 (voice->ESO & 0x00ffffff);
464 regs[3] = (voice->Alpha << 20) |
465 ((voice->FMS & 0x0000000f) << 16) | FmcRvolCvol;
472 outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
480 dev_dbg(trident->card->dev, "written %i channel:\n", voice->number);
481 dev_dbg(trident->card->dev, " regs[0] = 0x%x/0x%x\n",
483 dev_dbg(trident->card->dev, " regs[1] = 0x%x/0x%x\n",
485 dev_dbg(trident->card->dev, " regs[2] = 0x%x/0x%x\n",
487 dev_dbg(trident->card->dev, " regs[3] = 0x%x/0x%x\n",
489 dev_dbg(trident->card->dev, " regs[4] = 0x%x/0x%x\n",
496 /*---------------------------------------------------------------------------
502 Parameters: trident - pointer to target device class for 4DWave.
503 voice - synthesizer voice structure
504 CSO - new CSO value
506 ---------------------------------------------------------------------------*/
512 voice->CSO = CSO;
513 outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
514 if (trident->device != TRIDENT_DEVICE_ID_NX) {
515 outw(voice->CSO, TRID_REG(trident, CH_DX_CSO_ALPHA_FMS) + 2);
517 outl((voice->Delta << 24) |
518 (voice->CSO & 0x00ffffff), TRID_REG(trident, CH_NX_DELTA_CSO));
522 /*---------------------------------------------------------------------------
528 Parameters: trident - pointer to target device class for 4DWave.
529 voice - synthesizer voice structure
530 ESO - new ESO value
532 ---------------------------------------------------------------------------*/
538 voice->ESO = ESO;
539 outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
540 if (trident->device != TRIDENT_DEVICE_ID_NX) {
541 outw(voice->ESO, TRID_REG(trident, CH_DX_ESO_DELTA) + 2);
543 outl(((voice->Delta << 16) & 0xff000000) | (voice->ESO & 0x00ffffff),
548 /*---------------------------------------------------------------------------
554 Parameters: trident - pointer to target device class for 4DWave.
555 voice - synthesizer voice structure
556 Vol - new voice volume
558 ---------------------------------------------------------------------------*/
564 voice->Vol = Vol;
565 outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
566 switch (trident->device) {
569 outb(voice->Vol >> 2, TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC + 2));
572 /* dev_dbg(trident->card->dev, "voice->Vol = 0x%x\n", voice->Vol); */
573 outw((voice->CTRL << 12) | voice->Vol,
579 /*---------------------------------------------------------------------------
585 Parameters: trident - pointer to target device class for 4DWave.
586 voice - synthesizer voice structure
587 Pan - new pan value
589 ---------------------------------------------------------------------------*/
595 voice->Pan = Pan;
596 outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
597 outb(((voice->GVSel & 0x01) << 7) | (voice->Pan & 0x7f),
601 /*---------------------------------------------------------------------------
607 Parameters: trident - pointer to target device class for 4DWave.
608 voice - synthesizer voice structure
609 RVol - new reverb volume
611 ---------------------------------------------------------------------------*/
617 voice->RVol = RVol;
618 outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
619 outw(((voice->FMC & 0x0003) << 14) | ((voice->RVol & 0x007f) << 7) |
620 (voice->CVol & 0x007f),
621 TRID_REG(trident, trident->device == TRIDENT_DEVICE_ID_NX ?
625 /*---------------------------------------------------------------------------
631 Parameters: trident - pointer to target device class for 4DWave.
632 voice - synthesizer voice structure
633 CVol - new chorus volume
635 ---------------------------------------------------------------------------*/
641 voice->CVol = CVol;
642 outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
643 outw(((voice->FMC & 0x0003) << 14) | ((voice->RVol & 0x007f) << 7) |
644 (voice->CVol & 0x007f),
645 TRID_REG(trident, trident->device == TRIDENT_DEVICE_ID_NX ?
649 /*---------------------------------------------------------------------------
654 Parameters: trident - pointer to target device class for 4DWave.
655 rate - Real or Virtual channel number.
659 ---------------------------------------------------------------------------*/
679 /*---------------------------------------------------------------------------
684 Parameters: trident - pointer to target device class for 4DWave.
685 rate - Real or Virtual channel number.
689 ---------------------------------------------------------------------------*/
709 /*---------------------------------------------------------------------------
714 Parameters: trident - pointer to target device class for 4DWave.
715 rate - Real or Virtual channel number.
719 ---------------------------------------------------------------------------*/
727 res -= 32;
731 /*---------------------------------------------------------------------------
736 Parameters: trident - pointer to target device class for 4DWave.
737 substream - PCM substream
741 ---------------------------------------------------------------------------*/
745 struct snd_pcm_runtime *runtime = substream->runtime;
748 CTRL default: 8-bit (unsigned) mono, loop mode enabled
751 if (snd_pcm_format_width(runtime->format) == 16)
752 CTRL |= 0x00000008; // 16-bit data
753 if (snd_pcm_format_signed(runtime->format))
755 if (runtime->channels > 1)
764 /*---------------------------------------------------------------------------
769 Parameters: substream - PCM substream class
770 hw_params - hardware parameters
774 ---------------------------------------------------------------------------*/
780 struct snd_pcm_runtime *runtime = substream->runtime;
781 struct snd_trident_voice *voice = runtime->private_data;
783 if (trident->tlb.entries) {
784 if (runtime->buffer_changed) {
785 if (voice->memblk)
786 snd_trident_free_pages(trident, voice->memblk);
787 voice->memblk = snd_trident_alloc_pages(trident, substream);
788 if (voice->memblk == NULL)
789 return -ENOMEM;
795 /*---------------------------------------------------------------------------
800 Parameters: substream - PCM substream class
801 hw_params - hardware parameters
805 ---------------------------------------------------------------------------*/
811 struct snd_pcm_runtime *runtime = substream->runtime;
812 struct snd_trident_voice *voice = runtime->private_data;
813 struct snd_trident_voice *evoice = voice->extra;
821 return -ENOMEM;
822 voice->extra = evoice;
823 evoice->substream = substream;
828 voice->extra = evoice = NULL;
835 /*---------------------------------------------------------------------------
840 Parameters: substream - PCM substream class
841 hw_params - hardware parameters
845 ---------------------------------------------------------------------------*/
858 /*---------------------------------------------------------------------------
863 Parameters: substream - PCM substream class
867 ---------------------------------------------------------------------------*/
872 struct snd_pcm_runtime *runtime = substream->runtime;
873 struct snd_trident_voice *voice = runtime->private_data;
874 struct snd_trident_voice *evoice = voice ? voice->extra : NULL;
876 if (trident->tlb.entries) {
877 if (voice && voice->memblk) {
878 snd_trident_free_pages(trident, voice->memblk);
879 voice->memblk = NULL;
884 voice->extra = NULL;
889 /*---------------------------------------------------------------------------
894 Parameters: substream - PCM substream class
898 ---------------------------------------------------------------------------*/
903 struct snd_pcm_runtime *runtime = substream->runtime;
904 struct snd_trident_voice *voice = runtime->private_data;
905 struct snd_trident_voice *evoice = voice->extra;
906 struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[substream->number];
908 guard(spinlock_irq)(&trident->reg_lock);
911 voice->Delta = snd_trident_convert_rate(runtime->rate);
912 voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size);
915 if (voice->memblk)
916 voice->LBA = voice->memblk->offset;
918 voice->LBA = runtime->dma_addr;
920 voice->CSO = 0;
921 voice->ESO = runtime->buffer_size - 1; /* in samples */
922 voice->CTRL = snd_trident_control_mode(substream);
923 voice->FMC = 3;
924 voice->GVSel = 1;
925 voice->EC = 0;
926 voice->Alpha = 0;
927 voice->FMS = 0;
928 voice->Vol = mix->vol;
929 voice->RVol = mix->rvol;
930 voice->CVol = mix->cvol;
931 voice->Pan = mix->pan;
932 voice->Attribute = 0;
934 voice->Attribute = (1<<(30-16))|(2<<(26-16))|
935 (0<<(24-16))|(0x1f<<(19-16));
937 voice->Attribute = 0;
943 evoice->Delta = voice->Delta;
944 evoice->spurious_threshold = voice->spurious_threshold;
945 evoice->LBA = voice->LBA;
946 evoice->CSO = 0;
947 evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */
948 evoice->CTRL = voice->CTRL;
949 evoice->FMC = 3;
950 evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1;
951 evoice->EC = 0;
952 evoice->Alpha = 0;
953 evoice->FMS = 0;
954 evoice->Vol = 0x3ff; /* mute */
955 evoice->RVol = evoice->CVol = 0x7f; /* mute */
956 evoice->Pan = 0x7f; /* mute */
958 evoice->Attribute = (1<<(30-16))|(2<<(26-16))|
959 (0<<(24-16))|(0x1f<<(19-16));
961 evoice->Attribute = 0;
964 evoice->isync2 = 1;
965 evoice->isync_mark = runtime->period_size;
966 evoice->ESO = (runtime->period_size * 2) - 1;
972 /*---------------------------------------------------------------------------
977 Parameters: substream - PCM substream class
978 hw_params - hardware parameters
982 ---------------------------------------------------------------------------*/
990 /*---------------------------------------------------------------------------
995 Parameters: substream - PCM substream class
999 ---------------------------------------------------------------------------*/
1004 struct snd_pcm_runtime *runtime = substream->runtime;
1005 struct snd_trident_voice *voice = runtime->private_data;
1008 guard(spinlock_irq)(&trident->reg_lock);
1017 voice->LBA = runtime->dma_addr;
1018 outl(voice->LBA, TRID_REG(trident, LEGACY_DMAR0));
1019 if (voice->memblk)
1020 voice->LBA = voice->memblk->offset;
1023 ESO_bytes = snd_pcm_lib_buffer_bytes(substream) - 1;
1029 val = DIV_ROUND_CLOSEST(48000U << 12, runtime->rate);
1033 if (snd_pcm_format_width(runtime->format) == 16) {
1034 val = (unsigned short) ((ESO_bytes >> 1) - 1);
1036 val = (unsigned short) (ESO_bytes - 1);
1043 trident->bDMAStart = 0x19; // 0001 1001b
1045 if (snd_pcm_format_width(runtime->format) == 16)
1046 trident->bDMAStart |= 0x80;
1047 if (snd_pcm_format_signed(runtime->format))
1048 trident->bDMAStart |= 0x20;
1049 if (runtime->channels > 1)
1050 trident->bDMAStart |= 0x40;
1054 voice->Delta = snd_trident_convert_rate(runtime->rate);
1055 voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size);
1056 voice->isync = 1;
1057 voice->isync_mark = runtime->period_size;
1058 voice->isync_max = runtime->buffer_size;
1061 voice->CSO = 0;
1062 voice->ESO = voice->isync_ESO = (runtime->period_size * 2) + 6 - 1;
1063 voice->CTRL = snd_trident_control_mode(substream);
1064 voice->FMC = 3;
1065 voice->RVol = 0x7f;
1066 voice->CVol = 0x7f;
1067 voice->GVSel = 1;
1068 voice->Pan = 0x7f; /* mute */
1069 voice->Vol = 0x3ff; /* mute */
1070 voice->EC = 0;
1071 voice->Alpha = 0;
1072 voice->FMS = 0;
1073 voice->Attribute = 0;
1080 /*---------------------------------------------------------------------------
1085 Parameters: substream - PCM substream class
1086 hw_params - hardware parameters
1090 ---------------------------------------------------------------------------*/
1098 /*---------------------------------------------------------------------------
1103 Parameters: substream - PCM substream class
1107 ---------------------------------------------------------------------------*/
1112 struct snd_pcm_runtime *runtime = substream->runtime;
1113 struct snd_trident_voice *voice = runtime->private_data;
1114 struct snd_trident_voice *evoice = voice ? voice->extra : NULL;
1118 voice->extra = NULL;
1123 /*---------------------------------------------------------------------------
1128 Parameters: substream - PCM substream class
1132 ---------------------------------------------------------------------------*/
1137 struct snd_pcm_runtime *runtime = substream->runtime;
1138 struct snd_trident_voice *voice = runtime->private_data;
1139 struct snd_trident_voice *evoice = voice->extra;
1141 guard(spinlock_irq)(&trident->reg_lock);
1143 voice->LBA = runtime->dma_addr;
1144 voice->Delta = snd_trident_convert_adc_rate(runtime->rate);
1145 voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size);
1148 voice->CSO = 0;
1149 voice->ESO = runtime->buffer_size - 1; /* in samples */
1150 voice->CTRL = snd_trident_control_mode(substream);
1151 voice->FMC = 0;
1152 voice->RVol = 0;
1153 voice->CVol = 0;
1154 voice->GVSel = 1;
1155 voice->Pan = T4D_DEFAULT_PCM_PAN;
1156 voice->Vol = 0;
1157 voice->EC = 0;
1158 voice->Alpha = 0;
1159 voice->FMS = 0;
1161 voice->Attribute = (2 << (30-16)) |
1162 (2 << (26-16)) |
1163 (2 << (24-16)) |
1164 (1 << (23-16));
1169 evoice->Delta = snd_trident_convert_rate(runtime->rate);
1170 evoice->spurious_threshold = voice->spurious_threshold;
1171 evoice->LBA = voice->LBA;
1172 evoice->CSO = 0;
1173 evoice->ESO = (runtime->period_size * 2) + 20 - 1; /* in samples, 20 means correction */
1174 evoice->CTRL = voice->CTRL;
1175 evoice->FMC = 3;
1176 evoice->GVSel = 0;
1177 evoice->EC = 0;
1178 evoice->Alpha = 0;
1179 evoice->FMS = 0;
1180 evoice->Vol = 0x3ff; /* mute */
1181 evoice->RVol = evoice->CVol = 0x7f; /* mute */
1182 evoice->Pan = 0x7f; /* mute */
1183 evoice->Attribute = 0;
1185 evoice->isync2 = 1;
1186 evoice->isync_mark = runtime->period_size;
1187 evoice->ESO = (runtime->period_size * 2) - 1;
1193 /*---------------------------------------------------------------------------
1198 Parameters: substream - PCM substream class
1202 ---------------------------------------------------------------------------*/
1207 struct snd_pcm_runtime *runtime = substream->runtime;
1208 struct snd_trident_voice *voice = runtime->private_data;
1209 struct snd_trident_voice *evoice = voice->extra;
1211 guard(spinlock_irq)(&trident->reg_lock);
1214 if (voice->memblk)
1215 voice->LBA = voice->memblk->offset;
1217 voice->LBA = runtime->dma_addr;
1220 voice->ESO = runtime->buffer_size - 1; /* in samples */
1223 voice->Delta = 0x1000;
1224 voice->spurious_threshold = snd_trident_spurious_threshold(48000, runtime->period_size);
1226 voice->CSO = 0;
1227 voice->CTRL = snd_trident_control_mode(substream);
1228 voice->FMC = 3;
1229 voice->RVol = 0x7f;
1230 voice->CVol = 0x7f;
1231 voice->GVSel = 1;
1232 voice->Pan = 0x7f; /* mute */
1233 voice->Vol = 0x3ff; /* mute */
1234 voice->EC = 0;
1235 voice->Alpha = 0;
1236 voice->FMS = 0;
1237 voice->Attribute = 0;
1240 outb(((voice->number & 0x3f) | 0x80), TRID_REG(trident, T4D_RCI + voice->foldback_chan));
1245 evoice->Delta = voice->Delta;
1246 evoice->spurious_threshold = voice->spurious_threshold;
1247 evoice->LBA = voice->LBA;
1248 evoice->CSO = 0;
1249 evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */
1250 evoice->CTRL = voice->CTRL;
1251 evoice->FMC = 3;
1252 evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1;
1253 evoice->EC = 0;
1254 evoice->Alpha = 0;
1255 evoice->FMS = 0;
1256 evoice->Vol = 0x3ff; /* mute */
1257 evoice->RVol = evoice->CVol = 0x7f; /* mute */
1258 evoice->Pan = 0x7f; /* mute */
1259 evoice->Attribute = 0;
1261 evoice->isync2 = 1;
1262 evoice->isync_mark = runtime->period_size;
1263 evoice->ESO = (runtime->period_size * 2) - 1;
1269 /*---------------------------------------------------------------------------
1274 Parameters: substream - PCM substream class
1275 hw_params - hardware parameters
1279 ---------------------------------------------------------------------------*/
1292 if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
1299 scoped_guard(spinlock_irq, &trident->reg_lock) {
1300 old_bits = trident->spdif_pcm_bits;
1302 trident->spdif_pcm_bits &= ~IEC958_AES0_PRO_FS;
1304 trident->spdif_pcm_bits &= ~(IEC958_AES3_CON_FS << 24);
1306 trident->spdif_pcm_ctrl = 0x3c; // 48000 Hz
1307 trident->spdif_pcm_bits |=
1308 trident->spdif_bits & IEC958_AES0_PROFESSIONAL ?
1312 trident->spdif_pcm_ctrl = 0x3e; // 44100 Hz
1313 trident->spdif_pcm_bits |=
1314 trident->spdif_bits & IEC958_AES0_PROFESSIONAL ?
1318 trident->spdif_pcm_ctrl = 0x3d; // 32000 Hz
1319 trident->spdif_pcm_bits |=
1320 trident->spdif_bits & IEC958_AES0_PROFESSIONAL ?
1324 change = old_bits != trident->spdif_pcm_bits;
1328 snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE, &trident->spdif_pcm_ctl->id);
1333 /*---------------------------------------------------------------------------
1338 Parameters: substream - PCM substream class
1342 ---------------------------------------------------------------------------*/
1347 struct snd_pcm_runtime *runtime = substream->runtime;
1348 struct snd_trident_voice *voice = runtime->private_data;
1349 struct snd_trident_voice *evoice = voice->extra;
1350 struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[substream->number];
1354 guard(spinlock_irq)(&trident->reg_lock);
1356 if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
1359 voice->Delta = snd_trident_convert_rate(runtime->rate);
1360 voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size);
1363 LBAO = runtime->dma_addr;
1364 if (voice->memblk)
1365 voice->LBA = voice->memblk->offset;
1367 voice->LBA = LBAO;
1369 voice->isync = 1;
1370 voice->isync3 = 1;
1371 voice->isync_mark = runtime->period_size;
1372 voice->isync_max = runtime->buffer_size;
1375 RESO = runtime->buffer_size - 1;
1376 voice->ESO = voice->isync_ESO = (runtime->period_size * 2) + 6 - 1;
1379 voice->CTRL = snd_trident_control_mode(substream);
1381 voice->FMC = 3;
1382 voice->RVol = 0x7f;
1383 voice->CVol = 0x7f;
1384 voice->GVSel = 1;
1385 voice->Pan = 0x7f;
1386 voice->Vol = 0x3ff;
1387 voice->EC = 0;
1388 voice->CSO = 0;
1389 voice->Alpha = 0;
1390 voice->FMS = 0;
1391 voice->Attribute = 0;
1399 outw((voice->CSO & 0xffff), TRID_REG(trident, NX_SPCTRL_SPCSO));
1400 outb((voice->CSO >> 16), TRID_REG(trident, NX_SPCTRL_SPCSO + 2));
1403 outb(trident->spdif_pcm_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
1404 outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
1409 voice->Delta = 0x800;
1410 voice->spurious_threshold = snd_trident_spurious_threshold(48000, runtime->period_size);
1413 if (voice->memblk)
1414 voice->LBA = voice->memblk->offset;
1416 voice->LBA = runtime->dma_addr;
1418 voice->CSO = 0;
1419 voice->ESO = runtime->buffer_size - 1; /* in samples */
1420 voice->CTRL = snd_trident_control_mode(substream);
1421 voice->FMC = 3;
1422 voice->GVSel = 1;
1423 voice->EC = 0;
1424 voice->Alpha = 0;
1425 voice->FMS = 0;
1426 voice->Vol = mix->vol;
1427 voice->RVol = mix->rvol;
1428 voice->CVol = mix->cvol;
1429 voice->Pan = mix->pan;
1430 voice->Attribute = (1<<(30-16))|(7<<(26-16))|
1431 (0<<(24-16))|(0<<(19-16));
1436 evoice->Delta = voice->Delta;
1437 evoice->spurious_threshold = voice->spurious_threshold;
1438 evoice->LBA = voice->LBA;
1439 evoice->CSO = 0;
1440 evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */
1441 evoice->CTRL = voice->CTRL;
1442 evoice->FMC = 3;
1443 evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1;
1444 evoice->EC = 0;
1445 evoice->Alpha = 0;
1446 evoice->FMS = 0;
1447 evoice->Vol = 0x3ff; /* mute */
1448 evoice->RVol = evoice->CVol = 0x7f; /* mute */
1449 evoice->Pan = 0x7f; /* mute */
1450 evoice->Attribute = 0;
1452 evoice->isync2 = 1;
1453 evoice->isync_mark = runtime->period_size;
1454 evoice->ESO = (runtime->period_size * 2) - 1;
1457 outl(trident->spdif_pcm_bits, TRID_REG(trident, SI_SPDIF_CS));
1469 /*---------------------------------------------------------------------------
1474 Parameters: substream - PCM substream class
1475 cmd - trigger command (STOP, GO)
1479 ---------------------------------------------------------------------------*/
1503 return -EINVAL;
1506 guard(spinlock)(&trident->reg_lock);
1510 voice = s->runtime->private_data;
1511 evoice = voice->extra;
1512 what |= 1 << (voice->number & 0x1f);
1514 whati |= 1 << (voice->number & 0x1f);
1516 what |= 1 << (evoice->number & 0x1f);
1517 whati |= 1 << (evoice->number & 0x1f);
1519 evoice->stimer = val;
1522 voice->running = 1;
1523 voice->stimer = val;
1525 voice->running = 0;
1528 if (voice->capture)
1530 if (voice->spdif)
1535 if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
1536 outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
1537 val = trident->spdif_pcm_ctrl;
1542 outl(trident->spdif_pcm_bits, TRID_REG(trident, SI_SPDIF_CS));
1559 if (capture_flag && trident->device != TRIDENT_DEVICE_ID_SI7018)
1560 outb(trident->bDMAStart, TRID_REG(trident, T4D_SBCTRL_SBE2R_SBDD));
1562 if (capture_flag && trident->device != TRIDENT_DEVICE_ID_SI7018)
1568 /*---------------------------------------------------------------------------
1573 Parameters: substream - PCM substream class
1577 ---------------------------------------------------------------------------*/
1582 struct snd_pcm_runtime *runtime = substream->runtime;
1583 struct snd_trident_voice *voice = runtime->private_data;
1586 if (!voice->running)
1589 guard(spinlock)(&trident->reg_lock);
1591 outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
1593 if (trident->device != TRIDENT_DEVICE_ID_NX) {
1599 if (cso >= runtime->buffer_size)
1605 /*---------------------------------------------------------------------------
1610 Parameters: pcm1 - PCM device class
1614 ---------------------------------------------------------------------------*/
1619 struct snd_pcm_runtime *runtime = substream->runtime;
1620 struct snd_trident_voice *voice = runtime->private_data;
1623 if (!voice->running)
1627 if (runtime->channels > 1)
1630 result = runtime->buffer_size - result;
1635 /*---------------------------------------------------------------------------
1640 Parameters: substream - PCM substream class
1644 ---------------------------------------------------------------------------*/
1649 struct snd_pcm_runtime *runtime = substream->runtime;
1650 struct snd_trident_voice *voice = runtime->private_data;
1653 if (!voice->running)
1782 struct snd_trident_voice *voice = runtime->private_data;
1786 trident = voice->trident;
1794 struct snd_pcm_runtime *runtime = substream->runtime;
1799 return -EAGAIN;
1801 voice->substream = substream;
1802 runtime->private_data = voice;
1803 runtime->private_free = snd_trident_pcm_free_substream;
1804 runtime->hw = snd_trident_playback;
1810 /*---------------------------------------------------------------------------
1816 Parameters: substream - PCM substream class
1818 ---------------------------------------------------------------------------*/
1822 struct snd_pcm_runtime *runtime = substream->runtime;
1823 struct snd_trident_voice *voice = runtime->private_data;
1829 /*---------------------------------------------------------------------------
1834 Parameters: substream - PCM substream class
1836 Returns: status - success or failure flag
1838 ---------------------------------------------------------------------------*/
1844 struct snd_pcm_runtime *runtime = substream->runtime;
1848 return -EAGAIN;
1849 voice->spdif = 1;
1850 voice->substream = substream;
1851 scoped_guard(spinlock_irq, &trident->reg_lock) {
1852 trident->spdif_pcm_bits = trident->spdif_bits;
1855 runtime->private_data = voice;
1856 runtime->private_free = snd_trident_pcm_free_substream;
1857 if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
1858 runtime->hw = snd_trident_spdif;
1860 runtime->hw = snd_trident_spdif_7018;
1863 trident->spdif_pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1864 snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE |
1865 SNDRV_CTL_EVENT_MASK_INFO, &trident->spdif_pcm_ctl->id);
1872 /*---------------------------------------------------------------------------
1877 Parameters: substream - PCM substream class
1879 ---------------------------------------------------------------------------*/
1886 scoped_guard(spinlock_irq, &trident->reg_lock) {
1888 if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
1889 outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
1890 outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
1892 outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
1894 if (trident->spdif_ctrl) {
1902 trident->spdif_pcm_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1903 snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE |
1904 SNDRV_CTL_EVENT_MASK_INFO, &trident->spdif_pcm_ctl->id);
1908 /*---------------------------------------------------------------------------
1913 Parameters: substream - PCM substream class
1915 Returns: status - success or failure flag
1917 ---------------------------------------------------------------------------*/
1923 struct snd_pcm_runtime *runtime = substream->runtime;
1927 return -EAGAIN;
1928 voice->capture = 1;
1929 voice->substream = substream;
1930 runtime->private_data = voice;
1931 runtime->private_free = snd_trident_pcm_free_substream;
1932 runtime->hw = snd_trident_capture;
1938 /*---------------------------------------------------------------------------
1944 Parameters: substream - PCM substream class
1946 ---------------------------------------------------------------------------*/
1952 /*---------------------------------------------------------------------------
1957 Parameters: substream - PCM substream class
1959 Returns: status - success or failure flag
1961 ---------------------------------------------------------------------------*/
1967 struct snd_pcm_runtime *runtime = substream->runtime;
1971 return -EAGAIN;
1972 voice->foldback_chan = substream->number;
1973 voice->substream = substream;
1974 runtime->private_data = voice;
1975 runtime->private_free = snd_trident_pcm_free_substream;
1976 runtime->hw = snd_trident_foldback;
1981 /*---------------------------------------------------------------------------
1987 Parameters: substream - PCM substream class
1989 ---------------------------------------------------------------------------*/
1994 struct snd_pcm_runtime *runtime = substream->runtime;
1995 voice = runtime->private_data;
1998 guard(spinlock_irq)(&trident->reg_lock);
1999 outb(0x00, TRID_REG(trident, T4D_RCI + voice->foldback_chan));
2003 /*---------------------------------------------------------------------------
2005 ---------------------------------------------------------------------------*/
2087 /*---------------------------------------------------------------------------
2092 Parameters: trident - pointer to target device class for 4DWave.
2096 ---------------------------------------------------------------------------*/
2103 err = snd_pcm_new(trident->card, "trident_dx_nx", device, trident->ChanPCM, 1, &pcm);
2107 pcm->private_data = trident;
2109 if (trident->tlb.entries) {
2115 trident->device != TRIDENT_DEVICE_ID_SI7018 ?
2119 pcm->info_flags = 0;
2120 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
2121 strscpy(pcm->name, "Trident 4DWave");
2122 trident->pcm = pcm;
2124 if (trident->tlb.entries) {
2126 for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next)
2128 &trident->pci->dev,
2130 snd_pcm_set_managed_buffer(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream,
2132 &trident->pci->dev,
2136 &trident->pci->dev,
2143 /*---------------------------------------------------------------------------
2148 Parameters: trident - pointer to target device class for 4DWave.
2152 ---------------------------------------------------------------------------*/
2161 if (trident->device == TRIDENT_DEVICE_ID_NX)
2163 err = snd_pcm_new(trident->card, "trident_dx_nx", device, 0, num_chan, &foldback);
2167 foldback->private_data = trident;
2168 if (trident->tlb.entries)
2172 foldback->info_flags = 0;
2173 strscpy(foldback->name, "Trident 4DWave");
2174 substream = foldback->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
2175 strscpy(substream->name, "Front Mixer");
2176 substream = substream->next;
2177 strscpy(substream->name, "Reverb Mixer");
2178 substream = substream->next;
2179 strscpy(substream->name, "Chorus Mixer");
2181 substream = substream->next;
2182 strscpy(substream->name, "Second AC'97 ADC");
2184 trident->foldback = foldback;
2186 if (trident->tlb.entries)
2188 &trident->pci->dev,
2192 &trident->pci->dev,
2198 /*---------------------------------------------------------------------------
2201 Description: This routine registers the 4DWave-NX device for SPDIF support.
2203 Parameters: trident - pointer to target device class for 4DWave-NX.
2207 ---------------------------------------------------------------------------*/
2214 err = snd_pcm_new(trident->card, "trident_dx_nx IEC958", device, 1, 0, &spdif);
2218 spdif->private_data = trident;
2219 if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
2224 spdif->info_flags = 0;
2225 strscpy(spdif->name, "Trident 4DWave IEC958");
2226 trident->spdif = spdif;
2229 &trident->pci->dev, 64*1024, 128*1024);
2239 /*---------------------------------------------------------------------------
2243 ---------------------------------------------------------------------------*/
2253 guard(spinlock_irq)(&trident->reg_lock);
2254 val = trident->spdif_ctrl;
2255 ucontrol->value.integer.value[0] = val == kcontrol->private_value;
2266 val = ucontrol->value.integer.value[0] ? (unsigned char) kcontrol->private_value : 0x00;
2267 guard(spinlock_irq)(&trident->reg_lock);
2268 /* S/PDIF C Channel bits 0-31 : 48khz, SCMS disabled */
2269 change = trident->spdif_ctrl != val;
2270 trident->spdif_ctrl = val;
2271 if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
2273 outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
2274 outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
2277 if (trident->spdif == NULL) {
2279 outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
2299 /*---------------------------------------------------------------------------
2303 ---------------------------------------------------------------------------*/
2308 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
2309 uinfo->count = 1;
2318 guard(spinlock_irq)(&trident->reg_lock);
2319 ucontrol->value.iec958.status[0] = (trident->spdif_bits >> 0) & 0xff;
2320 ucontrol->value.iec958.status[1] = (trident->spdif_bits >> 8) & 0xff;
2321 ucontrol->value.iec958.status[2] = (trident->spdif_bits >> 16) & 0xff;
2322 ucontrol->value.iec958.status[3] = (trident->spdif_bits >> 24) & 0xff;
2333 val = (ucontrol->value.iec958.status[0] << 0) |
2334 (ucontrol->value.iec958.status[1] << 8) |
2335 (ucontrol->value.iec958.status[2] << 16) |
2336 (ucontrol->value.iec958.status[3] << 24);
2337 guard(spinlock_irq)(&trident->reg_lock);
2338 change = trident->spdif_bits != val;
2339 trident->spdif_bits = val;
2340 if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
2342 outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
2344 if (trident->spdif == NULL)
2345 outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
2359 /*---------------------------------------------------------------------------
2363 ---------------------------------------------------------------------------*/
2368 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
2369 uinfo->count = 1;
2376 ucontrol->value.iec958.status[0] = 0xff;
2377 ucontrol->value.iec958.status[1] = 0xff;
2378 ucontrol->value.iec958.status[2] = 0xff;
2379 ucontrol->value.iec958.status[3] = 0xff;
2392 /*---------------------------------------------------------------------------
2396 ---------------------------------------------------------------------------*/
2401 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
2402 uinfo->count = 1;
2411 guard(spinlock_irq)(&trident->reg_lock);
2412 ucontrol->value.iec958.status[0] = (trident->spdif_pcm_bits >> 0) & 0xff;
2413 ucontrol->value.iec958.status[1] = (trident->spdif_pcm_bits >> 8) & 0xff;
2414 ucontrol->value.iec958.status[2] = (trident->spdif_pcm_bits >> 16) & 0xff;
2415 ucontrol->value.iec958.status[3] = (trident->spdif_pcm_bits >> 24) & 0xff;
2426 val = (ucontrol->value.iec958.status[0] << 0) |
2427 (ucontrol->value.iec958.status[1] << 8) |
2428 (ucontrol->value.iec958.status[2] << 16) |
2429 (ucontrol->value.iec958.status[3] << 24);
2430 guard(spinlock_irq)(&trident->reg_lock);
2431 change = trident->spdif_pcm_bits != val;
2432 trident->spdif_pcm_bits = val;
2433 if (trident->spdif != NULL) {
2434 if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
2435 outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
2437 outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
2453 /*---------------------------------------------------------------------------
2457 ---------------------------------------------------------------------------*/
2467 guard(spinlock_irq)(&trident->reg_lock);
2468 val = trident->ac97_ctrl = inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
2469 ucontrol->value.integer.value[0] = (val & (1 << kcontrol->private_value)) ? 1 : 0;
2480 guard(spinlock_irq)(&trident->reg_lock);
2481 val = trident->ac97_ctrl = inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
2482 val &= ~(1 << kcontrol->private_value);
2483 if (ucontrol->value.integer.value[0])
2484 val |= 1 << kcontrol->private_value;
2485 change = val != trident->ac97_ctrl;
2486 trident->ac97_ctrl = val;
2487 outl(trident->ac97_ctrl = val, TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
2501 /*---------------------------------------------------------------------------
2505 ---------------------------------------------------------------------------*/
2510 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2511 uinfo->count = 2;
2512 uinfo->value.integer.min = 0;
2513 uinfo->value.integer.max = 255;
2523 val = trident->musicvol_wavevol;
2524 ucontrol->value.integer.value[0] = 255 - ((val >> kcontrol->private_value) & 0xff);
2525 ucontrol->value.integer.value[1] = 255 - ((val >> (kcontrol->private_value + 8)) & 0xff);
2529 static const DECLARE_TLV_DB_SCALE(db_scale_gvol, -6375, 25, 0);
2538 guard(spinlock_irq)(&trident->reg_lock);
2539 val = trident->musicvol_wavevol;
2540 val &= ~(0xffff << kcontrol->private_value);
2541 val |= ((255 - (ucontrol->value.integer.value[0] & 0xff)) |
2542 ((255 - (ucontrol->value.integer.value[1] & 0xff)) << 8)) << kcontrol->private_value;
2543 change = val != trident->musicvol_wavevol;
2544 outl(trident->musicvol_wavevol = val, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
2570 /*---------------------------------------------------------------------------
2574 ---------------------------------------------------------------------------*/
2581 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2582 uinfo->count = 1;
2583 uinfo->value.integer.min = 0;
2584 uinfo->value.integer.max = 255;
2585 if (trident->device == TRIDENT_DEVICE_ID_SI7018)
2586 uinfo->value.integer.max = 1023;
2594 struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
2596 if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
2597 ucontrol->value.integer.value[0] = 1023 - mix->vol;
2599 ucontrol->value.integer.value[0] = 255 - (mix->vol>>2);
2608 struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
2612 if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
2613 val = 1023 - (ucontrol->value.integer.value[0] & 1023);
2615 val = (255 - (ucontrol->value.integer.value[0] & 255)) << 2;
2617 guard(spinlock_irq)(&trident->reg_lock);
2618 change = val != mix->vol;
2619 mix->vol = val;
2620 if (mix->voice != NULL)
2621 snd_trident_write_vol_reg(trident, mix->voice, val);
2637 /*---------------------------------------------------------------------------
2641 ---------------------------------------------------------------------------*/
2646 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2647 uinfo->count = 1;
2648 uinfo->value.integer.min = 0;
2649 uinfo->value.integer.max = 127;
2657 struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
2659 ucontrol->value.integer.value[0] = mix->pan;
2660 if (ucontrol->value.integer.value[0] & 0x40) {
2661 ucontrol->value.integer.value[0] = (0x3f - (ucontrol->value.integer.value[0] & 0x3f));
2663 ucontrol->value.integer.value[0] |= 0x40;
2672 struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
2676 if (ucontrol->value.integer.value[0] & 0x40)
2677 val = ucontrol->value.integer.value[0] & 0x3f;
2679 val = (0x3f - (ucontrol->value.integer.value[0] & 0x3f)) | 0x40;
2680 guard(spinlock_irq)(&trident->reg_lock);
2681 change = val != mix->pan;
2682 mix->pan = val;
2683 if (mix->voice != NULL)
2684 snd_trident_write_pan_reg(trident, mix->voice, val);
2699 /*---------------------------------------------------------------------------
2703 ---------------------------------------------------------------------------*/
2708 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2709 uinfo->count = 1;
2710 uinfo->value.integer.min = 0;
2711 uinfo->value.integer.max = 127;
2719 struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
2721 ucontrol->value.integer.value[0] = 127 - mix->rvol;
2729 struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
2733 val = 0x7f - (ucontrol->value.integer.value[0] & 0x7f);
2734 guard(spinlock_irq)(&trident->reg_lock);
2735 change = val != mix->rvol;
2736 mix->rvol = val;
2737 if (mix->voice != NULL)
2738 snd_trident_write_rvol_reg(trident, mix->voice, val);
2742 static const DECLARE_TLV_DB_SCALE(db_scale_crvol, -3175, 25, 1);
2756 /*---------------------------------------------------------------------------
2760 ---------------------------------------------------------------------------*/
2765 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2766 uinfo->count = 1;
2767 uinfo->value.integer.min = 0;
2768 uinfo->value.integer.max = 127;
2776 struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
2778 ucontrol->value.integer.value[0] = 127 - mix->cvol;
2786 struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
2790 val = 0x7f - (ucontrol->value.integer.value[0] & 0x7f);
2791 guard(spinlock_irq)(&trident->reg_lock);
2792 change = val != mix->cvol;
2793 mix->cvol = val;
2794 if (mix->voice != NULL)
2795 snd_trident_write_cvol_reg(trident, mix->voice, val);
2820 kctl->vd[num].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
2822 kctl->vd[num].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
2832 snd_trident_notify_pcm_change1(trident->card, trident->ctl_vol, num, activate);
2833 snd_trident_notify_pcm_change1(trident->card, trident->ctl_pan, num, activate);
2834 snd_trident_notify_pcm_change1(trident->card, trident->ctl_rvol, num, activate);
2835 snd_trident_notify_pcm_change1(trident->card, trident->ctl_cvol, num, activate);
2845 return -EINVAL;
2846 tmix = &trident->pcm_mixer[substream->number];
2847 tmix->voice = voice;
2848 tmix->vol = T4D_DEFAULT_PCM_VOL;
2849 tmix->pan = T4D_DEFAULT_PCM_PAN;
2850 tmix->rvol = T4D_DEFAULT_PCM_RVOL;
2851 tmix->cvol = T4D_DEFAULT_PCM_CVOL;
2852 snd_trident_notify_pcm_change(trident, tmix, substream->number, 1);
2861 return -EINVAL;
2862 tmix = &trident->pcm_mixer[substream->number];
2863 tmix->voice = NULL;
2864 snd_trident_notify_pcm_change(trident, tmix, substream->number, 0);
2868 /*---------------------------------------------------------------------------
2873 Parameters: trident - pointer to target device class for 4DWave.
2877 ---------------------------------------------------------------------------*/
2882 struct snd_card *card = trident->card;
2893 return -ENOMEM;
2895 err = snd_ac97_bus(trident->card, 0, &ops, NULL, &trident->ac97_bus);
2901 trident->ac97_detect = 1;
2904 err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97);
2906 if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
2910 if (retries-- > 0)
2912 err = -EIO;
2917 /* secondary codec? */
2918 if (trident->device == TRIDENT_DEVICE_ID_SI7018 &&
2921 err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97_sec);
2923 dev_err(trident->card->dev,
2924 "SI7018: the secondary codec - invalid access\n");
2925 #if 0 // only for my testing purpose --jk
2928 err = snd_ac97_modem(trident->card, &_ac97, &mc97);
2930 dev_err(trident->card->dev,
2936 trident->ac97_detect = 0;
2938 if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
2943 kctl->put(kctl, uctl);
2948 kctl->put(kctl, uctl);
2949 outl(trident->musicvol_wavevol = 0x00000000, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
2951 outl(trident->musicvol_wavevol = 0xffff0000, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
2957 tmix = &trident->pcm_mixer[idx];
2958 tmix->voice = NULL;
2960 trident->ctl_vol = snd_ctl_new1(&snd_trident_pcm_vol_control, trident);
2961 if (!trident->ctl_vol)
2963 err = snd_ctl_add(card, trident->ctl_vol);
2967 trident->ctl_pan = snd_ctl_new1(&snd_trident_pcm_pan_control, trident);
2968 if (!trident->ctl_pan)
2970 err = snd_ctl_add(card, trident->ctl_pan);
2974 trident->ctl_rvol = snd_ctl_new1(&snd_trident_pcm_rvol_control, trident);
2975 if (!trident->ctl_rvol)
2977 err = snd_ctl_add(card, trident->ctl_rvol);
2981 trident->ctl_cvol = snd_ctl_new1(&snd_trident_pcm_cvol_control, trident);
2982 if (!trident->ctl_cvol)
2984 err = snd_ctl_add(card, trident->ctl_cvol);
2988 if (trident->device == TRIDENT_DEVICE_ID_NX) {
2993 kctl->put(kctl, uctl);
2995 if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) {
2999 err = -ENOMEM;
3002 if (trident->ac97->ext_id & AC97_EI_SPDIF)
3003 kctl->id.index++;
3004 if (trident->ac97_sec && (trident->ac97_sec->ext_id & AC97_EI_SPDIF))
3005 kctl->id.index++;
3006 idx = kctl->id.index;
3010 kctl->put(kctl, uctl);
3014 err = -ENOMEM;
3017 kctl->id.index = idx;
3018 kctl->id.device = pcm_spdif_device;
3025 err = -ENOMEM;
3028 kctl->id.index = idx;
3029 kctl->id.device = pcm_spdif_device;
3036 err = -ENOMEM;
3039 kctl->id.index = idx;
3040 kctl->id.device = pcm_spdif_device;
3044 trident->spdif_pcm_ctl = kctl;
3051 err = -ENOMEM;
3095 if (axes[i] == 0xffff) axes[i] = -1;
3117 return -1;
3125 chip->gameport = gp = gameport_allocate_port();
3127 dev_err(chip->card->dev,
3129 return -ENOMEM;
3133 gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
3134 gameport_set_dev_parent(gp, &chip->pci->dev);
3137 gp->fuzz = 64;
3138 gp->read = snd_trident_gameport_read;
3139 gp->trigger = snd_trident_gameport_trigger;
3140 gp->cooked_read = snd_trident_gameport_cooked_read;
3141 gp->open = snd_trident_gameport_open;
3150 if (chip->gameport) {
3151 gameport_unregister_port(chip->gameport);
3152 chip->gameport = NULL;
3156 int snd_trident_create_gameport(struct snd_trident *chip) { return -ENOSYS; }
3178 r = trident->in_suspend ? 0 : 2; /* count of retries */
3180 pci_write_config_byte(trident->pci, 0x46, 0x04); /* SOFTWARE RESET */
3182 pci_write_config_byte(trident->pci, 0x46, 0x00);
3194 /* wait, until the codec is ready */
3201 dev_err(trident->card->dev, "AC'97 codec ready error [0x%x]\n",
3203 if (r-- > 0) {
3211 /* wait for the second codec */
3229 struct snd_trident *trident = entry->private_data;
3232 switch (trident->device) {
3246 snd_iprintf(buffer, "Spurious IRQs : %d\n", trident->spurious_irq_count);
3247 snd_iprintf(buffer, "Spurious IRQ dlta: %d\n", trident->spurious_irq_max_delta);
3248 if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018)
3249 snd_iprintf(buffer, "IEC958 Mixer Out : %s\n", str_on_off(trident->spdif_ctrl == 0x28));
3250 if (trident->device == TRIDENT_DEVICE_ID_NX) {
3251 snd_iprintf(buffer, "Rear Speakers : %s\n", str_on_off(trident->ac97_ctrl & 0x00000010));
3252 if (trident->tlb.entries) {
3254 snd_iprintf(buffer, "Memory Maximum : %d\n", trident->tlb.memhdr->size);
3255 snd_iprintf(buffer, "Memory Used : %d\n", trident->tlb.memhdr->used);
3256 snd_iprintf(buffer, "Memory Free : %d\n", snd_util_mem_avail(trident->tlb.memhdr));
3265 if (trident->device == TRIDENT_DEVICE_ID_SI7018)
3267 snd_card_ro_proc_new(trident->card, s, trident, snd_trident_proc_read);
3270 /*---------------------------------------------------------------------------
3276 Parameters: trident - pointer to target device class for 4DWave.
3280 ---------------------------------------------------------------------------*/
3289 trident->tlb.buffer =
3290 snd_devm_alloc_pages(&trident->pci->dev, SNDRV_DMA_TYPE_DEV,
3292 if (!trident->tlb.buffer) {
3293 dev_err(trident->card->dev, "unable to allocate TLB buffer\n");
3294 return -ENOMEM;
3296 trident->tlb.entries = (__le32 *)ALIGN((unsigned long)trident->tlb.buffer->area, SNDRV_TRIDENT_MAX_PAGES * 4);
3297 trident->tlb.entries_dmaaddr = ALIGN(trident->tlb.buffer->addr, SNDRV_TRIDENT_MAX_PAGES * 4);
3300 trident->tlb.silent_page =
3301 snd_devm_alloc_pages(&trident->pci->dev, SNDRV_DMA_TYPE_DEV,
3303 if (!trident->tlb.silent_page) {
3304 dev_err(trident->card->dev, "unable to allocate silent page\n");
3305 return -ENOMEM;
3307 memset(trident->tlb.silent_page->area, 0, SNDRV_TRIDENT_PAGE_SIZE);
3309 trident->tlb.entries[i] = cpu_to_le32(trident->tlb.silent_page->addr & ~(SNDRV_TRIDENT_PAGE_SIZE-1));
3312 trident->tlb.memhdr = snd_util_memhdr_new(SNDRV_TRIDENT_PAGE_SIZE * SNDRV_TRIDENT_MAX_PAGES);
3313 if (trident->tlb.memhdr == NULL)
3314 return -ENOMEM;
3316 trident->tlb.memhdr->block_extra_size = sizeof(struct snd_trident_memblk_arg);
3334 struct pci_dev *pci = trident->pci;
3346 /* warm reset of the AC'97 codec */
3351 trident->ac97_ctrl = 0x0000004a;
3352 outl(trident->ac97_ctrl, TRID_REG(trident, DX_ACR2_AC97_COM_STAT));
3353 /* wait, until the codec is ready */
3360 dev_err(trident->card->dev, "AC'97 codec ready error\n");
3361 return -EIO;
3374 struct pci_dev *pci = trident->pci;
3387 /* warm reset of the AC'97 codec */
3391 /* wait, until the codec is ready */
3398 dev_err(trident->card->dev, "AC'97 codec ready error [0x%x]\n",
3400 return -EIO;
3404 trident->ac97_ctrl = 0x00000002;
3405 outl(trident->ac97_ctrl, TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
3411 if (trident->tlb.entries != NULL) {
3414 i = trident->tlb.entries_dmaaddr;
3421 outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
3422 outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
3441 outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
3446 /*---------------------------------------------------------------------------
3452 Parameters: card - which card to create
3453 pci - interface to PCI bus resource info
3454 dma1ptr - playback dma buffer
3455 dma2ptr - capture dma buffer
3456 irqptr - interrupt resource info
3460 ---------------------------------------------------------------------------*/
3468 struct snd_trident *trident = card->private_data;
3478 if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(30))) {
3479 dev_err(card->dev,
3481 return -ENXIO;
3484 trident->device = (pci->vendor << 16) | pci->device;
3485 trident->card = card;
3486 trident->pci = pci;
3487 spin_lock_init(&trident->reg_lock);
3488 spin_lock_init(&trident->event_lock);
3489 spin_lock_init(&trident->voice_alloc);
3494 trident->ChanPCM = pcm_streams;
3497 trident->synth.max_size = max_wavetable_size * 1024;
3498 trident->irq = -1;
3499 card->private_free = snd_trident_free;
3501 trident->midi_port = TRID_REG(trident, T4D_MPU401_BASE);
3507 trident->port = pci_resource_start(pci, 0);
3509 if (devm_request_irq(&pci->dev, pci->irq, snd_trident_interrupt,
3511 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
3512 return -EBUSY;
3514 trident->irq = pci->irq;
3515 card->sync_irq = trident->irq;
3517 /* allocate 16k-aligned TLB for NX cards */
3518 trident->tlb.entries = NULL;
3519 if (trident->device == TRIDENT_DEVICE_ID_NX) {
3525 trident->spdif_bits = trident->spdif_pcm_bits = SNDRV_PCM_DEFAULT_CON_SPDIF;
3528 switch (trident->device) {
3551 voice = &trident->synth.voices[i];
3552 voice->number = i;
3553 voice->trident = trident;
3557 tmix = &trident->pcm_mixer[i];
3558 tmix->vol = T4D_DEFAULT_PCM_VOL;
3559 tmix->pan = T4D_DEFAULT_PCM_PAN;
3560 tmix->rvol = T4D_DEFAULT_PCM_RVOL;
3561 tmix->cvol = T4D_DEFAULT_PCM_CVOL;
3570 /*---------------------------------------------------------------------------
3576 Parameters: card - card to release
3580 ---------------------------------------------------------------------------*/
3584 struct snd_trident *trident = card->private_data;
3589 if (trident->device == TRIDENT_DEVICE_ID_NX)
3591 else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
3594 if (trident->tlb.buffer) {
3596 snd_util_memhdr_free(trident->tlb.memhdr);
3600 /*---------------------------------------------------------------------------
3605 Parameters: trident - device specific private data for 4DWave card
3616 ---------------------------------------------------------------------------*/
3630 scoped_guard(spinlock, &trident->reg_lock) {
3638 for (channel = 63; channel >= 32; channel--) {
3642 voice = &trident->synth.voices[channel];
3643 if (!voice->pcm || voice->substream == NULL) {
3647 delta = (int)stimer - (int)voice->stimer;
3649 delta = -delta;
3650 if ((unsigned int)delta < voice->spurious_threshold) {
3652 trident->spurious_irq_count++;
3653 if (trident->spurious_irq_max_delta < (unsigned int)delta)
3654 trident->spurious_irq_max_delta = delta;
3657 voice->stimer = stimer;
3658 if (voice->isync) {
3659 if (!voice->isync3) {
3661 if (trident->bDMAStart & 0x40)
3664 tmp = voice->isync_max - tmp;
3668 if (tmp < voice->isync_mark) {
3670 tmp = voice->isync_ESO - 7;
3672 tmp = voice->isync_ESO + 2;
3674 snd_trident_stop_voice(trident, voice->number);
3676 snd_trident_start_voice(trident, voice->number);
3678 } else if (voice->isync2) {
3679 voice->isync2 = 0;
3681 snd_trident_stop_voice(trident, voice->number);
3682 snd_trident_write_cso_reg(trident, voice, voice->isync_mark);
3683 snd_trident_write_eso_reg(trident, voice, voice->ESO);
3684 snd_trident_start_voice(trident, voice->number);
3687 if (voice->extra) {
3689 snd_trident_stop_voice(trident, voice->extra->number);
3690 snd_trident_write_cso_reg(trident, voice->extra, 0);
3691 snd_trident_start_voice(trident, voice->extra->number);
3694 spin_unlock(&trident->reg_lock);
3695 snd_pcm_period_elapsed(voice->substream);
3696 spin_lock(&trident->reg_lock);
3702 if (trident->rmidi) {
3703 snd_mpu401_uart_interrupt(irq, trident->rmidi->private_data);
3717 guard(spinlock_irqsave)(&trident->voice_alloc);
3722 pvoice = &trident->synth.voices[idx];
3723 pvoice->use = 1;
3724 pvoice->pcm = 1;
3725 pvoice->capture = 0;
3726 pvoice->spdif = 0;
3727 pvoice->memblk = NULL;
3728 pvoice->substream = NULL;
3735 pvoice = &trident->synth.voices[idx];
3736 pvoice->use = 1;
3737 pvoice->synth = 1;
3738 pvoice->client = client;
3739 pvoice->port = port;
3740 pvoice->memblk = NULL;
3754 if (voice == NULL || !voice->use)
3756 snd_trident_clear_voices(trident, voice->number, voice->number);
3757 scoped_guard(spinlock_irqsave, &trident->voice_alloc) {
3758 private_free = voice->private_free;
3759 voice->private_free = NULL;
3760 voice->private_data = NULL;
3761 if (voice->pcm)
3762 snd_trident_free_pcm_channel(trident, voice->number);
3763 if (voice->synth)
3764 snd_trident_free_synth_channel(trident, voice->number);
3765 voice->use = voice->pcm = voice->synth = voice->midi = 0;
3766 voice->capture = voice->spdif = 0;
3767 voice->sample_ops = NULL;
3768 voice->substream = NULL;
3769 voice->extra = NULL;
3801 struct snd_trident *trident = card->private_data;
3803 trident->in_suspend = 1;
3805 snd_ac97_suspend(trident->ac97);
3806 snd_ac97_suspend(trident->ac97_sec);
3813 struct snd_trident *trident = card->private_data;
3815 switch (trident->device) {
3827 snd_ac97_resume(trident->ac97);
3828 snd_ac97_resume(trident->ac97_sec);
3831 outl(trident->musicvol_wavevol, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
3836 trident->in_suspend = 0;