33 #include <linux/pci.h>
34 #include <linux/slab.h>
36 #include <linux/gameport.h>
38 #include <linux/export.h>
49 static int snd_trident_pcm_mixer_build(
struct snd_trident *trident,
52 static int snd_trident_pcm_mixer_free(
struct snd_trident *trident,
56 static int snd_trident_sis_reset(
struct snd_trident *trident);
58 static void snd_trident_clear_voices(
struct snd_trident * trident,
59 unsigned short v_min,
unsigned short v_max);
60 static int snd_trident_free(
struct snd_trident *trident);
68 static void snd_trident_print_voice_regs(
struct snd_trident *trident,
int voice)
85 printk(
"Alpha: 0x%x\n", (val >> 4) & 0x0fff);
93 tmp = (val >> 24) & 0xff;
96 tmp |= (val >> 16) & 0xff00;
121 static unsigned short snd_trident_codec_read(
struct snd_ac97 *ac97,
unsigned short reg)
123 unsigned int data = 0, treg;
124 unsigned short count = 0xffff;
143 if ((data & 0x00000C00) == 0)
164 spin_unlock_irqrestore(&trident->
reg_lock, flags);
165 return ((
unsigned short) (data >> 16));
182 static void snd_trident_codec_write(
struct snd_ac97 *ac97,
unsigned short reg,
183 unsigned short wdata)
186 unsigned short count = 0xffff;
190 data = ((
unsigned long) wdata) << 16;
231 spin_unlock_irqrestore(&trident->
reg_lock, flags);
235 spin_unlock_irqrestore(&trident->
reg_lock, flags);
250 static void snd_trident_enable_eso(
struct snd_trident * trident)
277 static void snd_trident_disable_eso(
struct snd_trident * trident)
303 unsigned int mask = 1 << (voice & 0x1f);
327 unsigned int mask = 1 << (voice & 0x1f);
346 static int snd_trident_allocate_pcm_channel(
struct snd_trident * trident)
352 for (idx = 31; idx >= 0; idx--) {
396 static int snd_trident_allocate_synth_channel(
struct snd_trident * trident)
400 for (idx = 31; idx >= 0; idx--) {
403 trident->
synth.ChanSynthCount++;
422 static void snd_trident_free_synth_channel(
struct snd_trident *trident,
int channel)
429 trident->
synth.ChanSynthCount--;
448 unsigned int FmcRvolCvol;
449 unsigned int regs[5];
451 regs[1] = voice->
LBA;
452 regs[4] = (voice->
GVSel << 31) |
453 ((voice->
Pan & 0x0000007f) << 24) |
454 ((voice->
CTRL & 0x0000000f) << 12);
455 FmcRvolCvol = ((voice->
FMC & 3) << 14) |
456 ((voice->
RVol & 0x7f) << 7) |
457 (voice->
CVol & 0x7f);
459 switch (trident->
device) {
461 regs[4] |= voice->
number > 31 ?
462 (voice->
Vol & 0x000003ff) :
463 ((voice->
Vol & 0x00003fc) << (16-2)) |
464 (voice->
EC & 0x00000fff);
465 regs[0] = (voice->
CSO << 16) | ((voice->
Alpha & 0x00000fff) << 4) |
466 (voice->
FMS & 0x0000000f);
467 regs[2] = (voice->
ESO << 16) | (voice->
Delta & 0x0ffff);
468 regs[3] = (voice->
Attribute << 16) | FmcRvolCvol;
471 regs[4] |= ((voice->
Vol & 0x000003fc) << (16-2)) |
472 (voice->
EC & 0x00000fff);
473 regs[0] = (voice->
CSO << 16) | ((voice->
Alpha & 0x00000fff) << 4) |
474 (voice->
FMS & 0x0000000f);
475 regs[2] = (voice->
ESO << 16) | (voice->
Delta & 0x0ffff);
476 regs[3] = FmcRvolCvol;
479 regs[4] |= ((voice->
Vol & 0x000003fc) << (16-2)) |
480 (voice->
EC & 0x00000fff);
481 regs[0] = (voice->
Delta << 24) | (voice->
CSO & 0x00ffffff);
482 regs[2] = ((voice->
Delta << 16) & 0xff000000) |
483 (voice->
ESO & 0x00ffffff);
484 regs[3] = (voice->
Alpha << 20) |
485 ((voice->
FMS & 0x0000000f) << 16) | FmcRvolCvol;
528 static void snd_trident_write_cso_reg(
struct snd_trident * trident,
554 static void snd_trident_write_eso_reg(
struct snd_trident * trident,
563 outl(((voice->
Delta << 16) & 0xff000000) | (voice->
ESO & 0x00ffffff),
580 static void snd_trident_write_vol_reg(
struct snd_trident * trident,
586 switch (trident->
device) {
611 static void snd_trident_write_pan_reg(
struct snd_trident * trident,
617 outb(((voice->
GVSel & 0x01) << 7) | (voice->
Pan & 0x7f),
633 static void snd_trident_write_rvol_reg(
struct snd_trident * trident,
639 outw(((voice->
FMC & 0x0003) << 14) | ((voice->
RVol & 0x007f) << 7) |
640 (voice->
CVol & 0x007f),
657 static void snd_trident_write_cvol_reg(
struct snd_trident * trident,
663 outw(((voice->
FMC & 0x0003) << 14) | ((voice->
RVol & 0x007f) << 7) |
664 (voice->
CVol & 0x007f),
680 static unsigned int snd_trident_convert_rate(
unsigned int rate)
690 else if (rate == 8000)
692 else if (rate == 48000)
695 delta = (((rate << 12) + 24000) / 48000) & 0x0000ffff;
710 static unsigned int snd_trident_convert_adc_rate(
unsigned int rate)
720 else if (rate == 8000)
722 else if (rate == 48000)
725 delta = ((48000 << 12) / rate) & 0x0000ffff;
740 static unsigned int snd_trident_spurious_threshold(
unsigned int rate,
741 unsigned int period_size)
743 unsigned int res = (rate * period_size) / 48000;
762 static unsigned int snd_trident_control_mode(
struct snd_pcm_substream *substream)
829 if (trident->
tlb.entries) {
864 if (evoice ==
NULL) {
868 voice->
extra = evoice;
872 if (evoice !=
NULL) {
898 err = snd_trident_allocate_pcm_mem(substream, hw_params);
900 err = snd_trident_allocate_evoice(substream, hw_params);
922 if (trident->
tlb.entries) {
923 if (voice && voice->
memblk) {
929 if (evoice !=
NULL) {
958 voice->
Delta = snd_trident_convert_rate(runtime->
rate);
969 voice->
CTRL = snd_trident_control_mode(substream);
981 voice->
Attribute = (1<<(30-16))|(2<<(26-16))|
982 (0<<(24-16))|(0x1f<<(19-16));
989 if (evoice !=
NULL) {
1001 evoice->
Vol = 0x3ff;
1002 evoice->
RVol = evoice->
CVol = 0x7f;
1005 evoice->
Attribute = (1<<(30-16))|(2<<(26-16))|
1006 (0<<(24-16))|(0x1f<<(19-16));
1016 spin_unlock_irq(&trident->
reg_lock);
1036 return snd_trident_allocate_pcm_mem(substream, hw_params);
1055 unsigned int val, ESO_bytes;
1072 ESO_bytes = snd_pcm_lib_buffer_bytes(substream) - 1;
1078 val = (((
unsigned int) 48000L << 12) + (runtime->
rate/2)) / runtime->
rate;
1083 val = (
unsigned short) ((ESO_bytes >> 1) - 1);
1085 val = (
unsigned short) (ESO_bytes - 1);
1103 voice->
Delta = snd_trident_convert_rate(runtime->
rate);
1112 voice->
CTRL = snd_trident_control_mode(substream);
1126 spin_unlock_irq(&trident->
reg_lock);
1142 static int snd_trident_si7018_capture_hw_params(
struct snd_pcm_substream *substream,
1150 return snd_trident_allocate_evoice(substream, hw_params);
1164 static int snd_trident_si7018_capture_hw_free(
struct snd_pcm_substream *substream)
1172 if (evoice !=
NULL) {
1190 static int snd_trident_si7018_capture_prepare(
struct snd_pcm_substream *substream)
1200 voice->
Delta = snd_trident_convert_adc_rate(runtime->
rate);
1206 voice->
CTRL = snd_trident_control_mode(substream);
1224 if (evoice !=
NULL) {
1225 evoice->
Delta = snd_trident_convert_rate(runtime->
rate);
1227 evoice->
LBA = voice->
LBA;
1236 evoice->
Vol = 0x3ff;
1237 evoice->
RVol = evoice->
CVol = 0x7f;
1246 spin_unlock_irq(&trident->
reg_lock);
1280 voice->
Delta = 0x1000;
1284 voice->
CTRL = snd_trident_control_mode(substream);
1301 if (evoice !=
NULL) {
1304 evoice->
LBA = voice->
LBA;
1313 evoice->
Vol = 0x3ff;
1314 evoice->
RVol = evoice->
CVol = 0x7f;
1323 spin_unlock_irq(&trident->
reg_lock);
1343 unsigned int old_bits = 0, change = 0;
1346 err = snd_trident_allocate_pcm_mem(substream, hw_params);
1351 err = snd_trident_allocate_evoice(substream, hw_params);
1366 trident->
spdif_bits & IEC958_AES0_PROFESSIONAL ?
1373 trident->
spdif_bits & IEC958_AES0_PROFESSIONAL ?
1380 trident->
spdif_bits & IEC958_AES0_PROFESSIONAL ?
1385 spin_unlock_irq(&trident->
reg_lock);
1411 unsigned int RESO, LBAO;
1419 voice->
Delta = snd_trident_convert_rate(runtime->
rate);
1439 voice->
CTRL = snd_trident_control_mode(substream);
1469 voice->
Delta = 0x800;
1480 voice->
CTRL = snd_trident_control_mode(substream);
1490 voice->
Attribute = (1<<(30-16))|(7<<(26-16))|
1491 (0<<(24-16))|(0<<(19-16));
1495 if (evoice !=
NULL) {
1498 evoice->
LBA = voice->
LBA;
1507 evoice->
Vol = 0x3ff;
1508 evoice->
RVol = evoice->
CVol = 0x7f;
1526 spin_unlock_irq(&trident->
reg_lock);
1549 unsigned int what, whati, capture_flag, spdif_flag;
1551 unsigned int val,
go;
1567 what = whati = capture_flag = spdif_flag = 0;
1572 voice = s->
runtime->private_data;
1573 evoice = voice->
extra;
1574 what |= 1 << (voice->
number & 0x1f);
1575 if (evoice ==
NULL) {
1576 whati |= 1 << (voice->
number & 0x1f);
1578 what |= 1 << (evoice->
number & 0x1f);
1579 whati |= 1 << (evoice->
number & 0x1f);
1589 snd_pcm_trigger_done(s, substream);
1743 .buffer_bytes_max = (256*1024),
1747 .periods_max = 1024,
1768 .buffer_bytes_max = (128*1024),
1772 .periods_max = 1024,
1793 .period_bytes_min = 64,
1794 .period_bytes_max = (128*1024),
1817 .buffer_bytes_max = (128*1024),
1821 .periods_max = 1024,
1838 .period_bytes_min = 64,
1839 .period_bytes_max = (128*1024),
1845 static void snd_trident_pcm_free_substream(
struct snd_pcm_runtime *runtime)
1865 snd_trident_pcm_mixer_build(trident, voice, substream);
1868 runtime->
private_free = snd_trident_pcm_free_substream;
1869 runtime->
hw = snd_trident_playback;
1890 snd_trident_pcm_mixer_free(trident, voice, substream);
1918 spin_unlock_irq(&trident->
reg_lock);
1921 runtime->
private_free = snd_trident_pcm_free_substream;
1923 runtime->
hw = snd_trident_spdif;
1925 runtime->
hw = snd_trident_spdif_7018;
1966 spin_unlock_irq(&trident->
reg_lock);
1996 runtime->
private_free = snd_trident_pcm_free_substream;
1997 runtime->
hw = snd_trident_capture;
2040 runtime->
private_free = snd_trident_pcm_free_substream;
2041 runtime->
hw = snd_trident_foldback;
2065 spin_unlock_irq(&trident->
reg_lock);
2073 static struct snd_pcm_ops snd_trident_playback_ops = {
2074 .open = snd_trident_playback_open,
2075 .close = snd_trident_playback_close,
2076 .ioctl = snd_trident_ioctl,
2077 .hw_params = snd_trident_hw_params,
2078 .hw_free = snd_trident_hw_free,
2079 .prepare = snd_trident_playback_prepare,
2080 .trigger = snd_trident_trigger,
2081 .pointer = snd_trident_playback_pointer,
2084 static struct snd_pcm_ops snd_trident_nx_playback_ops = {
2085 .open = snd_trident_playback_open,
2086 .close = snd_trident_playback_close,
2087 .ioctl = snd_trident_ioctl,
2088 .hw_params = snd_trident_hw_params,
2089 .hw_free = snd_trident_hw_free,
2090 .prepare = snd_trident_playback_prepare,
2091 .trigger = snd_trident_trigger,
2092 .pointer = snd_trident_playback_pointer,
2096 static struct snd_pcm_ops snd_trident_capture_ops = {
2097 .open = snd_trident_capture_open,
2098 .close = snd_trident_capture_close,
2099 .ioctl = snd_trident_ioctl,
2100 .hw_params = snd_trident_capture_hw_params,
2101 .hw_free = snd_trident_hw_free,
2102 .prepare = snd_trident_capture_prepare,
2103 .trigger = snd_trident_trigger,
2104 .pointer = snd_trident_capture_pointer,
2107 static struct snd_pcm_ops snd_trident_si7018_capture_ops = {
2108 .open = snd_trident_capture_open,
2109 .close = snd_trident_capture_close,
2110 .ioctl = snd_trident_ioctl,
2111 .hw_params = snd_trident_si7018_capture_hw_params,
2112 .hw_free = snd_trident_si7018_capture_hw_free,
2113 .prepare = snd_trident_si7018_capture_prepare,
2114 .trigger = snd_trident_trigger,
2115 .pointer = snd_trident_playback_pointer,
2118 static struct snd_pcm_ops snd_trident_foldback_ops = {
2119 .open = snd_trident_foldback_open,
2120 .close = snd_trident_foldback_close,
2121 .ioctl = snd_trident_ioctl,
2122 .hw_params = snd_trident_hw_params,
2123 .hw_free = snd_trident_hw_free,
2124 .prepare = snd_trident_foldback_prepare,
2125 .trigger = snd_trident_trigger,
2126 .pointer = snd_trident_playback_pointer,
2129 static struct snd_pcm_ops snd_trident_nx_foldback_ops = {
2130 .open = snd_trident_foldback_open,
2131 .close = snd_trident_foldback_close,
2132 .ioctl = snd_trident_ioctl,
2133 .hw_params = snd_trident_hw_params,
2134 .hw_free = snd_trident_hw_free,
2135 .prepare = snd_trident_foldback_prepare,
2136 .trigger = snd_trident_trigger,
2137 .pointer = snd_trident_playback_pointer,
2141 static struct snd_pcm_ops snd_trident_spdif_ops = {
2142 .open = snd_trident_spdif_open,
2143 .close = snd_trident_spdif_close,
2144 .ioctl = snd_trident_ioctl,
2145 .hw_params = snd_trident_spdif_hw_params,
2146 .hw_free = snd_trident_hw_free,
2147 .prepare = snd_trident_spdif_prepare,
2148 .trigger = snd_trident_trigger,
2149 .pointer = snd_trident_spdif_pointer,
2152 static struct snd_pcm_ops snd_trident_spdif_7018_ops = {
2153 .open = snd_trident_spdif_open,
2154 .close = snd_trident_spdif_close,
2155 .ioctl = snd_trident_ioctl,
2156 .hw_params = snd_trident_spdif_hw_params,
2157 .hw_free = snd_trident_hw_free,
2158 .prepare = snd_trident_spdif_prepare,
2159 .trigger = snd_trident_trigger,
2160 .pointer = snd_trident_playback_pointer,
2187 if (trident->
tlb.entries) {
2194 &snd_trident_capture_ops :
2195 &snd_trident_si7018_capture_ops);
2202 if (trident->
tlb.entries) {
2244 if ((err =
snd_pcm_new(trident->
card,
"trident_dx_nx", device, 0, num_chan, &foldback)) < 0)
2248 if (trident->
tlb.entries)
2256 substream = substream->
next;
2258 substream = substream->
next;
2260 if (num_chan == 4) {
2261 substream = substream->
next;
2266 if (trident->
tlb.entries)
2297 if ((err =
snd_pcm_new(trident->
card,
"trident_dx_nx IEC958", device, 1, 0, &spdif)) < 0)
2307 strcpy(spdif->
name,
"Trident 4DWave IEC958");
2328 #define snd_trident_spdif_control_info snd_ctl_boolean_mono_info
2330 static int snd_trident_spdif_control_get(
struct snd_kcontrol *kcontrol,
2339 spin_unlock_irq(&trident->
reg_lock);
2343 static int snd_trident_spdif_control_put(
struct snd_kcontrol *kcontrol,
2370 spin_unlock_irq(&trident->
reg_lock);
2379 .get = snd_trident_spdif_control_get,
2380 .put = snd_trident_spdif_control_put,
2381 .private_value = 0x28,
2390 static int snd_trident_spdif_default_info(
struct snd_kcontrol *kcontrol,
2398 static int snd_trident_spdif_default_get(
struct snd_kcontrol *kcontrol,
2406 ucontrol->
value.iec958.status[2] = (trident->
spdif_bits >> 16) & 0xff;
2407 ucontrol->
value.iec958.status[3] = (trident->
spdif_bits >> 24) & 0xff;
2408 spin_unlock_irq(&trident->
reg_lock);
2412 static int snd_trident_spdif_default_put(
struct snd_kcontrol *kcontrol,
2419 val = (ucontrol->
value.iec958.status[0] << 0) |
2420 (ucontrol->
value.iec958.status[1] << 8) |
2421 (ucontrol->
value.iec958.status[2] << 16) |
2422 (ucontrol->
value.iec958.status[3] << 24);
2433 spin_unlock_irq(&trident->
reg_lock);
2441 .info = snd_trident_spdif_default_info,
2442 .get = snd_trident_spdif_default_get,
2443 .put = snd_trident_spdif_default_put
2452 static int snd_trident_spdif_mask_info(
struct snd_kcontrol *kcontrol,
2460 static int snd_trident_spdif_mask_get(
struct snd_kcontrol *kcontrol,
2463 ucontrol->
value.iec958.status[0] = 0xff;
2464 ucontrol->
value.iec958.status[1] = 0xff;
2465 ucontrol->
value.iec958.status[2] = 0xff;
2466 ucontrol->
value.iec958.status[3] = 0xff;
2475 .info = snd_trident_spdif_mask_info,
2476 .get = snd_trident_spdif_mask_get,
2485 static int snd_trident_spdif_stream_info(
struct snd_kcontrol *kcontrol,
2493 static int snd_trident_spdif_stream_get(
struct snd_kcontrol *kcontrol,
2503 spin_unlock_irq(&trident->
reg_lock);
2507 static int snd_trident_spdif_stream_put(
struct snd_kcontrol *kcontrol,
2514 val = (ucontrol->
value.iec958.status[0] << 0) |
2515 (ucontrol->
value.iec958.status[1] << 8) |
2516 (ucontrol->
value.iec958.status[2] << 16) |
2517 (ucontrol->
value.iec958.status[3] << 24);
2528 spin_unlock_irq(&trident->
reg_lock);
2537 .info = snd_trident_spdif_stream_info,
2538 .get = snd_trident_spdif_stream_get,
2539 .put = snd_trident_spdif_stream_put
2548 #define snd_trident_ac97_control_info snd_ctl_boolean_mono_info
2550 static int snd_trident_ac97_control_get(
struct snd_kcontrol *kcontrol,
2559 spin_unlock_irq(&trident->
reg_lock);
2563 static int snd_trident_ac97_control_put(
struct snd_kcontrol *kcontrol,
2573 if (ucontrol->
value.integer.value[0])
2578 spin_unlock_irq(&trident->
reg_lock);
2582 static struct snd_kcontrol_new snd_trident_ac97_rear_control __devinitdata =
2585 .name =
"Rear Path",
2587 .get = snd_trident_ac97_control_get,
2588 .put = snd_trident_ac97_control_put,
2598 static int snd_trident_vol_control_info(
struct snd_kcontrol *kcontrol,
2608 static int snd_trident_vol_control_get(
struct snd_kcontrol *kcontrol,
2616 ucontrol->
value.integer.value[1] = 255 - ((val >> (kcontrol->
private_value + 8)) & 0xff);
2622 static int snd_trident_vol_control_put(
struct snd_kcontrol *kcontrol,
2632 val |= ((255 - (ucontrol->
value.integer.value[0] & 0xff)) |
2633 ((255 - (ucontrol->
value.integer.value[1] & 0xff)) << 8)) << kcontrol->
private_value;
2636 spin_unlock_irq(&trident->
reg_lock);
2640 static struct snd_kcontrol_new snd_trident_vol_music_control __devinitdata =
2643 .name =
"Music Playback Volume",
2644 .info = snd_trident_vol_control_info,
2645 .get = snd_trident_vol_control_get,
2646 .put = snd_trident_vol_control_put,
2647 .private_value = 16,
2648 .tlv = { .p = db_scale_gvol },
2651 static struct snd_kcontrol_new snd_trident_vol_wave_control __devinitdata =
2654 .name =
"Wave Playback Volume",
2655 .info = snd_trident_vol_control_info,
2656 .get = snd_trident_vol_control_get,
2657 .put = snd_trident_vol_control_put,
2659 .tlv = { .p = db_scale_gvol },
2668 static int snd_trident_pcm_vol_control_info(
struct snd_kcontrol *kcontrol,
2682 static int snd_trident_pcm_vol_control_get(
struct snd_kcontrol *kcontrol,
2689 ucontrol->
value.integer.value[0] = 1023 - mix->
vol;
2691 ucontrol->
value.integer.value[0] = 255 - (mix->
vol>>2);
2696 static int snd_trident_pcm_vol_control_put(
struct snd_kcontrol *kcontrol,
2705 val = 1023 - (ucontrol->
value.integer.value[0] & 1023);
2707 val = (255 - (ucontrol->
value.integer.value[0] & 255)) << 2;
2710 change = val != mix->
vol;
2713 snd_trident_write_vol_reg(trident, mix->
voice, val);
2714 spin_unlock_irq(&trident->
reg_lock);
2721 .name =
"PCM Front Playback Volume",
2724 .info = snd_trident_pcm_vol_control_info,
2725 .get = snd_trident_pcm_vol_control_get,
2726 .put = snd_trident_pcm_vol_control_put,
2736 static int snd_trident_pcm_pan_control_info(
struct snd_kcontrol *kcontrol,
2746 static int snd_trident_pcm_pan_control_get(
struct snd_kcontrol *kcontrol,
2752 ucontrol->
value.integer.value[0] = mix->
pan;
2753 if (ucontrol->
value.integer.value[0] & 0x40) {
2754 ucontrol->
value.integer.value[0] = (0x3f - (ucontrol->
value.integer.value[0] & 0x3f));
2756 ucontrol->
value.integer.value[0] |= 0x40;
2761 static int snd_trident_pcm_pan_control_put(
struct snd_kcontrol *kcontrol,
2769 if (ucontrol->
value.integer.value[0] & 0x40)
2770 val = ucontrol->
value.integer.value[0] & 0x3f;
2772 val = (0x3f - (ucontrol->
value.integer.value[0] & 0x3f)) | 0x40;
2774 change = val != mix->
pan;
2777 snd_trident_write_pan_reg(trident, mix->
voice, val);
2778 spin_unlock_irq(&trident->
reg_lock);
2785 .name =
"PCM Pan Playback Control",
2788 .info = snd_trident_pcm_pan_control_info,
2789 .get = snd_trident_pcm_pan_control_get,
2790 .put = snd_trident_pcm_pan_control_put,
2799 static int snd_trident_pcm_rvol_control_info(
struct snd_kcontrol *kcontrol,
2809 static int snd_trident_pcm_rvol_control_get(
struct snd_kcontrol *kcontrol,
2815 ucontrol->
value.integer.value[0] = 127 - mix->
rvol;
2819 static int snd_trident_pcm_rvol_control_put(
struct snd_kcontrol *kcontrol,
2827 val = 0x7f - (ucontrol->
value.integer.value[0] & 0x7f);
2829 change = val != mix->
rvol;
2832 snd_trident_write_rvol_reg(trident, mix->
voice, val);
2833 spin_unlock_irq(&trident->
reg_lock);
2839 static struct snd_kcontrol_new snd_trident_pcm_rvol_control __devinitdata =
2842 .name =
"PCM Reverb Playback Volume",
2845 .info = snd_trident_pcm_rvol_control_info,
2846 .get = snd_trident_pcm_rvol_control_get,
2847 .put = snd_trident_pcm_rvol_control_put,
2848 .tlv = { .p = db_scale_crvol },
2857 static int snd_trident_pcm_cvol_control_info(
struct snd_kcontrol *kcontrol,
2867 static int snd_trident_pcm_cvol_control_get(
struct snd_kcontrol *kcontrol,
2873 ucontrol->
value.integer.value[0] = 127 - mix->
cvol;
2877 static int snd_trident_pcm_cvol_control_put(
struct snd_kcontrol *kcontrol,
2885 val = 0x7f - (ucontrol->
value.integer.value[0] & 0x7f);
2887 change = val != mix->
cvol;
2890 snd_trident_write_cvol_reg(trident, mix->
voice, val);
2891 spin_unlock_irq(&trident->
reg_lock);
2895 static struct snd_kcontrol_new snd_trident_pcm_cvol_control __devinitdata =
2898 .name =
"PCM Chorus Playback Volume",
2901 .info = snd_trident_pcm_cvol_control_info,
2902 .get = snd_trident_pcm_cvol_control_get,
2903 .put = snd_trident_pcm_cvol_control_put,
2904 .tlv = { .p = db_scale_crvol },
2907 static void snd_trident_notify_pcm_change1(
struct snd_card *
card,
2909 int num,
int activate)
2921 snd_ctl_build_ioff(&
id, kctl, num));
2924 static void snd_trident_notify_pcm_change(
struct snd_trident *trident,
2926 int num,
int activate)
2928 snd_trident_notify_pcm_change1(trident->
card, trident->
ctl_vol, num, activate);
2929 snd_trident_notify_pcm_change1(trident->
card, trident->
ctl_pan, num, activate);
2930 snd_trident_notify_pcm_change1(trident->
card, trident->
ctl_rvol, num, activate);
2931 snd_trident_notify_pcm_change1(trident->
card, trident->
ctl_cvol, num, activate);
2934 static int snd_trident_pcm_mixer_build(
struct snd_trident *trident,
2940 if (
snd_BUG_ON(!trident || !voice || !substream))
2948 snd_trident_notify_pcm_change(trident, tmix, substream->
number, 1);
2960 snd_trident_notify_pcm_change(trident, tmix, substream->
number, 0);
2983 .write = snd_trident_codec_write,
2984 .read = snd_trident_codec_read,
2994 memset(&_ac97, 0,
sizeof(_ac97));
2995 _ac97.private_data = trident;
3001 if ((err = snd_trident_sis_reset(trident)) < 0)
3017 #if 0 // only for my testing purpose --jk
3020 err = snd_ac97_modem(trident->
card, &_ac97, &mc97);
3032 kctl->
put(kctl, uctl);
3035 kctl->
put(kctl, uctl);
3041 for (idx = 0; idx < 32; idx++) {
3070 kctl->
put(kctl, uctl);
3074 kctl =
snd_ctl_new1(&snd_trident_spdif_control, trident);
3083 idx = kctl->
id.index;
3086 kctl->
put(kctl, uctl);
3088 kctl =
snd_ctl_new1(&snd_trident_spdif_default, trident);
3093 kctl->
id.index =
idx;
3094 kctl->
id.device = pcm_spdif_device;
3103 kctl->
id.index =
idx;
3104 kctl->
id.device = pcm_spdif_device;
3108 kctl =
snd_ctl_new1(&snd_trident_spdif_stream, trident);
3113 kctl->
id.index =
idx;
3114 kctl->
id.device = pcm_spdif_device;
3136 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
3147 static void snd_trident_gameport_trigger(
struct gameport *gameport)
3149 struct snd_trident *chip = gameport_get_port_data(gameport);
3156 static int snd_trident_gameport_cooked_read(
struct gameport *gameport,
int *axes,
int *
buttons)
3158 struct snd_trident *chip = gameport_get_port_data(gameport);
3166 for (i = 0; i < 4; i++) {
3168 if (axes[i] == 0xffff) axes[
i] = -1;
3174 static int snd_trident_gameport_open(
struct gameport *gameport,
int mode)
3176 struct snd_trident *chip = gameport_get_port_data(gameport);
3196 struct gameport *
gp;
3198 chip->
gameport = gp = gameport_allocate_port();
3200 printk(
KERN_ERR "trident: cannot allocate memory for gameport\n");
3204 gameport_set_name(gp,
"Trident 4DWave");
3206 gameport_set_dev_parent(gp, &chip->
pci->dev);
3208 gameport_set_port_data(gp, chip);
3210 gp->
read = snd_trident_gameport_read;
3211 gp->
trigger = snd_trident_gameport_trigger;
3212 gp->
cooked_read = snd_trident_gameport_cooked_read;
3213 gp->
open = snd_trident_gameport_open;
3215 gameport_register_port(gp);
3220 static inline void snd_trident_free_gameport(
struct snd_trident *chip)
3229 static inline void snd_trident_free_gameport(
struct snd_trident *chip) { }
3235 static inline void do_delay(
struct snd_trident *chip)
3244 static int snd_trident_sis_reset(
struct snd_trident *trident)
3246 unsigned long end_time;
3252 pci_write_config_byte(trident->
pci, 0x46, 0x04);
3254 pci_write_config_byte(trident->
pci, 0x46, 0x00);
3267 end_time = (
jiffies + (
HZ * 3) / 4) + 1;
3279 goto __si7018_retry;
3303 switch (trident->
device) {
3305 s =
"SiS 7018 Audio";
3308 s =
"Trident 4DWave PCI DX";
3311 s =
"Trident 4DWave PCI NX";
3316 snd_iprintf(buffer,
"%s\n\n", s);
3320 snd_iprintf(buffer,
"IEC958 Mixer Out : %s\n", trident->
spdif_ctrl == 0x28 ?
"on" :
"off");
3322 snd_iprintf(buffer,
"Rear Speakers : %s\n", trident->
ac97_ctrl & 0x00000010 ?
"on" :
"off");
3323 if (trident->
tlb.entries) {
3324 snd_iprintf(buffer,
"\nVirtual Memory\n");
3325 snd_iprintf(buffer,
"Memory Maximum : %d\n", trident->
tlb.memhdr->size);
3326 snd_iprintf(buffer,
"Memory Used : %d\n", trident->
tlb.memhdr->used);
3335 const char *s =
"trident";
3339 if (! snd_card_proc_new(trident->
card, s, &entry))
3340 snd_info_set_text_ops(entry, trident, snd_trident_proc_read);
3346 return snd_trident_free(trident);
3377 if (trident->
tlb.shadow_entries ==
NULL) {
3390 trident->
tlb.shadow_entries[
i] = (
unsigned long)trident->
tlb.silent_page.area;
3395 if (trident->
tlb.memhdr ==
NULL)
3406 static void snd_trident_stop_all_voices(
struct snd_trident *trident)
3414 static int snd_trident_4d_dx_init(
struct snd_trident *trident)
3417 unsigned long end_time;
3420 pci_write_config_dword(pci, 0x40, 0);
3421 pci_write_config_byte(pci, 0x44, 0);
3422 pci_write_config_byte(pci, 0x45, 0);
3423 pci_write_config_byte(pci, 0x46, 4);
3425 pci_write_config_byte(pci, 0x46, 0);
3436 end_time = (
jiffies + (HZ * 3) / 4) + 1;
3446 snd_trident_stop_all_voices(trident);
3454 static int snd_trident_4d_nx_init(
struct snd_trident *trident)
3457 unsigned long end_time;
3460 pci_write_config_dword(pci, 0x40, 0);
3461 pci_write_config_byte(pci, 0x44, 0);
3462 pci_write_config_byte(pci, 0x45, 0);
3464 pci_write_config_byte(pci, 0x46, 1);
3466 pci_write_config_byte(pci, 0x46, 0);
3474 end_time = (
jiffies + (HZ * 3) / 4) + 1;
3490 snd_trident_stop_all_voices(trident);
3492 if (trident->
tlb.entries !=
NULL) {
3495 i = trident->
tlb.entries_dmaaddr;
3511 static int snd_trident_sis_init(
struct snd_trident *trident)
3515 if ((err = snd_trident_sis_reset(trident)) < 0)
3518 snd_trident_stop_all_voices(trident);
3545 int pcm_spdif_device,
3546 int max_wavetable_size,
3564 pci_set_consistent_dma_mask(pci,
DMA_BIT_MASK(30)) < 0) {
3570 trident = kzalloc(
sizeof(*trident),
GFP_KERNEL);
3571 if (trident ==
NULL) {
3576 trident->
card = card;
3581 if (pcm_streams < 1)
3583 if (pcm_streams > 32)
3585 trident->
ChanPCM = pcm_streams;
3586 if (max_wavetable_size < 0 )
3587 max_wavetable_size = 0;
3588 trident->
synth.max_size = max_wavetable_size * 1024;
3602 KBUILD_MODNAME, trident)) {
3604 snd_trident_free(trident);
3611 trident->
tlb.buffer.area =
NULL;
3613 if ((err = snd_trident_tlb_alloc(trident)) < 0) {
3614 snd_trident_free(trident);
3622 switch (trident->
device) {
3624 err = snd_trident_4d_dx_init(trident);
3627 err = snd_trident_4d_nx_init(trident);
3630 err = snd_trident_sis_init(trident);
3637 snd_trident_free(trident);
3642 snd_trident_free(trident);
3646 if ((err = snd_trident_mixer(trident, pcm_spdif_device)) < 0)
3650 for (i = 0; i < 64; i++) {
3651 voice = &trident->
synth.voices[
i];
3656 for (i = 0; i < 32; i++) {
3664 snd_trident_enable_eso(trident);
3666 snd_trident_proc_init(trident);
3668 *rtrident = trident;
3684 static int snd_trident_free(
struct snd_trident *trident)
3686 snd_trident_free_gameport(trident);
3687 snd_trident_disable_eso(trident);
3694 if (trident->
irq >= 0)
3696 if (trident->
tlb.buffer.area) {
3698 if (trident->
tlb.memhdr)
3700 if (trident->
tlb.silent_page.area)
3702 vfree(trident->
tlb.shadow_entries);
3751 for (channel = 63; channel >= 32; channel--) {
3752 mask = 1 << (channel&0x1f);
3753 if ((chn_int & mask) == 0)
3760 delta = (
int)stimer - (
int)voice->
stimer;
3788 snd_trident_write_eso_reg(trident, voice, tmp);
3791 }
else if (voice->
isync2) {
3795 snd_trident_write_cso_reg(trident, voice, voice->
isync_mark);
3796 snd_trident_write_eso_reg(trident, voice, voice->
ESO);
3803 snd_trident_write_cso_reg(trident, voice->
extra, 0);
3816 if (trident->
rmidi) {
3829 unsigned long flags;
3834 idx = snd_trident_allocate_pcm_channel(trident);
3836 spin_unlock_irqrestore(&trident->
voice_alloc, flags);
3839 pvoice = &trident->
synth.voices[
idx];
3846 spin_unlock_irqrestore(&trident->
voice_alloc, flags);
3850 idx = snd_trident_allocate_synth_channel(trident);
3852 spin_unlock_irqrestore(&trident->
voice_alloc, flags);
3855 pvoice = &trident->
synth.voices[
idx];
3861 spin_unlock_irqrestore(&trident->
voice_alloc, flags);
3866 spin_unlock_irqrestore(&trident->
voice_alloc, flags);
3874 unsigned long flags;
3878 if (voice ==
NULL || !voice->
use)
3880 snd_trident_clear_voices(trident, voice->
number, voice->
number);
3887 snd_trident_free_pcm_channel(trident, voice->
number);
3889 snd_trident_free_synth_channel(trident, voice->
number);
3895 spin_unlock_irqrestore(&trident->
voice_alloc, flags);
3902 static void snd_trident_clear_voices(
struct snd_trident * trident,
unsigned short v_min,
unsigned short v_max)
3904 unsigned int i,
val, mask[2] = { 0, 0 };
3908 for (i = v_min; i <= v_max; i++)
3909 mask[i >> 5] |= 1 << (i & 0x1f);
3922 #ifdef CONFIG_PM_SLEEP
3923 static int snd_trident_suspend(
struct device *
dev)
3931 snd_pcm_suspend_all(trident->
pcm);
3932 snd_pcm_suspend_all(trident->
foldback);
3933 snd_pcm_suspend_all(trident->
spdif);
3935 snd_ac97_suspend(trident->
ac97);
3936 snd_ac97_suspend(trident->
ac97_sec);
3944 static int snd_trident_resume(
struct device *
dev)
3954 "disabling device\n");
3960 switch (trident->
device) {
3962 snd_trident_4d_dx_init(trident);
3965 snd_trident_4d_nx_init(trident);
3968 snd_trident_sis_init(trident);
3972 snd_ac97_resume(trident->
ac97);
3973 snd_ac97_resume(trident->
ac97_sec);
3978 snd_trident_enable_eso(trident);