1dd7b254dSGiuliano Pochini /* 2dd7b254dSGiuliano Pochini * ALSA driver for Echoaudio soundcards. 3dd7b254dSGiuliano Pochini * Copyright (C) 2003-2004 Giuliano Pochini <pochini@shiny.it> 4dd7b254dSGiuliano Pochini * 5dd7b254dSGiuliano Pochini * This program is free software; you can redistribute it and/or modify 6dd7b254dSGiuliano Pochini * it under the terms of the GNU General Public License as published by 7dd7b254dSGiuliano Pochini * the Free Software Foundation; version 2 of the License. 8dd7b254dSGiuliano Pochini * 9dd7b254dSGiuliano Pochini * This program is distributed in the hope that it will be useful, 10dd7b254dSGiuliano Pochini * but WITHOUT ANY WARRANTY; without even the implied warranty of 11dd7b254dSGiuliano Pochini * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12dd7b254dSGiuliano Pochini * GNU General Public License for more details. 13dd7b254dSGiuliano Pochini * 14dd7b254dSGiuliano Pochini * You should have received a copy of the GNU General Public License 15dd7b254dSGiuliano Pochini * along with this program; if not, write to the Free Software 16dd7b254dSGiuliano Pochini * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17dd7b254dSGiuliano Pochini */ 18dd7b254dSGiuliano Pochini 19dd7b254dSGiuliano Pochini MODULE_AUTHOR("Giuliano Pochini <pochini@shiny.it>"); 20dd7b254dSGiuliano Pochini MODULE_LICENSE("GPL v2"); 21dd7b254dSGiuliano Pochini MODULE_DESCRIPTION("Echoaudio " ECHOCARD_NAME " soundcards driver"); 22dd7b254dSGiuliano Pochini MODULE_SUPPORTED_DEVICE("{{Echoaudio," ECHOCARD_NAME "}}"); 23dd7b254dSGiuliano Pochini MODULE_DEVICE_TABLE(pci, snd_echo_ids); 24dd7b254dSGiuliano Pochini 25dd7b254dSGiuliano Pochini static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 26dd7b254dSGiuliano Pochini static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 27dd7b254dSGiuliano Pochini static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; 28dd7b254dSGiuliano Pochini 29dd7b254dSGiuliano Pochini module_param_array(index, int, NULL, 0444); 30dd7b254dSGiuliano Pochini MODULE_PARM_DESC(index, "Index value for " ECHOCARD_NAME " soundcard."); 31dd7b254dSGiuliano Pochini module_param_array(id, charp, NULL, 0444); 32dd7b254dSGiuliano Pochini MODULE_PARM_DESC(id, "ID string for " ECHOCARD_NAME " soundcard."); 33dd7b254dSGiuliano Pochini module_param_array(enable, bool, NULL, 0444); 34dd7b254dSGiuliano Pochini MODULE_PARM_DESC(enable, "Enable " ECHOCARD_NAME " soundcard."); 35dd7b254dSGiuliano Pochini 36dd7b254dSGiuliano Pochini static unsigned int channels_list[10] = {1, 2, 4, 6, 8, 10, 12, 14, 16, 999999}; 37dd7b254dSGiuliano Pochini 38dd7b254dSGiuliano Pochini static int get_firmware(const struct firmware **fw_entry, 39dd7b254dSGiuliano Pochini const struct firmware *frm, struct echoaudio *chip) 40dd7b254dSGiuliano Pochini { 41dd7b254dSGiuliano Pochini int err; 42dd7b254dSGiuliano Pochini char name[30]; 43dd7b254dSGiuliano Pochini DE_ACT(("firmware requested: %s\n", frm->data)); 44dd7b254dSGiuliano Pochini snprintf(name, sizeof(name), "ea/%s", frm->data); 45dd7b254dSGiuliano Pochini if ((err = request_firmware(fw_entry, name, pci_device(chip))) < 0) 46dd7b254dSGiuliano Pochini snd_printk(KERN_ERR "get_firmware(): Firmware not available (%d)\n", err); 47dd7b254dSGiuliano Pochini return err; 48dd7b254dSGiuliano Pochini } 49dd7b254dSGiuliano Pochini 50dd7b254dSGiuliano Pochini static void free_firmware(const struct firmware *fw_entry) 51dd7b254dSGiuliano Pochini { 52dd7b254dSGiuliano Pochini release_firmware(fw_entry); 53dd7b254dSGiuliano Pochini DE_ACT(("firmware released\n")); 54dd7b254dSGiuliano Pochini } 55dd7b254dSGiuliano Pochini 56dd7b254dSGiuliano Pochini 57dd7b254dSGiuliano Pochini 58dd7b254dSGiuliano Pochini /****************************************************************************** 59dd7b254dSGiuliano Pochini PCM interface 60dd7b254dSGiuliano Pochini ******************************************************************************/ 61dd7b254dSGiuliano Pochini 62dd7b254dSGiuliano Pochini static void audiopipe_free(struct snd_pcm_runtime *runtime) 63dd7b254dSGiuliano Pochini { 64dd7b254dSGiuliano Pochini struct audiopipe *pipe = runtime->private_data; 65dd7b254dSGiuliano Pochini 66dd7b254dSGiuliano Pochini if (pipe->sgpage.area) 67dd7b254dSGiuliano Pochini snd_dma_free_pages(&pipe->sgpage); 68dd7b254dSGiuliano Pochini kfree(pipe); 69dd7b254dSGiuliano Pochini } 70dd7b254dSGiuliano Pochini 71dd7b254dSGiuliano Pochini 72dd7b254dSGiuliano Pochini 73dd7b254dSGiuliano Pochini static int hw_rule_capture_format_by_channels(struct snd_pcm_hw_params *params, 74dd7b254dSGiuliano Pochini struct snd_pcm_hw_rule *rule) 75dd7b254dSGiuliano Pochini { 76dd7b254dSGiuliano Pochini struct snd_interval *c = hw_param_interval(params, 77dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_CHANNELS); 78dd7b254dSGiuliano Pochini struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 79dd7b254dSGiuliano Pochini struct snd_mask fmt; 80dd7b254dSGiuliano Pochini 81dd7b254dSGiuliano Pochini snd_mask_any(&fmt); 82dd7b254dSGiuliano Pochini 83dd7b254dSGiuliano Pochini #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32 84dd7b254dSGiuliano Pochini /* >=2 channels cannot be S32_BE */ 85dd7b254dSGiuliano Pochini if (c->min == 2) { 86dd7b254dSGiuliano Pochini fmt.bits[0] &= ~SNDRV_PCM_FMTBIT_S32_BE; 87dd7b254dSGiuliano Pochini return snd_mask_refine(f, &fmt); 88dd7b254dSGiuliano Pochini } 89dd7b254dSGiuliano Pochini #endif 90dd7b254dSGiuliano Pochini /* > 2 channels cannot be U8 and S32_BE */ 91dd7b254dSGiuliano Pochini if (c->min > 2) { 92dd7b254dSGiuliano Pochini fmt.bits[0] &= ~(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_BE); 93dd7b254dSGiuliano Pochini return snd_mask_refine(f, &fmt); 94dd7b254dSGiuliano Pochini } 95dd7b254dSGiuliano Pochini /* Mono is ok with any format */ 96dd7b254dSGiuliano Pochini return 0; 97dd7b254dSGiuliano Pochini } 98dd7b254dSGiuliano Pochini 99dd7b254dSGiuliano Pochini 100dd7b254dSGiuliano Pochini 101dd7b254dSGiuliano Pochini static int hw_rule_capture_channels_by_format(struct snd_pcm_hw_params *params, 102dd7b254dSGiuliano Pochini struct snd_pcm_hw_rule *rule) 103dd7b254dSGiuliano Pochini { 104dd7b254dSGiuliano Pochini struct snd_interval *c = hw_param_interval(params, 105dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_CHANNELS); 106dd7b254dSGiuliano Pochini struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 107dd7b254dSGiuliano Pochini struct snd_interval ch; 108dd7b254dSGiuliano Pochini 109dd7b254dSGiuliano Pochini snd_interval_any(&ch); 110dd7b254dSGiuliano Pochini 111dd7b254dSGiuliano Pochini /* S32_BE is mono (and stereo) only */ 112dd7b254dSGiuliano Pochini if (f->bits[0] == SNDRV_PCM_FMTBIT_S32_BE) { 113dd7b254dSGiuliano Pochini ch.min = 1; 114dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32 115dd7b254dSGiuliano Pochini ch.max = 2; 116dd7b254dSGiuliano Pochini #else 117dd7b254dSGiuliano Pochini ch.max = 1; 118dd7b254dSGiuliano Pochini #endif 119dd7b254dSGiuliano Pochini ch.integer = 1; 120dd7b254dSGiuliano Pochini return snd_interval_refine(c, &ch); 121dd7b254dSGiuliano Pochini } 122dd7b254dSGiuliano Pochini /* U8 can be only mono or stereo */ 123dd7b254dSGiuliano Pochini if (f->bits[0] == SNDRV_PCM_FMTBIT_U8) { 124dd7b254dSGiuliano Pochini ch.min = 1; 125dd7b254dSGiuliano Pochini ch.max = 2; 126dd7b254dSGiuliano Pochini ch.integer = 1; 127dd7b254dSGiuliano Pochini return snd_interval_refine(c, &ch); 128dd7b254dSGiuliano Pochini } 129dd7b254dSGiuliano Pochini /* S16_LE, S24_3LE and S32_LE support any number of channels. */ 130dd7b254dSGiuliano Pochini return 0; 131dd7b254dSGiuliano Pochini } 132dd7b254dSGiuliano Pochini 133dd7b254dSGiuliano Pochini 134dd7b254dSGiuliano Pochini 135dd7b254dSGiuliano Pochini static int hw_rule_playback_format_by_channels(struct snd_pcm_hw_params *params, 136dd7b254dSGiuliano Pochini struct snd_pcm_hw_rule *rule) 137dd7b254dSGiuliano Pochini { 138dd7b254dSGiuliano Pochini struct snd_interval *c = hw_param_interval(params, 139dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_CHANNELS); 140dd7b254dSGiuliano Pochini struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 141dd7b254dSGiuliano Pochini struct snd_mask fmt; 142dd7b254dSGiuliano Pochini u64 fmask; 143dd7b254dSGiuliano Pochini snd_mask_any(&fmt); 144dd7b254dSGiuliano Pochini 145dd7b254dSGiuliano Pochini fmask = fmt.bits[0] + ((u64)fmt.bits[1] << 32); 146dd7b254dSGiuliano Pochini 147dd7b254dSGiuliano Pochini /* >2 channels must be S16_LE, S24_3LE or S32_LE */ 148dd7b254dSGiuliano Pochini if (c->min > 2) { 149dd7b254dSGiuliano Pochini fmask &= SNDRV_PCM_FMTBIT_S16_LE | 150dd7b254dSGiuliano Pochini SNDRV_PCM_FMTBIT_S24_3LE | 151dd7b254dSGiuliano Pochini SNDRV_PCM_FMTBIT_S32_LE; 152dd7b254dSGiuliano Pochini /* 1 channel must be S32_BE or S32_LE */ 153dd7b254dSGiuliano Pochini } else if (c->max == 1) 154dd7b254dSGiuliano Pochini fmask &= SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE; 155dd7b254dSGiuliano Pochini #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32 156dd7b254dSGiuliano Pochini /* 2 channels cannot be S32_BE */ 157dd7b254dSGiuliano Pochini else if (c->min == 2 && c->max == 2) 158dd7b254dSGiuliano Pochini fmask &= ~SNDRV_PCM_FMTBIT_S32_BE; 159dd7b254dSGiuliano Pochini #endif 160dd7b254dSGiuliano Pochini else 161dd7b254dSGiuliano Pochini return 0; 162dd7b254dSGiuliano Pochini 163dd7b254dSGiuliano Pochini fmt.bits[0] &= (u32)fmask; 164dd7b254dSGiuliano Pochini fmt.bits[1] &= (u32)(fmask >> 32); 165dd7b254dSGiuliano Pochini return snd_mask_refine(f, &fmt); 166dd7b254dSGiuliano Pochini } 167dd7b254dSGiuliano Pochini 168dd7b254dSGiuliano Pochini 169dd7b254dSGiuliano Pochini 170dd7b254dSGiuliano Pochini static int hw_rule_playback_channels_by_format(struct snd_pcm_hw_params *params, 171dd7b254dSGiuliano Pochini struct snd_pcm_hw_rule *rule) 172dd7b254dSGiuliano Pochini { 173dd7b254dSGiuliano Pochini struct snd_interval *c = hw_param_interval(params, 174dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_CHANNELS); 175dd7b254dSGiuliano Pochini struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 176dd7b254dSGiuliano Pochini struct snd_interval ch; 177dd7b254dSGiuliano Pochini u64 fmask; 178dd7b254dSGiuliano Pochini 179dd7b254dSGiuliano Pochini snd_interval_any(&ch); 180dd7b254dSGiuliano Pochini ch.integer = 1; 181dd7b254dSGiuliano Pochini fmask = f->bits[0] + ((u64)f->bits[1] << 32); 182dd7b254dSGiuliano Pochini 183dd7b254dSGiuliano Pochini /* S32_BE is mono (and stereo) only */ 184dd7b254dSGiuliano Pochini if (fmask == SNDRV_PCM_FMTBIT_S32_BE) { 185dd7b254dSGiuliano Pochini ch.min = 1; 186dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32 187dd7b254dSGiuliano Pochini ch.max = 2; 188dd7b254dSGiuliano Pochini #else 189dd7b254dSGiuliano Pochini ch.max = 1; 190dd7b254dSGiuliano Pochini #endif 191dd7b254dSGiuliano Pochini /* U8 is stereo only */ 192dd7b254dSGiuliano Pochini } else if (fmask == SNDRV_PCM_FMTBIT_U8) 193dd7b254dSGiuliano Pochini ch.min = ch.max = 2; 194dd7b254dSGiuliano Pochini /* S16_LE and S24_3LE must be at least stereo */ 195dd7b254dSGiuliano Pochini else if (!(fmask & ~(SNDRV_PCM_FMTBIT_S16_LE | 196dd7b254dSGiuliano Pochini SNDRV_PCM_FMTBIT_S24_3LE))) 197dd7b254dSGiuliano Pochini ch.min = 2; 198dd7b254dSGiuliano Pochini else 199dd7b254dSGiuliano Pochini return 0; 200dd7b254dSGiuliano Pochini 201dd7b254dSGiuliano Pochini return snd_interval_refine(c, &ch); 202dd7b254dSGiuliano Pochini } 203dd7b254dSGiuliano Pochini 204dd7b254dSGiuliano Pochini 205dd7b254dSGiuliano Pochini 206dd7b254dSGiuliano Pochini /* Since the sample rate is a global setting, do allow the user to change the 207dd7b254dSGiuliano Pochini sample rate only if there is only one pcm device open. */ 208dd7b254dSGiuliano Pochini static int hw_rule_sample_rate(struct snd_pcm_hw_params *params, 209dd7b254dSGiuliano Pochini struct snd_pcm_hw_rule *rule) 210dd7b254dSGiuliano Pochini { 211dd7b254dSGiuliano Pochini struct snd_interval *rate = hw_param_interval(params, 212dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_RATE); 213dd7b254dSGiuliano Pochini struct echoaudio *chip = rule->private; 214dd7b254dSGiuliano Pochini struct snd_interval fixed; 215dd7b254dSGiuliano Pochini 216dd7b254dSGiuliano Pochini if (!chip->can_set_rate) { 217dd7b254dSGiuliano Pochini snd_interval_any(&fixed); 218dd7b254dSGiuliano Pochini fixed.min = fixed.max = chip->sample_rate; 219dd7b254dSGiuliano Pochini return snd_interval_refine(rate, &fixed); 220dd7b254dSGiuliano Pochini } 221dd7b254dSGiuliano Pochini return 0; 222dd7b254dSGiuliano Pochini } 223dd7b254dSGiuliano Pochini 224dd7b254dSGiuliano Pochini 225dd7b254dSGiuliano Pochini static int pcm_open(struct snd_pcm_substream *substream, 226dd7b254dSGiuliano Pochini signed char max_channels) 227dd7b254dSGiuliano Pochini { 228dd7b254dSGiuliano Pochini struct echoaudio *chip; 229dd7b254dSGiuliano Pochini struct snd_pcm_runtime *runtime; 230dd7b254dSGiuliano Pochini struct audiopipe *pipe; 231dd7b254dSGiuliano Pochini int err, i; 232dd7b254dSGiuliano Pochini 233dd7b254dSGiuliano Pochini if (max_channels <= 0) 234dd7b254dSGiuliano Pochini return -EAGAIN; 235dd7b254dSGiuliano Pochini 236dd7b254dSGiuliano Pochini chip = snd_pcm_substream_chip(substream); 237dd7b254dSGiuliano Pochini runtime = substream->runtime; 238dd7b254dSGiuliano Pochini 23959feddb2SPanagiotis Issaris pipe = kzalloc(sizeof(struct audiopipe), GFP_KERNEL); 24059feddb2SPanagiotis Issaris if (!pipe) 241dd7b254dSGiuliano Pochini return -ENOMEM; 242dd7b254dSGiuliano Pochini pipe->index = -1; /* Not configured yet */ 243dd7b254dSGiuliano Pochini 244dd7b254dSGiuliano Pochini /* Set up hw capabilities and contraints */ 245dd7b254dSGiuliano Pochini memcpy(&pipe->hw, &pcm_hardware_skel, sizeof(struct snd_pcm_hardware)); 246dd7b254dSGiuliano Pochini DE_HWP(("max_channels=%d\n", max_channels)); 247dd7b254dSGiuliano Pochini pipe->constr.list = channels_list; 248dd7b254dSGiuliano Pochini pipe->constr.mask = 0; 249dd7b254dSGiuliano Pochini for (i = 0; channels_list[i] <= max_channels; i++); 250dd7b254dSGiuliano Pochini pipe->constr.count = i; 251dd7b254dSGiuliano Pochini if (pipe->hw.channels_max > max_channels) 252dd7b254dSGiuliano Pochini pipe->hw.channels_max = max_channels; 253dd7b254dSGiuliano Pochini if (chip->digital_mode == DIGITAL_MODE_ADAT) { 254dd7b254dSGiuliano Pochini pipe->hw.rate_max = 48000; 255dd7b254dSGiuliano Pochini pipe->hw.rates &= SNDRV_PCM_RATE_8000_48000; 256dd7b254dSGiuliano Pochini } 257dd7b254dSGiuliano Pochini 258dd7b254dSGiuliano Pochini runtime->hw = pipe->hw; 259dd7b254dSGiuliano Pochini runtime->private_data = pipe; 260dd7b254dSGiuliano Pochini runtime->private_free = audiopipe_free; 261dd7b254dSGiuliano Pochini snd_pcm_set_sync(substream); 262dd7b254dSGiuliano Pochini 263dd7b254dSGiuliano Pochini /* Only mono and any even number of channels are allowed */ 264dd7b254dSGiuliano Pochini if ((err = snd_pcm_hw_constraint_list(runtime, 0, 265dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_CHANNELS, 266dd7b254dSGiuliano Pochini &pipe->constr)) < 0) 267dd7b254dSGiuliano Pochini return err; 268dd7b254dSGiuliano Pochini 269dd7b254dSGiuliano Pochini /* All periods should have the same size */ 270dd7b254dSGiuliano Pochini if ((err = snd_pcm_hw_constraint_integer(runtime, 271dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 272dd7b254dSGiuliano Pochini return err; 273dd7b254dSGiuliano Pochini 274dd7b254dSGiuliano Pochini /* The hw accesses memory in chunks 32 frames long and they should be 275dd7b254dSGiuliano Pochini 32-bytes-aligned. It's not a requirement, but it seems that IRQs are 276dd7b254dSGiuliano Pochini generated with a resolution of 32 frames. Thus we need the following */ 277dd7b254dSGiuliano Pochini if ((err = snd_pcm_hw_constraint_step(runtime, 0, 278dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 279dd7b254dSGiuliano Pochini 32)) < 0) 280dd7b254dSGiuliano Pochini return err; 281dd7b254dSGiuliano Pochini if ((err = snd_pcm_hw_constraint_step(runtime, 0, 282dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 283dd7b254dSGiuliano Pochini 32)) < 0) 284dd7b254dSGiuliano Pochini return err; 285dd7b254dSGiuliano Pochini 286dd7b254dSGiuliano Pochini if ((err = snd_pcm_hw_rule_add(substream->runtime, 0, 287dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_RATE, 288dd7b254dSGiuliano Pochini hw_rule_sample_rate, chip, 289dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_RATE, -1)) < 0) 290dd7b254dSGiuliano Pochini return err; 291dd7b254dSGiuliano Pochini 292dd7b254dSGiuliano Pochini /* Finally allocate a page for the scatter-gather list */ 293dd7b254dSGiuliano Pochini if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, 294dd7b254dSGiuliano Pochini snd_dma_pci_data(chip->pci), 295dd7b254dSGiuliano Pochini PAGE_SIZE, &pipe->sgpage)) < 0) { 296dd7b254dSGiuliano Pochini DE_HWP(("s-g list allocation failed\n")); 297dd7b254dSGiuliano Pochini return err; 298dd7b254dSGiuliano Pochini } 299dd7b254dSGiuliano Pochini 300dd7b254dSGiuliano Pochini return 0; 301dd7b254dSGiuliano Pochini } 302dd7b254dSGiuliano Pochini 303dd7b254dSGiuliano Pochini 304dd7b254dSGiuliano Pochini 305dd7b254dSGiuliano Pochini static int pcm_analog_in_open(struct snd_pcm_substream *substream) 306dd7b254dSGiuliano Pochini { 307dd7b254dSGiuliano Pochini struct echoaudio *chip = snd_pcm_substream_chip(substream); 308dd7b254dSGiuliano Pochini int err; 309dd7b254dSGiuliano Pochini 310dd7b254dSGiuliano Pochini DE_ACT(("pcm_analog_in_open\n")); 311dd7b254dSGiuliano Pochini if ((err = pcm_open(substream, num_analog_busses_in(chip) - 312dd7b254dSGiuliano Pochini substream->number)) < 0) 313dd7b254dSGiuliano Pochini return err; 314dd7b254dSGiuliano Pochini if ((err = snd_pcm_hw_rule_add(substream->runtime, 0, 315dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_CHANNELS, 316dd7b254dSGiuliano Pochini hw_rule_capture_channels_by_format, NULL, 317dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0) 318dd7b254dSGiuliano Pochini return err; 319dd7b254dSGiuliano Pochini if ((err = snd_pcm_hw_rule_add(substream->runtime, 0, 320dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_FORMAT, 321dd7b254dSGiuliano Pochini hw_rule_capture_format_by_channels, NULL, 322dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0) 323dd7b254dSGiuliano Pochini return err; 324dd7b254dSGiuliano Pochini atomic_inc(&chip->opencount); 325dd7b254dSGiuliano Pochini if (atomic_read(&chip->opencount) > 1 && chip->rate_set) 326dd7b254dSGiuliano Pochini chip->can_set_rate=0; 327dd7b254dSGiuliano Pochini DE_HWP(("pcm_analog_in_open cs=%d oc=%d r=%d\n", 328dd7b254dSGiuliano Pochini chip->can_set_rate, atomic_read(&chip->opencount), 329dd7b254dSGiuliano Pochini chip->sample_rate)); 330dd7b254dSGiuliano Pochini return 0; 331dd7b254dSGiuliano Pochini } 332dd7b254dSGiuliano Pochini 333dd7b254dSGiuliano Pochini 334dd7b254dSGiuliano Pochini 335dd7b254dSGiuliano Pochini static int pcm_analog_out_open(struct snd_pcm_substream *substream) 336dd7b254dSGiuliano Pochini { 337dd7b254dSGiuliano Pochini struct echoaudio *chip = snd_pcm_substream_chip(substream); 338dd7b254dSGiuliano Pochini int max_channels, err; 339dd7b254dSGiuliano Pochini 340dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_VMIXER 341dd7b254dSGiuliano Pochini max_channels = num_pipes_out(chip); 342dd7b254dSGiuliano Pochini #else 343dd7b254dSGiuliano Pochini max_channels = num_analog_busses_out(chip); 344dd7b254dSGiuliano Pochini #endif 345dd7b254dSGiuliano Pochini DE_ACT(("pcm_analog_out_open\n")); 346dd7b254dSGiuliano Pochini if ((err = pcm_open(substream, max_channels - substream->number)) < 0) 347dd7b254dSGiuliano Pochini return err; 348dd7b254dSGiuliano Pochini if ((err = snd_pcm_hw_rule_add(substream->runtime, 0, 349dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_CHANNELS, 350dd7b254dSGiuliano Pochini hw_rule_playback_channels_by_format, 351dd7b254dSGiuliano Pochini NULL, 352dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0) 353dd7b254dSGiuliano Pochini return err; 354dd7b254dSGiuliano Pochini if ((err = snd_pcm_hw_rule_add(substream->runtime, 0, 355dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_FORMAT, 356dd7b254dSGiuliano Pochini hw_rule_playback_format_by_channels, 357dd7b254dSGiuliano Pochini NULL, 358dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0) 359dd7b254dSGiuliano Pochini return err; 360dd7b254dSGiuliano Pochini atomic_inc(&chip->opencount); 361dd7b254dSGiuliano Pochini if (atomic_read(&chip->opencount) > 1 && chip->rate_set) 362dd7b254dSGiuliano Pochini chip->can_set_rate=0; 363dd7b254dSGiuliano Pochini DE_HWP(("pcm_analog_out_open cs=%d oc=%d r=%d\n", 364dd7b254dSGiuliano Pochini chip->can_set_rate, atomic_read(&chip->opencount), 365dd7b254dSGiuliano Pochini chip->sample_rate)); 366dd7b254dSGiuliano Pochini return 0; 367dd7b254dSGiuliano Pochini } 368dd7b254dSGiuliano Pochini 369dd7b254dSGiuliano Pochini 370dd7b254dSGiuliano Pochini 371dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_DIGITAL_IO 372dd7b254dSGiuliano Pochini 373dd7b254dSGiuliano Pochini static int pcm_digital_in_open(struct snd_pcm_substream *substream) 374dd7b254dSGiuliano Pochini { 375dd7b254dSGiuliano Pochini struct echoaudio *chip = snd_pcm_substream_chip(substream); 376dd7b254dSGiuliano Pochini int err, max_channels; 377dd7b254dSGiuliano Pochini 378dd7b254dSGiuliano Pochini DE_ACT(("pcm_digital_in_open\n")); 379dd7b254dSGiuliano Pochini max_channels = num_digital_busses_in(chip) - substream->number; 380dd7b254dSGiuliano Pochini down(&chip->mode_mutex); 381dd7b254dSGiuliano Pochini if (chip->digital_mode == DIGITAL_MODE_ADAT) 382dd7b254dSGiuliano Pochini err = pcm_open(substream, max_channels); 383dd7b254dSGiuliano Pochini else /* If the card has ADAT, subtract the 6 channels 384dd7b254dSGiuliano Pochini * that S/PDIF doesn't have 385dd7b254dSGiuliano Pochini */ 386dd7b254dSGiuliano Pochini err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT); 387dd7b254dSGiuliano Pochini 388dd7b254dSGiuliano Pochini if (err < 0) 389dd7b254dSGiuliano Pochini goto din_exit; 390dd7b254dSGiuliano Pochini 391dd7b254dSGiuliano Pochini if ((err = snd_pcm_hw_rule_add(substream->runtime, 0, 392dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_CHANNELS, 393dd7b254dSGiuliano Pochini hw_rule_capture_channels_by_format, NULL, 394dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0) 395dd7b254dSGiuliano Pochini goto din_exit; 396dd7b254dSGiuliano Pochini if ((err = snd_pcm_hw_rule_add(substream->runtime, 0, 397dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_FORMAT, 398dd7b254dSGiuliano Pochini hw_rule_capture_format_by_channels, NULL, 399dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0) 400dd7b254dSGiuliano Pochini goto din_exit; 401dd7b254dSGiuliano Pochini 402dd7b254dSGiuliano Pochini atomic_inc(&chip->opencount); 403dd7b254dSGiuliano Pochini if (atomic_read(&chip->opencount) > 1 && chip->rate_set) 404dd7b254dSGiuliano Pochini chip->can_set_rate=0; 405dd7b254dSGiuliano Pochini 406dd7b254dSGiuliano Pochini din_exit: 407dd7b254dSGiuliano Pochini up(&chip->mode_mutex); 408dd7b254dSGiuliano Pochini return err; 409dd7b254dSGiuliano Pochini } 410dd7b254dSGiuliano Pochini 411dd7b254dSGiuliano Pochini 412dd7b254dSGiuliano Pochini 413dd7b254dSGiuliano Pochini #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */ 414dd7b254dSGiuliano Pochini 415dd7b254dSGiuliano Pochini static int pcm_digital_out_open(struct snd_pcm_substream *substream) 416dd7b254dSGiuliano Pochini { 417dd7b254dSGiuliano Pochini struct echoaudio *chip = snd_pcm_substream_chip(substream); 418dd7b254dSGiuliano Pochini int err, max_channels; 419dd7b254dSGiuliano Pochini 420dd7b254dSGiuliano Pochini DE_ACT(("pcm_digital_out_open\n")); 421dd7b254dSGiuliano Pochini max_channels = num_digital_busses_out(chip) - substream->number; 422dd7b254dSGiuliano Pochini down(&chip->mode_mutex); 423dd7b254dSGiuliano Pochini if (chip->digital_mode == DIGITAL_MODE_ADAT) 424dd7b254dSGiuliano Pochini err = pcm_open(substream, max_channels); 425dd7b254dSGiuliano Pochini else /* If the card has ADAT, subtract the 6 channels 426dd7b254dSGiuliano Pochini * that S/PDIF doesn't have 427dd7b254dSGiuliano Pochini */ 428dd7b254dSGiuliano Pochini err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT); 429dd7b254dSGiuliano Pochini 430dd7b254dSGiuliano Pochini if (err < 0) 431dd7b254dSGiuliano Pochini goto dout_exit; 432dd7b254dSGiuliano Pochini 433dd7b254dSGiuliano Pochini if ((err = snd_pcm_hw_rule_add(substream->runtime, 0, 434dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_CHANNELS, 435dd7b254dSGiuliano Pochini hw_rule_playback_channels_by_format, 436dd7b254dSGiuliano Pochini NULL, SNDRV_PCM_HW_PARAM_FORMAT, 437dd7b254dSGiuliano Pochini -1)) < 0) 438dd7b254dSGiuliano Pochini goto dout_exit; 439dd7b254dSGiuliano Pochini if ((err = snd_pcm_hw_rule_add(substream->runtime, 0, 440dd7b254dSGiuliano Pochini SNDRV_PCM_HW_PARAM_FORMAT, 441dd7b254dSGiuliano Pochini hw_rule_playback_format_by_channels, 442dd7b254dSGiuliano Pochini NULL, SNDRV_PCM_HW_PARAM_CHANNELS, 443dd7b254dSGiuliano Pochini -1)) < 0) 444dd7b254dSGiuliano Pochini goto dout_exit; 445dd7b254dSGiuliano Pochini atomic_inc(&chip->opencount); 446dd7b254dSGiuliano Pochini if (atomic_read(&chip->opencount) > 1 && chip->rate_set) 447dd7b254dSGiuliano Pochini chip->can_set_rate=0; 448dd7b254dSGiuliano Pochini dout_exit: 449dd7b254dSGiuliano Pochini up(&chip->mode_mutex); 450dd7b254dSGiuliano Pochini return err; 451dd7b254dSGiuliano Pochini } 452dd7b254dSGiuliano Pochini 453dd7b254dSGiuliano Pochini #endif /* !ECHOCARD_HAS_VMIXER */ 454dd7b254dSGiuliano Pochini 455dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_DIGITAL_IO */ 456dd7b254dSGiuliano Pochini 457dd7b254dSGiuliano Pochini 458dd7b254dSGiuliano Pochini 459dd7b254dSGiuliano Pochini static int pcm_close(struct snd_pcm_substream *substream) 460dd7b254dSGiuliano Pochini { 461dd7b254dSGiuliano Pochini struct echoaudio *chip = snd_pcm_substream_chip(substream); 462dd7b254dSGiuliano Pochini int oc; 463dd7b254dSGiuliano Pochini 464dd7b254dSGiuliano Pochini /* Nothing to do here. Audio is already off and pipe will be 465dd7b254dSGiuliano Pochini * freed by its callback 466dd7b254dSGiuliano Pochini */ 467dd7b254dSGiuliano Pochini DE_ACT(("pcm_close\n")); 468dd7b254dSGiuliano Pochini 469dd7b254dSGiuliano Pochini atomic_dec(&chip->opencount); 470dd7b254dSGiuliano Pochini oc = atomic_read(&chip->opencount); 471dd7b254dSGiuliano Pochini DE_ACT(("pcm_close oc=%d cs=%d rs=%d\n", oc, 472dd7b254dSGiuliano Pochini chip->can_set_rate, chip->rate_set)); 473dd7b254dSGiuliano Pochini if (oc < 2) 474dd7b254dSGiuliano Pochini chip->can_set_rate = 1; 475dd7b254dSGiuliano Pochini if (oc == 0) 476dd7b254dSGiuliano Pochini chip->rate_set = 0; 477dd7b254dSGiuliano Pochini DE_ACT(("pcm_close2 oc=%d cs=%d rs=%d\n", oc, 478dd7b254dSGiuliano Pochini chip->can_set_rate,chip->rate_set)); 479dd7b254dSGiuliano Pochini 480dd7b254dSGiuliano Pochini return 0; 481dd7b254dSGiuliano Pochini } 482dd7b254dSGiuliano Pochini 483dd7b254dSGiuliano Pochini 484dd7b254dSGiuliano Pochini 485dd7b254dSGiuliano Pochini /* Channel allocation and scatter-gather list setup */ 486dd7b254dSGiuliano Pochini static int init_engine(struct snd_pcm_substream *substream, 487dd7b254dSGiuliano Pochini struct snd_pcm_hw_params *hw_params, 488dd7b254dSGiuliano Pochini int pipe_index, int interleave) 489dd7b254dSGiuliano Pochini { 490dd7b254dSGiuliano Pochini struct echoaudio *chip; 491dd7b254dSGiuliano Pochini int err, per, rest, page, edge, offs; 492dd7b254dSGiuliano Pochini struct snd_sg_buf *sgbuf; 493dd7b254dSGiuliano Pochini struct audiopipe *pipe; 494dd7b254dSGiuliano Pochini 495dd7b254dSGiuliano Pochini chip = snd_pcm_substream_chip(substream); 496dd7b254dSGiuliano Pochini pipe = (struct audiopipe *) substream->runtime->private_data; 497dd7b254dSGiuliano Pochini 498dd7b254dSGiuliano Pochini /* Sets up che hardware. If it's already initialized, reset and 499dd7b254dSGiuliano Pochini * redo with the new parameters 500dd7b254dSGiuliano Pochini */ 501dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 502dd7b254dSGiuliano Pochini if (pipe->index >= 0) { 503dd7b254dSGiuliano Pochini DE_HWP(("hwp_ie free(%d)\n", pipe->index)); 504dd7b254dSGiuliano Pochini err = free_pipes(chip, pipe); 505dd7b254dSGiuliano Pochini snd_assert(!err); 506dd7b254dSGiuliano Pochini chip->substream[pipe->index] = NULL; 507dd7b254dSGiuliano Pochini } 508dd7b254dSGiuliano Pochini 509dd7b254dSGiuliano Pochini err = allocate_pipes(chip, pipe, pipe_index, interleave); 510dd7b254dSGiuliano Pochini if (err < 0) { 511dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 512dd7b254dSGiuliano Pochini DE_ACT((KERN_NOTICE "allocate_pipes(%d) err=%d\n", 513dd7b254dSGiuliano Pochini pipe_index, err)); 514dd7b254dSGiuliano Pochini return err; 515dd7b254dSGiuliano Pochini } 516dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 517dd7b254dSGiuliano Pochini DE_ACT((KERN_NOTICE "allocate_pipes()=%d\n", pipe_index)); 518dd7b254dSGiuliano Pochini 519dd7b254dSGiuliano Pochini DE_HWP(("pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n", 520dd7b254dSGiuliano Pochini params_buffer_bytes(hw_params), params_periods(hw_params), 521dd7b254dSGiuliano Pochini params_period_bytes(hw_params))); 522dd7b254dSGiuliano Pochini err = snd_pcm_lib_malloc_pages(substream, 523dd7b254dSGiuliano Pochini params_buffer_bytes(hw_params)); 524dd7b254dSGiuliano Pochini if (err < 0) { 525dd7b254dSGiuliano Pochini snd_printk(KERN_ERR "malloc_pages err=%d\n", err); 526dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 527dd7b254dSGiuliano Pochini free_pipes(chip, pipe); 528dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 529dd7b254dSGiuliano Pochini pipe->index = -1; 530dd7b254dSGiuliano Pochini return err; 531dd7b254dSGiuliano Pochini } 532dd7b254dSGiuliano Pochini 533dd7b254dSGiuliano Pochini sgbuf = snd_pcm_substream_sgbuf(substream); 534dd7b254dSGiuliano Pochini 535dd7b254dSGiuliano Pochini DE_HWP(("pcm_hw_params table size=%d pages=%d\n", 536dd7b254dSGiuliano Pochini sgbuf->size, sgbuf->pages)); 537dd7b254dSGiuliano Pochini sglist_init(chip, pipe); 538dd7b254dSGiuliano Pochini edge = PAGE_SIZE; 539dd7b254dSGiuliano Pochini for (offs = page = per = 0; offs < params_buffer_bytes(hw_params); 540dd7b254dSGiuliano Pochini per++) { 541dd7b254dSGiuliano Pochini rest = params_period_bytes(hw_params); 542dd7b254dSGiuliano Pochini if (offs + rest > params_buffer_bytes(hw_params)) 543dd7b254dSGiuliano Pochini rest = params_buffer_bytes(hw_params) - offs; 544dd7b254dSGiuliano Pochini while (rest) { 545dd7b254dSGiuliano Pochini if (rest <= edge - offs) { 546dd7b254dSGiuliano Pochini sglist_add_mapping(chip, pipe, 547dd7b254dSGiuliano Pochini snd_sgbuf_get_addr(sgbuf, offs), 548dd7b254dSGiuliano Pochini rest); 549dd7b254dSGiuliano Pochini sglist_add_irq(chip, pipe); 550dd7b254dSGiuliano Pochini offs += rest; 551dd7b254dSGiuliano Pochini rest = 0; 552dd7b254dSGiuliano Pochini } else { 553dd7b254dSGiuliano Pochini sglist_add_mapping(chip, pipe, 554dd7b254dSGiuliano Pochini snd_sgbuf_get_addr(sgbuf, offs), 555dd7b254dSGiuliano Pochini edge - offs); 556dd7b254dSGiuliano Pochini rest -= edge - offs; 557dd7b254dSGiuliano Pochini offs = edge; 558dd7b254dSGiuliano Pochini } 559dd7b254dSGiuliano Pochini if (offs == edge) { 560dd7b254dSGiuliano Pochini edge += PAGE_SIZE; 561dd7b254dSGiuliano Pochini page++; 562dd7b254dSGiuliano Pochini } 563dd7b254dSGiuliano Pochini } 564dd7b254dSGiuliano Pochini } 565dd7b254dSGiuliano Pochini 566dd7b254dSGiuliano Pochini /* Close the ring buffer */ 567dd7b254dSGiuliano Pochini sglist_wrap(chip, pipe); 568dd7b254dSGiuliano Pochini 569dd7b254dSGiuliano Pochini /* This stuff is used by the irq handler, so it must be 570dd7b254dSGiuliano Pochini * initialized before chip->substream 571dd7b254dSGiuliano Pochini */ 572dd7b254dSGiuliano Pochini chip->last_period[pipe_index] = 0; 573dd7b254dSGiuliano Pochini pipe->last_counter = 0; 574dd7b254dSGiuliano Pochini pipe->position = 0; 575dd7b254dSGiuliano Pochini smp_wmb(); 576dd7b254dSGiuliano Pochini chip->substream[pipe_index] = substream; 577dd7b254dSGiuliano Pochini chip->rate_set = 1; 578dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 579dd7b254dSGiuliano Pochini set_sample_rate(chip, hw_params->rate_num / hw_params->rate_den); 580dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 581dd7b254dSGiuliano Pochini DE_HWP(("pcm_hw_params ok\n")); 582dd7b254dSGiuliano Pochini return 0; 583dd7b254dSGiuliano Pochini } 584dd7b254dSGiuliano Pochini 585dd7b254dSGiuliano Pochini 586dd7b254dSGiuliano Pochini 587dd7b254dSGiuliano Pochini static int pcm_analog_in_hw_params(struct snd_pcm_substream *substream, 588dd7b254dSGiuliano Pochini struct snd_pcm_hw_params *hw_params) 589dd7b254dSGiuliano Pochini { 590dd7b254dSGiuliano Pochini struct echoaudio *chip = snd_pcm_substream_chip(substream); 591dd7b254dSGiuliano Pochini 592dd7b254dSGiuliano Pochini return init_engine(substream, hw_params, px_analog_in(chip) + 593dd7b254dSGiuliano Pochini substream->number, params_channels(hw_params)); 594dd7b254dSGiuliano Pochini } 595dd7b254dSGiuliano Pochini 596dd7b254dSGiuliano Pochini 597dd7b254dSGiuliano Pochini 598dd7b254dSGiuliano Pochini static int pcm_analog_out_hw_params(struct snd_pcm_substream *substream, 599dd7b254dSGiuliano Pochini struct snd_pcm_hw_params *hw_params) 600dd7b254dSGiuliano Pochini { 601dd7b254dSGiuliano Pochini return init_engine(substream, hw_params, substream->number, 602dd7b254dSGiuliano Pochini params_channels(hw_params)); 603dd7b254dSGiuliano Pochini } 604dd7b254dSGiuliano Pochini 605dd7b254dSGiuliano Pochini 606dd7b254dSGiuliano Pochini 607dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_DIGITAL_IO 608dd7b254dSGiuliano Pochini 609dd7b254dSGiuliano Pochini static int pcm_digital_in_hw_params(struct snd_pcm_substream *substream, 610dd7b254dSGiuliano Pochini struct snd_pcm_hw_params *hw_params) 611dd7b254dSGiuliano Pochini { 612dd7b254dSGiuliano Pochini struct echoaudio *chip = snd_pcm_substream_chip(substream); 613dd7b254dSGiuliano Pochini 614dd7b254dSGiuliano Pochini return init_engine(substream, hw_params, px_digital_in(chip) + 615dd7b254dSGiuliano Pochini substream->number, params_channels(hw_params)); 616dd7b254dSGiuliano Pochini } 617dd7b254dSGiuliano Pochini 618dd7b254dSGiuliano Pochini 619dd7b254dSGiuliano Pochini 620dd7b254dSGiuliano Pochini #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */ 621dd7b254dSGiuliano Pochini static int pcm_digital_out_hw_params(struct snd_pcm_substream *substream, 622dd7b254dSGiuliano Pochini struct snd_pcm_hw_params *hw_params) 623dd7b254dSGiuliano Pochini { 624dd7b254dSGiuliano Pochini struct echoaudio *chip = snd_pcm_substream_chip(substream); 625dd7b254dSGiuliano Pochini 626dd7b254dSGiuliano Pochini return init_engine(substream, hw_params, px_digital_out(chip) + 627dd7b254dSGiuliano Pochini substream->number, params_channels(hw_params)); 628dd7b254dSGiuliano Pochini } 629dd7b254dSGiuliano Pochini #endif /* !ECHOCARD_HAS_VMIXER */ 630dd7b254dSGiuliano Pochini 631dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_DIGITAL_IO */ 632dd7b254dSGiuliano Pochini 633dd7b254dSGiuliano Pochini 634dd7b254dSGiuliano Pochini 635dd7b254dSGiuliano Pochini static int pcm_hw_free(struct snd_pcm_substream *substream) 636dd7b254dSGiuliano Pochini { 637dd7b254dSGiuliano Pochini struct echoaudio *chip; 638dd7b254dSGiuliano Pochini struct audiopipe *pipe; 639dd7b254dSGiuliano Pochini 640dd7b254dSGiuliano Pochini chip = snd_pcm_substream_chip(substream); 641dd7b254dSGiuliano Pochini pipe = (struct audiopipe *) substream->runtime->private_data; 642dd7b254dSGiuliano Pochini 643dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 644dd7b254dSGiuliano Pochini if (pipe->index >= 0) { 645dd7b254dSGiuliano Pochini DE_HWP(("pcm_hw_free(%d)\n", pipe->index)); 646dd7b254dSGiuliano Pochini free_pipes(chip, pipe); 647dd7b254dSGiuliano Pochini chip->substream[pipe->index] = NULL; 648dd7b254dSGiuliano Pochini pipe->index = -1; 649dd7b254dSGiuliano Pochini } 650dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 651dd7b254dSGiuliano Pochini 652dd7b254dSGiuliano Pochini DE_HWP(("pcm_hw_freed\n")); 653dd7b254dSGiuliano Pochini snd_pcm_lib_free_pages(substream); 654dd7b254dSGiuliano Pochini return 0; 655dd7b254dSGiuliano Pochini } 656dd7b254dSGiuliano Pochini 657dd7b254dSGiuliano Pochini 658dd7b254dSGiuliano Pochini 659dd7b254dSGiuliano Pochini static int pcm_prepare(struct snd_pcm_substream *substream) 660dd7b254dSGiuliano Pochini { 661dd7b254dSGiuliano Pochini struct echoaudio *chip = snd_pcm_substream_chip(substream); 662dd7b254dSGiuliano Pochini struct snd_pcm_runtime *runtime = substream->runtime; 663dd7b254dSGiuliano Pochini struct audioformat format; 664dd7b254dSGiuliano Pochini int pipe_index = ((struct audiopipe *)runtime->private_data)->index; 665dd7b254dSGiuliano Pochini 666dd7b254dSGiuliano Pochini DE_HWP(("Prepare rate=%d format=%d channels=%d\n", 667dd7b254dSGiuliano Pochini runtime->rate, runtime->format, runtime->channels)); 668dd7b254dSGiuliano Pochini format.interleave = runtime->channels; 669dd7b254dSGiuliano Pochini format.data_are_bigendian = 0; 670dd7b254dSGiuliano Pochini format.mono_to_stereo = 0; 671dd7b254dSGiuliano Pochini switch (runtime->format) { 672dd7b254dSGiuliano Pochini case SNDRV_PCM_FORMAT_U8: 673dd7b254dSGiuliano Pochini format.bits_per_sample = 8; 674dd7b254dSGiuliano Pochini break; 675dd7b254dSGiuliano Pochini case SNDRV_PCM_FORMAT_S16_LE: 676dd7b254dSGiuliano Pochini format.bits_per_sample = 16; 677dd7b254dSGiuliano Pochini break; 678dd7b254dSGiuliano Pochini case SNDRV_PCM_FORMAT_S24_3LE: 679dd7b254dSGiuliano Pochini format.bits_per_sample = 24; 680dd7b254dSGiuliano Pochini break; 681dd7b254dSGiuliano Pochini case SNDRV_PCM_FORMAT_S32_BE: 682dd7b254dSGiuliano Pochini format.data_are_bigendian = 1; 683dd7b254dSGiuliano Pochini case SNDRV_PCM_FORMAT_S32_LE: 684dd7b254dSGiuliano Pochini format.bits_per_sample = 32; 685dd7b254dSGiuliano Pochini break; 686dd7b254dSGiuliano Pochini default: 687dd7b254dSGiuliano Pochini DE_HWP(("Prepare error: unsupported format %d\n", 688dd7b254dSGiuliano Pochini runtime->format)); 689dd7b254dSGiuliano Pochini return -EINVAL; 690dd7b254dSGiuliano Pochini } 691dd7b254dSGiuliano Pochini 692dd7b254dSGiuliano Pochini snd_assert(pipe_index < px_num(chip), return -EINVAL); 693dd7b254dSGiuliano Pochini snd_assert(is_pipe_allocated(chip, pipe_index), return -EINVAL); 694dd7b254dSGiuliano Pochini set_audio_format(chip, pipe_index, &format); 695dd7b254dSGiuliano Pochini return 0; 696dd7b254dSGiuliano Pochini } 697dd7b254dSGiuliano Pochini 698dd7b254dSGiuliano Pochini 699dd7b254dSGiuliano Pochini 700dd7b254dSGiuliano Pochini static int pcm_trigger(struct snd_pcm_substream *substream, int cmd) 701dd7b254dSGiuliano Pochini { 702dd7b254dSGiuliano Pochini struct echoaudio *chip = snd_pcm_substream_chip(substream); 703dd7b254dSGiuliano Pochini struct snd_pcm_runtime *runtime = substream->runtime; 704dd7b254dSGiuliano Pochini struct audiopipe *pipe = runtime->private_data; 705dd7b254dSGiuliano Pochini int i, err; 706dd7b254dSGiuliano Pochini u32 channelmask = 0; 707dd7b254dSGiuliano Pochini struct list_head *pos; 708dd7b254dSGiuliano Pochini struct snd_pcm_substream *s; 709dd7b254dSGiuliano Pochini 710dd7b254dSGiuliano Pochini snd_pcm_group_for_each(pos, substream) { 711dd7b254dSGiuliano Pochini s = snd_pcm_group_substream_entry(pos); 712dd7b254dSGiuliano Pochini for (i = 0; i < DSP_MAXPIPES; i++) { 713dd7b254dSGiuliano Pochini if (s == chip->substream[i]) { 714dd7b254dSGiuliano Pochini channelmask |= 1 << i; 715dd7b254dSGiuliano Pochini snd_pcm_trigger_done(s, substream); 716dd7b254dSGiuliano Pochini } 717dd7b254dSGiuliano Pochini } 718dd7b254dSGiuliano Pochini } 719dd7b254dSGiuliano Pochini 720dd7b254dSGiuliano Pochini spin_lock(&chip->lock); 721dd7b254dSGiuliano Pochini switch (cmd) { 722dd7b254dSGiuliano Pochini case SNDRV_PCM_TRIGGER_START: 723dd7b254dSGiuliano Pochini case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 724dd7b254dSGiuliano Pochini DE_ACT(("pcm_trigger start\n")); 725dd7b254dSGiuliano Pochini for (i = 0; i < DSP_MAXPIPES; i++) { 726dd7b254dSGiuliano Pochini if (channelmask & (1 << i)) { 727dd7b254dSGiuliano Pochini pipe = chip->substream[i]->runtime->private_data; 728dd7b254dSGiuliano Pochini switch (pipe->state) { 729dd7b254dSGiuliano Pochini case PIPE_STATE_STOPPED: 730dd7b254dSGiuliano Pochini chip->last_period[i] = 0; 731dd7b254dSGiuliano Pochini pipe->last_counter = 0; 732dd7b254dSGiuliano Pochini pipe->position = 0; 733dd7b254dSGiuliano Pochini *pipe->dma_counter = 0; 734dd7b254dSGiuliano Pochini case PIPE_STATE_PAUSED: 735dd7b254dSGiuliano Pochini pipe->state = PIPE_STATE_STARTED; 736dd7b254dSGiuliano Pochini break; 737dd7b254dSGiuliano Pochini case PIPE_STATE_STARTED: 738dd7b254dSGiuliano Pochini break; 739dd7b254dSGiuliano Pochini } 740dd7b254dSGiuliano Pochini } 741dd7b254dSGiuliano Pochini } 742dd7b254dSGiuliano Pochini err = start_transport(chip, channelmask, 743dd7b254dSGiuliano Pochini chip->pipe_cyclic_mask); 744dd7b254dSGiuliano Pochini break; 745dd7b254dSGiuliano Pochini case SNDRV_PCM_TRIGGER_STOP: 746dd7b254dSGiuliano Pochini DE_ACT(("pcm_trigger stop\n")); 747dd7b254dSGiuliano Pochini for (i = 0; i < DSP_MAXPIPES; i++) { 748dd7b254dSGiuliano Pochini if (channelmask & (1 << i)) { 749dd7b254dSGiuliano Pochini pipe = chip->substream[i]->runtime->private_data; 750dd7b254dSGiuliano Pochini pipe->state = PIPE_STATE_STOPPED; 751dd7b254dSGiuliano Pochini } 752dd7b254dSGiuliano Pochini } 753dd7b254dSGiuliano Pochini err = stop_transport(chip, channelmask); 754dd7b254dSGiuliano Pochini break; 755dd7b254dSGiuliano Pochini case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 756dd7b254dSGiuliano Pochini DE_ACT(("pcm_trigger pause\n")); 757dd7b254dSGiuliano Pochini for (i = 0; i < DSP_MAXPIPES; i++) { 758dd7b254dSGiuliano Pochini if (channelmask & (1 << i)) { 759dd7b254dSGiuliano Pochini pipe = chip->substream[i]->runtime->private_data; 760dd7b254dSGiuliano Pochini pipe->state = PIPE_STATE_PAUSED; 761dd7b254dSGiuliano Pochini } 762dd7b254dSGiuliano Pochini } 763dd7b254dSGiuliano Pochini err = pause_transport(chip, channelmask); 764dd7b254dSGiuliano Pochini break; 765dd7b254dSGiuliano Pochini default: 766dd7b254dSGiuliano Pochini err = -EINVAL; 767dd7b254dSGiuliano Pochini } 768dd7b254dSGiuliano Pochini spin_unlock(&chip->lock); 769dd7b254dSGiuliano Pochini return err; 770dd7b254dSGiuliano Pochini } 771dd7b254dSGiuliano Pochini 772dd7b254dSGiuliano Pochini 773dd7b254dSGiuliano Pochini 774dd7b254dSGiuliano Pochini static snd_pcm_uframes_t pcm_pointer(struct snd_pcm_substream *substream) 775dd7b254dSGiuliano Pochini { 776dd7b254dSGiuliano Pochini struct snd_pcm_runtime *runtime = substream->runtime; 777dd7b254dSGiuliano Pochini struct audiopipe *pipe = runtime->private_data; 778dd7b254dSGiuliano Pochini size_t cnt, bufsize, pos; 779dd7b254dSGiuliano Pochini 780dd7b254dSGiuliano Pochini cnt = le32_to_cpu(*pipe->dma_counter); 781dd7b254dSGiuliano Pochini pipe->position += cnt - pipe->last_counter; 782dd7b254dSGiuliano Pochini pipe->last_counter = cnt; 783dd7b254dSGiuliano Pochini bufsize = substream->runtime->buffer_size; 784dd7b254dSGiuliano Pochini pos = bytes_to_frames(substream->runtime, pipe->position); 785dd7b254dSGiuliano Pochini 786dd7b254dSGiuliano Pochini while (pos >= bufsize) { 787dd7b254dSGiuliano Pochini pipe->position -= frames_to_bytes(substream->runtime, bufsize); 788dd7b254dSGiuliano Pochini pos -= bufsize; 789dd7b254dSGiuliano Pochini } 790dd7b254dSGiuliano Pochini return pos; 791dd7b254dSGiuliano Pochini } 792dd7b254dSGiuliano Pochini 793dd7b254dSGiuliano Pochini 794dd7b254dSGiuliano Pochini 795dd7b254dSGiuliano Pochini /* pcm *_ops structures */ 796dd7b254dSGiuliano Pochini static struct snd_pcm_ops analog_playback_ops = { 797dd7b254dSGiuliano Pochini .open = pcm_analog_out_open, 798dd7b254dSGiuliano Pochini .close = pcm_close, 799dd7b254dSGiuliano Pochini .ioctl = snd_pcm_lib_ioctl, 800dd7b254dSGiuliano Pochini .hw_params = pcm_analog_out_hw_params, 801dd7b254dSGiuliano Pochini .hw_free = pcm_hw_free, 802dd7b254dSGiuliano Pochini .prepare = pcm_prepare, 803dd7b254dSGiuliano Pochini .trigger = pcm_trigger, 804dd7b254dSGiuliano Pochini .pointer = pcm_pointer, 805dd7b254dSGiuliano Pochini .page = snd_pcm_sgbuf_ops_page, 806dd7b254dSGiuliano Pochini }; 807dd7b254dSGiuliano Pochini static struct snd_pcm_ops analog_capture_ops = { 808dd7b254dSGiuliano Pochini .open = pcm_analog_in_open, 809dd7b254dSGiuliano Pochini .close = pcm_close, 810dd7b254dSGiuliano Pochini .ioctl = snd_pcm_lib_ioctl, 811dd7b254dSGiuliano Pochini .hw_params = pcm_analog_in_hw_params, 812dd7b254dSGiuliano Pochini .hw_free = pcm_hw_free, 813dd7b254dSGiuliano Pochini .prepare = pcm_prepare, 814dd7b254dSGiuliano Pochini .trigger = pcm_trigger, 815dd7b254dSGiuliano Pochini .pointer = pcm_pointer, 816dd7b254dSGiuliano Pochini .page = snd_pcm_sgbuf_ops_page, 817dd7b254dSGiuliano Pochini }; 818dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_DIGITAL_IO 819dd7b254dSGiuliano Pochini #ifndef ECHOCARD_HAS_VMIXER 820dd7b254dSGiuliano Pochini static struct snd_pcm_ops digital_playback_ops = { 821dd7b254dSGiuliano Pochini .open = pcm_digital_out_open, 822dd7b254dSGiuliano Pochini .close = pcm_close, 823dd7b254dSGiuliano Pochini .ioctl = snd_pcm_lib_ioctl, 824dd7b254dSGiuliano Pochini .hw_params = pcm_digital_out_hw_params, 825dd7b254dSGiuliano Pochini .hw_free = pcm_hw_free, 826dd7b254dSGiuliano Pochini .prepare = pcm_prepare, 827dd7b254dSGiuliano Pochini .trigger = pcm_trigger, 828dd7b254dSGiuliano Pochini .pointer = pcm_pointer, 829dd7b254dSGiuliano Pochini .page = snd_pcm_sgbuf_ops_page, 830dd7b254dSGiuliano Pochini }; 831dd7b254dSGiuliano Pochini #endif /* !ECHOCARD_HAS_VMIXER */ 832dd7b254dSGiuliano Pochini static struct snd_pcm_ops digital_capture_ops = { 833dd7b254dSGiuliano Pochini .open = pcm_digital_in_open, 834dd7b254dSGiuliano Pochini .close = pcm_close, 835dd7b254dSGiuliano Pochini .ioctl = snd_pcm_lib_ioctl, 836dd7b254dSGiuliano Pochini .hw_params = pcm_digital_in_hw_params, 837dd7b254dSGiuliano Pochini .hw_free = pcm_hw_free, 838dd7b254dSGiuliano Pochini .prepare = pcm_prepare, 839dd7b254dSGiuliano Pochini .trigger = pcm_trigger, 840dd7b254dSGiuliano Pochini .pointer = pcm_pointer, 841dd7b254dSGiuliano Pochini .page = snd_pcm_sgbuf_ops_page, 842dd7b254dSGiuliano Pochini }; 843dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_DIGITAL_IO */ 844dd7b254dSGiuliano Pochini 845dd7b254dSGiuliano Pochini 846dd7b254dSGiuliano Pochini 847dd7b254dSGiuliano Pochini /* Preallocate memory only for the first substream because it's the most 848dd7b254dSGiuliano Pochini * used one 849dd7b254dSGiuliano Pochini */ 850dd7b254dSGiuliano Pochini static int snd_echo_preallocate_pages(struct snd_pcm *pcm, struct device *dev) 851dd7b254dSGiuliano Pochini { 852dd7b254dSGiuliano Pochini struct snd_pcm_substream *ss; 853dd7b254dSGiuliano Pochini int stream, err; 854dd7b254dSGiuliano Pochini 855dd7b254dSGiuliano Pochini for (stream = 0; stream < 2; stream++) 856dd7b254dSGiuliano Pochini for (ss = pcm->streams[stream].substream; ss; ss = ss->next) { 857dd7b254dSGiuliano Pochini err = snd_pcm_lib_preallocate_pages(ss, SNDRV_DMA_TYPE_DEV_SG, 858dd7b254dSGiuliano Pochini dev, 859dd7b254dSGiuliano Pochini ss->number ? 0 : 128<<10, 860dd7b254dSGiuliano Pochini 256<<10); 861dd7b254dSGiuliano Pochini if (err < 0) 862dd7b254dSGiuliano Pochini return err; 863dd7b254dSGiuliano Pochini } 864dd7b254dSGiuliano Pochini return 0; 865dd7b254dSGiuliano Pochini } 866dd7b254dSGiuliano Pochini 867dd7b254dSGiuliano Pochini 868dd7b254dSGiuliano Pochini 869dd7b254dSGiuliano Pochini /*<--snd_echo_probe() */ 870dd7b254dSGiuliano Pochini static int __devinit snd_echo_new_pcm(struct echoaudio *chip) 871dd7b254dSGiuliano Pochini { 872dd7b254dSGiuliano Pochini struct snd_pcm *pcm; 873dd7b254dSGiuliano Pochini int err; 874dd7b254dSGiuliano Pochini 875dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_VMIXER 876dd7b254dSGiuliano Pochini /* This card has a Vmixer, that is there is no direct mapping from PCM 877dd7b254dSGiuliano Pochini streams to physical outputs. The user can mix the streams as he wishes 878dd7b254dSGiuliano Pochini via control interface and it's possible to send any stream to any 879dd7b254dSGiuliano Pochini output, thus it makes no sense to keep analog and digital outputs 880dd7b254dSGiuliano Pochini separated */ 881dd7b254dSGiuliano Pochini 882dd7b254dSGiuliano Pochini /* PCM#0 Virtual outputs and analog inputs */ 883dd7b254dSGiuliano Pochini if ((err = snd_pcm_new(chip->card, "PCM", 0, num_pipes_out(chip), 884dd7b254dSGiuliano Pochini num_analog_busses_in(chip), &pcm)) < 0) 885dd7b254dSGiuliano Pochini return err; 886dd7b254dSGiuliano Pochini pcm->private_data = chip; 887dd7b254dSGiuliano Pochini chip->analog_pcm = pcm; 888dd7b254dSGiuliano Pochini strcpy(pcm->name, chip->card->shortname); 889dd7b254dSGiuliano Pochini snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops); 890dd7b254dSGiuliano Pochini snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops); 891dd7b254dSGiuliano Pochini if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0) 892dd7b254dSGiuliano Pochini return err; 893dd7b254dSGiuliano Pochini DE_INIT(("Analog PCM ok\n")); 894dd7b254dSGiuliano Pochini 895dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_DIGITAL_IO 896dd7b254dSGiuliano Pochini /* PCM#1 Digital inputs, no outputs */ 897dd7b254dSGiuliano Pochini if ((err = snd_pcm_new(chip->card, "Digital PCM", 1, 0, 898dd7b254dSGiuliano Pochini num_digital_busses_in(chip), &pcm)) < 0) 899dd7b254dSGiuliano Pochini return err; 900dd7b254dSGiuliano Pochini pcm->private_data = chip; 901dd7b254dSGiuliano Pochini chip->digital_pcm = pcm; 902dd7b254dSGiuliano Pochini strcpy(pcm->name, chip->card->shortname); 903dd7b254dSGiuliano Pochini snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops); 904dd7b254dSGiuliano Pochini if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0) 905dd7b254dSGiuliano Pochini return err; 906dd7b254dSGiuliano Pochini DE_INIT(("Digital PCM ok\n")); 907dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_DIGITAL_IO */ 908dd7b254dSGiuliano Pochini 909dd7b254dSGiuliano Pochini #else /* ECHOCARD_HAS_VMIXER */ 910dd7b254dSGiuliano Pochini 911dd7b254dSGiuliano Pochini /* The card can manage substreams formed by analog and digital channels 912dd7b254dSGiuliano Pochini at the same time, but I prefer to keep analog and digital channels 913dd7b254dSGiuliano Pochini separated, because that mixed thing is confusing and useless. So we 914dd7b254dSGiuliano Pochini register two PCM devices: */ 915dd7b254dSGiuliano Pochini 916dd7b254dSGiuliano Pochini /* PCM#0 Analog i/o */ 917dd7b254dSGiuliano Pochini if ((err = snd_pcm_new(chip->card, "Analog PCM", 0, 918dd7b254dSGiuliano Pochini num_analog_busses_out(chip), 919dd7b254dSGiuliano Pochini num_analog_busses_in(chip), &pcm)) < 0) 920dd7b254dSGiuliano Pochini return err; 921dd7b254dSGiuliano Pochini pcm->private_data = chip; 922dd7b254dSGiuliano Pochini chip->analog_pcm = pcm; 923dd7b254dSGiuliano Pochini strcpy(pcm->name, chip->card->shortname); 924dd7b254dSGiuliano Pochini snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops); 925dd7b254dSGiuliano Pochini snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops); 926dd7b254dSGiuliano Pochini if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0) 927dd7b254dSGiuliano Pochini return err; 928dd7b254dSGiuliano Pochini DE_INIT(("Analog PCM ok\n")); 929dd7b254dSGiuliano Pochini 930dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_DIGITAL_IO 931dd7b254dSGiuliano Pochini /* PCM#1 Digital i/o */ 932dd7b254dSGiuliano Pochini if ((err = snd_pcm_new(chip->card, "Digital PCM", 1, 933dd7b254dSGiuliano Pochini num_digital_busses_out(chip), 934dd7b254dSGiuliano Pochini num_digital_busses_in(chip), &pcm)) < 0) 935dd7b254dSGiuliano Pochini return err; 936dd7b254dSGiuliano Pochini pcm->private_data = chip; 937dd7b254dSGiuliano Pochini chip->digital_pcm = pcm; 938dd7b254dSGiuliano Pochini strcpy(pcm->name, chip->card->shortname); 939dd7b254dSGiuliano Pochini snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &digital_playback_ops); 940dd7b254dSGiuliano Pochini snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops); 941dd7b254dSGiuliano Pochini if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0) 942dd7b254dSGiuliano Pochini return err; 943dd7b254dSGiuliano Pochini DE_INIT(("Digital PCM ok\n")); 944dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_DIGITAL_IO */ 945dd7b254dSGiuliano Pochini 946dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_VMIXER */ 947dd7b254dSGiuliano Pochini 948dd7b254dSGiuliano Pochini return 0; 949dd7b254dSGiuliano Pochini } 950dd7b254dSGiuliano Pochini 951dd7b254dSGiuliano Pochini 952dd7b254dSGiuliano Pochini 953dd7b254dSGiuliano Pochini 954dd7b254dSGiuliano Pochini /****************************************************************************** 955dd7b254dSGiuliano Pochini Control interface 956dd7b254dSGiuliano Pochini ******************************************************************************/ 957dd7b254dSGiuliano Pochini 958dd7b254dSGiuliano Pochini /******************* PCM output volume *******************/ 959dd7b254dSGiuliano Pochini static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol, 960dd7b254dSGiuliano Pochini struct snd_ctl_elem_info *uinfo) 961dd7b254dSGiuliano Pochini { 962dd7b254dSGiuliano Pochini struct echoaudio *chip; 963dd7b254dSGiuliano Pochini 964dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 965dd7b254dSGiuliano Pochini uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 966dd7b254dSGiuliano Pochini uinfo->count = num_busses_out(chip); 967dd7b254dSGiuliano Pochini uinfo->value.integer.min = ECHOGAIN_MINOUT; 968dd7b254dSGiuliano Pochini uinfo->value.integer.max = ECHOGAIN_MAXOUT; 969dd7b254dSGiuliano Pochini return 0; 970dd7b254dSGiuliano Pochini } 971dd7b254dSGiuliano Pochini 972dd7b254dSGiuliano Pochini static int snd_echo_output_gain_get(struct snd_kcontrol *kcontrol, 973dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 974dd7b254dSGiuliano Pochini { 975dd7b254dSGiuliano Pochini struct echoaudio *chip; 976dd7b254dSGiuliano Pochini int c; 977dd7b254dSGiuliano Pochini 978dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 979dd7b254dSGiuliano Pochini for (c = 0; c < num_busses_out(chip); c++) 980dd7b254dSGiuliano Pochini ucontrol->value.integer.value[c] = chip->output_gain[c]; 981dd7b254dSGiuliano Pochini return 0; 982dd7b254dSGiuliano Pochini } 983dd7b254dSGiuliano Pochini 984dd7b254dSGiuliano Pochini static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol, 985dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 986dd7b254dSGiuliano Pochini { 987dd7b254dSGiuliano Pochini struct echoaudio *chip; 988dd7b254dSGiuliano Pochini int c, changed, gain; 989dd7b254dSGiuliano Pochini 990dd7b254dSGiuliano Pochini changed = 0; 991dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 992dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 993dd7b254dSGiuliano Pochini for (c = 0; c < num_busses_out(chip); c++) { 994dd7b254dSGiuliano Pochini gain = ucontrol->value.integer.value[c]; 995dd7b254dSGiuliano Pochini /* Ignore out of range values */ 996dd7b254dSGiuliano Pochini if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT) 997dd7b254dSGiuliano Pochini continue; 998dd7b254dSGiuliano Pochini if (chip->output_gain[c] != gain) { 999dd7b254dSGiuliano Pochini set_output_gain(chip, c, gain); 1000dd7b254dSGiuliano Pochini changed = 1; 1001dd7b254dSGiuliano Pochini } 1002dd7b254dSGiuliano Pochini } 1003dd7b254dSGiuliano Pochini if (changed) 1004dd7b254dSGiuliano Pochini update_output_line_level(chip); 1005dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 1006dd7b254dSGiuliano Pochini return changed; 1007dd7b254dSGiuliano Pochini } 1008dd7b254dSGiuliano Pochini 1009dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_VMIXER 1010dd7b254dSGiuliano Pochini /* On Vmixer cards this one controls the line-out volume */ 1011dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_line_output_gain __devinitdata = { 1012dd7b254dSGiuliano Pochini .name = "Line Playback Volume", 1013dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1014dd7b254dSGiuliano Pochini .info = snd_echo_output_gain_info, 1015dd7b254dSGiuliano Pochini .get = snd_echo_output_gain_get, 1016dd7b254dSGiuliano Pochini .put = snd_echo_output_gain_put, 1017dd7b254dSGiuliano Pochini }; 1018dd7b254dSGiuliano Pochini #else 1019dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_pcm_output_gain __devinitdata = { 1020dd7b254dSGiuliano Pochini .name = "PCM Playback Volume", 1021dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1022dd7b254dSGiuliano Pochini .info = snd_echo_output_gain_info, 1023dd7b254dSGiuliano Pochini .get = snd_echo_output_gain_get, 1024dd7b254dSGiuliano Pochini .put = snd_echo_output_gain_put, 1025dd7b254dSGiuliano Pochini }; 1026dd7b254dSGiuliano Pochini #endif 1027dd7b254dSGiuliano Pochini 1028dd7b254dSGiuliano Pochini 1029dd7b254dSGiuliano Pochini 1030dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_INPUT_GAIN 1031dd7b254dSGiuliano Pochini 1032dd7b254dSGiuliano Pochini /******************* Analog input volume *******************/ 1033dd7b254dSGiuliano Pochini static int snd_echo_input_gain_info(struct snd_kcontrol *kcontrol, 1034dd7b254dSGiuliano Pochini struct snd_ctl_elem_info *uinfo) 1035dd7b254dSGiuliano Pochini { 1036dd7b254dSGiuliano Pochini struct echoaudio *chip; 1037dd7b254dSGiuliano Pochini 1038dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1039dd7b254dSGiuliano Pochini uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1040dd7b254dSGiuliano Pochini uinfo->count = num_analog_busses_in(chip); 1041dd7b254dSGiuliano Pochini uinfo->value.integer.min = ECHOGAIN_MININP; 1042dd7b254dSGiuliano Pochini uinfo->value.integer.max = ECHOGAIN_MAXINP; 1043dd7b254dSGiuliano Pochini return 0; 1044dd7b254dSGiuliano Pochini } 1045dd7b254dSGiuliano Pochini 1046dd7b254dSGiuliano Pochini static int snd_echo_input_gain_get(struct snd_kcontrol *kcontrol, 1047dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1048dd7b254dSGiuliano Pochini { 1049dd7b254dSGiuliano Pochini struct echoaudio *chip; 1050dd7b254dSGiuliano Pochini int c; 1051dd7b254dSGiuliano Pochini 1052dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1053dd7b254dSGiuliano Pochini for (c = 0; c < num_analog_busses_in(chip); c++) 1054dd7b254dSGiuliano Pochini ucontrol->value.integer.value[c] = chip->input_gain[c]; 1055dd7b254dSGiuliano Pochini return 0; 1056dd7b254dSGiuliano Pochini } 1057dd7b254dSGiuliano Pochini 1058dd7b254dSGiuliano Pochini static int snd_echo_input_gain_put(struct snd_kcontrol *kcontrol, 1059dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1060dd7b254dSGiuliano Pochini { 1061dd7b254dSGiuliano Pochini struct echoaudio *chip; 1062dd7b254dSGiuliano Pochini int c, gain, changed; 1063dd7b254dSGiuliano Pochini 1064dd7b254dSGiuliano Pochini changed = 0; 1065dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1066dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 1067dd7b254dSGiuliano Pochini for (c = 0; c < num_analog_busses_in(chip); c++) { 1068dd7b254dSGiuliano Pochini gain = ucontrol->value.integer.value[c]; 1069dd7b254dSGiuliano Pochini /* Ignore out of range values */ 1070dd7b254dSGiuliano Pochini if (gain < ECHOGAIN_MININP || gain > ECHOGAIN_MAXINP) 1071dd7b254dSGiuliano Pochini continue; 1072dd7b254dSGiuliano Pochini if (chip->input_gain[c] != gain) { 1073dd7b254dSGiuliano Pochini set_input_gain(chip, c, gain); 1074dd7b254dSGiuliano Pochini changed = 1; 1075dd7b254dSGiuliano Pochini } 1076dd7b254dSGiuliano Pochini } 1077dd7b254dSGiuliano Pochini if (changed) 1078dd7b254dSGiuliano Pochini update_input_line_level(chip); 1079dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 1080dd7b254dSGiuliano Pochini return changed; 1081dd7b254dSGiuliano Pochini } 1082dd7b254dSGiuliano Pochini 1083dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_line_input_gain __devinitdata = { 1084dd7b254dSGiuliano Pochini .name = "Line Capture Volume", 1085dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1086dd7b254dSGiuliano Pochini .info = snd_echo_input_gain_info, 1087dd7b254dSGiuliano Pochini .get = snd_echo_input_gain_get, 1088dd7b254dSGiuliano Pochini .put = snd_echo_input_gain_put, 1089dd7b254dSGiuliano Pochini }; 1090dd7b254dSGiuliano Pochini 1091dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_INPUT_GAIN */ 1092dd7b254dSGiuliano Pochini 1093dd7b254dSGiuliano Pochini 1094dd7b254dSGiuliano Pochini 1095dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL 1096dd7b254dSGiuliano Pochini 1097dd7b254dSGiuliano Pochini /************ Analog output nominal level (+4dBu / -10dBV) ***************/ 1098dd7b254dSGiuliano Pochini static int snd_echo_output_nominal_info (struct snd_kcontrol *kcontrol, 1099dd7b254dSGiuliano Pochini struct snd_ctl_elem_info *uinfo) 1100dd7b254dSGiuliano Pochini { 1101dd7b254dSGiuliano Pochini struct echoaudio *chip; 1102dd7b254dSGiuliano Pochini 1103dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1104dd7b254dSGiuliano Pochini uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 1105dd7b254dSGiuliano Pochini uinfo->count = num_analog_busses_out(chip); 1106dd7b254dSGiuliano Pochini uinfo->value.integer.min = 0; 1107dd7b254dSGiuliano Pochini uinfo->value.integer.max = 1; 1108dd7b254dSGiuliano Pochini return 0; 1109dd7b254dSGiuliano Pochini } 1110dd7b254dSGiuliano Pochini 1111dd7b254dSGiuliano Pochini static int snd_echo_output_nominal_get(struct snd_kcontrol *kcontrol, 1112dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1113dd7b254dSGiuliano Pochini { 1114dd7b254dSGiuliano Pochini struct echoaudio *chip; 1115dd7b254dSGiuliano Pochini int c; 1116dd7b254dSGiuliano Pochini 1117dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1118dd7b254dSGiuliano Pochini for (c = 0; c < num_analog_busses_out(chip); c++) 1119dd7b254dSGiuliano Pochini ucontrol->value.integer.value[c] = chip->nominal_level[c]; 1120dd7b254dSGiuliano Pochini return 0; 1121dd7b254dSGiuliano Pochini } 1122dd7b254dSGiuliano Pochini 1123dd7b254dSGiuliano Pochini static int snd_echo_output_nominal_put(struct snd_kcontrol *kcontrol, 1124dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1125dd7b254dSGiuliano Pochini { 1126dd7b254dSGiuliano Pochini struct echoaudio *chip; 1127dd7b254dSGiuliano Pochini int c, changed; 1128dd7b254dSGiuliano Pochini 1129dd7b254dSGiuliano Pochini changed = 0; 1130dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1131dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 1132dd7b254dSGiuliano Pochini for (c = 0; c < num_analog_busses_out(chip); c++) { 1133dd7b254dSGiuliano Pochini if (chip->nominal_level[c] != ucontrol->value.integer.value[c]) { 1134dd7b254dSGiuliano Pochini set_nominal_level(chip, c, 1135dd7b254dSGiuliano Pochini ucontrol->value.integer.value[c]); 1136dd7b254dSGiuliano Pochini changed = 1; 1137dd7b254dSGiuliano Pochini } 1138dd7b254dSGiuliano Pochini } 1139dd7b254dSGiuliano Pochini if (changed) 1140dd7b254dSGiuliano Pochini update_output_line_level(chip); 1141dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 1142dd7b254dSGiuliano Pochini return changed; 1143dd7b254dSGiuliano Pochini } 1144dd7b254dSGiuliano Pochini 1145dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_output_nominal_level __devinitdata = { 1146dd7b254dSGiuliano Pochini .name = "Line Playback Switch (-10dBV)", 1147dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1148dd7b254dSGiuliano Pochini .info = snd_echo_output_nominal_info, 1149dd7b254dSGiuliano Pochini .get = snd_echo_output_nominal_get, 1150dd7b254dSGiuliano Pochini .put = snd_echo_output_nominal_put, 1151dd7b254dSGiuliano Pochini }; 1152dd7b254dSGiuliano Pochini 1153dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL */ 1154dd7b254dSGiuliano Pochini 1155dd7b254dSGiuliano Pochini 1156dd7b254dSGiuliano Pochini 1157dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL 1158dd7b254dSGiuliano Pochini 1159dd7b254dSGiuliano Pochini /*************** Analog input nominal level (+4dBu / -10dBV) ***************/ 1160dd7b254dSGiuliano Pochini static int snd_echo_input_nominal_info(struct snd_kcontrol *kcontrol, 1161dd7b254dSGiuliano Pochini struct snd_ctl_elem_info *uinfo) 1162dd7b254dSGiuliano Pochini { 1163dd7b254dSGiuliano Pochini struct echoaudio *chip; 1164dd7b254dSGiuliano Pochini 1165dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1166dd7b254dSGiuliano Pochini uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 1167dd7b254dSGiuliano Pochini uinfo->count = num_analog_busses_in(chip); 1168dd7b254dSGiuliano Pochini uinfo->value.integer.min = 0; 1169dd7b254dSGiuliano Pochini uinfo->value.integer.max = 1; 1170dd7b254dSGiuliano Pochini return 0; 1171dd7b254dSGiuliano Pochini } 1172dd7b254dSGiuliano Pochini 1173dd7b254dSGiuliano Pochini static int snd_echo_input_nominal_get(struct snd_kcontrol *kcontrol, 1174dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1175dd7b254dSGiuliano Pochini { 1176dd7b254dSGiuliano Pochini struct echoaudio *chip; 1177dd7b254dSGiuliano Pochini int c; 1178dd7b254dSGiuliano Pochini 1179dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1180dd7b254dSGiuliano Pochini for (c = 0; c < num_analog_busses_in(chip); c++) 1181dd7b254dSGiuliano Pochini ucontrol->value.integer.value[c] = 1182dd7b254dSGiuliano Pochini chip->nominal_level[bx_analog_in(chip) + c]; 1183dd7b254dSGiuliano Pochini return 0; 1184dd7b254dSGiuliano Pochini } 1185dd7b254dSGiuliano Pochini 1186dd7b254dSGiuliano Pochini static int snd_echo_input_nominal_put(struct snd_kcontrol *kcontrol, 1187dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1188dd7b254dSGiuliano Pochini { 1189dd7b254dSGiuliano Pochini struct echoaudio *chip; 1190dd7b254dSGiuliano Pochini int c, changed; 1191dd7b254dSGiuliano Pochini 1192dd7b254dSGiuliano Pochini changed = 0; 1193dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1194dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 1195dd7b254dSGiuliano Pochini for (c = 0; c < num_analog_busses_in(chip); c++) { 1196dd7b254dSGiuliano Pochini if (chip->nominal_level[bx_analog_in(chip) + c] != 1197dd7b254dSGiuliano Pochini ucontrol->value.integer.value[c]) { 1198dd7b254dSGiuliano Pochini set_nominal_level(chip, bx_analog_in(chip) + c, 1199dd7b254dSGiuliano Pochini ucontrol->value.integer.value[c]); 1200dd7b254dSGiuliano Pochini changed = 1; 1201dd7b254dSGiuliano Pochini } 1202dd7b254dSGiuliano Pochini } 1203dd7b254dSGiuliano Pochini if (changed) 1204dd7b254dSGiuliano Pochini update_output_line_level(chip); /* "Output" is not a mistake 1205dd7b254dSGiuliano Pochini * here. 1206dd7b254dSGiuliano Pochini */ 1207dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 1208dd7b254dSGiuliano Pochini return changed; 1209dd7b254dSGiuliano Pochini } 1210dd7b254dSGiuliano Pochini 1211dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_intput_nominal_level __devinitdata = { 1212dd7b254dSGiuliano Pochini .name = "Line Capture Switch (-10dBV)", 1213dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1214dd7b254dSGiuliano Pochini .info = snd_echo_input_nominal_info, 1215dd7b254dSGiuliano Pochini .get = snd_echo_input_nominal_get, 1216dd7b254dSGiuliano Pochini .put = snd_echo_input_nominal_put, 1217dd7b254dSGiuliano Pochini }; 1218dd7b254dSGiuliano Pochini 1219dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_INPUT_NOMINAL_LEVEL */ 1220dd7b254dSGiuliano Pochini 1221dd7b254dSGiuliano Pochini 1222dd7b254dSGiuliano Pochini 1223dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_MONITOR 1224dd7b254dSGiuliano Pochini 1225dd7b254dSGiuliano Pochini /******************* Monitor mixer *******************/ 1226dd7b254dSGiuliano Pochini static int snd_echo_mixer_info(struct snd_kcontrol *kcontrol, 1227dd7b254dSGiuliano Pochini struct snd_ctl_elem_info *uinfo) 1228dd7b254dSGiuliano Pochini { 1229dd7b254dSGiuliano Pochini struct echoaudio *chip; 1230dd7b254dSGiuliano Pochini 1231dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1232dd7b254dSGiuliano Pochini uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1233dd7b254dSGiuliano Pochini uinfo->count = 1; 1234dd7b254dSGiuliano Pochini uinfo->value.integer.min = ECHOGAIN_MINOUT; 1235dd7b254dSGiuliano Pochini uinfo->value.integer.max = ECHOGAIN_MAXOUT; 1236dd7b254dSGiuliano Pochini uinfo->dimen.d[0] = num_busses_out(chip); 1237dd7b254dSGiuliano Pochini uinfo->dimen.d[1] = num_busses_in(chip); 1238dd7b254dSGiuliano Pochini return 0; 1239dd7b254dSGiuliano Pochini } 1240dd7b254dSGiuliano Pochini 1241dd7b254dSGiuliano Pochini static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol, 1242dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1243dd7b254dSGiuliano Pochini { 1244dd7b254dSGiuliano Pochini struct echoaudio *chip; 1245dd7b254dSGiuliano Pochini 1246dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1247dd7b254dSGiuliano Pochini ucontrol->value.integer.value[0] = 1248dd7b254dSGiuliano Pochini chip->monitor_gain[ucontrol->id.index / num_busses_in(chip)] 1249dd7b254dSGiuliano Pochini [ucontrol->id.index % num_busses_in(chip)]; 1250dd7b254dSGiuliano Pochini return 0; 1251dd7b254dSGiuliano Pochini } 1252dd7b254dSGiuliano Pochini 1253dd7b254dSGiuliano Pochini static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol, 1254dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1255dd7b254dSGiuliano Pochini { 1256dd7b254dSGiuliano Pochini struct echoaudio *chip; 1257dd7b254dSGiuliano Pochini int changed, gain; 1258dd7b254dSGiuliano Pochini short out, in; 1259dd7b254dSGiuliano Pochini 1260dd7b254dSGiuliano Pochini changed = 0; 1261dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1262dd7b254dSGiuliano Pochini out = ucontrol->id.index / num_busses_in(chip); 1263dd7b254dSGiuliano Pochini in = ucontrol->id.index % num_busses_in(chip); 1264dd7b254dSGiuliano Pochini gain = ucontrol->value.integer.value[0]; 1265dd7b254dSGiuliano Pochini if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT) 1266dd7b254dSGiuliano Pochini return -EINVAL; 1267dd7b254dSGiuliano Pochini if (chip->monitor_gain[out][in] != gain) { 1268dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 1269dd7b254dSGiuliano Pochini set_monitor_gain(chip, out, in, gain); 1270dd7b254dSGiuliano Pochini update_output_line_level(chip); 1271dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 1272dd7b254dSGiuliano Pochini changed = 1; 1273dd7b254dSGiuliano Pochini } 1274dd7b254dSGiuliano Pochini return changed; 1275dd7b254dSGiuliano Pochini } 1276dd7b254dSGiuliano Pochini 1277dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_monitor_mixer __devinitdata = { 1278dd7b254dSGiuliano Pochini .name = "Monitor Mixer Volume", 1279dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1280dd7b254dSGiuliano Pochini .info = snd_echo_mixer_info, 1281dd7b254dSGiuliano Pochini .get = snd_echo_mixer_get, 1282dd7b254dSGiuliano Pochini .put = snd_echo_mixer_put, 1283dd7b254dSGiuliano Pochini }; 1284dd7b254dSGiuliano Pochini 1285dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_MONITOR */ 1286dd7b254dSGiuliano Pochini 1287dd7b254dSGiuliano Pochini 1288dd7b254dSGiuliano Pochini 1289dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_VMIXER 1290dd7b254dSGiuliano Pochini 1291dd7b254dSGiuliano Pochini /******************* Vmixer *******************/ 1292dd7b254dSGiuliano Pochini static int snd_echo_vmixer_info(struct snd_kcontrol *kcontrol, 1293dd7b254dSGiuliano Pochini struct snd_ctl_elem_info *uinfo) 1294dd7b254dSGiuliano Pochini { 1295dd7b254dSGiuliano Pochini struct echoaudio *chip; 1296dd7b254dSGiuliano Pochini 1297dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1298dd7b254dSGiuliano Pochini uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1299dd7b254dSGiuliano Pochini uinfo->count = 1; 1300dd7b254dSGiuliano Pochini uinfo->value.integer.min = ECHOGAIN_MINOUT; 1301dd7b254dSGiuliano Pochini uinfo->value.integer.max = ECHOGAIN_MAXOUT; 1302dd7b254dSGiuliano Pochini uinfo->dimen.d[0] = num_busses_out(chip); 1303dd7b254dSGiuliano Pochini uinfo->dimen.d[1] = num_pipes_out(chip); 1304dd7b254dSGiuliano Pochini return 0; 1305dd7b254dSGiuliano Pochini } 1306dd7b254dSGiuliano Pochini 1307dd7b254dSGiuliano Pochini static int snd_echo_vmixer_get(struct snd_kcontrol *kcontrol, 1308dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1309dd7b254dSGiuliano Pochini { 1310dd7b254dSGiuliano Pochini struct echoaudio *chip; 1311dd7b254dSGiuliano Pochini 1312dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1313dd7b254dSGiuliano Pochini ucontrol->value.integer.value[0] = 1314dd7b254dSGiuliano Pochini chip->vmixer_gain[ucontrol->id.index / num_pipes_out(chip)] 1315dd7b254dSGiuliano Pochini [ucontrol->id.index % num_pipes_out(chip)]; 1316dd7b254dSGiuliano Pochini return 0; 1317dd7b254dSGiuliano Pochini } 1318dd7b254dSGiuliano Pochini 1319dd7b254dSGiuliano Pochini static int snd_echo_vmixer_put(struct snd_kcontrol *kcontrol, 1320dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1321dd7b254dSGiuliano Pochini { 1322dd7b254dSGiuliano Pochini struct echoaudio *chip; 1323dd7b254dSGiuliano Pochini int gain, changed; 1324dd7b254dSGiuliano Pochini short vch, out; 1325dd7b254dSGiuliano Pochini 1326dd7b254dSGiuliano Pochini changed = 0; 1327dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1328dd7b254dSGiuliano Pochini out = ucontrol->id.index / num_pipes_out(chip); 1329dd7b254dSGiuliano Pochini vch = ucontrol->id.index % num_pipes_out(chip); 1330dd7b254dSGiuliano Pochini gain = ucontrol->value.integer.value[0]; 1331dd7b254dSGiuliano Pochini if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT) 1332dd7b254dSGiuliano Pochini return -EINVAL; 1333dd7b254dSGiuliano Pochini if (chip->vmixer_gain[out][vch] != ucontrol->value.integer.value[0]) { 1334dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 1335dd7b254dSGiuliano Pochini set_vmixer_gain(chip, out, vch, ucontrol->value.integer.value[0]); 1336dd7b254dSGiuliano Pochini update_vmixer_level(chip); 1337dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 1338dd7b254dSGiuliano Pochini changed = 1; 1339dd7b254dSGiuliano Pochini } 1340dd7b254dSGiuliano Pochini return changed; 1341dd7b254dSGiuliano Pochini } 1342dd7b254dSGiuliano Pochini 1343dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_vmixer __devinitdata = { 1344dd7b254dSGiuliano Pochini .name = "VMixer Volume", 1345dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1346dd7b254dSGiuliano Pochini .info = snd_echo_vmixer_info, 1347dd7b254dSGiuliano Pochini .get = snd_echo_vmixer_get, 1348dd7b254dSGiuliano Pochini .put = snd_echo_vmixer_put, 1349dd7b254dSGiuliano Pochini }; 1350dd7b254dSGiuliano Pochini 1351dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_VMIXER */ 1352dd7b254dSGiuliano Pochini 1353dd7b254dSGiuliano Pochini 1354dd7b254dSGiuliano Pochini 1355dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH 1356dd7b254dSGiuliano Pochini 1357dd7b254dSGiuliano Pochini /******************* Digital mode switch *******************/ 1358dd7b254dSGiuliano Pochini static int snd_echo_digital_mode_info(struct snd_kcontrol *kcontrol, 1359dd7b254dSGiuliano Pochini struct snd_ctl_elem_info *uinfo) 1360dd7b254dSGiuliano Pochini { 1361dd7b254dSGiuliano Pochini static char *names[4] = { 1362dd7b254dSGiuliano Pochini "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical", 1363dd7b254dSGiuliano Pochini "S/PDIF Cdrom" 1364dd7b254dSGiuliano Pochini }; 1365dd7b254dSGiuliano Pochini struct echoaudio *chip; 1366dd7b254dSGiuliano Pochini 1367dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1368dd7b254dSGiuliano Pochini uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1369dd7b254dSGiuliano Pochini uinfo->value.enumerated.items = chip->num_digital_modes; 1370dd7b254dSGiuliano Pochini uinfo->count = 1; 1371dd7b254dSGiuliano Pochini if (uinfo->value.enumerated.item >= chip->num_digital_modes) 1372dd7b254dSGiuliano Pochini uinfo->value.enumerated.item = chip->num_digital_modes - 1; 1373dd7b254dSGiuliano Pochini strcpy(uinfo->value.enumerated.name, names[ 1374dd7b254dSGiuliano Pochini chip->digital_mode_list[uinfo->value.enumerated.item]]); 1375dd7b254dSGiuliano Pochini return 0; 1376dd7b254dSGiuliano Pochini } 1377dd7b254dSGiuliano Pochini 1378dd7b254dSGiuliano Pochini static int snd_echo_digital_mode_get(struct snd_kcontrol *kcontrol, 1379dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1380dd7b254dSGiuliano Pochini { 1381dd7b254dSGiuliano Pochini struct echoaudio *chip; 1382dd7b254dSGiuliano Pochini int i, mode; 1383dd7b254dSGiuliano Pochini 1384dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1385dd7b254dSGiuliano Pochini mode = chip->digital_mode; 1386dd7b254dSGiuliano Pochini for (i = chip->num_digital_modes - 1; i >= 0; i--) 1387dd7b254dSGiuliano Pochini if (mode == chip->digital_mode_list[i]) { 1388dd7b254dSGiuliano Pochini ucontrol->value.enumerated.item[0] = i; 1389dd7b254dSGiuliano Pochini break; 1390dd7b254dSGiuliano Pochini } 1391dd7b254dSGiuliano Pochini return 0; 1392dd7b254dSGiuliano Pochini } 1393dd7b254dSGiuliano Pochini 1394dd7b254dSGiuliano Pochini static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol, 1395dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1396dd7b254dSGiuliano Pochini { 1397dd7b254dSGiuliano Pochini struct echoaudio *chip; 1398dd7b254dSGiuliano Pochini int changed; 1399dd7b254dSGiuliano Pochini unsigned short emode, dmode; 1400dd7b254dSGiuliano Pochini 1401dd7b254dSGiuliano Pochini changed = 0; 1402dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1403dd7b254dSGiuliano Pochini 1404dd7b254dSGiuliano Pochini emode = ucontrol->value.enumerated.item[0]; 1405dd7b254dSGiuliano Pochini if (emode >= chip->num_digital_modes) 1406dd7b254dSGiuliano Pochini return -EINVAL; 1407dd7b254dSGiuliano Pochini dmode = chip->digital_mode_list[emode]; 1408dd7b254dSGiuliano Pochini 1409dd7b254dSGiuliano Pochini if (dmode != chip->digital_mode) { 1410dd7b254dSGiuliano Pochini /* mode_mutex is required to make this operation atomic wrt 1411dd7b254dSGiuliano Pochini pcm_digital_*_open() and set_input_clock() functions. */ 1412dd7b254dSGiuliano Pochini down(&chip->mode_mutex); 1413dd7b254dSGiuliano Pochini 1414dd7b254dSGiuliano Pochini /* Do not allow the user to change the digital mode when a pcm 1415dd7b254dSGiuliano Pochini device is open because it also changes the number of channels 1416dd7b254dSGiuliano Pochini and the allowed sample rates */ 1417dd7b254dSGiuliano Pochini if (atomic_read(&chip->opencount)) { 1418dd7b254dSGiuliano Pochini changed = -EAGAIN; 1419dd7b254dSGiuliano Pochini } else { 1420dd7b254dSGiuliano Pochini changed = set_digital_mode(chip, dmode); 1421dd7b254dSGiuliano Pochini /* If we had to change the clock source, report it */ 1422dd7b254dSGiuliano Pochini if (changed > 0 && chip->clock_src_ctl) { 1423dd7b254dSGiuliano Pochini snd_ctl_notify(chip->card, 1424dd7b254dSGiuliano Pochini SNDRV_CTL_EVENT_MASK_VALUE, 1425dd7b254dSGiuliano Pochini &chip->clock_src_ctl->id); 1426dd7b254dSGiuliano Pochini DE_ACT(("SDM() =%d\n", changed)); 1427dd7b254dSGiuliano Pochini } 1428dd7b254dSGiuliano Pochini if (changed >= 0) 1429dd7b254dSGiuliano Pochini changed = 1; /* No errors */ 1430dd7b254dSGiuliano Pochini } 1431dd7b254dSGiuliano Pochini up(&chip->mode_mutex); 1432dd7b254dSGiuliano Pochini } 1433dd7b254dSGiuliano Pochini return changed; 1434dd7b254dSGiuliano Pochini } 1435dd7b254dSGiuliano Pochini 1436dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_digital_mode_switch __devinitdata = { 1437dd7b254dSGiuliano Pochini .name = "Digital mode Switch", 1438dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_CARD, 1439dd7b254dSGiuliano Pochini .info = snd_echo_digital_mode_info, 1440dd7b254dSGiuliano Pochini .get = snd_echo_digital_mode_get, 1441dd7b254dSGiuliano Pochini .put = snd_echo_digital_mode_put, 1442dd7b254dSGiuliano Pochini }; 1443dd7b254dSGiuliano Pochini 1444dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */ 1445dd7b254dSGiuliano Pochini 1446dd7b254dSGiuliano Pochini 1447dd7b254dSGiuliano Pochini 1448dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_DIGITAL_IO 1449dd7b254dSGiuliano Pochini 1450dd7b254dSGiuliano Pochini /******************* S/PDIF mode switch *******************/ 1451dd7b254dSGiuliano Pochini static int snd_echo_spdif_mode_info(struct snd_kcontrol *kcontrol, 1452dd7b254dSGiuliano Pochini struct snd_ctl_elem_info *uinfo) 1453dd7b254dSGiuliano Pochini { 1454dd7b254dSGiuliano Pochini static char *names[2] = {"Consumer", "Professional"}; 1455dd7b254dSGiuliano Pochini 1456dd7b254dSGiuliano Pochini uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1457dd7b254dSGiuliano Pochini uinfo->value.enumerated.items = 2; 1458dd7b254dSGiuliano Pochini uinfo->count = 1; 1459dd7b254dSGiuliano Pochini if (uinfo->value.enumerated.item) 1460dd7b254dSGiuliano Pochini uinfo->value.enumerated.item = 1; 1461dd7b254dSGiuliano Pochini strcpy(uinfo->value.enumerated.name, 1462dd7b254dSGiuliano Pochini names[uinfo->value.enumerated.item]); 1463dd7b254dSGiuliano Pochini return 0; 1464dd7b254dSGiuliano Pochini } 1465dd7b254dSGiuliano Pochini 1466dd7b254dSGiuliano Pochini static int snd_echo_spdif_mode_get(struct snd_kcontrol *kcontrol, 1467dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1468dd7b254dSGiuliano Pochini { 1469dd7b254dSGiuliano Pochini struct echoaudio *chip; 1470dd7b254dSGiuliano Pochini 1471dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1472dd7b254dSGiuliano Pochini ucontrol->value.enumerated.item[0] = !!chip->professional_spdif; 1473dd7b254dSGiuliano Pochini return 0; 1474dd7b254dSGiuliano Pochini } 1475dd7b254dSGiuliano Pochini 1476dd7b254dSGiuliano Pochini static int snd_echo_spdif_mode_put(struct snd_kcontrol *kcontrol, 1477dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1478dd7b254dSGiuliano Pochini { 1479dd7b254dSGiuliano Pochini struct echoaudio *chip; 1480dd7b254dSGiuliano Pochini int mode; 1481dd7b254dSGiuliano Pochini 1482dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1483dd7b254dSGiuliano Pochini mode = !!ucontrol->value.enumerated.item[0]; 1484dd7b254dSGiuliano Pochini if (mode != chip->professional_spdif) { 1485dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 1486dd7b254dSGiuliano Pochini set_professional_spdif(chip, mode); 1487dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 1488dd7b254dSGiuliano Pochini return 1; 1489dd7b254dSGiuliano Pochini } 1490dd7b254dSGiuliano Pochini return 0; 1491dd7b254dSGiuliano Pochini } 1492dd7b254dSGiuliano Pochini 1493dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_spdif_mode_switch __devinitdata = { 1494dd7b254dSGiuliano Pochini .name = "S/PDIF mode Switch", 1495dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_CARD, 1496dd7b254dSGiuliano Pochini .info = snd_echo_spdif_mode_info, 1497dd7b254dSGiuliano Pochini .get = snd_echo_spdif_mode_get, 1498dd7b254dSGiuliano Pochini .put = snd_echo_spdif_mode_put, 1499dd7b254dSGiuliano Pochini }; 1500dd7b254dSGiuliano Pochini 1501dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_DIGITAL_IO */ 1502dd7b254dSGiuliano Pochini 1503dd7b254dSGiuliano Pochini 1504dd7b254dSGiuliano Pochini 1505dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK 1506dd7b254dSGiuliano Pochini 1507dd7b254dSGiuliano Pochini /******************* Select input clock source *******************/ 1508dd7b254dSGiuliano Pochini static int snd_echo_clock_source_info(struct snd_kcontrol *kcontrol, 1509dd7b254dSGiuliano Pochini struct snd_ctl_elem_info *uinfo) 1510dd7b254dSGiuliano Pochini { 1511dd7b254dSGiuliano Pochini static char *names[8] = { 1512dd7b254dSGiuliano Pochini "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync", 1513dd7b254dSGiuliano Pochini "ESync96", "MTC" 1514dd7b254dSGiuliano Pochini }; 1515dd7b254dSGiuliano Pochini struct echoaudio *chip; 1516dd7b254dSGiuliano Pochini 1517dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1518dd7b254dSGiuliano Pochini uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1519dd7b254dSGiuliano Pochini uinfo->value.enumerated.items = chip->num_clock_sources; 1520dd7b254dSGiuliano Pochini uinfo->count = 1; 1521dd7b254dSGiuliano Pochini if (uinfo->value.enumerated.item >= chip->num_clock_sources) 1522dd7b254dSGiuliano Pochini uinfo->value.enumerated.item = chip->num_clock_sources - 1; 1523dd7b254dSGiuliano Pochini strcpy(uinfo->value.enumerated.name, names[ 1524dd7b254dSGiuliano Pochini chip->clock_source_list[uinfo->value.enumerated.item]]); 1525dd7b254dSGiuliano Pochini return 0; 1526dd7b254dSGiuliano Pochini } 1527dd7b254dSGiuliano Pochini 1528dd7b254dSGiuliano Pochini static int snd_echo_clock_source_get(struct snd_kcontrol *kcontrol, 1529dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1530dd7b254dSGiuliano Pochini { 1531dd7b254dSGiuliano Pochini struct echoaudio *chip; 1532dd7b254dSGiuliano Pochini int i, clock; 1533dd7b254dSGiuliano Pochini 1534dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1535dd7b254dSGiuliano Pochini clock = chip->input_clock; 1536dd7b254dSGiuliano Pochini 1537dd7b254dSGiuliano Pochini for (i = 0; i < chip->num_clock_sources; i++) 1538dd7b254dSGiuliano Pochini if (clock == chip->clock_source_list[i]) 1539dd7b254dSGiuliano Pochini ucontrol->value.enumerated.item[0] = i; 1540dd7b254dSGiuliano Pochini 1541dd7b254dSGiuliano Pochini return 0; 1542dd7b254dSGiuliano Pochini } 1543dd7b254dSGiuliano Pochini 1544dd7b254dSGiuliano Pochini static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol, 1545dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1546dd7b254dSGiuliano Pochini { 1547dd7b254dSGiuliano Pochini struct echoaudio *chip; 1548dd7b254dSGiuliano Pochini int changed; 1549dd7b254dSGiuliano Pochini unsigned int eclock, dclock; 1550dd7b254dSGiuliano Pochini 1551dd7b254dSGiuliano Pochini changed = 0; 1552dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1553dd7b254dSGiuliano Pochini eclock = ucontrol->value.enumerated.item[0]; 1554dd7b254dSGiuliano Pochini if (eclock >= chip->input_clock_types) 1555dd7b254dSGiuliano Pochini return -EINVAL; 1556dd7b254dSGiuliano Pochini dclock = chip->clock_source_list[eclock]; 1557dd7b254dSGiuliano Pochini if (chip->input_clock != dclock) { 1558dd7b254dSGiuliano Pochini down(&chip->mode_mutex); 1559dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 1560dd7b254dSGiuliano Pochini if ((changed = set_input_clock(chip, dclock)) == 0) 1561dd7b254dSGiuliano Pochini changed = 1; /* no errors */ 1562dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 1563dd7b254dSGiuliano Pochini up(&chip->mode_mutex); 1564dd7b254dSGiuliano Pochini } 1565dd7b254dSGiuliano Pochini 1566dd7b254dSGiuliano Pochini if (changed < 0) 1567dd7b254dSGiuliano Pochini DE_ACT(("seticlk val%d err 0x%x\n", dclock, changed)); 1568dd7b254dSGiuliano Pochini 1569dd7b254dSGiuliano Pochini return changed; 1570dd7b254dSGiuliano Pochini } 1571dd7b254dSGiuliano Pochini 1572dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_clock_source_switch __devinitdata = { 1573dd7b254dSGiuliano Pochini .name = "Sample Clock Source", 1574dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1575dd7b254dSGiuliano Pochini .info = snd_echo_clock_source_info, 1576dd7b254dSGiuliano Pochini .get = snd_echo_clock_source_get, 1577dd7b254dSGiuliano Pochini .put = snd_echo_clock_source_put, 1578dd7b254dSGiuliano Pochini }; 1579dd7b254dSGiuliano Pochini 1580dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */ 1581dd7b254dSGiuliano Pochini 1582dd7b254dSGiuliano Pochini 1583dd7b254dSGiuliano Pochini 1584dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_PHANTOM_POWER 1585dd7b254dSGiuliano Pochini 1586dd7b254dSGiuliano Pochini /******************* Phantom power switch *******************/ 1587dd7b254dSGiuliano Pochini static int snd_echo_phantom_power_info(struct snd_kcontrol *kcontrol, 1588dd7b254dSGiuliano Pochini struct snd_ctl_elem_info *uinfo) 1589dd7b254dSGiuliano Pochini { 1590dd7b254dSGiuliano Pochini uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 1591dd7b254dSGiuliano Pochini uinfo->count = 1; 1592dd7b254dSGiuliano Pochini uinfo->value.integer.min = 0; 1593dd7b254dSGiuliano Pochini uinfo->value.integer.max = 1; 1594dd7b254dSGiuliano Pochini return 0; 1595dd7b254dSGiuliano Pochini } 1596dd7b254dSGiuliano Pochini 1597dd7b254dSGiuliano Pochini static int snd_echo_phantom_power_get(struct snd_kcontrol *kcontrol, 1598dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1599dd7b254dSGiuliano Pochini { 1600dd7b254dSGiuliano Pochini struct echoaudio *chip = snd_kcontrol_chip(kcontrol); 1601dd7b254dSGiuliano Pochini 1602dd7b254dSGiuliano Pochini ucontrol->value.integer.value[0] = chip->phantom_power; 1603dd7b254dSGiuliano Pochini return 0; 1604dd7b254dSGiuliano Pochini } 1605dd7b254dSGiuliano Pochini 1606dd7b254dSGiuliano Pochini static int snd_echo_phantom_power_put(struct snd_kcontrol *kcontrol, 1607dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1608dd7b254dSGiuliano Pochini { 1609dd7b254dSGiuliano Pochini struct echoaudio *chip = snd_kcontrol_chip(kcontrol); 1610dd7b254dSGiuliano Pochini int power, changed = 0; 1611dd7b254dSGiuliano Pochini 1612dd7b254dSGiuliano Pochini power = !!ucontrol->value.integer.value[0]; 1613dd7b254dSGiuliano Pochini if (chip->phantom_power != power) { 1614dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 1615dd7b254dSGiuliano Pochini changed = set_phantom_power(chip, power); 1616dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 1617dd7b254dSGiuliano Pochini if (changed == 0) 1618dd7b254dSGiuliano Pochini changed = 1; /* no errors */ 1619dd7b254dSGiuliano Pochini } 1620dd7b254dSGiuliano Pochini return changed; 1621dd7b254dSGiuliano Pochini } 1622dd7b254dSGiuliano Pochini 1623dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_phantom_power_switch __devinitdata = { 1624dd7b254dSGiuliano Pochini .name = "Phantom power Switch", 1625dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_CARD, 1626dd7b254dSGiuliano Pochini .info = snd_echo_phantom_power_info, 1627dd7b254dSGiuliano Pochini .get = snd_echo_phantom_power_get, 1628dd7b254dSGiuliano Pochini .put = snd_echo_phantom_power_put, 1629dd7b254dSGiuliano Pochini }; 1630dd7b254dSGiuliano Pochini 1631dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_PHANTOM_POWER */ 1632dd7b254dSGiuliano Pochini 1633dd7b254dSGiuliano Pochini 1634dd7b254dSGiuliano Pochini 1635dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE 1636dd7b254dSGiuliano Pochini 1637dd7b254dSGiuliano Pochini /******************* Digital input automute switch *******************/ 1638dd7b254dSGiuliano Pochini static int snd_echo_automute_info(struct snd_kcontrol *kcontrol, 1639dd7b254dSGiuliano Pochini struct snd_ctl_elem_info *uinfo) 1640dd7b254dSGiuliano Pochini { 1641dd7b254dSGiuliano Pochini uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 1642dd7b254dSGiuliano Pochini uinfo->count = 1; 1643dd7b254dSGiuliano Pochini uinfo->value.integer.min = 0; 1644dd7b254dSGiuliano Pochini uinfo->value.integer.max = 1; 1645dd7b254dSGiuliano Pochini return 0; 1646dd7b254dSGiuliano Pochini } 1647dd7b254dSGiuliano Pochini 1648dd7b254dSGiuliano Pochini static int snd_echo_automute_get(struct snd_kcontrol *kcontrol, 1649dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1650dd7b254dSGiuliano Pochini { 1651dd7b254dSGiuliano Pochini struct echoaudio *chip = snd_kcontrol_chip(kcontrol); 1652dd7b254dSGiuliano Pochini 1653dd7b254dSGiuliano Pochini ucontrol->value.integer.value[0] = chip->digital_in_automute; 1654dd7b254dSGiuliano Pochini return 0; 1655dd7b254dSGiuliano Pochini } 1656dd7b254dSGiuliano Pochini 1657dd7b254dSGiuliano Pochini static int snd_echo_automute_put(struct snd_kcontrol *kcontrol, 1658dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1659dd7b254dSGiuliano Pochini { 1660dd7b254dSGiuliano Pochini struct echoaudio *chip = snd_kcontrol_chip(kcontrol); 1661dd7b254dSGiuliano Pochini int automute, changed = 0; 1662dd7b254dSGiuliano Pochini 1663dd7b254dSGiuliano Pochini automute = !!ucontrol->value.integer.value[0]; 1664dd7b254dSGiuliano Pochini if (chip->digital_in_automute != automute) { 1665dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 1666dd7b254dSGiuliano Pochini changed = set_input_auto_mute(chip, automute); 1667dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 1668dd7b254dSGiuliano Pochini if (changed == 0) 1669dd7b254dSGiuliano Pochini changed = 1; /* no errors */ 1670dd7b254dSGiuliano Pochini } 1671dd7b254dSGiuliano Pochini return changed; 1672dd7b254dSGiuliano Pochini } 1673dd7b254dSGiuliano Pochini 1674dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_automute_switch __devinitdata = { 1675dd7b254dSGiuliano Pochini .name = "Digital Capture Switch (automute)", 1676dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_CARD, 1677dd7b254dSGiuliano Pochini .info = snd_echo_automute_info, 1678dd7b254dSGiuliano Pochini .get = snd_echo_automute_get, 1679dd7b254dSGiuliano Pochini .put = snd_echo_automute_put, 1680dd7b254dSGiuliano Pochini }; 1681dd7b254dSGiuliano Pochini 1682dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */ 1683dd7b254dSGiuliano Pochini 1684dd7b254dSGiuliano Pochini 1685dd7b254dSGiuliano Pochini 1686dd7b254dSGiuliano Pochini /******************* VU-meters switch *******************/ 1687dd7b254dSGiuliano Pochini static int snd_echo_vumeters_switch_info(struct snd_kcontrol *kcontrol, 1688dd7b254dSGiuliano Pochini struct snd_ctl_elem_info *uinfo) 1689dd7b254dSGiuliano Pochini { 1690dd7b254dSGiuliano Pochini struct echoaudio *chip; 1691dd7b254dSGiuliano Pochini 1692dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1693dd7b254dSGiuliano Pochini uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 1694dd7b254dSGiuliano Pochini uinfo->count = 1; 1695dd7b254dSGiuliano Pochini uinfo->value.integer.min = 0; 1696dd7b254dSGiuliano Pochini uinfo->value.integer.max = 1; 1697dd7b254dSGiuliano Pochini return 0; 1698dd7b254dSGiuliano Pochini } 1699dd7b254dSGiuliano Pochini 1700dd7b254dSGiuliano Pochini static int snd_echo_vumeters_switch_put(struct snd_kcontrol *kcontrol, 1701dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1702dd7b254dSGiuliano Pochini { 1703dd7b254dSGiuliano Pochini struct echoaudio *chip; 1704dd7b254dSGiuliano Pochini 1705dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1706dd7b254dSGiuliano Pochini spin_lock_irq(&chip->lock); 1707dd7b254dSGiuliano Pochini set_meters_on(chip, ucontrol->value.integer.value[0]); 1708dd7b254dSGiuliano Pochini spin_unlock_irq(&chip->lock); 1709dd7b254dSGiuliano Pochini return 1; 1710dd7b254dSGiuliano Pochini } 1711dd7b254dSGiuliano Pochini 1712dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_vumeters_switch __devinitdata = { 1713dd7b254dSGiuliano Pochini .name = "VU-meters Switch", 1714dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_CARD, 1715dd7b254dSGiuliano Pochini .access = SNDRV_CTL_ELEM_ACCESS_WRITE, 1716dd7b254dSGiuliano Pochini .info = snd_echo_vumeters_switch_info, 1717dd7b254dSGiuliano Pochini .put = snd_echo_vumeters_switch_put, 1718dd7b254dSGiuliano Pochini }; 1719dd7b254dSGiuliano Pochini 1720dd7b254dSGiuliano Pochini 1721dd7b254dSGiuliano Pochini 1722dd7b254dSGiuliano Pochini /***** Read VU-meters (input, output, analog and digital together) *****/ 1723dd7b254dSGiuliano Pochini static int snd_echo_vumeters_info(struct snd_kcontrol *kcontrol, 1724dd7b254dSGiuliano Pochini struct snd_ctl_elem_info *uinfo) 1725dd7b254dSGiuliano Pochini { 1726dd7b254dSGiuliano Pochini struct echoaudio *chip; 1727dd7b254dSGiuliano Pochini 1728dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1729dd7b254dSGiuliano Pochini uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1730dd7b254dSGiuliano Pochini uinfo->count = 96; 1731dd7b254dSGiuliano Pochini uinfo->value.integer.min = ECHOGAIN_MINOUT; 1732dd7b254dSGiuliano Pochini uinfo->value.integer.max = 0; 1733dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_VMIXER 1734dd7b254dSGiuliano Pochini uinfo->dimen.d[0] = 3; /* Out, In, Virt */ 1735dd7b254dSGiuliano Pochini #else 1736dd7b254dSGiuliano Pochini uinfo->dimen.d[0] = 2; /* Out, In */ 1737dd7b254dSGiuliano Pochini #endif 1738dd7b254dSGiuliano Pochini uinfo->dimen.d[1] = 16; /* 16 channels */ 1739dd7b254dSGiuliano Pochini uinfo->dimen.d[2] = 2; /* 0=level, 1=peak */ 1740dd7b254dSGiuliano Pochini return 0; 1741dd7b254dSGiuliano Pochini } 1742dd7b254dSGiuliano Pochini 1743dd7b254dSGiuliano Pochini static int snd_echo_vumeters_get(struct snd_kcontrol *kcontrol, 1744dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1745dd7b254dSGiuliano Pochini { 1746dd7b254dSGiuliano Pochini struct echoaudio *chip; 1747dd7b254dSGiuliano Pochini 1748dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1749dd7b254dSGiuliano Pochini get_audio_meters(chip, ucontrol->value.integer.value); 1750dd7b254dSGiuliano Pochini return 0; 1751dd7b254dSGiuliano Pochini } 1752dd7b254dSGiuliano Pochini 1753dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_vumeters __devinitdata = { 1754dd7b254dSGiuliano Pochini .name = "VU-meters", 1755dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1756dd7b254dSGiuliano Pochini .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 1757dd7b254dSGiuliano Pochini .info = snd_echo_vumeters_info, 1758dd7b254dSGiuliano Pochini .get = snd_echo_vumeters_get, 1759dd7b254dSGiuliano Pochini }; 1760dd7b254dSGiuliano Pochini 1761dd7b254dSGiuliano Pochini 1762dd7b254dSGiuliano Pochini 1763dd7b254dSGiuliano Pochini /*** Channels info - it exports informations about the number of channels ***/ 1764dd7b254dSGiuliano Pochini static int snd_echo_channels_info_info(struct snd_kcontrol *kcontrol, 1765dd7b254dSGiuliano Pochini struct snd_ctl_elem_info *uinfo) 1766dd7b254dSGiuliano Pochini { 1767dd7b254dSGiuliano Pochini struct echoaudio *chip; 1768dd7b254dSGiuliano Pochini 1769dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1770dd7b254dSGiuliano Pochini uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1771dd7b254dSGiuliano Pochini uinfo->count = 6; 1772dd7b254dSGiuliano Pochini uinfo->value.integer.min = 0; 1773dd7b254dSGiuliano Pochini uinfo->value.integer.max = 1 << ECHO_CLOCK_NUMBER; 1774dd7b254dSGiuliano Pochini return 0; 1775dd7b254dSGiuliano Pochini } 1776dd7b254dSGiuliano Pochini 1777dd7b254dSGiuliano Pochini static int snd_echo_channels_info_get(struct snd_kcontrol *kcontrol, 1778dd7b254dSGiuliano Pochini struct snd_ctl_elem_value *ucontrol) 1779dd7b254dSGiuliano Pochini { 1780dd7b254dSGiuliano Pochini struct echoaudio *chip; 1781dd7b254dSGiuliano Pochini int detected, clocks, bit, src; 1782dd7b254dSGiuliano Pochini 1783dd7b254dSGiuliano Pochini chip = snd_kcontrol_chip(kcontrol); 1784dd7b254dSGiuliano Pochini ucontrol->value.integer.value[0] = num_busses_in(chip); 1785dd7b254dSGiuliano Pochini ucontrol->value.integer.value[1] = num_analog_busses_in(chip); 1786dd7b254dSGiuliano Pochini ucontrol->value.integer.value[2] = num_busses_out(chip); 1787dd7b254dSGiuliano Pochini ucontrol->value.integer.value[3] = num_analog_busses_out(chip); 1788dd7b254dSGiuliano Pochini ucontrol->value.integer.value[4] = num_pipes_out(chip); 1789dd7b254dSGiuliano Pochini 1790dd7b254dSGiuliano Pochini /* Compute the bitmask of the currently valid input clocks */ 1791dd7b254dSGiuliano Pochini detected = detect_input_clocks(chip); 1792dd7b254dSGiuliano Pochini clocks = 0; 1793dd7b254dSGiuliano Pochini src = chip->num_clock_sources - 1; 1794dd7b254dSGiuliano Pochini for (bit = ECHO_CLOCK_NUMBER - 1; bit >= 0; bit--) 1795dd7b254dSGiuliano Pochini if (detected & (1 << bit)) 1796dd7b254dSGiuliano Pochini for (; src >= 0; src--) 1797dd7b254dSGiuliano Pochini if (bit == chip->clock_source_list[src]) { 1798dd7b254dSGiuliano Pochini clocks |= 1 << src; 1799dd7b254dSGiuliano Pochini break; 1800dd7b254dSGiuliano Pochini } 1801dd7b254dSGiuliano Pochini ucontrol->value.integer.value[5] = clocks; 1802dd7b254dSGiuliano Pochini 1803dd7b254dSGiuliano Pochini return 0; 1804dd7b254dSGiuliano Pochini } 1805dd7b254dSGiuliano Pochini 1806dd7b254dSGiuliano Pochini static struct snd_kcontrol_new snd_echo_channels_info __devinitdata = { 1807dd7b254dSGiuliano Pochini .name = "Channels info", 1808dd7b254dSGiuliano Pochini .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, 1809dd7b254dSGiuliano Pochini .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 1810dd7b254dSGiuliano Pochini .info = snd_echo_channels_info_info, 1811dd7b254dSGiuliano Pochini .get = snd_echo_channels_info_get, 1812dd7b254dSGiuliano Pochini }; 1813dd7b254dSGiuliano Pochini 1814dd7b254dSGiuliano Pochini 1815dd7b254dSGiuliano Pochini 1816dd7b254dSGiuliano Pochini 1817dd7b254dSGiuliano Pochini /****************************************************************************** 1818dd7b254dSGiuliano Pochini IRQ Handler 1819dd7b254dSGiuliano Pochini ******************************************************************************/ 1820dd7b254dSGiuliano Pochini 18217d12e780SDavid Howells static irqreturn_t snd_echo_interrupt(int irq, void *dev_id) 1822dd7b254dSGiuliano Pochini { 1823dd7b254dSGiuliano Pochini struct echoaudio *chip = dev_id; 1824dd7b254dSGiuliano Pochini struct snd_pcm_substream *substream; 1825dd7b254dSGiuliano Pochini int period, ss, st; 1826dd7b254dSGiuliano Pochini 1827dd7b254dSGiuliano Pochini spin_lock(&chip->lock); 1828dd7b254dSGiuliano Pochini st = service_irq(chip); 1829dd7b254dSGiuliano Pochini if (st < 0) { 1830dd7b254dSGiuliano Pochini spin_unlock(&chip->lock); 1831dd7b254dSGiuliano Pochini return IRQ_NONE; 1832dd7b254dSGiuliano Pochini } 1833dd7b254dSGiuliano Pochini /* The hardware doesn't tell us which substream caused the irq, 1834dd7b254dSGiuliano Pochini thus we have to check all running substreams. */ 1835dd7b254dSGiuliano Pochini for (ss = 0; ss < DSP_MAXPIPES; ss++) { 1836dd7b254dSGiuliano Pochini if ((substream = chip->substream[ss])) { 1837dd7b254dSGiuliano Pochini period = pcm_pointer(substream) / 1838dd7b254dSGiuliano Pochini substream->runtime->period_size; 1839dd7b254dSGiuliano Pochini if (period != chip->last_period[ss]) { 1840dd7b254dSGiuliano Pochini chip->last_period[ss] = period; 1841dd7b254dSGiuliano Pochini spin_unlock(&chip->lock); 1842dd7b254dSGiuliano Pochini snd_pcm_period_elapsed(substream); 1843dd7b254dSGiuliano Pochini spin_lock(&chip->lock); 1844dd7b254dSGiuliano Pochini } 1845dd7b254dSGiuliano Pochini } 1846dd7b254dSGiuliano Pochini } 1847dd7b254dSGiuliano Pochini spin_unlock(&chip->lock); 1848dd7b254dSGiuliano Pochini 1849dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_MIDI 1850dd7b254dSGiuliano Pochini if (st > 0 && chip->midi_in) { 1851dd7b254dSGiuliano Pochini snd_rawmidi_receive(chip->midi_in, chip->midi_buffer, st); 1852dd7b254dSGiuliano Pochini DE_MID(("rawmidi_iread=%d\n", st)); 1853dd7b254dSGiuliano Pochini } 1854dd7b254dSGiuliano Pochini #endif 1855dd7b254dSGiuliano Pochini return IRQ_HANDLED; 1856dd7b254dSGiuliano Pochini } 1857dd7b254dSGiuliano Pochini 1858dd7b254dSGiuliano Pochini 1859dd7b254dSGiuliano Pochini 1860dd7b254dSGiuliano Pochini 1861dd7b254dSGiuliano Pochini /****************************************************************************** 1862dd7b254dSGiuliano Pochini Module construction / destruction 1863dd7b254dSGiuliano Pochini ******************************************************************************/ 1864dd7b254dSGiuliano Pochini 1865dd7b254dSGiuliano Pochini static int snd_echo_free(struct echoaudio *chip) 1866dd7b254dSGiuliano Pochini { 1867dd7b254dSGiuliano Pochini DE_INIT(("Stop DSP...\n")); 1868dd7b254dSGiuliano Pochini if (chip->comm_page) { 1869dd7b254dSGiuliano Pochini rest_in_peace(chip); 1870dd7b254dSGiuliano Pochini snd_dma_free_pages(&chip->commpage_dma_buf); 1871dd7b254dSGiuliano Pochini } 1872dd7b254dSGiuliano Pochini DE_INIT(("Stopped.\n")); 1873dd7b254dSGiuliano Pochini 1874dd7b254dSGiuliano Pochini if (chip->irq >= 0) 1875*437a5a46STakashi Iwai free_irq(chip->irq, chip); 1876dd7b254dSGiuliano Pochini 1877dd7b254dSGiuliano Pochini if (chip->dsp_registers) 1878dd7b254dSGiuliano Pochini iounmap(chip->dsp_registers); 1879dd7b254dSGiuliano Pochini 18808caf7aa2STakashi Iwai if (chip->iores) 18818caf7aa2STakashi Iwai release_and_free_resource(chip->iores); 18828caf7aa2STakashi Iwai 1883dd7b254dSGiuliano Pochini DE_INIT(("MMIO freed.\n")); 1884dd7b254dSGiuliano Pochini 1885dd7b254dSGiuliano Pochini pci_disable_device(chip->pci); 1886dd7b254dSGiuliano Pochini 1887dd7b254dSGiuliano Pochini /* release chip data */ 1888dd7b254dSGiuliano Pochini kfree(chip); 1889dd7b254dSGiuliano Pochini DE_INIT(("Chip freed.\n")); 1890dd7b254dSGiuliano Pochini return 0; 1891dd7b254dSGiuliano Pochini } 1892dd7b254dSGiuliano Pochini 1893dd7b254dSGiuliano Pochini 1894dd7b254dSGiuliano Pochini 1895dd7b254dSGiuliano Pochini static int snd_echo_dev_free(struct snd_device *device) 1896dd7b254dSGiuliano Pochini { 1897dd7b254dSGiuliano Pochini struct echoaudio *chip = device->device_data; 1898dd7b254dSGiuliano Pochini 1899dd7b254dSGiuliano Pochini DE_INIT(("snd_echo_dev_free()...\n")); 1900dd7b254dSGiuliano Pochini return snd_echo_free(chip); 1901dd7b254dSGiuliano Pochini } 1902dd7b254dSGiuliano Pochini 1903dd7b254dSGiuliano Pochini 1904dd7b254dSGiuliano Pochini 1905dd7b254dSGiuliano Pochini /* <--snd_echo_probe() */ 1906dd7b254dSGiuliano Pochini static __devinit int snd_echo_create(struct snd_card *card, 1907dd7b254dSGiuliano Pochini struct pci_dev *pci, 1908dd7b254dSGiuliano Pochini struct echoaudio **rchip) 1909dd7b254dSGiuliano Pochini { 1910dd7b254dSGiuliano Pochini struct echoaudio *chip; 1911dd7b254dSGiuliano Pochini int err; 1912dd7b254dSGiuliano Pochini size_t sz; 1913dd7b254dSGiuliano Pochini static struct snd_device_ops ops = { 1914dd7b254dSGiuliano Pochini .dev_free = snd_echo_dev_free, 1915dd7b254dSGiuliano Pochini }; 1916dd7b254dSGiuliano Pochini 1917dd7b254dSGiuliano Pochini *rchip = NULL; 1918dd7b254dSGiuliano Pochini 1919dd7b254dSGiuliano Pochini pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0xC0); 1920dd7b254dSGiuliano Pochini 1921dd7b254dSGiuliano Pochini if ((err = pci_enable_device(pci)) < 0) 1922dd7b254dSGiuliano Pochini return err; 1923dd7b254dSGiuliano Pochini pci_set_master(pci); 1924dd7b254dSGiuliano Pochini 1925dd7b254dSGiuliano Pochini /* allocate a chip-specific data */ 1926dd7b254dSGiuliano Pochini chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1927dd7b254dSGiuliano Pochini if (!chip) { 1928dd7b254dSGiuliano Pochini pci_disable_device(pci); 1929dd7b254dSGiuliano Pochini return -ENOMEM; 1930dd7b254dSGiuliano Pochini } 1931dd7b254dSGiuliano Pochini DE_INIT(("chip=%p\n", chip)); 1932dd7b254dSGiuliano Pochini 1933dd7b254dSGiuliano Pochini spin_lock_init(&chip->lock); 1934dd7b254dSGiuliano Pochini chip->card = card; 1935dd7b254dSGiuliano Pochini chip->pci = pci; 1936dd7b254dSGiuliano Pochini chip->irq = -1; 1937dd7b254dSGiuliano Pochini 1938dd7b254dSGiuliano Pochini /* PCI resource allocation */ 1939dd7b254dSGiuliano Pochini chip->dsp_registers_phys = pci_resource_start(pci, 0); 1940dd7b254dSGiuliano Pochini sz = pci_resource_len(pci, 0); 1941dd7b254dSGiuliano Pochini if (sz > PAGE_SIZE) 1942dd7b254dSGiuliano Pochini sz = PAGE_SIZE; /* We map only the required part */ 1943dd7b254dSGiuliano Pochini 1944dd7b254dSGiuliano Pochini if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz, 1945dd7b254dSGiuliano Pochini ECHOCARD_NAME)) == NULL) { 1946dd7b254dSGiuliano Pochini snd_echo_free(chip); 1947dd7b254dSGiuliano Pochini snd_printk(KERN_ERR "cannot get memory region\n"); 1948dd7b254dSGiuliano Pochini return -EBUSY; 1949dd7b254dSGiuliano Pochini } 1950dd7b254dSGiuliano Pochini chip->dsp_registers = (volatile u32 __iomem *) 1951dd7b254dSGiuliano Pochini ioremap_nocache(chip->dsp_registers_phys, sz); 1952dd7b254dSGiuliano Pochini 1953*437a5a46STakashi Iwai if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED, 1954*437a5a46STakashi Iwai ECHOCARD_NAME, chip)) { 1955dd7b254dSGiuliano Pochini snd_echo_free(chip); 1956dd7b254dSGiuliano Pochini snd_printk(KERN_ERR "cannot grab irq\n"); 1957dd7b254dSGiuliano Pochini return -EBUSY; 1958dd7b254dSGiuliano Pochini } 1959dd7b254dSGiuliano Pochini chip->irq = pci->irq; 1960dd7b254dSGiuliano Pochini DE_INIT(("pci=%p irq=%d subdev=%04x Init hardware...\n", 1961dd7b254dSGiuliano Pochini chip->pci, chip->irq, chip->pci->subsystem_device)); 1962dd7b254dSGiuliano Pochini 1963dd7b254dSGiuliano Pochini /* Create the DSP comm page - this is the area of memory used for most 1964dd7b254dSGiuliano Pochini of the communication with the DSP, which accesses it via bus mastering */ 1965dd7b254dSGiuliano Pochini if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), 1966dd7b254dSGiuliano Pochini sizeof(struct comm_page), 1967dd7b254dSGiuliano Pochini &chip->commpage_dma_buf) < 0) { 1968dd7b254dSGiuliano Pochini snd_echo_free(chip); 1969dd7b254dSGiuliano Pochini snd_printk(KERN_ERR "cannot allocate the comm page\n"); 1970dd7b254dSGiuliano Pochini return -ENOMEM; 1971dd7b254dSGiuliano Pochini } 1972dd7b254dSGiuliano Pochini chip->comm_page_phys = chip->commpage_dma_buf.addr; 1973dd7b254dSGiuliano Pochini chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area; 1974dd7b254dSGiuliano Pochini 1975dd7b254dSGiuliano Pochini err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device); 1976dd7b254dSGiuliano Pochini if (err) { 1977dd7b254dSGiuliano Pochini DE_INIT(("init_hw err=%d\n", err)); 1978dd7b254dSGiuliano Pochini snd_echo_free(chip); 1979dd7b254dSGiuliano Pochini return err; 1980dd7b254dSGiuliano Pochini } 1981dd7b254dSGiuliano Pochini DE_INIT(("Card init OK\n")); 1982dd7b254dSGiuliano Pochini 1983dd7b254dSGiuliano Pochini if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 1984dd7b254dSGiuliano Pochini snd_echo_free(chip); 1985dd7b254dSGiuliano Pochini return err; 1986dd7b254dSGiuliano Pochini } 1987dd7b254dSGiuliano Pochini atomic_set(&chip->opencount, 0); 1988dd7b254dSGiuliano Pochini init_MUTEX(&chip->mode_mutex); 1989dd7b254dSGiuliano Pochini chip->can_set_rate = 1; 1990dd7b254dSGiuliano Pochini *rchip = chip; 1991dd7b254dSGiuliano Pochini /* Init done ! */ 1992dd7b254dSGiuliano Pochini return 0; 1993dd7b254dSGiuliano Pochini } 1994dd7b254dSGiuliano Pochini 1995dd7b254dSGiuliano Pochini 1996dd7b254dSGiuliano Pochini 1997dd7b254dSGiuliano Pochini /* constructor */ 1998dd7b254dSGiuliano Pochini static int __devinit snd_echo_probe(struct pci_dev *pci, 1999dd7b254dSGiuliano Pochini const struct pci_device_id *pci_id) 2000dd7b254dSGiuliano Pochini { 2001dd7b254dSGiuliano Pochini static int dev; 2002dd7b254dSGiuliano Pochini struct snd_card *card; 2003dd7b254dSGiuliano Pochini struct echoaudio *chip; 2004dd7b254dSGiuliano Pochini char *dsp; 2005dd7b254dSGiuliano Pochini int i, err; 2006dd7b254dSGiuliano Pochini 2007dd7b254dSGiuliano Pochini if (dev >= SNDRV_CARDS) 2008dd7b254dSGiuliano Pochini return -ENODEV; 2009dd7b254dSGiuliano Pochini if (!enable[dev]) { 2010dd7b254dSGiuliano Pochini dev++; 2011dd7b254dSGiuliano Pochini return -ENOENT; 2012dd7b254dSGiuliano Pochini } 2013dd7b254dSGiuliano Pochini 2014dd7b254dSGiuliano Pochini DE_INIT(("Echoaudio driver starting...\n")); 2015dd7b254dSGiuliano Pochini i = 0; 2016dd7b254dSGiuliano Pochini card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 2017dd7b254dSGiuliano Pochini if (card == NULL) 2018dd7b254dSGiuliano Pochini return -ENOMEM; 2019dd7b254dSGiuliano Pochini 2020dd7b254dSGiuliano Pochini if ((err = snd_echo_create(card, pci, &chip)) < 0) { 2021dd7b254dSGiuliano Pochini snd_card_free(card); 2022dd7b254dSGiuliano Pochini return err; 2023dd7b254dSGiuliano Pochini } 2024dd7b254dSGiuliano Pochini 2025dd7b254dSGiuliano Pochini strcpy(card->driver, "Echo_" ECHOCARD_NAME); 2026dd7b254dSGiuliano Pochini strcpy(card->shortname, chip->card_name); 2027dd7b254dSGiuliano Pochini 2028dd7b254dSGiuliano Pochini dsp = "56301"; 2029dd7b254dSGiuliano Pochini if (pci_id->device == 0x3410) 2030dd7b254dSGiuliano Pochini dsp = "56361"; 2031dd7b254dSGiuliano Pochini 2032dd7b254dSGiuliano Pochini sprintf(card->longname, "%s rev.%d (DSP%s) at 0x%lx irq %i", 2033dd7b254dSGiuliano Pochini card->shortname, pci_id->subdevice & 0x000f, dsp, 2034dd7b254dSGiuliano Pochini chip->dsp_registers_phys, chip->irq); 2035dd7b254dSGiuliano Pochini 2036dd7b254dSGiuliano Pochini if ((err = snd_echo_new_pcm(chip)) < 0) { 2037dd7b254dSGiuliano Pochini snd_printk(KERN_ERR "new pcm error %d\n", err); 2038dd7b254dSGiuliano Pochini snd_card_free(card); 2039dd7b254dSGiuliano Pochini return err; 2040dd7b254dSGiuliano Pochini } 2041dd7b254dSGiuliano Pochini 2042dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_MIDI 2043dd7b254dSGiuliano Pochini if (chip->has_midi) { /* Some Mia's do not have midi */ 2044dd7b254dSGiuliano Pochini if ((err = snd_echo_midi_create(card, chip)) < 0) { 2045dd7b254dSGiuliano Pochini snd_printk(KERN_ERR "new midi error %d\n", err); 2046dd7b254dSGiuliano Pochini snd_card_free(card); 2047dd7b254dSGiuliano Pochini return err; 2048dd7b254dSGiuliano Pochini } 2049dd7b254dSGiuliano Pochini } 2050dd7b254dSGiuliano Pochini #endif 2051dd7b254dSGiuliano Pochini 2052dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_VMIXER 2053dd7b254dSGiuliano Pochini snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip); 2054dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_output_gain, chip))) < 0) 2055dd7b254dSGiuliano Pochini goto ctl_error; 2056dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0) 2057dd7b254dSGiuliano Pochini goto ctl_error; 2058dd7b254dSGiuliano Pochini #else 2059dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_pcm_output_gain, chip))) < 0) 2060dd7b254dSGiuliano Pochini goto ctl_error; 2061dd7b254dSGiuliano Pochini #endif 2062dd7b254dSGiuliano Pochini 2063dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_INPUT_GAIN 2064dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0) 2065dd7b254dSGiuliano Pochini goto ctl_error; 2066dd7b254dSGiuliano Pochini #endif 2067dd7b254dSGiuliano Pochini 2068dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL 2069dd7b254dSGiuliano Pochini if (!chip->hasnt_input_nominal_level) 2070dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip))) < 0) 2071dd7b254dSGiuliano Pochini goto ctl_error; 2072dd7b254dSGiuliano Pochini #endif 2073dd7b254dSGiuliano Pochini 2074dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL 2075dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip))) < 0) 2076dd7b254dSGiuliano Pochini goto ctl_error; 2077dd7b254dSGiuliano Pochini #endif 2078dd7b254dSGiuliano Pochini 2079dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip))) < 0) 2080dd7b254dSGiuliano Pochini goto ctl_error; 2081dd7b254dSGiuliano Pochini 2082dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip))) < 0) 2083dd7b254dSGiuliano Pochini goto ctl_error; 2084dd7b254dSGiuliano Pochini 2085dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_MONITOR 2086dd7b254dSGiuliano Pochini snd_echo_monitor_mixer.count = num_busses_in(chip) * num_busses_out(chip); 2087dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip))) < 0) 2088dd7b254dSGiuliano Pochini goto ctl_error; 2089dd7b254dSGiuliano Pochini #endif 2090dd7b254dSGiuliano Pochini 2091dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE 2092dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip))) < 0) 2093dd7b254dSGiuliano Pochini goto ctl_error; 2094dd7b254dSGiuliano Pochini #endif 2095dd7b254dSGiuliano Pochini 2096dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip))) < 0) 2097dd7b254dSGiuliano Pochini goto ctl_error; 2098dd7b254dSGiuliano Pochini 2099dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH 2100dd7b254dSGiuliano Pochini /* Creates a list of available digital modes */ 2101dd7b254dSGiuliano Pochini chip->num_digital_modes = 0; 2102dd7b254dSGiuliano Pochini for (i = 0; i < 6; i++) 2103dd7b254dSGiuliano Pochini if (chip->digital_modes & (1 << i)) 2104dd7b254dSGiuliano Pochini chip->digital_mode_list[chip->num_digital_modes++] = i; 2105dd7b254dSGiuliano Pochini 2106dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip))) < 0) 2107dd7b254dSGiuliano Pochini goto ctl_error; 2108dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */ 2109dd7b254dSGiuliano Pochini 2110dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK 2111dd7b254dSGiuliano Pochini /* Creates a list of available clock sources */ 2112dd7b254dSGiuliano Pochini chip->num_clock_sources = 0; 2113dd7b254dSGiuliano Pochini for (i = 0; i < 10; i++) 2114dd7b254dSGiuliano Pochini if (chip->input_clock_types & (1 << i)) 2115dd7b254dSGiuliano Pochini chip->clock_source_list[chip->num_clock_sources++] = i; 2116dd7b254dSGiuliano Pochini 2117dd7b254dSGiuliano Pochini if (chip->num_clock_sources > 1) { 2118dd7b254dSGiuliano Pochini chip->clock_src_ctl = snd_ctl_new1(&snd_echo_clock_source_switch, chip); 2119dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, chip->clock_src_ctl)) < 0) 2120dd7b254dSGiuliano Pochini goto ctl_error; 2121dd7b254dSGiuliano Pochini } 2122dd7b254dSGiuliano Pochini #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */ 2123dd7b254dSGiuliano Pochini 2124dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_DIGITAL_IO 2125dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip))) < 0) 2126dd7b254dSGiuliano Pochini goto ctl_error; 2127dd7b254dSGiuliano Pochini #endif 2128dd7b254dSGiuliano Pochini 2129dd7b254dSGiuliano Pochini #ifdef ECHOCARD_HAS_PHANTOM_POWER 2130dd7b254dSGiuliano Pochini if (chip->has_phantom_power) 2131dd7b254dSGiuliano Pochini if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip))) < 0) 2132dd7b254dSGiuliano Pochini goto ctl_error; 2133dd7b254dSGiuliano Pochini #endif 2134dd7b254dSGiuliano Pochini 2135dd7b254dSGiuliano Pochini if ((err = snd_card_register(card)) < 0) { 2136dd7b254dSGiuliano Pochini snd_card_free(card); 2137dd7b254dSGiuliano Pochini goto ctl_error; 2138dd7b254dSGiuliano Pochini } 2139dd7b254dSGiuliano Pochini snd_printk(KERN_INFO "Card registered: %s\n", card->longname); 2140dd7b254dSGiuliano Pochini 2141dd7b254dSGiuliano Pochini pci_set_drvdata(pci, chip); 2142dd7b254dSGiuliano Pochini dev++; 2143dd7b254dSGiuliano Pochini return 0; 2144dd7b254dSGiuliano Pochini 2145dd7b254dSGiuliano Pochini ctl_error: 2146dd7b254dSGiuliano Pochini snd_printk(KERN_ERR "new control error %d\n", err); 2147dd7b254dSGiuliano Pochini snd_card_free(card); 2148dd7b254dSGiuliano Pochini return err; 2149dd7b254dSGiuliano Pochini } 2150dd7b254dSGiuliano Pochini 2151dd7b254dSGiuliano Pochini 2152dd7b254dSGiuliano Pochini 2153dd7b254dSGiuliano Pochini static void __devexit snd_echo_remove(struct pci_dev *pci) 2154dd7b254dSGiuliano Pochini { 2155dd7b254dSGiuliano Pochini struct echoaudio *chip; 2156dd7b254dSGiuliano Pochini 2157dd7b254dSGiuliano Pochini chip = pci_get_drvdata(pci); 2158dd7b254dSGiuliano Pochini if (chip) 2159dd7b254dSGiuliano Pochini snd_card_free(chip->card); 2160dd7b254dSGiuliano Pochini pci_set_drvdata(pci, NULL); 2161dd7b254dSGiuliano Pochini } 2162dd7b254dSGiuliano Pochini 2163dd7b254dSGiuliano Pochini 2164dd7b254dSGiuliano Pochini 2165dd7b254dSGiuliano Pochini /****************************************************************************** 2166dd7b254dSGiuliano Pochini Everything starts and ends here 2167dd7b254dSGiuliano Pochini ******************************************************************************/ 2168dd7b254dSGiuliano Pochini 2169dd7b254dSGiuliano Pochini /* pci_driver definition */ 2170dd7b254dSGiuliano Pochini static struct pci_driver driver = { 2171dd7b254dSGiuliano Pochini .name = "Echoaudio " ECHOCARD_NAME, 2172dd7b254dSGiuliano Pochini .id_table = snd_echo_ids, 2173dd7b254dSGiuliano Pochini .probe = snd_echo_probe, 2174dd7b254dSGiuliano Pochini .remove = __devexit_p(snd_echo_remove), 2175dd7b254dSGiuliano Pochini }; 2176dd7b254dSGiuliano Pochini 2177dd7b254dSGiuliano Pochini 2178dd7b254dSGiuliano Pochini 2179dd7b254dSGiuliano Pochini /* initialization of the module */ 2180dd7b254dSGiuliano Pochini static int __init alsa_card_echo_init(void) 2181dd7b254dSGiuliano Pochini { 2182dd7b254dSGiuliano Pochini return pci_register_driver(&driver); 2183dd7b254dSGiuliano Pochini } 2184dd7b254dSGiuliano Pochini 2185dd7b254dSGiuliano Pochini 2186dd7b254dSGiuliano Pochini 2187dd7b254dSGiuliano Pochini /* clean up the module */ 2188dd7b254dSGiuliano Pochini static void __exit alsa_card_echo_exit(void) 2189dd7b254dSGiuliano Pochini { 2190dd7b254dSGiuliano Pochini pci_unregister_driver(&driver); 2191dd7b254dSGiuliano Pochini } 2192dd7b254dSGiuliano Pochini 2193dd7b254dSGiuliano Pochini 2194dd7b254dSGiuliano Pochini module_init(alsa_card_echo_init) 2195dd7b254dSGiuliano Pochini module_exit(alsa_card_echo_exit) 2196