18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 48c2ecf20Sopenharmony_ci * Routines for control of GF1 chip (PCM things) 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * InterWave chips supports interleaved DMA, but this feature isn't used in 78c2ecf20Sopenharmony_ci * this code. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * This code emulates autoinit DMA transfer for playback, recording by GF1 108c2ecf20Sopenharmony_ci * chip doesn't support autoinit DMA. 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <asm/dma.h> 148c2ecf20Sopenharmony_ci#include <linux/slab.h> 158c2ecf20Sopenharmony_ci#include <linux/sched/signal.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <sound/core.h> 188c2ecf20Sopenharmony_ci#include <sound/control.h> 198c2ecf20Sopenharmony_ci#include <sound/gus.h> 208c2ecf20Sopenharmony_ci#include <sound/pcm_params.h> 218c2ecf20Sopenharmony_ci#include "gus_tables.h" 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci/* maximum rate */ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define SNDRV_GF1_PCM_RATE 48000 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define SNDRV_GF1_PCM_PFLG_NONE 0 288c2ecf20Sopenharmony_ci#define SNDRV_GF1_PCM_PFLG_ACTIVE (1<<0) 298c2ecf20Sopenharmony_ci#define SNDRV_GF1_PCM_PFLG_NEUTRAL (2<<0) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistruct gus_pcm_private { 328c2ecf20Sopenharmony_ci struct snd_gus_card * gus; 338c2ecf20Sopenharmony_ci struct snd_pcm_substream *substream; 348c2ecf20Sopenharmony_ci spinlock_t lock; 358c2ecf20Sopenharmony_ci unsigned int voices; 368c2ecf20Sopenharmony_ci struct snd_gus_voice *pvoices[2]; 378c2ecf20Sopenharmony_ci unsigned int memory; 388c2ecf20Sopenharmony_ci unsigned short flags; 398c2ecf20Sopenharmony_ci unsigned char voice_ctrl, ramp_ctrl; 408c2ecf20Sopenharmony_ci unsigned int bpos; 418c2ecf20Sopenharmony_ci unsigned int blocks; 428c2ecf20Sopenharmony_ci unsigned int block_size; 438c2ecf20Sopenharmony_ci unsigned int dma_size; 448c2ecf20Sopenharmony_ci wait_queue_head_t sleep; 458c2ecf20Sopenharmony_ci atomic_t dma_count; 468c2ecf20Sopenharmony_ci int final_volume; 478c2ecf20Sopenharmony_ci}; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistatic void snd_gf1_pcm_block_change_ack(struct snd_gus_card * gus, void *private_data) 508c2ecf20Sopenharmony_ci{ 518c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp = private_data; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci if (pcmp) { 548c2ecf20Sopenharmony_ci atomic_dec(&pcmp->dma_count); 558c2ecf20Sopenharmony_ci wake_up(&pcmp->sleep); 568c2ecf20Sopenharmony_ci } 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_block_change(struct snd_pcm_substream *substream, 608c2ecf20Sopenharmony_ci unsigned int offset, 618c2ecf20Sopenharmony_ci unsigned int addr, 628c2ecf20Sopenharmony_ci unsigned int count) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci struct snd_gf1_dma_block block; 658c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 668c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp = runtime->private_data; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci count += offset & 31; 698c2ecf20Sopenharmony_ci offset &= ~31; 708c2ecf20Sopenharmony_ci /* 718c2ecf20Sopenharmony_ci snd_printk(KERN_DEBUG "block change - offset = 0x%x, count = 0x%x\n", 728c2ecf20Sopenharmony_ci offset, count); 738c2ecf20Sopenharmony_ci */ 748c2ecf20Sopenharmony_ci memset(&block, 0, sizeof(block)); 758c2ecf20Sopenharmony_ci block.cmd = SNDRV_GF1_DMA_IRQ; 768c2ecf20Sopenharmony_ci if (snd_pcm_format_unsigned(runtime->format)) 778c2ecf20Sopenharmony_ci block.cmd |= SNDRV_GF1_DMA_UNSIGNED; 788c2ecf20Sopenharmony_ci if (snd_pcm_format_width(runtime->format) == 16) 798c2ecf20Sopenharmony_ci block.cmd |= SNDRV_GF1_DMA_16BIT; 808c2ecf20Sopenharmony_ci block.addr = addr & ~31; 818c2ecf20Sopenharmony_ci block.buffer = runtime->dma_area + offset; 828c2ecf20Sopenharmony_ci block.buf_addr = runtime->dma_addr + offset; 838c2ecf20Sopenharmony_ci block.count = count; 848c2ecf20Sopenharmony_ci block.private_data = pcmp; 858c2ecf20Sopenharmony_ci block.ack = snd_gf1_pcm_block_change_ack; 868c2ecf20Sopenharmony_ci if (!snd_gf1_dma_transfer_block(pcmp->gus, &block, 0, 0)) 878c2ecf20Sopenharmony_ci atomic_inc(&pcmp->dma_count); 888c2ecf20Sopenharmony_ci return 0; 898c2ecf20Sopenharmony_ci} 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic void snd_gf1_pcm_trigger_up(struct snd_pcm_substream *substream) 928c2ecf20Sopenharmony_ci{ 938c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 948c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp = runtime->private_data; 958c2ecf20Sopenharmony_ci struct snd_gus_card * gus = pcmp->gus; 968c2ecf20Sopenharmony_ci unsigned long flags; 978c2ecf20Sopenharmony_ci unsigned char voice_ctrl, ramp_ctrl; 988c2ecf20Sopenharmony_ci unsigned short rate; 998c2ecf20Sopenharmony_ci unsigned int curr, begin, end; 1008c2ecf20Sopenharmony_ci unsigned short vol; 1018c2ecf20Sopenharmony_ci unsigned char pan; 1028c2ecf20Sopenharmony_ci unsigned int voice; 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci spin_lock_irqsave(&pcmp->lock, flags); 1058c2ecf20Sopenharmony_ci if (pcmp->flags & SNDRV_GF1_PCM_PFLG_ACTIVE) { 1068c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pcmp->lock, flags); 1078c2ecf20Sopenharmony_ci return; 1088c2ecf20Sopenharmony_ci } 1098c2ecf20Sopenharmony_ci pcmp->flags |= SNDRV_GF1_PCM_PFLG_ACTIVE; 1108c2ecf20Sopenharmony_ci pcmp->final_volume = 0; 1118c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pcmp->lock, flags); 1128c2ecf20Sopenharmony_ci rate = snd_gf1_translate_freq(gus, runtime->rate << 4); 1138c2ecf20Sopenharmony_ci /* enable WAVE IRQ */ 1148c2ecf20Sopenharmony_ci voice_ctrl = snd_pcm_format_width(runtime->format) == 16 ? 0x24 : 0x20; 1158c2ecf20Sopenharmony_ci /* enable RAMP IRQ + rollover */ 1168c2ecf20Sopenharmony_ci ramp_ctrl = 0x24; 1178c2ecf20Sopenharmony_ci if (pcmp->blocks == 1) { 1188c2ecf20Sopenharmony_ci voice_ctrl |= 0x08; /* loop enable */ 1198c2ecf20Sopenharmony_ci ramp_ctrl &= ~0x04; /* disable rollover */ 1208c2ecf20Sopenharmony_ci } 1218c2ecf20Sopenharmony_ci for (voice = 0; voice < pcmp->voices; voice++) { 1228c2ecf20Sopenharmony_ci begin = pcmp->memory + voice * (pcmp->dma_size / runtime->channels); 1238c2ecf20Sopenharmony_ci curr = begin + (pcmp->bpos * pcmp->block_size) / runtime->channels; 1248c2ecf20Sopenharmony_ci end = curr + (pcmp->block_size / runtime->channels); 1258c2ecf20Sopenharmony_ci end -= snd_pcm_format_width(runtime->format) == 16 ? 2 : 1; 1268c2ecf20Sopenharmony_ci /* 1278c2ecf20Sopenharmony_ci snd_printk(KERN_DEBUG "init: curr=0x%x, begin=0x%x, end=0x%x, " 1288c2ecf20Sopenharmony_ci "ctrl=0x%x, ramp=0x%x, rate=0x%x\n", 1298c2ecf20Sopenharmony_ci curr, begin, end, voice_ctrl, ramp_ctrl, rate); 1308c2ecf20Sopenharmony_ci */ 1318c2ecf20Sopenharmony_ci pan = runtime->channels == 2 ? (!voice ? 1 : 14) : 8; 1328c2ecf20Sopenharmony_ci vol = !voice ? gus->gf1.pcm_volume_level_left : gus->gf1.pcm_volume_level_right; 1338c2ecf20Sopenharmony_ci spin_lock_irqsave(&gus->reg_lock, flags); 1348c2ecf20Sopenharmony_ci snd_gf1_select_voice(gus, pcmp->pvoices[voice]->number); 1358c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_VB_PAN, pan); 1368c2ecf20Sopenharmony_ci snd_gf1_write16(gus, SNDRV_GF1_VW_FREQUENCY, rate); 1378c2ecf20Sopenharmony_ci snd_gf1_write_addr(gus, SNDRV_GF1_VA_START, begin << 4, voice_ctrl & 4); 1388c2ecf20Sopenharmony_ci snd_gf1_write_addr(gus, SNDRV_GF1_VA_END, end << 4, voice_ctrl & 4); 1398c2ecf20Sopenharmony_ci snd_gf1_write_addr(gus, SNDRV_GF1_VA_CURRENT, curr << 4, voice_ctrl & 4); 1408c2ecf20Sopenharmony_ci snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, SNDRV_GF1_MIN_VOLUME << 4); 1418c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_RATE, 0x2f); 1428c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_START, SNDRV_GF1_MIN_OFFSET); 1438c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_END, vol >> 8); 1448c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, ramp_ctrl); 1458c2ecf20Sopenharmony_ci if (!gus->gf1.enh_mode) { 1468c2ecf20Sopenharmony_ci snd_gf1_delay(gus); 1478c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, ramp_ctrl); 1488c2ecf20Sopenharmony_ci } 1498c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&gus->reg_lock, flags); 1508c2ecf20Sopenharmony_ci } 1518c2ecf20Sopenharmony_ci spin_lock_irqsave(&gus->reg_lock, flags); 1528c2ecf20Sopenharmony_ci for (voice = 0; voice < pcmp->voices; voice++) { 1538c2ecf20Sopenharmony_ci snd_gf1_select_voice(gus, pcmp->pvoices[voice]->number); 1548c2ecf20Sopenharmony_ci if (gus->gf1.enh_mode) 1558c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_VB_MODE, 0x00); /* deactivate voice */ 1568c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, voice_ctrl); 1578c2ecf20Sopenharmony_ci voice_ctrl &= ~0x20; 1588c2ecf20Sopenharmony_ci } 1598c2ecf20Sopenharmony_ci voice_ctrl |= 0x20; 1608c2ecf20Sopenharmony_ci if (!gus->gf1.enh_mode) { 1618c2ecf20Sopenharmony_ci snd_gf1_delay(gus); 1628c2ecf20Sopenharmony_ci for (voice = 0; voice < pcmp->voices; voice++) { 1638c2ecf20Sopenharmony_ci snd_gf1_select_voice(gus, pcmp->pvoices[voice]->number); 1648c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, voice_ctrl); 1658c2ecf20Sopenharmony_ci voice_ctrl &= ~0x20; /* disable IRQ for next voice */ 1668c2ecf20Sopenharmony_ci } 1678c2ecf20Sopenharmony_ci } 1688c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&gus->reg_lock, flags); 1698c2ecf20Sopenharmony_ci} 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_cistatic void snd_gf1_pcm_interrupt_wave(struct snd_gus_card * gus, 1728c2ecf20Sopenharmony_ci struct snd_gus_voice *pvoice) 1738c2ecf20Sopenharmony_ci{ 1748c2ecf20Sopenharmony_ci struct gus_pcm_private * pcmp; 1758c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime; 1768c2ecf20Sopenharmony_ci unsigned char voice_ctrl, ramp_ctrl; 1778c2ecf20Sopenharmony_ci unsigned int idx; 1788c2ecf20Sopenharmony_ci unsigned int end, step; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci if (!pvoice->private_data) { 1818c2ecf20Sopenharmony_ci snd_printd("snd_gf1_pcm: unknown wave irq?\n"); 1828c2ecf20Sopenharmony_ci snd_gf1_smart_stop_voice(gus, pvoice->number); 1838c2ecf20Sopenharmony_ci return; 1848c2ecf20Sopenharmony_ci } 1858c2ecf20Sopenharmony_ci pcmp = pvoice->private_data; 1868c2ecf20Sopenharmony_ci if (pcmp == NULL) { 1878c2ecf20Sopenharmony_ci snd_printd("snd_gf1_pcm: unknown wave irq?\n"); 1888c2ecf20Sopenharmony_ci snd_gf1_smart_stop_voice(gus, pvoice->number); 1898c2ecf20Sopenharmony_ci return; 1908c2ecf20Sopenharmony_ci } 1918c2ecf20Sopenharmony_ci gus = pcmp->gus; 1928c2ecf20Sopenharmony_ci runtime = pcmp->substream->runtime; 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci spin_lock(&gus->reg_lock); 1958c2ecf20Sopenharmony_ci snd_gf1_select_voice(gus, pvoice->number); 1968c2ecf20Sopenharmony_ci voice_ctrl = snd_gf1_read8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL) & ~0x8b; 1978c2ecf20Sopenharmony_ci ramp_ctrl = (snd_gf1_read8(gus, SNDRV_GF1_VB_VOLUME_CONTROL) & ~0xa4) | 0x03; 1988c2ecf20Sopenharmony_ci#if 0 1998c2ecf20Sopenharmony_ci snd_gf1_select_voice(gus, pvoice->number); 2008c2ecf20Sopenharmony_ci printk(KERN_DEBUG "position = 0x%x\n", 2018c2ecf20Sopenharmony_ci (snd_gf1_read_addr(gus, SNDRV_GF1_VA_CURRENT, voice_ctrl & 4) >> 4)); 2028c2ecf20Sopenharmony_ci snd_gf1_select_voice(gus, pcmp->pvoices[1]->number); 2038c2ecf20Sopenharmony_ci printk(KERN_DEBUG "position = 0x%x\n", 2048c2ecf20Sopenharmony_ci (snd_gf1_read_addr(gus, SNDRV_GF1_VA_CURRENT, voice_ctrl & 4) >> 4)); 2058c2ecf20Sopenharmony_ci snd_gf1_select_voice(gus, pvoice->number); 2068c2ecf20Sopenharmony_ci#endif 2078c2ecf20Sopenharmony_ci pcmp->bpos++; 2088c2ecf20Sopenharmony_ci pcmp->bpos %= pcmp->blocks; 2098c2ecf20Sopenharmony_ci if (pcmp->bpos + 1 >= pcmp->blocks) { /* last block? */ 2108c2ecf20Sopenharmony_ci voice_ctrl |= 0x08; /* enable loop */ 2118c2ecf20Sopenharmony_ci } else { 2128c2ecf20Sopenharmony_ci ramp_ctrl |= 0x04; /* enable rollover */ 2138c2ecf20Sopenharmony_ci } 2148c2ecf20Sopenharmony_ci end = pcmp->memory + (((pcmp->bpos + 1) * pcmp->block_size) / runtime->channels); 2158c2ecf20Sopenharmony_ci end -= voice_ctrl & 4 ? 2 : 1; 2168c2ecf20Sopenharmony_ci step = pcmp->dma_size / runtime->channels; 2178c2ecf20Sopenharmony_ci voice_ctrl |= 0x20; 2188c2ecf20Sopenharmony_ci if (!pcmp->final_volume) { 2198c2ecf20Sopenharmony_ci ramp_ctrl |= 0x20; 2208c2ecf20Sopenharmony_ci ramp_ctrl &= ~0x03; 2218c2ecf20Sopenharmony_ci } 2228c2ecf20Sopenharmony_ci for (idx = 0; idx < pcmp->voices; idx++, end += step) { 2238c2ecf20Sopenharmony_ci snd_gf1_select_voice(gus, pcmp->pvoices[idx]->number); 2248c2ecf20Sopenharmony_ci snd_gf1_write_addr(gus, SNDRV_GF1_VA_END, end << 4, voice_ctrl & 4); 2258c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, voice_ctrl); 2268c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, ramp_ctrl); 2278c2ecf20Sopenharmony_ci voice_ctrl &= ~0x20; 2288c2ecf20Sopenharmony_ci } 2298c2ecf20Sopenharmony_ci if (!gus->gf1.enh_mode) { 2308c2ecf20Sopenharmony_ci snd_gf1_delay(gus); 2318c2ecf20Sopenharmony_ci voice_ctrl |= 0x20; 2328c2ecf20Sopenharmony_ci for (idx = 0; idx < pcmp->voices; idx++) { 2338c2ecf20Sopenharmony_ci snd_gf1_select_voice(gus, pcmp->pvoices[idx]->number); 2348c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, voice_ctrl); 2358c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, ramp_ctrl); 2368c2ecf20Sopenharmony_ci voice_ctrl &= ~0x20; 2378c2ecf20Sopenharmony_ci } 2388c2ecf20Sopenharmony_ci } 2398c2ecf20Sopenharmony_ci spin_unlock(&gus->reg_lock); 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci snd_pcm_period_elapsed(pcmp->substream); 2428c2ecf20Sopenharmony_ci#if 0 2438c2ecf20Sopenharmony_ci if ((runtime->flags & SNDRV_PCM_FLG_MMAP) && 2448c2ecf20Sopenharmony_ci *runtime->state == SNDRV_PCM_STATE_RUNNING) { 2458c2ecf20Sopenharmony_ci end = pcmp->bpos * pcmp->block_size; 2468c2ecf20Sopenharmony_ci if (runtime->channels > 1) { 2478c2ecf20Sopenharmony_ci snd_gf1_pcm_block_change(pcmp->substream, end, pcmp->memory + (end / 2), pcmp->block_size / 2); 2488c2ecf20Sopenharmony_ci snd_gf1_pcm_block_change(pcmp->substream, end + (pcmp->block_size / 2), pcmp->memory + (pcmp->dma_size / 2) + (end / 2), pcmp->block_size / 2); 2498c2ecf20Sopenharmony_ci } else { 2508c2ecf20Sopenharmony_ci snd_gf1_pcm_block_change(pcmp->substream, end, pcmp->memory + end, pcmp->block_size); 2518c2ecf20Sopenharmony_ci } 2528c2ecf20Sopenharmony_ci } 2538c2ecf20Sopenharmony_ci#endif 2548c2ecf20Sopenharmony_ci} 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_cistatic void snd_gf1_pcm_interrupt_volume(struct snd_gus_card * gus, 2578c2ecf20Sopenharmony_ci struct snd_gus_voice * pvoice) 2588c2ecf20Sopenharmony_ci{ 2598c2ecf20Sopenharmony_ci unsigned short vol; 2608c2ecf20Sopenharmony_ci int cvoice; 2618c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp = pvoice->private_data; 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci /* stop ramp, but leave rollover bit untouched */ 2648c2ecf20Sopenharmony_ci spin_lock(&gus->reg_lock); 2658c2ecf20Sopenharmony_ci snd_gf1_select_voice(gus, pvoice->number); 2668c2ecf20Sopenharmony_ci snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL); 2678c2ecf20Sopenharmony_ci spin_unlock(&gus->reg_lock); 2688c2ecf20Sopenharmony_ci if (pcmp == NULL) 2698c2ecf20Sopenharmony_ci return; 2708c2ecf20Sopenharmony_ci /* are we active? */ 2718c2ecf20Sopenharmony_ci if (!(pcmp->flags & SNDRV_GF1_PCM_PFLG_ACTIVE)) 2728c2ecf20Sopenharmony_ci return; 2738c2ecf20Sopenharmony_ci /* load real volume - better precision */ 2748c2ecf20Sopenharmony_ci cvoice = pcmp->pvoices[0] == pvoice ? 0 : 1; 2758c2ecf20Sopenharmony_ci if (pcmp->substream == NULL) 2768c2ecf20Sopenharmony_ci return; 2778c2ecf20Sopenharmony_ci vol = !cvoice ? gus->gf1.pcm_volume_level_left : gus->gf1.pcm_volume_level_right; 2788c2ecf20Sopenharmony_ci spin_lock(&gus->reg_lock); 2798c2ecf20Sopenharmony_ci snd_gf1_select_voice(gus, pvoice->number); 2808c2ecf20Sopenharmony_ci snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, vol); 2818c2ecf20Sopenharmony_ci pcmp->final_volume = 1; 2828c2ecf20Sopenharmony_ci spin_unlock(&gus->reg_lock); 2838c2ecf20Sopenharmony_ci} 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_cistatic void snd_gf1_pcm_volume_change(struct snd_gus_card * gus) 2868c2ecf20Sopenharmony_ci{ 2878c2ecf20Sopenharmony_ci} 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_poke_block(struct snd_gus_card *gus, unsigned char *buf, 2908c2ecf20Sopenharmony_ci unsigned int pos, unsigned int count, 2918c2ecf20Sopenharmony_ci int w16, int invert) 2928c2ecf20Sopenharmony_ci{ 2938c2ecf20Sopenharmony_ci unsigned int len; 2948c2ecf20Sopenharmony_ci unsigned long flags; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci /* 2978c2ecf20Sopenharmony_ci printk(KERN_DEBUG 2988c2ecf20Sopenharmony_ci "poke block; buf = 0x%x, pos = %i, count = %i, port = 0x%x\n", 2998c2ecf20Sopenharmony_ci (int)buf, pos, count, gus->gf1.port); 3008c2ecf20Sopenharmony_ci */ 3018c2ecf20Sopenharmony_ci while (count > 0) { 3028c2ecf20Sopenharmony_ci len = count; 3038c2ecf20Sopenharmony_ci if (len > 512) /* limit, to allow IRQ */ 3048c2ecf20Sopenharmony_ci len = 512; 3058c2ecf20Sopenharmony_ci count -= len; 3068c2ecf20Sopenharmony_ci if (gus->interwave) { 3078c2ecf20Sopenharmony_ci spin_lock_irqsave(&gus->reg_lock, flags); 3088c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01 | (invert ? 0x08 : 0x00)); 3098c2ecf20Sopenharmony_ci snd_gf1_dram_addr(gus, pos); 3108c2ecf20Sopenharmony_ci if (w16) { 3118c2ecf20Sopenharmony_ci outb(SNDRV_GF1_GW_DRAM_IO16, GUSP(gus, GF1REGSEL)); 3128c2ecf20Sopenharmony_ci outsw(GUSP(gus, GF1DATALOW), buf, len >> 1); 3138c2ecf20Sopenharmony_ci } else { 3148c2ecf20Sopenharmony_ci outsb(GUSP(gus, DRAM), buf, len); 3158c2ecf20Sopenharmony_ci } 3168c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&gus->reg_lock, flags); 3178c2ecf20Sopenharmony_ci buf += 512; 3188c2ecf20Sopenharmony_ci pos += 512; 3198c2ecf20Sopenharmony_ci } else { 3208c2ecf20Sopenharmony_ci invert = invert ? 0x80 : 0x00; 3218c2ecf20Sopenharmony_ci if (w16) { 3228c2ecf20Sopenharmony_ci len >>= 1; 3238c2ecf20Sopenharmony_ci while (len--) { 3248c2ecf20Sopenharmony_ci snd_gf1_poke(gus, pos++, *buf++); 3258c2ecf20Sopenharmony_ci snd_gf1_poke(gus, pos++, *buf++ ^ invert); 3268c2ecf20Sopenharmony_ci } 3278c2ecf20Sopenharmony_ci } else { 3288c2ecf20Sopenharmony_ci while (len--) 3298c2ecf20Sopenharmony_ci snd_gf1_poke(gus, pos++, *buf++ ^ invert); 3308c2ecf20Sopenharmony_ci } 3318c2ecf20Sopenharmony_ci } 3328c2ecf20Sopenharmony_ci if (count > 0 && !in_interrupt()) { 3338c2ecf20Sopenharmony_ci schedule_timeout_interruptible(1); 3348c2ecf20Sopenharmony_ci if (signal_pending(current)) 3358c2ecf20Sopenharmony_ci return -EAGAIN; 3368c2ecf20Sopenharmony_ci } 3378c2ecf20Sopenharmony_ci } 3388c2ecf20Sopenharmony_ci return 0; 3398c2ecf20Sopenharmony_ci} 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_cistatic int get_bpos(struct gus_pcm_private *pcmp, int voice, unsigned int pos, 3428c2ecf20Sopenharmony_ci unsigned int len) 3438c2ecf20Sopenharmony_ci{ 3448c2ecf20Sopenharmony_ci unsigned int bpos = pos + (voice * (pcmp->dma_size / 2)); 3458c2ecf20Sopenharmony_ci if (snd_BUG_ON(bpos > pcmp->dma_size)) 3468c2ecf20Sopenharmony_ci return -EIO; 3478c2ecf20Sopenharmony_ci if (snd_BUG_ON(bpos + len > pcmp->dma_size)) 3488c2ecf20Sopenharmony_ci return -EIO; 3498c2ecf20Sopenharmony_ci return bpos; 3508c2ecf20Sopenharmony_ci} 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_cistatic int playback_copy_ack(struct snd_pcm_substream *substream, 3538c2ecf20Sopenharmony_ci unsigned int bpos, unsigned int len) 3548c2ecf20Sopenharmony_ci{ 3558c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 3568c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp = runtime->private_data; 3578c2ecf20Sopenharmony_ci struct snd_gus_card *gus = pcmp->gus; 3588c2ecf20Sopenharmony_ci int w16, invert; 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_ci if (len > 32) 3618c2ecf20Sopenharmony_ci return snd_gf1_pcm_block_change(substream, bpos, 3628c2ecf20Sopenharmony_ci pcmp->memory + bpos, len); 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci w16 = (snd_pcm_format_width(runtime->format) == 16); 3658c2ecf20Sopenharmony_ci invert = snd_pcm_format_unsigned(runtime->format); 3668c2ecf20Sopenharmony_ci return snd_gf1_pcm_poke_block(gus, runtime->dma_area + bpos, 3678c2ecf20Sopenharmony_ci pcmp->memory + bpos, len, w16, invert); 3688c2ecf20Sopenharmony_ci} 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_playback_copy(struct snd_pcm_substream *substream, 3718c2ecf20Sopenharmony_ci int voice, unsigned long pos, 3728c2ecf20Sopenharmony_ci void __user *src, unsigned long count) 3738c2ecf20Sopenharmony_ci{ 3748c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 3758c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp = runtime->private_data; 3768c2ecf20Sopenharmony_ci unsigned int len = count; 3778c2ecf20Sopenharmony_ci int bpos; 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci bpos = get_bpos(pcmp, voice, pos, len); 3808c2ecf20Sopenharmony_ci if (bpos < 0) 3818c2ecf20Sopenharmony_ci return pos; 3828c2ecf20Sopenharmony_ci if (copy_from_user(runtime->dma_area + bpos, src, len)) 3838c2ecf20Sopenharmony_ci return -EFAULT; 3848c2ecf20Sopenharmony_ci return playback_copy_ack(substream, bpos, len); 3858c2ecf20Sopenharmony_ci} 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_playback_copy_kernel(struct snd_pcm_substream *substream, 3888c2ecf20Sopenharmony_ci int voice, unsigned long pos, 3898c2ecf20Sopenharmony_ci void *src, unsigned long count) 3908c2ecf20Sopenharmony_ci{ 3918c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 3928c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp = runtime->private_data; 3938c2ecf20Sopenharmony_ci unsigned int len = count; 3948c2ecf20Sopenharmony_ci int bpos; 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci bpos = get_bpos(pcmp, voice, pos, len); 3978c2ecf20Sopenharmony_ci if (bpos < 0) 3988c2ecf20Sopenharmony_ci return pos; 3998c2ecf20Sopenharmony_ci memcpy(runtime->dma_area + bpos, src, len); 4008c2ecf20Sopenharmony_ci return playback_copy_ack(substream, bpos, len); 4018c2ecf20Sopenharmony_ci} 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_playback_silence(struct snd_pcm_substream *substream, 4048c2ecf20Sopenharmony_ci int voice, unsigned long pos, 4058c2ecf20Sopenharmony_ci unsigned long count) 4068c2ecf20Sopenharmony_ci{ 4078c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 4088c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp = runtime->private_data; 4098c2ecf20Sopenharmony_ci unsigned int len = count; 4108c2ecf20Sopenharmony_ci int bpos; 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci bpos = get_bpos(pcmp, voice, pos, len); 4138c2ecf20Sopenharmony_ci if (bpos < 0) 4148c2ecf20Sopenharmony_ci return pos; 4158c2ecf20Sopenharmony_ci snd_pcm_format_set_silence(runtime->format, runtime->dma_area + bpos, 4168c2ecf20Sopenharmony_ci bytes_to_samples(runtime, count)); 4178c2ecf20Sopenharmony_ci return playback_copy_ack(substream, bpos, len); 4188c2ecf20Sopenharmony_ci} 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_playback_hw_params(struct snd_pcm_substream *substream, 4218c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *hw_params) 4228c2ecf20Sopenharmony_ci{ 4238c2ecf20Sopenharmony_ci struct snd_gus_card *gus = snd_pcm_substream_chip(substream); 4248c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 4258c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp = runtime->private_data; 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci if (runtime->buffer_changed) { 4288c2ecf20Sopenharmony_ci struct snd_gf1_mem_block *block; 4298c2ecf20Sopenharmony_ci if (pcmp->memory > 0) { 4308c2ecf20Sopenharmony_ci snd_gf1_mem_free(&gus->gf1.mem_alloc, pcmp->memory); 4318c2ecf20Sopenharmony_ci pcmp->memory = 0; 4328c2ecf20Sopenharmony_ci } 4338c2ecf20Sopenharmony_ci if ((block = snd_gf1_mem_alloc(&gus->gf1.mem_alloc, 4348c2ecf20Sopenharmony_ci SNDRV_GF1_MEM_OWNER_DRIVER, 4358c2ecf20Sopenharmony_ci "GF1 PCM", 4368c2ecf20Sopenharmony_ci runtime->dma_bytes, 1, 32, 4378c2ecf20Sopenharmony_ci NULL)) == NULL) 4388c2ecf20Sopenharmony_ci return -ENOMEM; 4398c2ecf20Sopenharmony_ci pcmp->memory = block->ptr; 4408c2ecf20Sopenharmony_ci } 4418c2ecf20Sopenharmony_ci pcmp->voices = params_channels(hw_params); 4428c2ecf20Sopenharmony_ci if (pcmp->pvoices[0] == NULL) { 4438c2ecf20Sopenharmony_ci if ((pcmp->pvoices[0] = snd_gf1_alloc_voice(pcmp->gus, SNDRV_GF1_VOICE_TYPE_PCM, 0, 0)) == NULL) 4448c2ecf20Sopenharmony_ci return -ENOMEM; 4458c2ecf20Sopenharmony_ci pcmp->pvoices[0]->handler_wave = snd_gf1_pcm_interrupt_wave; 4468c2ecf20Sopenharmony_ci pcmp->pvoices[0]->handler_volume = snd_gf1_pcm_interrupt_volume; 4478c2ecf20Sopenharmony_ci pcmp->pvoices[0]->volume_change = snd_gf1_pcm_volume_change; 4488c2ecf20Sopenharmony_ci pcmp->pvoices[0]->private_data = pcmp; 4498c2ecf20Sopenharmony_ci } 4508c2ecf20Sopenharmony_ci if (pcmp->voices > 1 && pcmp->pvoices[1] == NULL) { 4518c2ecf20Sopenharmony_ci if ((pcmp->pvoices[1] = snd_gf1_alloc_voice(pcmp->gus, SNDRV_GF1_VOICE_TYPE_PCM, 0, 0)) == NULL) 4528c2ecf20Sopenharmony_ci return -ENOMEM; 4538c2ecf20Sopenharmony_ci pcmp->pvoices[1]->handler_wave = snd_gf1_pcm_interrupt_wave; 4548c2ecf20Sopenharmony_ci pcmp->pvoices[1]->handler_volume = snd_gf1_pcm_interrupt_volume; 4558c2ecf20Sopenharmony_ci pcmp->pvoices[1]->volume_change = snd_gf1_pcm_volume_change; 4568c2ecf20Sopenharmony_ci pcmp->pvoices[1]->private_data = pcmp; 4578c2ecf20Sopenharmony_ci } else if (pcmp->voices == 1) { 4588c2ecf20Sopenharmony_ci if (pcmp->pvoices[1]) { 4598c2ecf20Sopenharmony_ci snd_gf1_free_voice(pcmp->gus, pcmp->pvoices[1]); 4608c2ecf20Sopenharmony_ci pcmp->pvoices[1] = NULL; 4618c2ecf20Sopenharmony_ci } 4628c2ecf20Sopenharmony_ci } 4638c2ecf20Sopenharmony_ci return 0; 4648c2ecf20Sopenharmony_ci} 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_playback_hw_free(struct snd_pcm_substream *substream) 4678c2ecf20Sopenharmony_ci{ 4688c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 4698c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp = runtime->private_data; 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci if (pcmp->pvoices[0]) { 4728c2ecf20Sopenharmony_ci snd_gf1_free_voice(pcmp->gus, pcmp->pvoices[0]); 4738c2ecf20Sopenharmony_ci pcmp->pvoices[0] = NULL; 4748c2ecf20Sopenharmony_ci } 4758c2ecf20Sopenharmony_ci if (pcmp->pvoices[1]) { 4768c2ecf20Sopenharmony_ci snd_gf1_free_voice(pcmp->gus, pcmp->pvoices[1]); 4778c2ecf20Sopenharmony_ci pcmp->pvoices[1] = NULL; 4788c2ecf20Sopenharmony_ci } 4798c2ecf20Sopenharmony_ci if (pcmp->memory > 0) { 4808c2ecf20Sopenharmony_ci snd_gf1_mem_free(&pcmp->gus->gf1.mem_alloc, pcmp->memory); 4818c2ecf20Sopenharmony_ci pcmp->memory = 0; 4828c2ecf20Sopenharmony_ci } 4838c2ecf20Sopenharmony_ci return 0; 4848c2ecf20Sopenharmony_ci} 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_playback_prepare(struct snd_pcm_substream *substream) 4878c2ecf20Sopenharmony_ci{ 4888c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 4898c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp = runtime->private_data; 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci pcmp->bpos = 0; 4928c2ecf20Sopenharmony_ci pcmp->dma_size = snd_pcm_lib_buffer_bytes(substream); 4938c2ecf20Sopenharmony_ci pcmp->block_size = snd_pcm_lib_period_bytes(substream); 4948c2ecf20Sopenharmony_ci pcmp->blocks = pcmp->dma_size / pcmp->block_size; 4958c2ecf20Sopenharmony_ci return 0; 4968c2ecf20Sopenharmony_ci} 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_playback_trigger(struct snd_pcm_substream *substream, 4998c2ecf20Sopenharmony_ci int cmd) 5008c2ecf20Sopenharmony_ci{ 5018c2ecf20Sopenharmony_ci struct snd_gus_card *gus = snd_pcm_substream_chip(substream); 5028c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 5038c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp = runtime->private_data; 5048c2ecf20Sopenharmony_ci int voice; 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci if (cmd == SNDRV_PCM_TRIGGER_START) { 5078c2ecf20Sopenharmony_ci snd_gf1_pcm_trigger_up(substream); 5088c2ecf20Sopenharmony_ci } else if (cmd == SNDRV_PCM_TRIGGER_STOP) { 5098c2ecf20Sopenharmony_ci spin_lock(&pcmp->lock); 5108c2ecf20Sopenharmony_ci pcmp->flags &= ~SNDRV_GF1_PCM_PFLG_ACTIVE; 5118c2ecf20Sopenharmony_ci spin_unlock(&pcmp->lock); 5128c2ecf20Sopenharmony_ci voice = pcmp->pvoices[0]->number; 5138c2ecf20Sopenharmony_ci snd_gf1_stop_voices(gus, voice, voice); 5148c2ecf20Sopenharmony_ci if (pcmp->pvoices[1]) { 5158c2ecf20Sopenharmony_ci voice = pcmp->pvoices[1]->number; 5168c2ecf20Sopenharmony_ci snd_gf1_stop_voices(gus, voice, voice); 5178c2ecf20Sopenharmony_ci } 5188c2ecf20Sopenharmony_ci } else { 5198c2ecf20Sopenharmony_ci return -EINVAL; 5208c2ecf20Sopenharmony_ci } 5218c2ecf20Sopenharmony_ci return 0; 5228c2ecf20Sopenharmony_ci} 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_cistatic snd_pcm_uframes_t snd_gf1_pcm_playback_pointer(struct snd_pcm_substream *substream) 5258c2ecf20Sopenharmony_ci{ 5268c2ecf20Sopenharmony_ci struct snd_gus_card *gus = snd_pcm_substream_chip(substream); 5278c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 5288c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp = runtime->private_data; 5298c2ecf20Sopenharmony_ci unsigned int pos; 5308c2ecf20Sopenharmony_ci unsigned char voice_ctrl; 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci pos = 0; 5338c2ecf20Sopenharmony_ci spin_lock(&gus->reg_lock); 5348c2ecf20Sopenharmony_ci if (pcmp->flags & SNDRV_GF1_PCM_PFLG_ACTIVE) { 5358c2ecf20Sopenharmony_ci snd_gf1_select_voice(gus, pcmp->pvoices[0]->number); 5368c2ecf20Sopenharmony_ci voice_ctrl = snd_gf1_read8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL); 5378c2ecf20Sopenharmony_ci pos = (snd_gf1_read_addr(gus, SNDRV_GF1_VA_CURRENT, voice_ctrl & 4) >> 4) - pcmp->memory; 5388c2ecf20Sopenharmony_ci if (substream->runtime->channels > 1) 5398c2ecf20Sopenharmony_ci pos <<= 1; 5408c2ecf20Sopenharmony_ci pos = bytes_to_frames(runtime, pos); 5418c2ecf20Sopenharmony_ci } 5428c2ecf20Sopenharmony_ci spin_unlock(&gus->reg_lock); 5438c2ecf20Sopenharmony_ci return pos; 5448c2ecf20Sopenharmony_ci} 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_cistatic const struct snd_ratnum clock = { 5478c2ecf20Sopenharmony_ci .num = 9878400/16, 5488c2ecf20Sopenharmony_ci .den_min = 2, 5498c2ecf20Sopenharmony_ci .den_max = 257, 5508c2ecf20Sopenharmony_ci .den_step = 1, 5518c2ecf20Sopenharmony_ci}; 5528c2ecf20Sopenharmony_ci 5538c2ecf20Sopenharmony_cistatic const struct snd_pcm_hw_constraint_ratnums hw_constraints_clocks = { 5548c2ecf20Sopenharmony_ci .nrats = 1, 5558c2ecf20Sopenharmony_ci .rats = &clock, 5568c2ecf20Sopenharmony_ci}; 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_capture_hw_params(struct snd_pcm_substream *substream, 5598c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *hw_params) 5608c2ecf20Sopenharmony_ci{ 5618c2ecf20Sopenharmony_ci struct snd_gus_card *gus = snd_pcm_substream_chip(substream); 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci gus->c_dma_size = params_buffer_bytes(hw_params); 5648c2ecf20Sopenharmony_ci gus->c_period_size = params_period_bytes(hw_params); 5658c2ecf20Sopenharmony_ci gus->c_pos = 0; 5668c2ecf20Sopenharmony_ci gus->gf1.pcm_rcntrl_reg = 0x21; /* IRQ at end, enable & start */ 5678c2ecf20Sopenharmony_ci if (params_channels(hw_params) > 1) 5688c2ecf20Sopenharmony_ci gus->gf1.pcm_rcntrl_reg |= 2; 5698c2ecf20Sopenharmony_ci if (gus->gf1.dma2 > 3) 5708c2ecf20Sopenharmony_ci gus->gf1.pcm_rcntrl_reg |= 4; 5718c2ecf20Sopenharmony_ci if (snd_pcm_format_unsigned(params_format(hw_params))) 5728c2ecf20Sopenharmony_ci gus->gf1.pcm_rcntrl_reg |= 0x80; 5738c2ecf20Sopenharmony_ci return 0; 5748c2ecf20Sopenharmony_ci} 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_capture_prepare(struct snd_pcm_substream *substream) 5778c2ecf20Sopenharmony_ci{ 5788c2ecf20Sopenharmony_ci struct snd_gus_card *gus = snd_pcm_substream_chip(substream); 5798c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci snd_gf1_i_write8(gus, SNDRV_GF1_GB_RECORD_RATE, runtime->rate_den - 2); 5828c2ecf20Sopenharmony_ci snd_gf1_i_write8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL, 0); /* disable sampling */ 5838c2ecf20Sopenharmony_ci snd_gf1_i_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL); /* Sampling Control Register */ 5848c2ecf20Sopenharmony_ci snd_dma_program(gus->gf1.dma2, runtime->dma_addr, gus->c_period_size, DMA_MODE_READ); 5858c2ecf20Sopenharmony_ci return 0; 5868c2ecf20Sopenharmony_ci} 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_capture_trigger(struct snd_pcm_substream *substream, 5898c2ecf20Sopenharmony_ci int cmd) 5908c2ecf20Sopenharmony_ci{ 5918c2ecf20Sopenharmony_ci struct snd_gus_card *gus = snd_pcm_substream_chip(substream); 5928c2ecf20Sopenharmony_ci int val; 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci if (cmd == SNDRV_PCM_TRIGGER_START) { 5958c2ecf20Sopenharmony_ci val = gus->gf1.pcm_rcntrl_reg; 5968c2ecf20Sopenharmony_ci } else if (cmd == SNDRV_PCM_TRIGGER_STOP) { 5978c2ecf20Sopenharmony_ci val = 0; 5988c2ecf20Sopenharmony_ci } else { 5998c2ecf20Sopenharmony_ci return -EINVAL; 6008c2ecf20Sopenharmony_ci } 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci spin_lock(&gus->reg_lock); 6038c2ecf20Sopenharmony_ci snd_gf1_write8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL, val); 6048c2ecf20Sopenharmony_ci snd_gf1_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL); 6058c2ecf20Sopenharmony_ci spin_unlock(&gus->reg_lock); 6068c2ecf20Sopenharmony_ci return 0; 6078c2ecf20Sopenharmony_ci} 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_cistatic snd_pcm_uframes_t snd_gf1_pcm_capture_pointer(struct snd_pcm_substream *substream) 6108c2ecf20Sopenharmony_ci{ 6118c2ecf20Sopenharmony_ci struct snd_gus_card *gus = snd_pcm_substream_chip(substream); 6128c2ecf20Sopenharmony_ci int pos = snd_dma_pointer(gus->gf1.dma2, gus->c_period_size); 6138c2ecf20Sopenharmony_ci pos = bytes_to_frames(substream->runtime, (gus->c_pos + pos) % gus->c_dma_size); 6148c2ecf20Sopenharmony_ci return pos; 6158c2ecf20Sopenharmony_ci} 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_cistatic void snd_gf1_pcm_interrupt_dma_read(struct snd_gus_card * gus) 6188c2ecf20Sopenharmony_ci{ 6198c2ecf20Sopenharmony_ci snd_gf1_i_write8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL, 0); /* disable sampling */ 6208c2ecf20Sopenharmony_ci snd_gf1_i_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL); /* Sampling Control Register */ 6218c2ecf20Sopenharmony_ci if (gus->pcm_cap_substream != NULL) { 6228c2ecf20Sopenharmony_ci snd_gf1_pcm_capture_prepare(gus->pcm_cap_substream); 6238c2ecf20Sopenharmony_ci snd_gf1_pcm_capture_trigger(gus->pcm_cap_substream, SNDRV_PCM_TRIGGER_START); 6248c2ecf20Sopenharmony_ci gus->c_pos += gus->c_period_size; 6258c2ecf20Sopenharmony_ci snd_pcm_period_elapsed(gus->pcm_cap_substream); 6268c2ecf20Sopenharmony_ci } 6278c2ecf20Sopenharmony_ci} 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_cistatic const struct snd_pcm_hardware snd_gf1_pcm_playback = 6308c2ecf20Sopenharmony_ci{ 6318c2ecf20Sopenharmony_ci .info = SNDRV_PCM_INFO_NONINTERLEAVED, 6328c2ecf20Sopenharmony_ci .formats = (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 | 6338c2ecf20Sopenharmony_ci SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE), 6348c2ecf20Sopenharmony_ci .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, 6358c2ecf20Sopenharmony_ci .rate_min = 5510, 6368c2ecf20Sopenharmony_ci .rate_max = 48000, 6378c2ecf20Sopenharmony_ci .channels_min = 1, 6388c2ecf20Sopenharmony_ci .channels_max = 2, 6398c2ecf20Sopenharmony_ci .buffer_bytes_max = (128*1024), 6408c2ecf20Sopenharmony_ci .period_bytes_min = 64, 6418c2ecf20Sopenharmony_ci .period_bytes_max = (128*1024), 6428c2ecf20Sopenharmony_ci .periods_min = 1, 6438c2ecf20Sopenharmony_ci .periods_max = 1024, 6448c2ecf20Sopenharmony_ci .fifo_size = 0, 6458c2ecf20Sopenharmony_ci}; 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_cistatic const struct snd_pcm_hardware snd_gf1_pcm_capture = 6488c2ecf20Sopenharmony_ci{ 6498c2ecf20Sopenharmony_ci .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 6508c2ecf20Sopenharmony_ci SNDRV_PCM_INFO_MMAP_VALID), 6518c2ecf20Sopenharmony_ci .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8, 6528c2ecf20Sopenharmony_ci .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_44100, 6538c2ecf20Sopenharmony_ci .rate_min = 5510, 6548c2ecf20Sopenharmony_ci .rate_max = 44100, 6558c2ecf20Sopenharmony_ci .channels_min = 1, 6568c2ecf20Sopenharmony_ci .channels_max = 2, 6578c2ecf20Sopenharmony_ci .buffer_bytes_max = (128*1024), 6588c2ecf20Sopenharmony_ci .period_bytes_min = 64, 6598c2ecf20Sopenharmony_ci .period_bytes_max = (128*1024), 6608c2ecf20Sopenharmony_ci .periods_min = 1, 6618c2ecf20Sopenharmony_ci .periods_max = 1024, 6628c2ecf20Sopenharmony_ci .fifo_size = 0, 6638c2ecf20Sopenharmony_ci}; 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_cistatic void snd_gf1_pcm_playback_free(struct snd_pcm_runtime *runtime) 6668c2ecf20Sopenharmony_ci{ 6678c2ecf20Sopenharmony_ci kfree(runtime->private_data); 6688c2ecf20Sopenharmony_ci} 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_playback_open(struct snd_pcm_substream *substream) 6718c2ecf20Sopenharmony_ci{ 6728c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp; 6738c2ecf20Sopenharmony_ci struct snd_gus_card *gus = snd_pcm_substream_chip(substream); 6748c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 6758c2ecf20Sopenharmony_ci int err; 6768c2ecf20Sopenharmony_ci 6778c2ecf20Sopenharmony_ci pcmp = kzalloc(sizeof(*pcmp), GFP_KERNEL); 6788c2ecf20Sopenharmony_ci if (pcmp == NULL) 6798c2ecf20Sopenharmony_ci return -ENOMEM; 6808c2ecf20Sopenharmony_ci pcmp->gus = gus; 6818c2ecf20Sopenharmony_ci spin_lock_init(&pcmp->lock); 6828c2ecf20Sopenharmony_ci init_waitqueue_head(&pcmp->sleep); 6838c2ecf20Sopenharmony_ci atomic_set(&pcmp->dma_count, 0); 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_ci runtime->private_data = pcmp; 6868c2ecf20Sopenharmony_ci runtime->private_free = snd_gf1_pcm_playback_free; 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_ci#if 0 6898c2ecf20Sopenharmony_ci printk(KERN_DEBUG "playback.buffer = 0x%lx, gf1.pcm_buffer = 0x%lx\n", 6908c2ecf20Sopenharmony_ci (long) pcm->playback.buffer, (long) gus->gf1.pcm_buffer); 6918c2ecf20Sopenharmony_ci#endif 6928c2ecf20Sopenharmony_ci if ((err = snd_gf1_dma_init(gus)) < 0) 6938c2ecf20Sopenharmony_ci return err; 6948c2ecf20Sopenharmony_ci pcmp->flags = SNDRV_GF1_PCM_PFLG_NONE; 6958c2ecf20Sopenharmony_ci pcmp->substream = substream; 6968c2ecf20Sopenharmony_ci runtime->hw = snd_gf1_pcm_playback; 6978c2ecf20Sopenharmony_ci snd_pcm_limit_isa_dma_size(gus->gf1.dma1, &runtime->hw.buffer_bytes_max); 6988c2ecf20Sopenharmony_ci snd_pcm_limit_isa_dma_size(gus->gf1.dma1, &runtime->hw.period_bytes_max); 6998c2ecf20Sopenharmony_ci snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64); 7008c2ecf20Sopenharmony_ci return 0; 7018c2ecf20Sopenharmony_ci} 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_playback_close(struct snd_pcm_substream *substream) 7048c2ecf20Sopenharmony_ci{ 7058c2ecf20Sopenharmony_ci struct snd_gus_card *gus = snd_pcm_substream_chip(substream); 7068c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 7078c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp = runtime->private_data; 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci if (!wait_event_timeout(pcmp->sleep, (atomic_read(&pcmp->dma_count) <= 0), 2*HZ)) 7108c2ecf20Sopenharmony_ci snd_printk(KERN_ERR "gf1 pcm - serious DMA problem\n"); 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci snd_gf1_dma_done(gus); 7138c2ecf20Sopenharmony_ci return 0; 7148c2ecf20Sopenharmony_ci} 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_capture_open(struct snd_pcm_substream *substream) 7178c2ecf20Sopenharmony_ci{ 7188c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 7198c2ecf20Sopenharmony_ci struct snd_gus_card *gus = snd_pcm_substream_chip(substream); 7208c2ecf20Sopenharmony_ci 7218c2ecf20Sopenharmony_ci gus->gf1.interrupt_handler_dma_read = snd_gf1_pcm_interrupt_dma_read; 7228c2ecf20Sopenharmony_ci gus->pcm_cap_substream = substream; 7238c2ecf20Sopenharmony_ci substream->runtime->hw = snd_gf1_pcm_capture; 7248c2ecf20Sopenharmony_ci snd_pcm_limit_isa_dma_size(gus->gf1.dma2, &runtime->hw.buffer_bytes_max); 7258c2ecf20Sopenharmony_ci snd_pcm_limit_isa_dma_size(gus->gf1.dma2, &runtime->hw.period_bytes_max); 7268c2ecf20Sopenharmony_ci snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 7278c2ecf20Sopenharmony_ci &hw_constraints_clocks); 7288c2ecf20Sopenharmony_ci return 0; 7298c2ecf20Sopenharmony_ci} 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_capture_close(struct snd_pcm_substream *substream) 7328c2ecf20Sopenharmony_ci{ 7338c2ecf20Sopenharmony_ci struct snd_gus_card *gus = snd_pcm_substream_chip(substream); 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_ci gus->pcm_cap_substream = NULL; 7368c2ecf20Sopenharmony_ci snd_gf1_set_default_handlers(gus, SNDRV_GF1_HANDLER_DMA_READ); 7378c2ecf20Sopenharmony_ci return 0; 7388c2ecf20Sopenharmony_ci} 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 7418c2ecf20Sopenharmony_ci{ 7428c2ecf20Sopenharmony_ci uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 7438c2ecf20Sopenharmony_ci uinfo->count = 2; 7448c2ecf20Sopenharmony_ci uinfo->value.integer.min = 0; 7458c2ecf20Sopenharmony_ci uinfo->value.integer.max = 127; 7468c2ecf20Sopenharmony_ci return 0; 7478c2ecf20Sopenharmony_ci} 7488c2ecf20Sopenharmony_ci 7498c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 7508c2ecf20Sopenharmony_ci{ 7518c2ecf20Sopenharmony_ci struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol); 7528c2ecf20Sopenharmony_ci unsigned long flags; 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_ci spin_lock_irqsave(&gus->pcm_volume_level_lock, flags); 7558c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = gus->gf1.pcm_volume_level_left1; 7568c2ecf20Sopenharmony_ci ucontrol->value.integer.value[1] = gus->gf1.pcm_volume_level_right1; 7578c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&gus->pcm_volume_level_lock, flags); 7588c2ecf20Sopenharmony_ci return 0; 7598c2ecf20Sopenharmony_ci} 7608c2ecf20Sopenharmony_ci 7618c2ecf20Sopenharmony_cistatic int snd_gf1_pcm_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 7628c2ecf20Sopenharmony_ci{ 7638c2ecf20Sopenharmony_ci struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol); 7648c2ecf20Sopenharmony_ci unsigned long flags; 7658c2ecf20Sopenharmony_ci int change; 7668c2ecf20Sopenharmony_ci unsigned int idx; 7678c2ecf20Sopenharmony_ci unsigned short val1, val2, vol; 7688c2ecf20Sopenharmony_ci struct gus_pcm_private *pcmp; 7698c2ecf20Sopenharmony_ci struct snd_gus_voice *pvoice; 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_ci val1 = ucontrol->value.integer.value[0] & 127; 7728c2ecf20Sopenharmony_ci val2 = ucontrol->value.integer.value[1] & 127; 7738c2ecf20Sopenharmony_ci spin_lock_irqsave(&gus->pcm_volume_level_lock, flags); 7748c2ecf20Sopenharmony_ci change = val1 != gus->gf1.pcm_volume_level_left1 || 7758c2ecf20Sopenharmony_ci val2 != gus->gf1.pcm_volume_level_right1; 7768c2ecf20Sopenharmony_ci gus->gf1.pcm_volume_level_left1 = val1; 7778c2ecf20Sopenharmony_ci gus->gf1.pcm_volume_level_right1 = val2; 7788c2ecf20Sopenharmony_ci gus->gf1.pcm_volume_level_left = snd_gf1_lvol_to_gvol_raw(val1 << 9) << 4; 7798c2ecf20Sopenharmony_ci gus->gf1.pcm_volume_level_right = snd_gf1_lvol_to_gvol_raw(val2 << 9) << 4; 7808c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&gus->pcm_volume_level_lock, flags); 7818c2ecf20Sopenharmony_ci /* are we active? */ 7828c2ecf20Sopenharmony_ci spin_lock_irqsave(&gus->voice_alloc, flags); 7838c2ecf20Sopenharmony_ci for (idx = 0; idx < 32; idx++) { 7848c2ecf20Sopenharmony_ci pvoice = &gus->gf1.voices[idx]; 7858c2ecf20Sopenharmony_ci if (!pvoice->pcm) 7868c2ecf20Sopenharmony_ci continue; 7878c2ecf20Sopenharmony_ci pcmp = pvoice->private_data; 7888c2ecf20Sopenharmony_ci if (!(pcmp->flags & SNDRV_GF1_PCM_PFLG_ACTIVE)) 7898c2ecf20Sopenharmony_ci continue; 7908c2ecf20Sopenharmony_ci /* load real volume - better precision */ 7918c2ecf20Sopenharmony_ci spin_lock(&gus->reg_lock); 7928c2ecf20Sopenharmony_ci snd_gf1_select_voice(gus, pvoice->number); 7938c2ecf20Sopenharmony_ci snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL); 7948c2ecf20Sopenharmony_ci vol = pvoice == pcmp->pvoices[0] ? gus->gf1.pcm_volume_level_left : gus->gf1.pcm_volume_level_right; 7958c2ecf20Sopenharmony_ci snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, vol); 7968c2ecf20Sopenharmony_ci pcmp->final_volume = 1; 7978c2ecf20Sopenharmony_ci spin_unlock(&gus->reg_lock); 7988c2ecf20Sopenharmony_ci } 7998c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&gus->voice_alloc, flags); 8008c2ecf20Sopenharmony_ci return change; 8018c2ecf20Sopenharmony_ci} 8028c2ecf20Sopenharmony_ci 8038c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_gf1_pcm_volume_control = 8048c2ecf20Sopenharmony_ci{ 8058c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8068c2ecf20Sopenharmony_ci .name = "PCM Playback Volume", 8078c2ecf20Sopenharmony_ci .info = snd_gf1_pcm_volume_info, 8088c2ecf20Sopenharmony_ci .get = snd_gf1_pcm_volume_get, 8098c2ecf20Sopenharmony_ci .put = snd_gf1_pcm_volume_put 8108c2ecf20Sopenharmony_ci}; 8118c2ecf20Sopenharmony_ci 8128c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_gf1_pcm_volume_control1 = 8138c2ecf20Sopenharmony_ci{ 8148c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8158c2ecf20Sopenharmony_ci .name = "GPCM Playback Volume", 8168c2ecf20Sopenharmony_ci .info = snd_gf1_pcm_volume_info, 8178c2ecf20Sopenharmony_ci .get = snd_gf1_pcm_volume_get, 8188c2ecf20Sopenharmony_ci .put = snd_gf1_pcm_volume_put 8198c2ecf20Sopenharmony_ci}; 8208c2ecf20Sopenharmony_ci 8218c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_gf1_pcm_playback_ops = { 8228c2ecf20Sopenharmony_ci .open = snd_gf1_pcm_playback_open, 8238c2ecf20Sopenharmony_ci .close = snd_gf1_pcm_playback_close, 8248c2ecf20Sopenharmony_ci .hw_params = snd_gf1_pcm_playback_hw_params, 8258c2ecf20Sopenharmony_ci .hw_free = snd_gf1_pcm_playback_hw_free, 8268c2ecf20Sopenharmony_ci .prepare = snd_gf1_pcm_playback_prepare, 8278c2ecf20Sopenharmony_ci .trigger = snd_gf1_pcm_playback_trigger, 8288c2ecf20Sopenharmony_ci .pointer = snd_gf1_pcm_playback_pointer, 8298c2ecf20Sopenharmony_ci .copy_user = snd_gf1_pcm_playback_copy, 8308c2ecf20Sopenharmony_ci .copy_kernel = snd_gf1_pcm_playback_copy_kernel, 8318c2ecf20Sopenharmony_ci .fill_silence = snd_gf1_pcm_playback_silence, 8328c2ecf20Sopenharmony_ci}; 8338c2ecf20Sopenharmony_ci 8348c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_gf1_pcm_capture_ops = { 8358c2ecf20Sopenharmony_ci .open = snd_gf1_pcm_capture_open, 8368c2ecf20Sopenharmony_ci .close = snd_gf1_pcm_capture_close, 8378c2ecf20Sopenharmony_ci .hw_params = snd_gf1_pcm_capture_hw_params, 8388c2ecf20Sopenharmony_ci .prepare = snd_gf1_pcm_capture_prepare, 8398c2ecf20Sopenharmony_ci .trigger = snd_gf1_pcm_capture_trigger, 8408c2ecf20Sopenharmony_ci .pointer = snd_gf1_pcm_capture_pointer, 8418c2ecf20Sopenharmony_ci}; 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_ciint snd_gf1_pcm_new(struct snd_gus_card *gus, int pcm_dev, int control_index) 8448c2ecf20Sopenharmony_ci{ 8458c2ecf20Sopenharmony_ci struct snd_card *card; 8468c2ecf20Sopenharmony_ci struct snd_kcontrol *kctl; 8478c2ecf20Sopenharmony_ci struct snd_pcm *pcm; 8488c2ecf20Sopenharmony_ci struct snd_pcm_substream *substream; 8498c2ecf20Sopenharmony_ci int capture, err; 8508c2ecf20Sopenharmony_ci 8518c2ecf20Sopenharmony_ci card = gus->card; 8528c2ecf20Sopenharmony_ci capture = !gus->interwave && !gus->ess_flag && !gus->ace_flag ? 1 : 0; 8538c2ecf20Sopenharmony_ci err = snd_pcm_new(card, 8548c2ecf20Sopenharmony_ci gus->interwave ? "AMD InterWave" : "GF1", 8558c2ecf20Sopenharmony_ci pcm_dev, 8568c2ecf20Sopenharmony_ci gus->gf1.pcm_channels / 2, 8578c2ecf20Sopenharmony_ci capture, 8588c2ecf20Sopenharmony_ci &pcm); 8598c2ecf20Sopenharmony_ci if (err < 0) 8608c2ecf20Sopenharmony_ci return err; 8618c2ecf20Sopenharmony_ci pcm->private_data = gus; 8628c2ecf20Sopenharmony_ci /* playback setup */ 8638c2ecf20Sopenharmony_ci snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_gf1_pcm_playback_ops); 8648c2ecf20Sopenharmony_ci 8658c2ecf20Sopenharmony_ci for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) 8668c2ecf20Sopenharmony_ci snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV, 8678c2ecf20Sopenharmony_ci card->dev, 8688c2ecf20Sopenharmony_ci 64*1024, gus->gf1.dma1 > 3 ? 128*1024 : 64*1024); 8698c2ecf20Sopenharmony_ci 8708c2ecf20Sopenharmony_ci pcm->info_flags = 0; 8718c2ecf20Sopenharmony_ci pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; 8728c2ecf20Sopenharmony_ci if (capture) { 8738c2ecf20Sopenharmony_ci snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_gf1_pcm_capture_ops); 8748c2ecf20Sopenharmony_ci if (gus->gf1.dma2 == gus->gf1.dma1) 8758c2ecf20Sopenharmony_ci pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX; 8768c2ecf20Sopenharmony_ci snd_pcm_set_managed_buffer(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream, 8778c2ecf20Sopenharmony_ci SNDRV_DMA_TYPE_DEV, card->dev, 8788c2ecf20Sopenharmony_ci 64*1024, gus->gf1.dma2 > 3 ? 128*1024 : 64*1024); 8798c2ecf20Sopenharmony_ci } 8808c2ecf20Sopenharmony_ci strcpy(pcm->name, pcm->id); 8818c2ecf20Sopenharmony_ci if (gus->interwave) { 8828c2ecf20Sopenharmony_ci sprintf(pcm->name + strlen(pcm->name), " rev %c", gus->revision + 'A'); 8838c2ecf20Sopenharmony_ci } 8848c2ecf20Sopenharmony_ci strcat(pcm->name, " (synth)"); 8858c2ecf20Sopenharmony_ci gus->pcm = pcm; 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_ci if (gus->codec_flag) 8888c2ecf20Sopenharmony_ci kctl = snd_ctl_new1(&snd_gf1_pcm_volume_control1, gus); 8898c2ecf20Sopenharmony_ci else 8908c2ecf20Sopenharmony_ci kctl = snd_ctl_new1(&snd_gf1_pcm_volume_control, gus); 8918c2ecf20Sopenharmony_ci if ((err = snd_ctl_add(card, kctl)) < 0) 8928c2ecf20Sopenharmony_ci return err; 8938c2ecf20Sopenharmony_ci kctl->id.index = control_index; 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_ci return 0; 8968c2ecf20Sopenharmony_ci} 8978c2ecf20Sopenharmony_ci 898