11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Copyright (c) by Jaroslav Kysela <perex@suse.cz>, 31da177e4SLinus Torvalds * Takashi Iwai <tiwai@suse.de> 41da177e4SLinus Torvalds * Creative Labs, Inc. 51da177e4SLinus Torvalds * Routines for control of EMU10K1 chips / mixer routines 61da177e4SLinus Torvalds * Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com> 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * BUGS: 91da177e4SLinus Torvalds * -- 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds * TODO: 121da177e4SLinus Torvalds * -- 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 151da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 161da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 171da177e4SLinus Torvalds * (at your option) any later version. 181da177e4SLinus Torvalds * 191da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 201da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 211da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 221da177e4SLinus Torvalds * GNU General Public License for more details. 231da177e4SLinus Torvalds * 241da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 251da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 261da177e4SLinus Torvalds * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 271da177e4SLinus Torvalds * 281da177e4SLinus Torvalds */ 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds #include <sound/driver.h> 311da177e4SLinus Torvalds #include <linux/time.h> 321da177e4SLinus Torvalds #include <linux/init.h> 331da177e4SLinus Torvalds #include <sound/core.h> 341da177e4SLinus Torvalds #include <sound/emu10k1.h> 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds #define AC97_ID_STAC9758 0x83847658 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds static int snd_emu10k1_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 391da177e4SLinus Torvalds { 401da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; 411da177e4SLinus Torvalds uinfo->count = 1; 421da177e4SLinus Torvalds return 0; 431da177e4SLinus Torvalds } 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds static int snd_emu10k1_spdif_get(snd_kcontrol_t * kcontrol, 461da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 471da177e4SLinus Torvalds { 481da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 491da177e4SLinus Torvalds unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 501da177e4SLinus Torvalds unsigned long flags; 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 531da177e4SLinus Torvalds ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff; 541da177e4SLinus Torvalds ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff; 551da177e4SLinus Torvalds ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff; 561da177e4SLinus Torvalds ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff; 571da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 581da177e4SLinus Torvalds return 0; 591da177e4SLinus Torvalds } 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds static int snd_emu10k1_spdif_get_mask(snd_kcontrol_t * kcontrol, 621da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 631da177e4SLinus Torvalds { 641da177e4SLinus Torvalds ucontrol->value.iec958.status[0] = 0xff; 651da177e4SLinus Torvalds ucontrol->value.iec958.status[1] = 0xff; 661da177e4SLinus Torvalds ucontrol->value.iec958.status[2] = 0xff; 671da177e4SLinus Torvalds ucontrol->value.iec958.status[3] = 0xff; 681da177e4SLinus Torvalds return 0; 691da177e4SLinus Torvalds } 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds static int snd_audigy_spdif_output_rate_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 721da177e4SLinus Torvalds { 731da177e4SLinus Torvalds static char *texts[] = {"44100", "48000", "96000"}; 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 761da177e4SLinus Torvalds uinfo->count = 1; 771da177e4SLinus Torvalds uinfo->value.enumerated.items = 3; 781da177e4SLinus Torvalds if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 791da177e4SLinus Torvalds uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 801da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 811da177e4SLinus Torvalds return 0; 821da177e4SLinus Torvalds } 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds static int snd_audigy_spdif_output_rate_get(snd_kcontrol_t * kcontrol, 851da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 861da177e4SLinus Torvalds { 871da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 881da177e4SLinus Torvalds unsigned int tmp; 891da177e4SLinus Torvalds unsigned long flags; 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 931da177e4SLinus Torvalds tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0); 941da177e4SLinus Torvalds switch (tmp & A_SPDIF_RATE_MASK) { 951da177e4SLinus Torvalds case A_SPDIF_44100: 961da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 0; 971da177e4SLinus Torvalds break; 981da177e4SLinus Torvalds case A_SPDIF_48000: 991da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 1; 1001da177e4SLinus Torvalds break; 1011da177e4SLinus Torvalds case A_SPDIF_96000: 1021da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 2; 1031da177e4SLinus Torvalds break; 1041da177e4SLinus Torvalds default: 1051da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 1; 1061da177e4SLinus Torvalds } 1071da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 1081da177e4SLinus Torvalds return 0; 1091da177e4SLinus Torvalds } 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds static int snd_audigy_spdif_output_rate_put(snd_kcontrol_t * kcontrol, 1121da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 1131da177e4SLinus Torvalds { 1141da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 1151da177e4SLinus Torvalds int change; 1161da177e4SLinus Torvalds unsigned int reg, val, tmp; 1171da177e4SLinus Torvalds unsigned long flags; 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds switch(ucontrol->value.enumerated.item[0]) { 1201da177e4SLinus Torvalds case 0: 1211da177e4SLinus Torvalds val = A_SPDIF_44100; 1221da177e4SLinus Torvalds break; 1231da177e4SLinus Torvalds case 1: 1241da177e4SLinus Torvalds val = A_SPDIF_48000; 1251da177e4SLinus Torvalds break; 1261da177e4SLinus Torvalds case 2: 1271da177e4SLinus Torvalds val = A_SPDIF_96000; 1281da177e4SLinus Torvalds break; 1291da177e4SLinus Torvalds default: 1301da177e4SLinus Torvalds val = A_SPDIF_48000; 1311da177e4SLinus Torvalds break; 1321da177e4SLinus Torvalds } 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 1361da177e4SLinus Torvalds reg = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0); 1371da177e4SLinus Torvalds tmp = reg & ~A_SPDIF_RATE_MASK; 1381da177e4SLinus Torvalds tmp |= val; 1391da177e4SLinus Torvalds if ((change = (tmp != reg))) 1401da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp); 1411da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 1421da177e4SLinus Torvalds return change; 1431da177e4SLinus Torvalds } 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds static snd_kcontrol_new_t snd_audigy_spdif_output_rate = 1461da177e4SLinus Torvalds { 1471da177e4SLinus Torvalds .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 1481da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1491da177e4SLinus Torvalds .name = "Audigy SPDIF Output Sample Rate", 1501da177e4SLinus Torvalds .count = 1, 1511da177e4SLinus Torvalds .info = snd_audigy_spdif_output_rate_info, 1521da177e4SLinus Torvalds .get = snd_audigy_spdif_output_rate_get, 1531da177e4SLinus Torvalds .put = snd_audigy_spdif_output_rate_put 1541da177e4SLinus Torvalds }; 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds static int snd_emu10k1_spdif_put(snd_kcontrol_t * kcontrol, 1571da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 1581da177e4SLinus Torvalds { 1591da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 1601da177e4SLinus Torvalds unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 1611da177e4SLinus Torvalds int change; 1621da177e4SLinus Torvalds unsigned int val; 1631da177e4SLinus Torvalds unsigned long flags; 1641da177e4SLinus Torvalds 1651da177e4SLinus Torvalds val = (ucontrol->value.iec958.status[0] << 0) | 1661da177e4SLinus Torvalds (ucontrol->value.iec958.status[1] << 8) | 1671da177e4SLinus Torvalds (ucontrol->value.iec958.status[2] << 16) | 1681da177e4SLinus Torvalds (ucontrol->value.iec958.status[3] << 24); 1691da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 1701da177e4SLinus Torvalds change = val != emu->spdif_bits[idx]; 1711da177e4SLinus Torvalds if (change) { 1721da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, SPCS0 + idx, 0, val); 1731da177e4SLinus Torvalds emu->spdif_bits[idx] = val; 1741da177e4SLinus Torvalds } 1751da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 1761da177e4SLinus Torvalds return change; 1771da177e4SLinus Torvalds } 1781da177e4SLinus Torvalds 1791da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_spdif_mask_control = 1801da177e4SLinus Torvalds { 1811da177e4SLinus Torvalds .access = SNDRV_CTL_ELEM_ACCESS_READ, 1821da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1831da177e4SLinus Torvalds .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), 1841da177e4SLinus Torvalds .count = 4, 1851da177e4SLinus Torvalds .info = snd_emu10k1_spdif_info, 1861da177e4SLinus Torvalds .get = snd_emu10k1_spdif_get_mask 1871da177e4SLinus Torvalds }; 1881da177e4SLinus Torvalds 1891da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_spdif_control = 1901da177e4SLinus Torvalds { 1911da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1921da177e4SLinus Torvalds .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), 1931da177e4SLinus Torvalds .count = 4, 1941da177e4SLinus Torvalds .info = snd_emu10k1_spdif_info, 1951da177e4SLinus Torvalds .get = snd_emu10k1_spdif_get, 1961da177e4SLinus Torvalds .put = snd_emu10k1_spdif_put 1971da177e4SLinus Torvalds }; 1981da177e4SLinus Torvalds 1991da177e4SLinus Torvalds 2001da177e4SLinus Torvalds static void update_emu10k1_fxrt(emu10k1_t *emu, int voice, unsigned char *route) 2011da177e4SLinus Torvalds { 2021da177e4SLinus Torvalds if (emu->audigy) { 2031da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, A_FXRT1, voice, 2041da177e4SLinus Torvalds snd_emu10k1_compose_audigy_fxrt1(route)); 2051da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, A_FXRT2, voice, 2061da177e4SLinus Torvalds snd_emu10k1_compose_audigy_fxrt2(route)); 2071da177e4SLinus Torvalds } else { 2081da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, FXRT, voice, 2091da177e4SLinus Torvalds snd_emu10k1_compose_send_routing(route)); 2101da177e4SLinus Torvalds } 2111da177e4SLinus Torvalds } 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds static void update_emu10k1_send_volume(emu10k1_t *emu, int voice, unsigned char *volume) 2141da177e4SLinus Torvalds { 2151da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_A, voice, volume[0]); 2161da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_B, voice, volume[1]); 2171da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, PSST_FXSENDAMOUNT_C, voice, volume[2]); 2181da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, DSL_FXSENDAMOUNT_D, voice, volume[3]); 2191da177e4SLinus Torvalds if (emu->audigy) { 2201da177e4SLinus Torvalds unsigned int val = ((unsigned int)volume[4] << 24) | 2211da177e4SLinus Torvalds ((unsigned int)volume[5] << 16) | 2221da177e4SLinus Torvalds ((unsigned int)volume[6] << 8) | 2231da177e4SLinus Torvalds (unsigned int)volume[7]; 2241da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice, val); 2251da177e4SLinus Torvalds } 2261da177e4SLinus Torvalds } 2271da177e4SLinus Torvalds 2281da177e4SLinus Torvalds /* PCM stream controls */ 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvalds static int snd_emu10k1_send_routing_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 2311da177e4SLinus Torvalds { 2321da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 2331da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2341da177e4SLinus Torvalds uinfo->count = emu->audigy ? 3*8 : 3*4; 2351da177e4SLinus Torvalds uinfo->value.integer.min = 0; 2361da177e4SLinus Torvalds uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f; 2371da177e4SLinus Torvalds return 0; 2381da177e4SLinus Torvalds } 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds static int snd_emu10k1_send_routing_get(snd_kcontrol_t * kcontrol, 2411da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 2421da177e4SLinus Torvalds { 2431da177e4SLinus Torvalds unsigned long flags; 2441da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 2451da177e4SLinus Torvalds emu10k1_pcm_mixer_t *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 2461da177e4SLinus Torvalds int voice, idx; 2471da177e4SLinus Torvalds int num_efx = emu->audigy ? 8 : 4; 2481da177e4SLinus Torvalds int mask = emu->audigy ? 0x3f : 0x0f; 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 2511da177e4SLinus Torvalds for (voice = 0; voice < 3; voice++) 2521da177e4SLinus Torvalds for (idx = 0; idx < num_efx; idx++) 2531da177e4SLinus Torvalds ucontrol->value.integer.value[(voice * num_efx) + idx] = 2541da177e4SLinus Torvalds mix->send_routing[voice][idx] & mask; 2551da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 2561da177e4SLinus Torvalds return 0; 2571da177e4SLinus Torvalds } 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvalds static int snd_emu10k1_send_routing_put(snd_kcontrol_t * kcontrol, 2601da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 2611da177e4SLinus Torvalds { 2621da177e4SLinus Torvalds unsigned long flags; 2631da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 2641da177e4SLinus Torvalds emu10k1_pcm_mixer_t *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 2651da177e4SLinus Torvalds int change = 0, voice, idx, val; 2661da177e4SLinus Torvalds int num_efx = emu->audigy ? 8 : 4; 2671da177e4SLinus Torvalds int mask = emu->audigy ? 0x3f : 0x0f; 2681da177e4SLinus Torvalds 2691da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 2701da177e4SLinus Torvalds for (voice = 0; voice < 3; voice++) 2711da177e4SLinus Torvalds for (idx = 0; idx < num_efx; idx++) { 2721da177e4SLinus Torvalds val = ucontrol->value.integer.value[(voice * num_efx) + idx] & mask; 2731da177e4SLinus Torvalds if (mix->send_routing[voice][idx] != val) { 2741da177e4SLinus Torvalds mix->send_routing[voice][idx] = val; 2751da177e4SLinus Torvalds change = 1; 2761da177e4SLinus Torvalds } 2771da177e4SLinus Torvalds } 2781da177e4SLinus Torvalds if (change && mix->epcm) { 2791da177e4SLinus Torvalds if (mix->epcm->voices[0] && mix->epcm->voices[1]) { 2801da177e4SLinus Torvalds update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number, 2811da177e4SLinus Torvalds &mix->send_routing[1][0]); 2821da177e4SLinus Torvalds update_emu10k1_fxrt(emu, mix->epcm->voices[1]->number, 2831da177e4SLinus Torvalds &mix->send_routing[2][0]); 2841da177e4SLinus Torvalds } else if (mix->epcm->voices[0]) { 2851da177e4SLinus Torvalds update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number, 2861da177e4SLinus Torvalds &mix->send_routing[0][0]); 2871da177e4SLinus Torvalds } 2881da177e4SLinus Torvalds } 2891da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 2901da177e4SLinus Torvalds return change; 2911da177e4SLinus Torvalds } 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_send_routing_control = 2941da177e4SLinus Torvalds { 2951da177e4SLinus Torvalds .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, 2961da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2971da177e4SLinus Torvalds .name = "EMU10K1 PCM Send Routing", 2981da177e4SLinus Torvalds .count = 32, 2991da177e4SLinus Torvalds .info = snd_emu10k1_send_routing_info, 3001da177e4SLinus Torvalds .get = snd_emu10k1_send_routing_get, 3011da177e4SLinus Torvalds .put = snd_emu10k1_send_routing_put 3021da177e4SLinus Torvalds }; 3031da177e4SLinus Torvalds 3041da177e4SLinus Torvalds static int snd_emu10k1_send_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 3051da177e4SLinus Torvalds { 3061da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 3071da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 3081da177e4SLinus Torvalds uinfo->count = emu->audigy ? 3*8 : 3*4; 3091da177e4SLinus Torvalds uinfo->value.integer.min = 0; 3101da177e4SLinus Torvalds uinfo->value.integer.max = 255; 3111da177e4SLinus Torvalds return 0; 3121da177e4SLinus Torvalds } 3131da177e4SLinus Torvalds 3141da177e4SLinus Torvalds static int snd_emu10k1_send_volume_get(snd_kcontrol_t * kcontrol, 3151da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 3161da177e4SLinus Torvalds { 3171da177e4SLinus Torvalds unsigned long flags; 3181da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 3191da177e4SLinus Torvalds emu10k1_pcm_mixer_t *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 3201da177e4SLinus Torvalds int idx; 3211da177e4SLinus Torvalds int num_efx = emu->audigy ? 8 : 4; 3221da177e4SLinus Torvalds 3231da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 3241da177e4SLinus Torvalds for (idx = 0; idx < 3*num_efx; idx++) 3251da177e4SLinus Torvalds ucontrol->value.integer.value[idx] = mix->send_volume[idx/num_efx][idx%num_efx]; 3261da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 3271da177e4SLinus Torvalds return 0; 3281da177e4SLinus Torvalds } 3291da177e4SLinus Torvalds 3301da177e4SLinus Torvalds static int snd_emu10k1_send_volume_put(snd_kcontrol_t * kcontrol, 3311da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 3321da177e4SLinus Torvalds { 3331da177e4SLinus Torvalds unsigned long flags; 3341da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 3351da177e4SLinus Torvalds emu10k1_pcm_mixer_t *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 3361da177e4SLinus Torvalds int change = 0, idx, val; 3371da177e4SLinus Torvalds int num_efx = emu->audigy ? 8 : 4; 3381da177e4SLinus Torvalds 3391da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 3401da177e4SLinus Torvalds for (idx = 0; idx < 3*num_efx; idx++) { 3411da177e4SLinus Torvalds val = ucontrol->value.integer.value[idx] & 255; 3421da177e4SLinus Torvalds if (mix->send_volume[idx/num_efx][idx%num_efx] != val) { 3431da177e4SLinus Torvalds mix->send_volume[idx/num_efx][idx%num_efx] = val; 3441da177e4SLinus Torvalds change = 1; 3451da177e4SLinus Torvalds } 3461da177e4SLinus Torvalds } 3471da177e4SLinus Torvalds if (change && mix->epcm) { 3481da177e4SLinus Torvalds if (mix->epcm->voices[0] && mix->epcm->voices[1]) { 3491da177e4SLinus Torvalds update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number, 3501da177e4SLinus Torvalds &mix->send_volume[1][0]); 3511da177e4SLinus Torvalds update_emu10k1_send_volume(emu, mix->epcm->voices[1]->number, 3521da177e4SLinus Torvalds &mix->send_volume[2][0]); 3531da177e4SLinus Torvalds } else if (mix->epcm->voices[0]) { 3541da177e4SLinus Torvalds update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number, 3551da177e4SLinus Torvalds &mix->send_volume[0][0]); 3561da177e4SLinus Torvalds } 3571da177e4SLinus Torvalds } 3581da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 3591da177e4SLinus Torvalds return change; 3601da177e4SLinus Torvalds } 3611da177e4SLinus Torvalds 3621da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_send_volume_control = 3631da177e4SLinus Torvalds { 3641da177e4SLinus Torvalds .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, 3651da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3661da177e4SLinus Torvalds .name = "EMU10K1 PCM Send Volume", 3671da177e4SLinus Torvalds .count = 32, 3681da177e4SLinus Torvalds .info = snd_emu10k1_send_volume_info, 3691da177e4SLinus Torvalds .get = snd_emu10k1_send_volume_get, 3701da177e4SLinus Torvalds .put = snd_emu10k1_send_volume_put 3711da177e4SLinus Torvalds }; 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvalds static int snd_emu10k1_attn_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 3741da177e4SLinus Torvalds { 3751da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 3761da177e4SLinus Torvalds uinfo->count = 3; 3771da177e4SLinus Torvalds uinfo->value.integer.min = 0; 3781da177e4SLinus Torvalds uinfo->value.integer.max = 0xffff; 3791da177e4SLinus Torvalds return 0; 3801da177e4SLinus Torvalds } 3811da177e4SLinus Torvalds 3821da177e4SLinus Torvalds static int snd_emu10k1_attn_get(snd_kcontrol_t * kcontrol, 3831da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 3841da177e4SLinus Torvalds { 3851da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 3861da177e4SLinus Torvalds emu10k1_pcm_mixer_t *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 3871da177e4SLinus Torvalds unsigned long flags; 3881da177e4SLinus Torvalds int idx; 3891da177e4SLinus Torvalds 3901da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 3911da177e4SLinus Torvalds for (idx = 0; idx < 3; idx++) 3921da177e4SLinus Torvalds ucontrol->value.integer.value[idx] = mix->attn[idx]; 3931da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 3941da177e4SLinus Torvalds return 0; 3951da177e4SLinus Torvalds } 3961da177e4SLinus Torvalds 3971da177e4SLinus Torvalds static int snd_emu10k1_attn_put(snd_kcontrol_t * kcontrol, 3981da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 3991da177e4SLinus Torvalds { 4001da177e4SLinus Torvalds unsigned long flags; 4011da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 4021da177e4SLinus Torvalds emu10k1_pcm_mixer_t *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 4031da177e4SLinus Torvalds int change = 0, idx, val; 4041da177e4SLinus Torvalds 4051da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 4061da177e4SLinus Torvalds for (idx = 0; idx < 3; idx++) { 4071da177e4SLinus Torvalds val = ucontrol->value.integer.value[idx] & 0xffff; 4081da177e4SLinus Torvalds if (mix->attn[idx] != val) { 4091da177e4SLinus Torvalds mix->attn[idx] = val; 4101da177e4SLinus Torvalds change = 1; 4111da177e4SLinus Torvalds } 4121da177e4SLinus Torvalds } 4131da177e4SLinus Torvalds if (change && mix->epcm) { 4141da177e4SLinus Torvalds if (mix->epcm->voices[0] && mix->epcm->voices[1]) { 4151da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[1]); 4161da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[1]->number, mix->attn[2]); 4171da177e4SLinus Torvalds } else if (mix->epcm->voices[0]) { 4181da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[0]); 4191da177e4SLinus Torvalds } 4201da177e4SLinus Torvalds } 4211da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 4221da177e4SLinus Torvalds return change; 4231da177e4SLinus Torvalds } 4241da177e4SLinus Torvalds 4251da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_attn_control = 4261da177e4SLinus Torvalds { 4271da177e4SLinus Torvalds .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, 4281da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 4291da177e4SLinus Torvalds .name = "EMU10K1 PCM Volume", 4301da177e4SLinus Torvalds .count = 32, 4311da177e4SLinus Torvalds .info = snd_emu10k1_attn_info, 4321da177e4SLinus Torvalds .get = snd_emu10k1_attn_get, 4331da177e4SLinus Torvalds .put = snd_emu10k1_attn_put 4341da177e4SLinus Torvalds }; 4351da177e4SLinus Torvalds 4361da177e4SLinus Torvalds /* Mutichannel PCM stream controls */ 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds static int snd_emu10k1_efx_send_routing_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 4391da177e4SLinus Torvalds { 4401da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 4411da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 4421da177e4SLinus Torvalds uinfo->count = emu->audigy ? 8 : 4; 4431da177e4SLinus Torvalds uinfo->value.integer.min = 0; 4441da177e4SLinus Torvalds uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f; 4451da177e4SLinus Torvalds return 0; 4461da177e4SLinus Torvalds } 4471da177e4SLinus Torvalds 4481da177e4SLinus Torvalds static int snd_emu10k1_efx_send_routing_get(snd_kcontrol_t * kcontrol, 4491da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 4501da177e4SLinus Torvalds { 4511da177e4SLinus Torvalds unsigned long flags; 4521da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 4531da177e4SLinus Torvalds emu10k1_pcm_mixer_t *mix = &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 4541da177e4SLinus Torvalds int idx; 4551da177e4SLinus Torvalds int num_efx = emu->audigy ? 8 : 4; 4561da177e4SLinus Torvalds int mask = emu->audigy ? 0x3f : 0x0f; 4571da177e4SLinus Torvalds 4581da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 4591da177e4SLinus Torvalds for (idx = 0; idx < num_efx; idx++) 4601da177e4SLinus Torvalds ucontrol->value.integer.value[idx] = 4611da177e4SLinus Torvalds mix->send_routing[0][idx] & mask; 4621da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 4631da177e4SLinus Torvalds return 0; 4641da177e4SLinus Torvalds } 4651da177e4SLinus Torvalds 4661da177e4SLinus Torvalds static int snd_emu10k1_efx_send_routing_put(snd_kcontrol_t * kcontrol, 4671da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 4681da177e4SLinus Torvalds { 4691da177e4SLinus Torvalds unsigned long flags; 4701da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 4711da177e4SLinus Torvalds int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 4721da177e4SLinus Torvalds emu10k1_pcm_mixer_t *mix = &emu->efx_pcm_mixer[ch]; 4731da177e4SLinus Torvalds int change = 0, idx, val; 4741da177e4SLinus Torvalds int num_efx = emu->audigy ? 8 : 4; 4751da177e4SLinus Torvalds int mask = emu->audigy ? 0x3f : 0x0f; 4761da177e4SLinus Torvalds 4771da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 4781da177e4SLinus Torvalds for (idx = 0; idx < num_efx; idx++) { 4791da177e4SLinus Torvalds val = ucontrol->value.integer.value[idx] & mask; 4801da177e4SLinus Torvalds if (mix->send_routing[0][idx] != val) { 4811da177e4SLinus Torvalds mix->send_routing[0][idx] = val; 4821da177e4SLinus Torvalds change = 1; 4831da177e4SLinus Torvalds } 4841da177e4SLinus Torvalds } 4851da177e4SLinus Torvalds 4861da177e4SLinus Torvalds if (change && mix->epcm) { 4871da177e4SLinus Torvalds if (mix->epcm->voices[ch]) { 4881da177e4SLinus Torvalds update_emu10k1_fxrt(emu, mix->epcm->voices[ch]->number, 4891da177e4SLinus Torvalds &mix->send_routing[0][0]); 4901da177e4SLinus Torvalds } 4911da177e4SLinus Torvalds } 4921da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 4931da177e4SLinus Torvalds return change; 4941da177e4SLinus Torvalds } 4951da177e4SLinus Torvalds 4961da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_efx_send_routing_control = 4971da177e4SLinus Torvalds { 4981da177e4SLinus Torvalds .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, 4991da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_PCM, 5001da177e4SLinus Torvalds .name = "Multichannel PCM Send Routing", 5011da177e4SLinus Torvalds .count = 16, 5021da177e4SLinus Torvalds .info = snd_emu10k1_efx_send_routing_info, 5031da177e4SLinus Torvalds .get = snd_emu10k1_efx_send_routing_get, 5041da177e4SLinus Torvalds .put = snd_emu10k1_efx_send_routing_put 5051da177e4SLinus Torvalds }; 5061da177e4SLinus Torvalds 5071da177e4SLinus Torvalds static int snd_emu10k1_efx_send_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 5081da177e4SLinus Torvalds { 5091da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 5101da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 5111da177e4SLinus Torvalds uinfo->count = emu->audigy ? 8 : 4; 5121da177e4SLinus Torvalds uinfo->value.integer.min = 0; 5131da177e4SLinus Torvalds uinfo->value.integer.max = 255; 5141da177e4SLinus Torvalds return 0; 5151da177e4SLinus Torvalds } 5161da177e4SLinus Torvalds 5171da177e4SLinus Torvalds static int snd_emu10k1_efx_send_volume_get(snd_kcontrol_t * kcontrol, 5181da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 5191da177e4SLinus Torvalds { 5201da177e4SLinus Torvalds unsigned long flags; 5211da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 5221da177e4SLinus Torvalds emu10k1_pcm_mixer_t *mix = &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 5231da177e4SLinus Torvalds int idx; 5241da177e4SLinus Torvalds int num_efx = emu->audigy ? 8 : 4; 5251da177e4SLinus Torvalds 5261da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 5271da177e4SLinus Torvalds for (idx = 0; idx < num_efx; idx++) 5281da177e4SLinus Torvalds ucontrol->value.integer.value[idx] = mix->send_volume[0][idx]; 5291da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 5301da177e4SLinus Torvalds return 0; 5311da177e4SLinus Torvalds } 5321da177e4SLinus Torvalds 5331da177e4SLinus Torvalds static int snd_emu10k1_efx_send_volume_put(snd_kcontrol_t * kcontrol, 5341da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 5351da177e4SLinus Torvalds { 5361da177e4SLinus Torvalds unsigned long flags; 5371da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 5381da177e4SLinus Torvalds int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 5391da177e4SLinus Torvalds emu10k1_pcm_mixer_t *mix = &emu->efx_pcm_mixer[ch]; 5401da177e4SLinus Torvalds int change = 0, idx, val; 5411da177e4SLinus Torvalds int num_efx = emu->audigy ? 8 : 4; 5421da177e4SLinus Torvalds 5431da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 5441da177e4SLinus Torvalds for (idx = 0; idx < num_efx; idx++) { 5451da177e4SLinus Torvalds val = ucontrol->value.integer.value[idx] & 255; 5461da177e4SLinus Torvalds if (mix->send_volume[0][idx] != val) { 5471da177e4SLinus Torvalds mix->send_volume[0][idx] = val; 5481da177e4SLinus Torvalds change = 1; 5491da177e4SLinus Torvalds } 5501da177e4SLinus Torvalds } 5511da177e4SLinus Torvalds if (change && mix->epcm) { 5521da177e4SLinus Torvalds if (mix->epcm->voices[ch]) { 5531da177e4SLinus Torvalds update_emu10k1_send_volume(emu, mix->epcm->voices[ch]->number, 5541da177e4SLinus Torvalds &mix->send_volume[0][0]); 5551da177e4SLinus Torvalds } 5561da177e4SLinus Torvalds } 5571da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 5581da177e4SLinus Torvalds return change; 5591da177e4SLinus Torvalds } 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds 5621da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_efx_send_volume_control = 5631da177e4SLinus Torvalds { 5641da177e4SLinus Torvalds .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, 5651da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_PCM, 5661da177e4SLinus Torvalds .name = "Multichannel PCM Send Volume", 5671da177e4SLinus Torvalds .count = 16, 5681da177e4SLinus Torvalds .info = snd_emu10k1_efx_send_volume_info, 5691da177e4SLinus Torvalds .get = snd_emu10k1_efx_send_volume_get, 5701da177e4SLinus Torvalds .put = snd_emu10k1_efx_send_volume_put 5711da177e4SLinus Torvalds }; 5721da177e4SLinus Torvalds 5731da177e4SLinus Torvalds static int snd_emu10k1_efx_attn_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 5741da177e4SLinus Torvalds { 5751da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 5761da177e4SLinus Torvalds uinfo->count = 1; 5771da177e4SLinus Torvalds uinfo->value.integer.min = 0; 5781da177e4SLinus Torvalds uinfo->value.integer.max = 0xffff; 5791da177e4SLinus Torvalds return 0; 5801da177e4SLinus Torvalds } 5811da177e4SLinus Torvalds 5821da177e4SLinus Torvalds static int snd_emu10k1_efx_attn_get(snd_kcontrol_t * kcontrol, 5831da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 5841da177e4SLinus Torvalds { 5851da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 5861da177e4SLinus Torvalds emu10k1_pcm_mixer_t *mix = &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 5871da177e4SLinus Torvalds unsigned long flags; 5881da177e4SLinus Torvalds 5891da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 5901da177e4SLinus Torvalds ucontrol->value.integer.value[0] = mix->attn[0]; 5911da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 5921da177e4SLinus Torvalds return 0; 5931da177e4SLinus Torvalds } 5941da177e4SLinus Torvalds 5951da177e4SLinus Torvalds static int snd_emu10k1_efx_attn_put(snd_kcontrol_t * kcontrol, 5961da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 5971da177e4SLinus Torvalds { 5981da177e4SLinus Torvalds unsigned long flags; 5991da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 6001da177e4SLinus Torvalds int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 6011da177e4SLinus Torvalds emu10k1_pcm_mixer_t *mix = &emu->efx_pcm_mixer[ch]; 6021da177e4SLinus Torvalds int change = 0, val; 6031da177e4SLinus Torvalds 6041da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 6051da177e4SLinus Torvalds val = ucontrol->value.integer.value[0] & 0xffff; 6061da177e4SLinus Torvalds if (mix->attn[0] != val) { 6071da177e4SLinus Torvalds mix->attn[0] = val; 6081da177e4SLinus Torvalds change = 1; 6091da177e4SLinus Torvalds } 6101da177e4SLinus Torvalds if (change && mix->epcm) { 6111da177e4SLinus Torvalds if (mix->epcm->voices[ch]) { 6121da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[ch]->number, mix->attn[0]); 6131da177e4SLinus Torvalds } 6141da177e4SLinus Torvalds } 6151da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 6161da177e4SLinus Torvalds return change; 6171da177e4SLinus Torvalds } 6181da177e4SLinus Torvalds 6191da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_efx_attn_control = 6201da177e4SLinus Torvalds { 6211da177e4SLinus Torvalds .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, 6221da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_PCM, 6231da177e4SLinus Torvalds .name = "Multichannel PCM Volume", 6241da177e4SLinus Torvalds .count = 16, 6251da177e4SLinus Torvalds .info = snd_emu10k1_efx_attn_info, 6261da177e4SLinus Torvalds .get = snd_emu10k1_efx_attn_get, 6271da177e4SLinus Torvalds .put = snd_emu10k1_efx_attn_put 6281da177e4SLinus Torvalds }; 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds static int snd_emu10k1_shared_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 6311da177e4SLinus Torvalds { 6321da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 6331da177e4SLinus Torvalds uinfo->count = 1; 6341da177e4SLinus Torvalds uinfo->value.integer.min = 0; 6351da177e4SLinus Torvalds uinfo->value.integer.max = 1; 6361da177e4SLinus Torvalds return 0; 6371da177e4SLinus Torvalds } 6381da177e4SLinus Torvalds 6391da177e4SLinus Torvalds static int snd_emu10k1_shared_spdif_get(snd_kcontrol_t * kcontrol, 6401da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 6411da177e4SLinus Torvalds { 6421da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 6431da177e4SLinus Torvalds 6441da177e4SLinus Torvalds if (emu->audigy) 6451da177e4SLinus Torvalds ucontrol->value.integer.value[0] = inl(emu->port + A_IOCFG) & A_IOCFG_GPOUT0 ? 1 : 0; 6461da177e4SLinus Torvalds else 6471da177e4SLinus Torvalds ucontrol->value.integer.value[0] = inl(emu->port + HCFG) & HCFG_GPOUT0 ? 1 : 0; 6481da177e4SLinus Torvalds return 0; 6491da177e4SLinus Torvalds } 6501da177e4SLinus Torvalds 6511da177e4SLinus Torvalds static int snd_emu10k1_shared_spdif_put(snd_kcontrol_t * kcontrol, 6521da177e4SLinus Torvalds snd_ctl_elem_value_t * ucontrol) 6531da177e4SLinus Torvalds { 6541da177e4SLinus Torvalds unsigned long flags; 6551da177e4SLinus Torvalds emu10k1_t *emu = snd_kcontrol_chip(kcontrol); 6561da177e4SLinus Torvalds unsigned int reg, val; 6571da177e4SLinus Torvalds int change = 0; 6581da177e4SLinus Torvalds 6591da177e4SLinus Torvalds spin_lock_irqsave(&emu->reg_lock, flags); 6601da177e4SLinus Torvalds if (emu->audigy) { 6611da177e4SLinus Torvalds reg = inl(emu->port + A_IOCFG); 6621da177e4SLinus Torvalds val = ucontrol->value.integer.value[0] ? A_IOCFG_GPOUT0 : 0; 6631da177e4SLinus Torvalds change = (reg & A_IOCFG_GPOUT0) != val; 6641da177e4SLinus Torvalds if (change) { 6651da177e4SLinus Torvalds reg &= ~A_IOCFG_GPOUT0; 6661da177e4SLinus Torvalds reg |= val; 6671da177e4SLinus Torvalds outl(reg | val, emu->port + A_IOCFG); 6681da177e4SLinus Torvalds } 6691da177e4SLinus Torvalds } 6701da177e4SLinus Torvalds reg = inl(emu->port + HCFG); 6711da177e4SLinus Torvalds val = ucontrol->value.integer.value[0] ? HCFG_GPOUT0 : 0; 6721da177e4SLinus Torvalds change |= (reg & HCFG_GPOUT0) != val; 6731da177e4SLinus Torvalds if (change) { 6741da177e4SLinus Torvalds reg &= ~HCFG_GPOUT0; 6751da177e4SLinus Torvalds reg |= val; 6761da177e4SLinus Torvalds outl(reg | val, emu->port + HCFG); 6771da177e4SLinus Torvalds } 6781da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->reg_lock, flags); 6791da177e4SLinus Torvalds return change; 6801da177e4SLinus Torvalds } 6811da177e4SLinus Torvalds 6821da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_shared_spdif __devinitdata = 6831da177e4SLinus Torvalds { 6841da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 6851da177e4SLinus Torvalds .name = "SB Live Analog/Digital Output Jack", 6861da177e4SLinus Torvalds .info = snd_emu10k1_shared_spdif_info, 6871da177e4SLinus Torvalds .get = snd_emu10k1_shared_spdif_get, 6881da177e4SLinus Torvalds .put = snd_emu10k1_shared_spdif_put 6891da177e4SLinus Torvalds }; 6901da177e4SLinus Torvalds 6911da177e4SLinus Torvalds static snd_kcontrol_new_t snd_audigy_shared_spdif __devinitdata = 6921da177e4SLinus Torvalds { 6931da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 6941da177e4SLinus Torvalds .name = "Audigy Analog/Digital Output Jack", 6951da177e4SLinus Torvalds .info = snd_emu10k1_shared_spdif_info, 6961da177e4SLinus Torvalds .get = snd_emu10k1_shared_spdif_get, 6971da177e4SLinus Torvalds .put = snd_emu10k1_shared_spdif_put 6981da177e4SLinus Torvalds }; 6991da177e4SLinus Torvalds 7001da177e4SLinus Torvalds /* 7011da177e4SLinus Torvalds */ 7021da177e4SLinus Torvalds static void snd_emu10k1_mixer_free_ac97(ac97_t *ac97) 7031da177e4SLinus Torvalds { 7041da177e4SLinus Torvalds emu10k1_t *emu = ac97->private_data; 7051da177e4SLinus Torvalds emu->ac97 = NULL; 7061da177e4SLinus Torvalds } 7071da177e4SLinus Torvalds 7081da177e4SLinus Torvalds /* 7091da177e4SLinus Torvalds */ 7101da177e4SLinus Torvalds static int remove_ctl(snd_card_t *card, const char *name) 7111da177e4SLinus Torvalds { 7121da177e4SLinus Torvalds snd_ctl_elem_id_t id; 7131da177e4SLinus Torvalds memset(&id, 0, sizeof(id)); 7141da177e4SLinus Torvalds strcpy(id.name, name); 7151da177e4SLinus Torvalds id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 7161da177e4SLinus Torvalds return snd_ctl_remove_id(card, &id); 7171da177e4SLinus Torvalds } 7181da177e4SLinus Torvalds 7191da177e4SLinus Torvalds static snd_kcontrol_t *ctl_find(snd_card_t *card, const char *name) 7201da177e4SLinus Torvalds { 7211da177e4SLinus Torvalds snd_ctl_elem_id_t sid; 7221da177e4SLinus Torvalds memset(&sid, 0, sizeof(sid)); 7231da177e4SLinus Torvalds strcpy(sid.name, name); 7241da177e4SLinus Torvalds sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 7251da177e4SLinus Torvalds return snd_ctl_find_id(card, &sid); 7261da177e4SLinus Torvalds } 7271da177e4SLinus Torvalds 7281da177e4SLinus Torvalds static int rename_ctl(snd_card_t *card, const char *src, const char *dst) 7291da177e4SLinus Torvalds { 7301da177e4SLinus Torvalds snd_kcontrol_t *kctl = ctl_find(card, src); 7311da177e4SLinus Torvalds if (kctl) { 7321da177e4SLinus Torvalds strcpy(kctl->id.name, dst); 7331da177e4SLinus Torvalds return 0; 7341da177e4SLinus Torvalds } 7351da177e4SLinus Torvalds return -ENOENT; 7361da177e4SLinus Torvalds } 7371da177e4SLinus Torvalds 7381da177e4SLinus Torvalds int __devinit snd_emu10k1_mixer(emu10k1_t *emu) 7391da177e4SLinus Torvalds { 7401da177e4SLinus Torvalds int err, pcm; 7411da177e4SLinus Torvalds snd_kcontrol_t *kctl; 7421da177e4SLinus Torvalds snd_card_t *card = emu->card; 7431da177e4SLinus Torvalds char **c; 7441da177e4SLinus Torvalds static char *emu10k1_remove_ctls[] = { 7451da177e4SLinus Torvalds /* no AC97 mono, surround, center/lfe */ 7461da177e4SLinus Torvalds "Master Mono Playback Switch", 7471da177e4SLinus Torvalds "Master Mono Playback Volume", 7481da177e4SLinus Torvalds "PCM Out Path & Mute", 7491da177e4SLinus Torvalds "Mono Output Select", 7501da177e4SLinus Torvalds "Surround Playback Switch", 7511da177e4SLinus Torvalds "Surround Playback Volume", 7521da177e4SLinus Torvalds "Center Playback Switch", 7531da177e4SLinus Torvalds "Center Playback Volume", 7541da177e4SLinus Torvalds "LFE Playback Switch", 7551da177e4SLinus Torvalds "LFE Playback Volume", 7561da177e4SLinus Torvalds NULL 7571da177e4SLinus Torvalds }; 7581da177e4SLinus Torvalds static char *emu10k1_rename_ctls[] = { 7591da177e4SLinus Torvalds "Surround Digital Playback Volume", "Surround Playback Volume", 7601da177e4SLinus Torvalds "Center Digital Playback Volume", "Center Playback Volume", 7611da177e4SLinus Torvalds "LFE Digital Playback Volume", "LFE Playback Volume", 7621da177e4SLinus Torvalds NULL 7631da177e4SLinus Torvalds }; 7641da177e4SLinus Torvalds static char *audigy_remove_ctls[] = { 7651da177e4SLinus Torvalds /* Master/PCM controls on ac97 of Audigy has no effect */ 7661da177e4SLinus Torvalds "PCM Playback Switch", 7671da177e4SLinus Torvalds "PCM Playback Volume", 7681da177e4SLinus Torvalds "Master Mono Playback Switch", 7691da177e4SLinus Torvalds "Master Mono Playback Volume", 7701da177e4SLinus Torvalds "Master Playback Switch", 7711da177e4SLinus Torvalds "Master Playback Volume", 7721da177e4SLinus Torvalds "PCM Out Path & Mute", 7731da177e4SLinus Torvalds "Mono Output Select", 7741da177e4SLinus Torvalds /* remove unused AC97 capture controls */ 7751da177e4SLinus Torvalds "Capture Source", 7761da177e4SLinus Torvalds "Capture Switch", 7771da177e4SLinus Torvalds "Capture Volume", 7781da177e4SLinus Torvalds "Mic Select", 7791da177e4SLinus Torvalds "Video Playback Switch", 7801da177e4SLinus Torvalds "Video Playback Volume", 7811da177e4SLinus Torvalds "Mic Playback Switch", 7821da177e4SLinus Torvalds "Mic Playback Volume", 7831da177e4SLinus Torvalds NULL 7841da177e4SLinus Torvalds }; 7851da177e4SLinus Torvalds static char *audigy_rename_ctls[] = { 7861da177e4SLinus Torvalds /* use conventional names */ 7871da177e4SLinus Torvalds "Wave Playback Volume", "PCM Playback Volume", 7881da177e4SLinus Torvalds /* "Wave Capture Volume", "PCM Capture Volume", */ 7891da177e4SLinus Torvalds "Wave Master Playback Volume", "Master Playback Volume", 7901da177e4SLinus Torvalds "AMic Playback Volume", "Mic Playback Volume", 7911da177e4SLinus Torvalds NULL 7921da177e4SLinus Torvalds }; 7931da177e4SLinus Torvalds 794*2b637da5SLee Revell if (emu->card_capabilities->ac97_chip) { 7951da177e4SLinus Torvalds ac97_bus_t *pbus; 7961da177e4SLinus Torvalds ac97_template_t ac97; 7971da177e4SLinus Torvalds static ac97_bus_ops_t ops = { 7981da177e4SLinus Torvalds .write = snd_emu10k1_ac97_write, 7991da177e4SLinus Torvalds .read = snd_emu10k1_ac97_read, 8001da177e4SLinus Torvalds }; 8011da177e4SLinus Torvalds 8021da177e4SLinus Torvalds if ((err = snd_ac97_bus(emu->card, 0, &ops, NULL, &pbus)) < 0) 8031da177e4SLinus Torvalds return err; 8041da177e4SLinus Torvalds pbus->no_vra = 1; /* we don't need VRA */ 8051da177e4SLinus Torvalds 8061da177e4SLinus Torvalds memset(&ac97, 0, sizeof(ac97)); 8071da177e4SLinus Torvalds ac97.private_data = emu; 8081da177e4SLinus Torvalds ac97.private_free = snd_emu10k1_mixer_free_ac97; 8091da177e4SLinus Torvalds ac97.scaps = AC97_SCAP_NO_SPDIF; 8101da177e4SLinus Torvalds if ((err = snd_ac97_mixer(pbus, &ac97, &emu->ac97)) < 0) 8111da177e4SLinus Torvalds return err; 8121da177e4SLinus Torvalds if (emu->audigy) { 8131da177e4SLinus Torvalds /* set master volume to 0 dB */ 8141da177e4SLinus Torvalds snd_ac97_write(emu->ac97, AC97_MASTER, 0x0000); 8151da177e4SLinus Torvalds /* set capture source to mic */ 8161da177e4SLinus Torvalds snd_ac97_write(emu->ac97, AC97_REC_SEL, 0x0000); 8171da177e4SLinus Torvalds c = audigy_remove_ctls; 8181da177e4SLinus Torvalds } else { 8191da177e4SLinus Torvalds /* 8201da177e4SLinus Torvalds * Credits for cards based on STAC9758: 8211da177e4SLinus Torvalds * James Courtier-Dutton <James@superbug.demon.co.uk> 8221da177e4SLinus Torvalds * Voluspa <voluspa@comhem.se> 8231da177e4SLinus Torvalds */ 8241da177e4SLinus Torvalds if (emu->ac97->id == AC97_ID_STAC9758) { 8251da177e4SLinus Torvalds emu->rear_ac97 = 1; 8261da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT); 8271da177e4SLinus Torvalds } 8281da177e4SLinus Torvalds /* remove unused AC97 controls */ 8291da177e4SLinus Torvalds snd_ac97_write(emu->ac97, AC97_SURROUND_MASTER, 0x0202); 8301da177e4SLinus Torvalds snd_ac97_write(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202); 8311da177e4SLinus Torvalds c = emu10k1_remove_ctls; 8321da177e4SLinus Torvalds } 8331da177e4SLinus Torvalds for (; *c; c++) 8341da177e4SLinus Torvalds remove_ctl(card, *c); 8351da177e4SLinus Torvalds } else { 836*2b637da5SLee Revell if (emu->card_capabilities->ecard) 8371da177e4SLinus Torvalds strcpy(emu->card->mixername, "EMU APS"); 8381da177e4SLinus Torvalds else if (emu->audigy) 8391da177e4SLinus Torvalds strcpy(emu->card->mixername, "SB Audigy"); 8401da177e4SLinus Torvalds else 8411da177e4SLinus Torvalds strcpy(emu->card->mixername, "Emu10k1"); 8421da177e4SLinus Torvalds } 8431da177e4SLinus Torvalds 8441da177e4SLinus Torvalds if (emu->audigy) 8451da177e4SLinus Torvalds c = audigy_rename_ctls; 8461da177e4SLinus Torvalds else 8471da177e4SLinus Torvalds c = emu10k1_rename_ctls; 8481da177e4SLinus Torvalds for (; *c; c += 2) 8491da177e4SLinus Torvalds rename_ctl(card, c[0], c[1]); 8501da177e4SLinus Torvalds 8511da177e4SLinus Torvalds if ((kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu)) == NULL) 8521da177e4SLinus Torvalds return -ENOMEM; 8531da177e4SLinus Torvalds if ((err = snd_ctl_add(card, kctl))) 8541da177e4SLinus Torvalds return err; 8551da177e4SLinus Torvalds if ((kctl = emu->ctl_send_volume = snd_ctl_new1(&snd_emu10k1_send_volume_control, emu)) == NULL) 8561da177e4SLinus Torvalds return -ENOMEM; 8571da177e4SLinus Torvalds if ((err = snd_ctl_add(card, kctl))) 8581da177e4SLinus Torvalds return err; 8591da177e4SLinus Torvalds if ((kctl = emu->ctl_attn = snd_ctl_new1(&snd_emu10k1_attn_control, emu)) == NULL) 8601da177e4SLinus Torvalds return -ENOMEM; 8611da177e4SLinus Torvalds if ((err = snd_ctl_add(card, kctl))) 8621da177e4SLinus Torvalds return err; 8631da177e4SLinus Torvalds 8641da177e4SLinus Torvalds if ((kctl = emu->ctl_efx_send_routing = snd_ctl_new1(&snd_emu10k1_efx_send_routing_control, emu)) == NULL) 8651da177e4SLinus Torvalds return -ENOMEM; 8661da177e4SLinus Torvalds if ((err = snd_ctl_add(card, kctl))) 8671da177e4SLinus Torvalds return err; 8681da177e4SLinus Torvalds 8691da177e4SLinus Torvalds if ((kctl = emu->ctl_efx_send_volume = snd_ctl_new1(&snd_emu10k1_efx_send_volume_control, emu)) == NULL) 8701da177e4SLinus Torvalds return -ENOMEM; 8711da177e4SLinus Torvalds if ((err = snd_ctl_add(card, kctl))) 8721da177e4SLinus Torvalds return err; 8731da177e4SLinus Torvalds 8741da177e4SLinus Torvalds if ((kctl = emu->ctl_efx_attn = snd_ctl_new1(&snd_emu10k1_efx_attn_control, emu)) == NULL) 8751da177e4SLinus Torvalds return -ENOMEM; 8761da177e4SLinus Torvalds if ((err = snd_ctl_add(card, kctl))) 8771da177e4SLinus Torvalds return err; 8781da177e4SLinus Torvalds 8791da177e4SLinus Torvalds /* initialize the routing and volume table for each pcm playback stream */ 8801da177e4SLinus Torvalds for (pcm = 0; pcm < 32; pcm++) { 8811da177e4SLinus Torvalds emu10k1_pcm_mixer_t *mix; 8821da177e4SLinus Torvalds int v; 8831da177e4SLinus Torvalds 8841da177e4SLinus Torvalds mix = &emu->pcm_mixer[pcm]; 8851da177e4SLinus Torvalds mix->epcm = NULL; 8861da177e4SLinus Torvalds 8871da177e4SLinus Torvalds for (v = 0; v < 4; v++) 8881da177e4SLinus Torvalds mix->send_routing[0][v] = 8891da177e4SLinus Torvalds mix->send_routing[1][v] = 8901da177e4SLinus Torvalds mix->send_routing[2][v] = v; 8911da177e4SLinus Torvalds 8921da177e4SLinus Torvalds memset(&mix->send_volume, 0, sizeof(mix->send_volume)); 8931da177e4SLinus Torvalds mix->send_volume[0][0] = mix->send_volume[0][1] = 8941da177e4SLinus Torvalds mix->send_volume[1][0] = mix->send_volume[2][1] = 255; 8951da177e4SLinus Torvalds 8961da177e4SLinus Torvalds mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff; 8971da177e4SLinus Torvalds } 8981da177e4SLinus Torvalds 8991da177e4SLinus Torvalds /* initialize the routing and volume table for the multichannel playback stream */ 9001da177e4SLinus Torvalds for (pcm = 0; pcm < NUM_EFX_PLAYBACK; pcm++) { 9011da177e4SLinus Torvalds emu10k1_pcm_mixer_t *mix; 9021da177e4SLinus Torvalds int v; 9031da177e4SLinus Torvalds 9041da177e4SLinus Torvalds mix = &emu->efx_pcm_mixer[pcm]; 9051da177e4SLinus Torvalds mix->epcm = NULL; 9061da177e4SLinus Torvalds 9071da177e4SLinus Torvalds mix->send_routing[0][0] = pcm; 9081da177e4SLinus Torvalds mix->send_routing[0][1] = (pcm == 0) ? 1 : 0; 9091da177e4SLinus Torvalds for (v = 0; v < 2; v++) 9101da177e4SLinus Torvalds mix->send_routing[0][2+v] = 13+v; 9111da177e4SLinus Torvalds if (emu->audigy) 9121da177e4SLinus Torvalds for (v = 0; v < 4; v++) 9131da177e4SLinus Torvalds mix->send_routing[0][4+v] = 60+v; 9141da177e4SLinus Torvalds 9151da177e4SLinus Torvalds memset(&mix->send_volume, 0, sizeof(mix->send_volume)); 9161da177e4SLinus Torvalds mix->send_volume[0][0] = 255; 9171da177e4SLinus Torvalds 9181da177e4SLinus Torvalds mix->attn[0] = 0xffff; 9191da177e4SLinus Torvalds } 9201da177e4SLinus Torvalds 921*2b637da5SLee Revell if (! emu->card_capabilities->ecard) { /* FIXME: APS has these controls? */ 9221da177e4SLinus Torvalds /* sb live! and audigy */ 9231da177e4SLinus Torvalds if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_mask_control, emu)) == NULL) 9241da177e4SLinus Torvalds return -ENOMEM; 9251da177e4SLinus Torvalds if ((err = snd_ctl_add(card, kctl))) 9261da177e4SLinus Torvalds return err; 9271da177e4SLinus Torvalds if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_control, emu)) == NULL) 9281da177e4SLinus Torvalds return -ENOMEM; 9291da177e4SLinus Torvalds if ((err = snd_ctl_add(card, kctl))) 9301da177e4SLinus Torvalds return err; 9311da177e4SLinus Torvalds } 9321da177e4SLinus Torvalds 9331da177e4SLinus Torvalds if (emu->audigy) { 9341da177e4SLinus Torvalds if ((kctl = snd_ctl_new1(&snd_audigy_shared_spdif, emu)) == NULL) 9351da177e4SLinus Torvalds return -ENOMEM; 9361da177e4SLinus Torvalds if ((err = snd_ctl_add(card, kctl))) 9371da177e4SLinus Torvalds return err; 9381da177e4SLinus Torvalds if ((kctl = snd_ctl_new1(&snd_audigy_spdif_output_rate, emu)) == NULL) 9391da177e4SLinus Torvalds return -ENOMEM; 9401da177e4SLinus Torvalds if ((err = snd_ctl_add(card, kctl))) 9411da177e4SLinus Torvalds return err; 942*2b637da5SLee Revell } else if (! emu->card_capabilities->ecard) { 9431da177e4SLinus Torvalds /* sb live! */ 9441da177e4SLinus Torvalds if ((kctl = snd_ctl_new1(&snd_emu10k1_shared_spdif, emu)) == NULL) 9451da177e4SLinus Torvalds return -ENOMEM; 9461da177e4SLinus Torvalds if ((err = snd_ctl_add(card, kctl))) 9471da177e4SLinus Torvalds return err; 9481da177e4SLinus Torvalds } 949*2b637da5SLee Revell if (emu->card_capabilities->ca0151_chip) { /* P16V */ 9501da177e4SLinus Torvalds if ((err = snd_p16v_mixer(emu))) 9511da177e4SLinus Torvalds return err; 9521da177e4SLinus Torvalds } 9531da177e4SLinus Torvalds 9541da177e4SLinus Torvalds return 0; 9551da177e4SLinus Torvalds } 956