Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004 James Courtier-Dutton <James@superbug.demon.co.uk> |
| 3 | * Driver CA0106 chips. e.g. Sound Blaster Audigy LS and Live 24bit |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 4 | * Version: 0.0.17 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * FEATURES currently supported: |
| 7 | * See ca0106_main.c for features. |
| 8 | * |
| 9 | * Changelog: |
| 10 | * Support interrupts per period. |
| 11 | * Removed noise from Center/LFE channel when in Analog mode. |
| 12 | * Rename and remove mixer controls. |
| 13 | * 0.0.6 |
| 14 | * Use separate card based DMA buffer for periods table list. |
| 15 | * 0.0.7 |
| 16 | * Change remove and rename ctrls into lists. |
| 17 | * 0.0.8 |
| 18 | * Try to fix capture sources. |
| 19 | * 0.0.9 |
| 20 | * Fix AC3 output. |
| 21 | * Enable S32_LE format support. |
| 22 | * 0.0.10 |
| 23 | * Enable playback 48000 and 96000 rates. (Rates other that these do not work, even with "plug:front".) |
| 24 | * 0.0.11 |
| 25 | * Add Model name recognition. |
| 26 | * 0.0.12 |
| 27 | * Correct interrupt timing. interrupt at end of period, instead of in the middle of a playback period. |
| 28 | * Remove redundent "voice" handling. |
| 29 | * 0.0.13 |
| 30 | * Single trigger call for multi channels. |
| 31 | * 0.0.14 |
| 32 | * Set limits based on what the sound card hardware can do. |
| 33 | * playback periods_min=2, periods_max=8 |
| 34 | * capture hw constraints require period_size = n * 64 bytes. |
| 35 | * playback hw constraints require period_size = n * 64 bytes. |
| 36 | * 0.0.15 |
| 37 | * Separated ca0106.c into separate functional .c files. |
| 38 | * 0.0.16 |
| 39 | * Modified Copyright message. |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 40 | * 0.0.17 |
| 41 | * Implement Mic and Line in Capture. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | * |
| 43 | * This code was initally based on code from ALSA's emu10k1x.c which is: |
| 44 | * Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com> |
| 45 | * |
| 46 | * This program is free software; you can redistribute it and/or modify |
| 47 | * it under the terms of the GNU General Public License as published by |
| 48 | * the Free Software Foundation; either version 2 of the License, or |
| 49 | * (at your option) any later version. |
| 50 | * |
| 51 | * This program is distributed in the hope that it will be useful, |
| 52 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 53 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 54 | * GNU General Public License for more details. |
| 55 | * |
| 56 | * You should have received a copy of the GNU General Public License |
| 57 | * along with this program; if not, write to the Free Software |
| 58 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 59 | * |
| 60 | */ |
| 61 | #include <sound/driver.h> |
| 62 | #include <linux/delay.h> |
| 63 | #include <linux/init.h> |
| 64 | #include <linux/interrupt.h> |
| 65 | #include <linux/pci.h> |
| 66 | #include <linux/slab.h> |
| 67 | #include <linux/moduleparam.h> |
| 68 | #include <sound/core.h> |
| 69 | #include <sound/initval.h> |
| 70 | #include <sound/pcm.h> |
| 71 | #include <sound/ac97_codec.h> |
| 72 | #include <sound/info.h> |
| 73 | |
| 74 | #include "ca0106.h" |
| 75 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 76 | static int snd_ca0106_shared_spdif_info(struct snd_kcontrol *kcontrol, |
| 77 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
| 79 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 80 | uinfo->count = 1; |
| 81 | uinfo->value.integer.min = 0; |
| 82 | uinfo->value.integer.max = 1; |
| 83 | return 0; |
| 84 | } |
| 85 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 86 | static int snd_ca0106_shared_spdif_get(struct snd_kcontrol *kcontrol, |
| 87 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 89 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | ucontrol->value.enumerated.item[0] = emu->spdif_enable; |
| 92 | return 0; |
| 93 | } |
| 94 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 95 | static int snd_ca0106_shared_spdif_put(struct snd_kcontrol *kcontrol, |
| 96 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 98 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | unsigned int val; |
| 100 | int change = 0; |
| 101 | u32 mask; |
| 102 | |
| 103 | val = ucontrol->value.enumerated.item[0] ; |
| 104 | change = (emu->spdif_enable != val); |
| 105 | if (change) { |
| 106 | emu->spdif_enable = val; |
| 107 | if (val == 1) { |
| 108 | /* Digital */ |
| 109 | snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf); |
| 110 | snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x0b000000); |
| 111 | snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0, |
| 112 | snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) & ~0x1000); |
| 113 | mask = inl(emu->port + GPIO) & ~0x101; |
| 114 | outl(mask, emu->port + GPIO); |
| 115 | |
| 116 | } else { |
| 117 | /* Analog */ |
| 118 | snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf); |
James Courtier-Dutton | 1f82941 | 2005-05-21 16:23:37 +0200 | [diff] [blame] | 119 | snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x000f0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0, |
| 121 | snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) | 0x1000); |
| 122 | mask = inl(emu->port + GPIO) | 0x101; |
| 123 | outl(mask, emu->port + GPIO); |
| 124 | } |
| 125 | } |
| 126 | return change; |
| 127 | } |
| 128 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 129 | static int snd_ca0106_capture_source_info(struct snd_kcontrol *kcontrol, |
| 130 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 132 | static char *texts[6] = { |
James Courtier-Dutton | 39596dc | 2005-12-16 21:59:59 +0100 | [diff] [blame^] | 133 | "IEC958 out", "i2s mixer out", "IEC958 in", "i2s in", "AC97 in", "SRC out" |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 134 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 137 | uinfo->count = 1; |
| 138 | uinfo->value.enumerated.items = 6; |
| 139 | if (uinfo->value.enumerated.item > 5) |
| 140 | uinfo->value.enumerated.item = 5; |
| 141 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 142 | return 0; |
| 143 | } |
| 144 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 145 | static int snd_ca0106_capture_source_get(struct snd_kcontrol *kcontrol, |
| 146 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 148 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | ucontrol->value.enumerated.item[0] = emu->capture_source; |
| 151 | return 0; |
| 152 | } |
| 153 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 154 | static int snd_ca0106_capture_source_put(struct snd_kcontrol *kcontrol, |
| 155 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 157 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | unsigned int val; |
| 159 | int change = 0; |
| 160 | u32 mask; |
| 161 | u32 source; |
| 162 | |
| 163 | val = ucontrol->value.enumerated.item[0] ; |
| 164 | change = (emu->capture_source != val); |
| 165 | if (change) { |
| 166 | emu->capture_source = val; |
| 167 | source = (val << 28) | (val << 24) | (val << 20) | (val << 16); |
| 168 | mask = snd_ca0106_ptr_read(emu, CAPTURE_SOURCE, 0) & 0xffff; |
| 169 | snd_ca0106_ptr_write(emu, CAPTURE_SOURCE, 0, source | mask); |
| 170 | } |
| 171 | return change; |
| 172 | } |
| 173 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 174 | static int snd_ca0106_capture_mic_line_in_info(struct snd_kcontrol *kcontrol, |
| 175 | struct snd_ctl_elem_info *uinfo) |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 176 | { |
| 177 | static char *texts[2] = { "Line in", "Mic in" }; |
| 178 | |
| 179 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 180 | uinfo->count = 1; |
| 181 | uinfo->value.enumerated.items = 2; |
| 182 | if (uinfo->value.enumerated.item > 1) |
| 183 | uinfo->value.enumerated.item = 1; |
| 184 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 185 | return 0; |
| 186 | } |
| 187 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 188 | static int snd_ca0106_capture_mic_line_in_get(struct snd_kcontrol *kcontrol, |
| 189 | struct snd_ctl_elem_value *ucontrol) |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 190 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 191 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 192 | |
| 193 | ucontrol->value.enumerated.item[0] = emu->capture_mic_line_in; |
| 194 | return 0; |
| 195 | } |
| 196 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 197 | static int snd_ca0106_capture_mic_line_in_put(struct snd_kcontrol *kcontrol, |
| 198 | struct snd_ctl_elem_value *ucontrol) |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 199 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 200 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 201 | unsigned int val; |
| 202 | int change = 0; |
| 203 | u32 tmp; |
| 204 | |
| 205 | val = ucontrol->value.enumerated.item[0] ; |
| 206 | change = (emu->capture_mic_line_in != val); |
| 207 | if (change) { |
| 208 | emu->capture_mic_line_in = val; |
| 209 | if (val) { |
| 210 | snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_PHONE); /* Mute input */ |
| 211 | tmp = inl(emu->port+GPIO) & ~0x400; |
| 212 | tmp = tmp | 0x400; |
| 213 | outl(tmp, emu->port+GPIO); |
| 214 | snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_MIC); |
| 215 | } else { |
| 216 | snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_PHONE); /* Mute input */ |
| 217 | tmp = inl(emu->port+GPIO) & ~0x400; |
| 218 | outl(tmp, emu->port+GPIO); |
| 219 | snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_LINEIN); |
| 220 | } |
| 221 | } |
| 222 | return change; |
| 223 | } |
| 224 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 225 | static struct snd_kcontrol_new snd_ca0106_capture_mic_line_in __devinitdata = |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 226 | { |
| 227 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 228 | .name = "Mic/Line in Capture", |
| 229 | .info = snd_ca0106_capture_mic_line_in_info, |
| 230 | .get = snd_ca0106_capture_mic_line_in_get, |
| 231 | .put = snd_ca0106_capture_mic_line_in_put |
| 232 | }; |
| 233 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 234 | static int snd_ca0106_spdif_info(struct snd_kcontrol *kcontrol, |
| 235 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
| 237 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 238 | uinfo->count = 1; |
| 239 | return 0; |
| 240 | } |
| 241 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 242 | static int snd_ca0106_spdif_get(struct snd_kcontrol *kcontrol, |
| 243 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 245 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 247 | |
| 248 | ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff; |
| 249 | ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff; |
| 250 | ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff; |
| 251 | ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff; |
| 252 | return 0; |
| 253 | } |
| 254 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 255 | static int snd_ca0106_spdif_get_mask(struct snd_kcontrol *kcontrol, |
| 256 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | { |
| 258 | ucontrol->value.iec958.status[0] = 0xff; |
| 259 | ucontrol->value.iec958.status[1] = 0xff; |
| 260 | ucontrol->value.iec958.status[2] = 0xff; |
| 261 | ucontrol->value.iec958.status[3] = 0xff; |
| 262 | return 0; |
| 263 | } |
| 264 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 265 | static int snd_ca0106_spdif_put(struct snd_kcontrol *kcontrol, |
| 266 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 268 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 270 | int change; |
| 271 | unsigned int val; |
| 272 | |
| 273 | val = (ucontrol->value.iec958.status[0] << 0) | |
| 274 | (ucontrol->value.iec958.status[1] << 8) | |
| 275 | (ucontrol->value.iec958.status[2] << 16) | |
| 276 | (ucontrol->value.iec958.status[3] << 24); |
| 277 | change = val != emu->spdif_bits[idx]; |
| 278 | if (change) { |
| 279 | snd_ca0106_ptr_write(emu, SPCS0 + idx, 0, val); |
| 280 | emu->spdif_bits[idx] = val; |
| 281 | } |
| 282 | return change; |
| 283 | } |
| 284 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 285 | static int snd_ca0106_volume_info(struct snd_kcontrol *kcontrol, |
| 286 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
| 288 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 289 | uinfo->count = 2; |
| 290 | uinfo->value.integer.min = 0; |
| 291 | uinfo->value.integer.max = 255; |
| 292 | return 0; |
| 293 | } |
| 294 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 295 | static int snd_ca0106_volume_get(struct snd_kcontrol *kcontrol, |
| 296 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 298 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | unsigned int value; |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 300 | int channel_id, reg; |
| 301 | |
| 302 | channel_id = (kcontrol->private_value >> 8) & 0xff; |
| 303 | reg = kcontrol->private_value & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
| 305 | value = snd_ca0106_ptr_read(emu, reg, channel_id); |
| 306 | ucontrol->value.integer.value[0] = 0xff - ((value >> 24) & 0xff); /* Left */ |
| 307 | ucontrol->value.integer.value[1] = 0xff - ((value >> 16) & 0xff); /* Right */ |
| 308 | return 0; |
| 309 | } |
| 310 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 311 | static int snd_ca0106_volume_put(struct snd_kcontrol *kcontrol, |
| 312 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 314 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 315 | unsigned int oval, nval; |
| 316 | int channel_id, reg; |
| 317 | |
| 318 | channel_id = (kcontrol->private_value >> 8) & 0xff; |
| 319 | reg = kcontrol->private_value & 0xff; |
| 320 | |
| 321 | oval = snd_ca0106_ptr_read(emu, reg, channel_id); |
| 322 | nval = ((0xff - ucontrol->value.integer.value[0]) << 24) | |
| 323 | ((0xff - ucontrol->value.integer.value[1]) << 16); |
| 324 | nval |= ((0xff - ucontrol->value.integer.value[0]) << 8) | |
| 325 | ((0xff - ucontrol->value.integer.value[1]) ); |
| 326 | if (oval == nval) |
| 327 | return 0; |
| 328 | snd_ca0106_ptr_write(emu, reg, channel_id, nval); |
| 329 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 332 | #define CA_VOLUME(xname,chid,reg) \ |
| 333 | { \ |
| 334 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 335 | .info = snd_ca0106_volume_info, \ |
| 336 | .get = snd_ca0106_volume_get, \ |
| 337 | .put = snd_ca0106_volume_put, \ |
| 338 | .private_value = ((chid) << 8) | (reg) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 341 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 342 | static struct snd_kcontrol_new snd_ca0106_volume_ctls[] __devinitdata = { |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 343 | CA_VOLUME("Analog Front Playback Volume", |
| 344 | CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME2), |
| 345 | CA_VOLUME("Analog Rear Playback Volume", |
| 346 | CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME2), |
| 347 | CA_VOLUME("Analog Center/LFE Playback Volume", |
| 348 | CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME2), |
| 349 | CA_VOLUME("Analog Side Playback Volume", |
| 350 | CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME2), |
| 351 | |
James Courtier-Dutton | 39596dc | 2005-12-16 21:59:59 +0100 | [diff] [blame^] | 352 | CA_VOLUME("IEC958 Front Playback Volume", |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 353 | CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME1), |
James Courtier-Dutton | 39596dc | 2005-12-16 21:59:59 +0100 | [diff] [blame^] | 354 | CA_VOLUME("IEC958 Rear Playback Volume", |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 355 | CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME1), |
James Courtier-Dutton | 39596dc | 2005-12-16 21:59:59 +0100 | [diff] [blame^] | 356 | CA_VOLUME("IEC958 Center/LFE Playback Volume", |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 357 | CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME1), |
James Courtier-Dutton | 39596dc | 2005-12-16 21:59:59 +0100 | [diff] [blame^] | 358 | CA_VOLUME("IEC958 Unknown Playback Volume", |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 359 | CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME1), |
| 360 | |
| 361 | CA_VOLUME("CAPTURE feedback Playback Volume", |
| 362 | 1, CAPTURE_CONTROL), |
| 363 | |
| 364 | { |
| 365 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 366 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 367 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), |
| 368 | .count = 4, |
| 369 | .info = snd_ca0106_spdif_info, |
| 370 | .get = snd_ca0106_spdif_get_mask |
| 371 | }, |
| 372 | { |
| 373 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
James Courtier-Dutton | 39596dc | 2005-12-16 21:59:59 +0100 | [diff] [blame^] | 374 | .name = "IEC958 Playback Switch", |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 375 | .info = snd_ca0106_shared_spdif_info, |
| 376 | .get = snd_ca0106_shared_spdif_get, |
| 377 | .put = snd_ca0106_shared_spdif_put |
| 378 | }, |
| 379 | { |
| 380 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 381 | .name = "Capture Source", |
| 382 | .info = snd_ca0106_capture_source_info, |
| 383 | .get = snd_ca0106_capture_source_get, |
| 384 | .put = snd_ca0106_capture_source_put |
| 385 | }, |
| 386 | { |
| 387 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 388 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), |
| 389 | .count = 4, |
| 390 | .info = snd_ca0106_spdif_info, |
| 391 | .get = snd_ca0106_spdif_get, |
| 392 | .put = snd_ca0106_spdif_put |
| 393 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | }; |
| 395 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 396 | static int __devinit remove_ctl(struct snd_card *card, const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 398 | struct snd_ctl_elem_id id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | memset(&id, 0, sizeof(id)); |
| 400 | strcpy(id.name, name); |
| 401 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 402 | return snd_ctl_remove_id(card, &id); |
| 403 | } |
| 404 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 405 | static struct snd_kcontrol __devinit *ctl_find(struct snd_card *card, const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 407 | struct snd_ctl_elem_id sid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | memset(&sid, 0, sizeof(sid)); |
| 409 | /* FIXME: strcpy is bad. */ |
| 410 | strcpy(sid.name, name); |
| 411 | sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 412 | return snd_ctl_find_id(card, &sid); |
| 413 | } |
| 414 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 415 | static int __devinit rename_ctl(struct snd_card *card, const char *src, const char *dst) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 417 | struct snd_kcontrol *kctl = ctl_find(card, src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | if (kctl) { |
| 419 | strcpy(kctl->id.name, dst); |
| 420 | return 0; |
| 421 | } |
| 422 | return -ENOENT; |
| 423 | } |
| 424 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 425 | int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | { |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 427 | int i, err; |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 428 | struct snd_card *card = emu->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | char **c; |
| 430 | static char *ca0106_remove_ctls[] = { |
| 431 | "Master Mono Playback Switch", |
| 432 | "Master Mono Playback Volume", |
| 433 | "3D Control - Switch", |
| 434 | "3D Control Sigmatel - Depth", |
| 435 | "PCM Playback Switch", |
| 436 | "PCM Playback Volume", |
| 437 | "CD Playback Switch", |
| 438 | "CD Playback Volume", |
| 439 | "Phone Playback Switch", |
| 440 | "Phone Playback Volume", |
| 441 | "Video Playback Switch", |
| 442 | "Video Playback Volume", |
| 443 | "PC Speaker Playback Switch", |
| 444 | "PC Speaker Playback Volume", |
| 445 | "Mono Output Select", |
| 446 | "Capture Source", |
| 447 | "Capture Switch", |
| 448 | "Capture Volume", |
| 449 | "External Amplifier", |
| 450 | "Sigmatel 4-Speaker Stereo Playback Switch", |
| 451 | "Sigmatel Surround Phase Inversion Playback ", |
| 452 | NULL |
| 453 | }; |
| 454 | static char *ca0106_rename_ctls[] = { |
| 455 | "Master Playback Switch", "Capture Switch", |
| 456 | "Master Playback Volume", "Capture Volume", |
| 457 | "Line Playback Switch", "AC97 Line Capture Switch", |
| 458 | "Line Playback Volume", "AC97 Line Capture Volume", |
| 459 | "Aux Playback Switch", "AC97 Aux Capture Switch", |
| 460 | "Aux Playback Volume", "AC97 Aux Capture Volume", |
| 461 | "Mic Playback Switch", "AC97 Mic Capture Switch", |
| 462 | "Mic Playback Volume", "AC97 Mic Capture Volume", |
| 463 | "Mic Select", "AC97 Mic Select", |
| 464 | "Mic Boost (+20dB)", "AC97 Mic Boost (+20dB)", |
| 465 | NULL |
| 466 | }; |
| 467 | #if 1 |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 468 | for (c = ca0106_remove_ctls; *c; c++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | remove_ctl(card, *c); |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 470 | for (c = ca0106_rename_ctls; *c; c += 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | rename_ctl(card, c[0], c[1]); |
| 472 | #endif |
| 473 | |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 474 | for (i = 0; i < ARRAY_SIZE(snd_ca0106_volume_ctls); i++) { |
| 475 | err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_volume_ctls[i], emu)); |
| 476 | if (err < 0) |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 477 | return err; |
| 478 | } |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 479 | if (emu->details->i2c_adc == 1) { |
| 480 | err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_mic_line_in, emu)); |
| 481 | if (err < 0) |
| 482 | return err; |
| 483 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | return 0; |
| 485 | } |
| 486 | |