29 #include <linux/slab.h>
38 #define SNDRV_GF1_PCM_RATE 48000
40 #define SNDRV_GF1_PCM_PFLG_NONE 0
41 #define SNDRV_GF1_PCM_PFLG_ACTIVE (1<<0)
42 #define SNDRV_GF1_PCM_PFLG_NEUTRAL (2<<0)
62 static int snd_gf1_pcm_use_dma = 1;
95 block.addr = addr & ~31;
99 block.private_data = pcmp;
100 block.ack = snd_gf1_pcm_block_change_ack;
112 unsigned char voice_ctrl, ramp_ctrl;
121 spin_unlock_irqrestore(&pcmp->
lock, flags);
126 spin_unlock_irqrestore(&pcmp->
lock, flags);
136 for (voice = 0; voice < pcmp->
voices; voice++) {
146 pan = runtime->
channels == 2 ? (!voice ? 1 : 14) : 8;
147 vol = !voice ? gus->
gf1.pcm_volume_level_left : gus->
gf1.pcm_volume_level_right;
149 snd_gf1_select_voice(gus, pcmp->
pvoices[voice]->number);
160 if (!gus->
gf1.enh_mode) {
164 spin_unlock_irqrestore(&gus->
reg_lock, flags);
167 for (voice = 0; voice < pcmp->
voices; voice++) {
168 snd_gf1_select_voice(gus, pcmp->
pvoices[voice]->number);
169 if (gus->
gf1.enh_mode)
175 if (!gus->
gf1.enh_mode) {
177 for (voice = 0; voice < pcmp->
voices; voice++) {
178 snd_gf1_select_voice(gus, pcmp->
pvoices[voice]->number);
183 spin_unlock_irqrestore(&gus->
reg_lock, flags);
186 static void snd_gf1_pcm_interrupt_wave(
struct snd_gus_card * gus,
191 unsigned char voice_ctrl, ramp_ctrl;
196 snd_printd(
"snd_gf1_pcm: unknown wave irq?\n");
202 snd_printd(
"snd_gf1_pcm: unknown wave irq?\n");
210 snd_gf1_select_voice(gus, pvoice->
number);
214 snd_gf1_select_voice(gus, pvoice->
number);
217 snd_gf1_select_voice(gus, pcmp->
pvoices[1]->number);
220 snd_gf1_select_voice(gus, pvoice->
number);
230 end -= voice_ctrl & 4 ? 2 : 1;
237 for (idx = 0; idx < pcmp->
voices; idx++, end +=
step) {
238 snd_gf1_select_voice(gus, pcmp->
pvoices[idx]->number);
244 if (!gus->
gf1.enh_mode) {
247 for (idx = 0; idx < pcmp->
voices; idx++) {
248 snd_gf1_select_voice(gus, pcmp->
pvoices[idx]->number);
258 if ((runtime->flags & SNDRV_PCM_FLG_MMAP) &&
271 static void snd_gf1_pcm_interrupt_volume(
struct snd_gus_card * gus,
280 snd_gf1_select_voice(gus, pvoice->
number);
289 cvoice = pcmp->
pvoices[0] == pvoice ? 0 : 1;
292 vol = !cvoice ? gus->
gf1.pcm_volume_level_left : gus->
gf1.pcm_volume_level_right;
294 snd_gf1_select_voice(gus, pvoice->
number);
300 static void snd_gf1_pcm_volume_change(
struct snd_gus_card * gus)
304 static int snd_gf1_pcm_poke_block(
struct snd_gus_card *gus,
unsigned char *
buf,
305 unsigned int pos,
unsigned int count,
327 outsw(
GUSP(gus, GF1DATALOW), buf, len >> 1);
331 spin_unlock_irqrestore(&gus->
reg_lock, flags);
335 invert = invert ? 0x80 : 0x00;
364 unsigned int bpos, len;
366 bpos = samples_to_bytes(runtime, pos) + (voice * (pcmp->
dma_size / 2));
367 len = samples_to_bytes(runtime, count);
374 if (snd_gf1_pcm_use_dma && len > 32) {
375 return snd_gf1_pcm_block_change(substream, bpos, pcmp->
memory + bpos, len);
378 int err, w16, invert;
382 if ((err = snd_gf1_pcm_poke_block(gus, runtime->
dma_area + bpos, pcmp->
memory + bpos, len, w16, invert)) < 0)
395 unsigned int bpos, len;
397 bpos = samples_to_bytes(runtime, pos) + (voice * (pcmp->
dma_size / 2));
398 len = samples_to_bytes(runtime, count);
404 if (snd_gf1_pcm_use_dma && len > 32) {
405 return snd_gf1_pcm_block_change(substream, bpos, pcmp->
memory + bpos, len);
408 int err, w16, invert;
412 if ((err = snd_gf1_pcm_poke_block(gus, runtime->
dma_area + bpos, pcmp->
memory + bpos, len, w16, invert)) < 0)
446 pcmp->
pvoices[0]->handler_wave = snd_gf1_pcm_interrupt_wave;
447 pcmp->
pvoices[0]->handler_volume = snd_gf1_pcm_interrupt_volume;
448 pcmp->
pvoices[0]->volume_change = snd_gf1_pcm_volume_change;
449 pcmp->
pvoices[0]->private_data = pcmp;
454 pcmp->
pvoices[1]->handler_wave = snd_gf1_pcm_interrupt_wave;
455 pcmp->
pvoices[1]->handler_volume = snd_gf1_pcm_interrupt_volume;
456 pcmp->
pvoices[1]->volume_change = snd_gf1_pcm_volume_change;
457 pcmp->
pvoices[1]->private_data = pcmp;
458 }
else if (pcmp->
voices == 1) {
494 pcmp->
dma_size = snd_pcm_lib_buffer_bytes(substream);
495 pcmp->
block_size = snd_pcm_lib_period_bytes(substream);
509 snd_gf1_pcm_trigger_up(substream);
511 spin_lock(&pcmp->
lock);
513 spin_unlock(&pcmp->
lock);
514 voice = pcmp->
pvoices[0]->number;
517 voice = pcmp->
pvoices[1]->number;
537 snd_gf1_select_voice(gus, pcmp->
pvoices[0]->number);
542 pos = bytes_to_frames(runtime, pos);
568 gus->
gf1.pcm_rcntrl_reg = 0x21;
570 gus->
gf1.pcm_rcntrl_reg |= 2;
571 if (gus->
gf1.dma2 > 3)
572 gus->
gf1.pcm_rcntrl_reg |= 4;
574 gus->
gf1.pcm_rcntrl_reg |= 0x80;
602 val = gus->
gf1.pcm_rcntrl_reg;
624 static void snd_gf1_pcm_interrupt_dma_read(
struct snd_gus_card * gus)
647 .period_bytes_min = 64,
648 .period_bytes_max = (128*1024),
665 .period_bytes_min = 64,
666 .period_bytes_max = (128*1024),
697 (
long)
pcm->playback.buffer, (
long) gus->
gf1.pcm_buffer);
703 runtime->
hw = snd_gf1_pcm_playback;
704 snd_pcm_limit_isa_dma_size(gus->
gf1.dma1, &runtime->
hw.buffer_bytes_max);
705 snd_pcm_limit_isa_dma_size(gus->
gf1.dma1, &runtime->
hw.period_bytes_max);
728 gus->
gf1.interrupt_handler_dma_read = snd_gf1_pcm_interrupt_dma_read;
730 substream->
runtime->hw = snd_gf1_pcm_capture;
731 snd_pcm_limit_isa_dma_size(gus->
gf1.dma2, &runtime->
hw.buffer_bytes_max);
732 snd_pcm_limit_isa_dma_size(gus->
gf1.dma2, &runtime->
hw.period_bytes_max);
734 &hw_constraints_clocks);
762 ucontrol->
value.integer.value[0] = gus->
gf1.pcm_volume_level_left1;
763 ucontrol->
value.integer.value[1] = gus->
gf1.pcm_volume_level_right1;
774 unsigned short val1, val2,
vol;
778 val1 = ucontrol->
value.integer.value[0] & 127;
779 val2 = ucontrol->
value.integer.value[1] & 127;
781 change = val1 != gus->
gf1.pcm_volume_level_left1 ||
782 val2 != gus->
gf1.pcm_volume_level_right1;
783 gus->
gf1.pcm_volume_level_left1 = val1;
784 gus->
gf1.pcm_volume_level_right1 = val2;
790 for (idx = 0; idx < 32; idx++) {
791 pvoice = &gus->
gf1.voices[
idx];
799 snd_gf1_select_voice(gus, pvoice->
number);
801 vol = pvoice == pcmp->
pvoices[0] ? gus->
gf1.pcm_volume_level_left : gus->
gf1.pcm_volume_level_right;
813 .name =
"PCM Playback Volume",
814 .info = snd_gf1_pcm_volume_info,
815 .get = snd_gf1_pcm_volume_get,
816 .put = snd_gf1_pcm_volume_put
822 .name =
"GPCM Playback Volume",
823 .info = snd_gf1_pcm_volume_info,
824 .get = snd_gf1_pcm_volume_get,
825 .put = snd_gf1_pcm_volume_put
828 static struct snd_pcm_ops snd_gf1_pcm_playback_ops = {
829 .open = snd_gf1_pcm_playback_open,
830 .close = snd_gf1_pcm_playback_close,
832 .hw_params = snd_gf1_pcm_playback_hw_params,
833 .hw_free = snd_gf1_pcm_playback_hw_free,
834 .prepare = snd_gf1_pcm_playback_prepare,
835 .trigger = snd_gf1_pcm_playback_trigger,
836 .pointer = snd_gf1_pcm_playback_pointer,
837 .copy = snd_gf1_pcm_playback_copy,
838 .silence = snd_gf1_pcm_playback_silence,
841 static struct snd_pcm_ops snd_gf1_pcm_capture_ops = {
842 .open = snd_gf1_pcm_capture_open,
843 .close = snd_gf1_pcm_capture_close,
845 .hw_params = snd_gf1_pcm_capture_hw_params,
846 .hw_free = snd_gf1_pcm_capture_hw_free,
847 .prepare = snd_gf1_pcm_capture_prepare,
848 .trigger = snd_gf1_pcm_capture_trigger,
849 .pointer = snd_gf1_pcm_capture_pointer,
865 gus->
interwave ?
"AMD InterWave" :
"GF1",
867 gus->
gf1.pcm_channels / 2,
879 64*1024, gus->
gf1.dma1 > 3 ? 128*1024 : 64*1024);
885 if (gus->
gf1.dma2 == gus->
gf1.dma1)
889 64*1024, gus->
gf1.dma2 > 3 ? 128*1024 : 64*1024);
904 kctl->
id.index = control_index;