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 |
Trent Piepho | b18cd53 | 2007-07-24 12:06:16 +0200 | [diff] [blame] | 4 | * Version: 0.0.18 |
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. |
Trent Piepho | b18cd53 | 2007-07-24 12:06:16 +0200 | [diff] [blame] | 42 | * 0.0.18 |
| 43 | * Add support for mute control on SB Live 24bit (cards w/ SPI DAC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | * |
| 45 | * This code was initally based on code from ALSA's emu10k1x.c which is: |
| 46 | * Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com> |
| 47 | * |
| 48 | * This program is free software; you can redistribute it and/or modify |
| 49 | * it under the terms of the GNU General Public License as published by |
| 50 | * the Free Software Foundation; either version 2 of the License, or |
| 51 | * (at your option) any later version. |
| 52 | * |
| 53 | * This program is distributed in the hope that it will be useful, |
| 54 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 55 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 56 | * GNU General Public License for more details. |
| 57 | * |
| 58 | * You should have received a copy of the GNU General Public License |
| 59 | * along with this program; if not, write to the Free Software |
| 60 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 61 | * |
| 62 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #include <linux/delay.h> |
| 64 | #include <linux/init.h> |
| 65 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #include <linux/moduleparam.h> |
| 67 | #include <sound/core.h> |
| 68 | #include <sound/initval.h> |
| 69 | #include <sound/pcm.h> |
| 70 | #include <sound/ac97_codec.h> |
| 71 | #include <sound/info.h> |
Jaroslav Kysela | 42750b0 | 2006-06-01 18:34:01 +0200 | [diff] [blame] | 72 | #include <sound/tlv.h> |
Jean Delvare | 6473d16 | 2007-03-06 02:45:12 -0800 | [diff] [blame] | 73 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | #include "ca0106.h" |
| 76 | |
Takashi Iwai | 5da9527 | 2008-11-24 14:06:08 +0100 | [diff] [blame] | 77 | static void ca0106_spdif_enable(struct snd_ca0106 *emu) |
| 78 | { |
| 79 | unsigned int val; |
| 80 | |
| 81 | if (emu->spdif_enable) { |
| 82 | /* Digital */ |
| 83 | snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf); |
| 84 | snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x0b000000); |
| 85 | val = snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) & ~0x1000; |
| 86 | snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0, val); |
| 87 | val = inl(emu->port + GPIO) & ~0x101; |
| 88 | outl(val, emu->port + GPIO); |
| 89 | |
| 90 | } else { |
| 91 | /* Analog */ |
| 92 | snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf); |
| 93 | snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x000f0000); |
| 94 | val = snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) | 0x1000; |
| 95 | snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0, val); |
| 96 | val = inl(emu->port + GPIO) | 0x101; |
| 97 | outl(val, emu->port + GPIO); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | static void ca0106_set_capture_source(struct snd_ca0106 *emu) |
| 102 | { |
| 103 | unsigned int val = emu->capture_source; |
| 104 | unsigned int source, mask; |
| 105 | source = (val << 28) | (val << 24) | (val << 20) | (val << 16); |
| 106 | mask = snd_ca0106_ptr_read(emu, CAPTURE_SOURCE, 0) & 0xffff; |
| 107 | snd_ca0106_ptr_write(emu, CAPTURE_SOURCE, 0, source | mask); |
| 108 | } |
| 109 | |
| 110 | static void ca0106_set_i2c_capture_source(struct snd_ca0106 *emu, |
| 111 | unsigned int val, int force) |
| 112 | { |
| 113 | unsigned int ngain, ogain; |
| 114 | u32 source; |
| 115 | |
| 116 | snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */ |
| 117 | ngain = emu->i2c_capture_volume[val][0]; /* Left */ |
| 118 | ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */ |
| 119 | if (force || ngain != ogain) |
| 120 | snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ngain & 0xff); |
| 121 | ngain = emu->i2c_capture_volume[val][1]; /* Right */ |
| 122 | ogain = emu->i2c_capture_volume[emu->i2c_capture_source][1]; /* Right */ |
| 123 | if (force || ngain != ogain) |
| 124 | snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ngain & 0xff); |
| 125 | source = 1 << val; |
| 126 | snd_ca0106_i2c_write(emu, ADC_MUX, source); /* Set source */ |
| 127 | emu->i2c_capture_source = val; |
| 128 | } |
| 129 | |
| 130 | static void ca0106_set_capture_mic_line_in(struct snd_ca0106 *emu) |
| 131 | { |
| 132 | u32 tmp; |
| 133 | |
| 134 | if (emu->capture_mic_line_in) { |
| 135 | /* snd_ca0106_i2c_write(emu, ADC_MUX, 0); */ /* Mute input */ |
| 136 | tmp = inl(emu->port+GPIO) & ~0x400; |
| 137 | tmp = tmp | 0x400; |
| 138 | outl(tmp, emu->port+GPIO); |
| 139 | /* snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_MIC); */ |
| 140 | } else { |
| 141 | /* snd_ca0106_i2c_write(emu, ADC_MUX, 0); */ /* Mute input */ |
| 142 | tmp = inl(emu->port+GPIO) & ~0x400; |
| 143 | outl(tmp, emu->port+GPIO); |
| 144 | /* snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_LINEIN); */ |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | static void ca0106_set_spdif_bits(struct snd_ca0106 *emu, int idx) |
| 149 | { |
Takashi Iwai | 3d47582 | 2008-12-19 12:13:18 +0100 | [diff] [blame] | 150 | snd_ca0106_ptr_write(emu, SPCS0 + idx, 0, emu->spdif_str_bits[idx]); |
Takashi Iwai | 5da9527 | 2008-11-24 14:06:08 +0100 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /* |
| 154 | */ |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 155 | static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale1, -5175, 25, 1); |
| 156 | static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale2, -10350, 50, 1); |
Jaroslav Kysela | 42750b0 | 2006-06-01 18:34:01 +0200 | [diff] [blame] | 157 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 158 | #define snd_ca0106_shared_spdif_info snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 160 | static int snd_ca0106_shared_spdif_get(struct snd_kcontrol *kcontrol, |
| 161 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 163 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Takashi Iwai | 5fe619f | 2007-11-15 14:42:34 +0100 | [diff] [blame] | 165 | ucontrol->value.integer.value[0] = emu->spdif_enable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | return 0; |
| 167 | } |
| 168 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 169 | static int snd_ca0106_shared_spdif_put(struct snd_kcontrol *kcontrol, |
| 170 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 172 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | unsigned int val; |
| 174 | int change = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Takashi Iwai | 5fe619f | 2007-11-15 14:42:34 +0100 | [diff] [blame] | 176 | val = !!ucontrol->value.integer.value[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | change = (emu->spdif_enable != val); |
| 178 | if (change) { |
| 179 | emu->spdif_enable = val; |
Takashi Iwai | 5da9527 | 2008-11-24 14:06:08 +0100 | [diff] [blame] | 180 | ca0106_spdif_enable(emu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |
| 182 | return change; |
| 183 | } |
| 184 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 185 | static int snd_ca0106_capture_source_info(struct snd_kcontrol *kcontrol, |
| 186 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 188 | static char *texts[6] = { |
James Courtier-Dutton | 39596dc | 2005-12-16 21:59:59 +0100 | [diff] [blame] | 189 | "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] | 190 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
| 192 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 193 | uinfo->count = 1; |
| 194 | uinfo->value.enumerated.items = 6; |
| 195 | if (uinfo->value.enumerated.item > 5) |
| 196 | uinfo->value.enumerated.item = 5; |
| 197 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 198 | return 0; |
| 199 | } |
| 200 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 201 | static int snd_ca0106_capture_source_get(struct snd_kcontrol *kcontrol, |
| 202 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 204 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | ucontrol->value.enumerated.item[0] = emu->capture_source; |
| 207 | return 0; |
| 208 | } |
| 209 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 210 | static int snd_ca0106_capture_source_put(struct snd_kcontrol *kcontrol, |
| 211 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 213 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | unsigned int val; |
| 215 | int change = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | val = ucontrol->value.enumerated.item[0] ; |
Takashi Iwai | 5fe619f | 2007-11-15 14:42:34 +0100 | [diff] [blame] | 218 | if (val >= 6) |
| 219 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | change = (emu->capture_source != val); |
| 221 | if (change) { |
| 222 | emu->capture_source = val; |
Takashi Iwai | 5da9527 | 2008-11-24 14:06:08 +0100 | [diff] [blame] | 223 | ca0106_set_capture_source(emu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | return change; |
| 226 | } |
| 227 | |
James Courtier-Dutton | 6129daa | 2006-04-09 13:01:34 +0100 | [diff] [blame] | 228 | static int snd_ca0106_i2c_capture_source_info(struct snd_kcontrol *kcontrol, |
| 229 | struct snd_ctl_elem_info *uinfo) |
| 230 | { |
| 231 | static char *texts[6] = { |
| 232 | "Phone", "Mic", "Line in", "Aux" |
| 233 | }; |
| 234 | |
| 235 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 236 | uinfo->count = 1; |
| 237 | uinfo->value.enumerated.items = 4; |
| 238 | if (uinfo->value.enumerated.item > 3) |
| 239 | uinfo->value.enumerated.item = 3; |
| 240 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | static int snd_ca0106_i2c_capture_source_get(struct snd_kcontrol *kcontrol, |
| 245 | struct snd_ctl_elem_value *ucontrol) |
| 246 | { |
| 247 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
| 248 | |
| 249 | ucontrol->value.enumerated.item[0] = emu->i2c_capture_source; |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | static int snd_ca0106_i2c_capture_source_put(struct snd_kcontrol *kcontrol, |
| 254 | struct snd_ctl_elem_value *ucontrol) |
| 255 | { |
| 256 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
| 257 | unsigned int source_id; |
James Courtier-Dutton | 6129daa | 2006-04-09 13:01:34 +0100 | [diff] [blame] | 258 | int change = 0; |
James Courtier-Dutton | 6129daa | 2006-04-09 13:01:34 +0100 | [diff] [blame] | 259 | /* If the capture source has changed, |
| 260 | * update the capture volume from the cached value |
| 261 | * for the particular source. |
| 262 | */ |
| 263 | source_id = ucontrol->value.enumerated.item[0] ; |
Takashi Iwai | 5fe619f | 2007-11-15 14:42:34 +0100 | [diff] [blame] | 264 | if (source_id >= 4) |
| 265 | return -EINVAL; |
James Courtier-Dutton | 6129daa | 2006-04-09 13:01:34 +0100 | [diff] [blame] | 266 | change = (emu->i2c_capture_source != source_id); |
| 267 | if (change) { |
Takashi Iwai | 5da9527 | 2008-11-24 14:06:08 +0100 | [diff] [blame] | 268 | ca0106_set_i2c_capture_source(emu, source_id, 0); |
James Courtier-Dutton | 6129daa | 2006-04-09 13:01:34 +0100 | [diff] [blame] | 269 | } |
| 270 | return change; |
| 271 | } |
| 272 | |
James Courtier-Dutton | be0b7b0 | 2006-04-09 20:48:44 +0100 | [diff] [blame] | 273 | static int snd_ca0106_capture_line_in_side_out_info(struct snd_kcontrol *kcontrol, |
| 274 | struct snd_ctl_elem_info *uinfo) |
| 275 | { |
| 276 | static char *texts[2] = { "Side out", "Line in" }; |
| 277 | |
| 278 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 279 | uinfo->count = 1; |
| 280 | uinfo->value.enumerated.items = 2; |
| 281 | if (uinfo->value.enumerated.item > 1) |
| 282 | uinfo->value.enumerated.item = 1; |
| 283 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 284 | return 0; |
| 285 | } |
| 286 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 287 | static int snd_ca0106_capture_mic_line_in_info(struct snd_kcontrol *kcontrol, |
| 288 | struct snd_ctl_elem_info *uinfo) |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 289 | { |
| 290 | static char *texts[2] = { "Line in", "Mic in" }; |
| 291 | |
| 292 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 293 | uinfo->count = 1; |
| 294 | uinfo->value.enumerated.items = 2; |
| 295 | if (uinfo->value.enumerated.item > 1) |
| 296 | uinfo->value.enumerated.item = 1; |
| 297 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 298 | return 0; |
| 299 | } |
| 300 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 301 | static int snd_ca0106_capture_mic_line_in_get(struct snd_kcontrol *kcontrol, |
| 302 | struct snd_ctl_elem_value *ucontrol) |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 303 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 304 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 305 | |
| 306 | ucontrol->value.enumerated.item[0] = emu->capture_mic_line_in; |
| 307 | return 0; |
| 308 | } |
| 309 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 310 | static int snd_ca0106_capture_mic_line_in_put(struct snd_kcontrol *kcontrol, |
| 311 | struct snd_ctl_elem_value *ucontrol) |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 312 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 313 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 314 | unsigned int val; |
| 315 | int change = 0; |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 316 | |
| 317 | val = ucontrol->value.enumerated.item[0] ; |
Takashi Iwai | 5fe619f | 2007-11-15 14:42:34 +0100 | [diff] [blame] | 318 | if (val > 1) |
| 319 | return -EINVAL; |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 320 | change = (emu->capture_mic_line_in != val); |
| 321 | if (change) { |
| 322 | emu->capture_mic_line_in = val; |
Takashi Iwai | 5da9527 | 2008-11-24 14:06:08 +0100 | [diff] [blame] | 323 | ca0106_set_capture_mic_line_in(emu); |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 324 | } |
| 325 | return change; |
| 326 | } |
| 327 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 328 | 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] | 329 | { |
| 330 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
James Courtier-Dutton | 6129daa | 2006-04-09 13:01:34 +0100 | [diff] [blame] | 331 | .name = "Shared Mic/Line in Capture Switch", |
James Courtier-Dutton | ed144f3 | 2005-05-27 23:28:27 +0200 | [diff] [blame] | 332 | .info = snd_ca0106_capture_mic_line_in_info, |
| 333 | .get = snd_ca0106_capture_mic_line_in_get, |
| 334 | .put = snd_ca0106_capture_mic_line_in_put |
| 335 | }; |
| 336 | |
James Courtier-Dutton | be0b7b0 | 2006-04-09 20:48:44 +0100 | [diff] [blame] | 337 | static struct snd_kcontrol_new snd_ca0106_capture_line_in_side_out __devinitdata = |
| 338 | { |
| 339 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 340 | .name = "Shared Line in/Side out Capture Switch", |
| 341 | .info = snd_ca0106_capture_line_in_side_out_info, |
| 342 | .get = snd_ca0106_capture_mic_line_in_get, |
| 343 | .put = snd_ca0106_capture_mic_line_in_put |
| 344 | }; |
| 345 | |
| 346 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 347 | static int snd_ca0106_spdif_info(struct snd_kcontrol *kcontrol, |
| 348 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
| 350 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 351 | uinfo->count = 1; |
| 352 | return 0; |
| 353 | } |
| 354 | |
Takashi Iwai | 3d47582 | 2008-12-19 12:13:18 +0100 | [diff] [blame] | 355 | static void decode_spdif_bits(unsigned char *status, unsigned int bits) |
| 356 | { |
| 357 | status[0] = (bits >> 0) & 0xff; |
| 358 | status[1] = (bits >> 8) & 0xff; |
| 359 | status[2] = (bits >> 16) & 0xff; |
| 360 | status[3] = (bits >> 24) & 0xff; |
| 361 | } |
| 362 | |
| 363 | static int snd_ca0106_spdif_get_default(struct snd_kcontrol *kcontrol, |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 364 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 366 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 368 | |
Takashi Iwai | 3d47582 | 2008-12-19 12:13:18 +0100 | [diff] [blame] | 369 | decode_spdif_bits(ucontrol->value.iec958.status, |
| 370 | emu->spdif_bits[idx]); |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | static int snd_ca0106_spdif_get_stream(struct snd_kcontrol *kcontrol, |
| 375 | struct snd_ctl_elem_value *ucontrol) |
| 376 | { |
| 377 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
| 378 | unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 379 | |
| 380 | decode_spdif_bits(ucontrol->value.iec958.status, |
| 381 | emu->spdif_str_bits[idx]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | return 0; |
| 383 | } |
| 384 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 385 | static int snd_ca0106_spdif_get_mask(struct snd_kcontrol *kcontrol, |
| 386 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | { |
| 388 | ucontrol->value.iec958.status[0] = 0xff; |
| 389 | ucontrol->value.iec958.status[1] = 0xff; |
| 390 | ucontrol->value.iec958.status[2] = 0xff; |
| 391 | ucontrol->value.iec958.status[3] = 0xff; |
| 392 | return 0; |
| 393 | } |
| 394 | |
Takashi Iwai | 3d47582 | 2008-12-19 12:13:18 +0100 | [diff] [blame] | 395 | static unsigned int encode_spdif_bits(unsigned char *status) |
| 396 | { |
| 397 | return ((unsigned int)status[0] << 0) | |
| 398 | ((unsigned int)status[1] << 8) | |
| 399 | ((unsigned int)status[2] << 16) | |
| 400 | ((unsigned int)status[3] << 24); |
| 401 | } |
| 402 | |
| 403 | static int snd_ca0106_spdif_put_default(struct snd_kcontrol *kcontrol, |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 404 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 406 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | unsigned int val; |
| 409 | |
Takashi Iwai | 3d47582 | 2008-12-19 12:13:18 +0100 | [diff] [blame] | 410 | val = encode_spdif_bits(ucontrol->value.iec958.status); |
| 411 | if (val != emu->spdif_bits[idx]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | emu->spdif_bits[idx] = val; |
Takashi Iwai | 3d47582 | 2008-12-19 12:13:18 +0100 | [diff] [blame] | 413 | /* FIXME: this isn't safe, but needed to keep the compatibility |
| 414 | * with older alsa-lib config |
| 415 | */ |
| 416 | emu->spdif_str_bits[idx] = val; |
Takashi Iwai | 5da9527 | 2008-11-24 14:06:08 +0100 | [diff] [blame] | 417 | ca0106_set_spdif_bits(emu, idx); |
Takashi Iwai | 3d47582 | 2008-12-19 12:13:18 +0100 | [diff] [blame] | 418 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
Takashi Iwai | 3d47582 | 2008-12-19 12:13:18 +0100 | [diff] [blame] | 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | static int snd_ca0106_spdif_put_stream(struct snd_kcontrol *kcontrol, |
| 424 | struct snd_ctl_elem_value *ucontrol) |
| 425 | { |
| 426 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
| 427 | unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 428 | unsigned int val; |
| 429 | |
| 430 | val = encode_spdif_bits(ucontrol->value.iec958.status); |
| 431 | if (val != emu->spdif_str_bits[idx]) { |
| 432 | emu->spdif_str_bits[idx] = val; |
| 433 | ca0106_set_spdif_bits(emu, idx); |
| 434 | return 1; |
| 435 | } |
| 436 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 439 | static int snd_ca0106_volume_info(struct snd_kcontrol *kcontrol, |
| 440 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | { |
| 442 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 443 | uinfo->count = 2; |
| 444 | uinfo->value.integer.min = 0; |
| 445 | uinfo->value.integer.max = 255; |
| 446 | return 0; |
| 447 | } |
| 448 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 449 | static int snd_ca0106_volume_get(struct snd_kcontrol *kcontrol, |
| 450 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 452 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | unsigned int value; |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 454 | int channel_id, reg; |
| 455 | |
| 456 | channel_id = (kcontrol->private_value >> 8) & 0xff; |
| 457 | reg = kcontrol->private_value & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
| 459 | value = snd_ca0106_ptr_read(emu, reg, channel_id); |
| 460 | ucontrol->value.integer.value[0] = 0xff - ((value >> 24) & 0xff); /* Left */ |
| 461 | ucontrol->value.integer.value[1] = 0xff - ((value >> 16) & 0xff); /* Right */ |
| 462 | return 0; |
| 463 | } |
| 464 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 465 | static int snd_ca0106_volume_put(struct snd_kcontrol *kcontrol, |
| 466 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 468 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 469 | unsigned int oval, nval; |
| 470 | int channel_id, reg; |
| 471 | |
| 472 | channel_id = (kcontrol->private_value >> 8) & 0xff; |
| 473 | reg = kcontrol->private_value & 0xff; |
| 474 | |
| 475 | oval = snd_ca0106_ptr_read(emu, reg, channel_id); |
| 476 | nval = ((0xff - ucontrol->value.integer.value[0]) << 24) | |
| 477 | ((0xff - ucontrol->value.integer.value[1]) << 16); |
| 478 | nval |= ((0xff - ucontrol->value.integer.value[0]) << 8) | |
| 479 | ((0xff - ucontrol->value.integer.value[1]) ); |
| 480 | if (oval == nval) |
| 481 | return 0; |
| 482 | snd_ca0106_ptr_write(emu, reg, channel_id, nval); |
| 483 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | } |
| 485 | |
James Courtier-Dutton | 6129daa | 2006-04-09 13:01:34 +0100 | [diff] [blame] | 486 | static int snd_ca0106_i2c_volume_info(struct snd_kcontrol *kcontrol, |
| 487 | struct snd_ctl_elem_info *uinfo) |
| 488 | { |
| 489 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 490 | uinfo->count = 2; |
| 491 | uinfo->value.integer.min = 0; |
| 492 | uinfo->value.integer.max = 255; |
| 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | static int snd_ca0106_i2c_volume_get(struct snd_kcontrol *kcontrol, |
| 497 | struct snd_ctl_elem_value *ucontrol) |
| 498 | { |
| 499 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
| 500 | int source_id; |
| 501 | |
| 502 | source_id = kcontrol->private_value; |
| 503 | |
| 504 | ucontrol->value.integer.value[0] = emu->i2c_capture_volume[source_id][0]; |
| 505 | ucontrol->value.integer.value[1] = emu->i2c_capture_volume[source_id][1]; |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | static int snd_ca0106_i2c_volume_put(struct snd_kcontrol *kcontrol, |
| 510 | struct snd_ctl_elem_value *ucontrol) |
| 511 | { |
| 512 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
| 513 | unsigned int ogain; |
| 514 | unsigned int ngain; |
| 515 | int source_id; |
| 516 | int change = 0; |
| 517 | |
| 518 | source_id = kcontrol->private_value; |
| 519 | ogain = emu->i2c_capture_volume[source_id][0]; /* Left */ |
| 520 | ngain = ucontrol->value.integer.value[0]; |
| 521 | if (ngain > 0xff) |
Takashi Iwai | 5fe619f | 2007-11-15 14:42:34 +0100 | [diff] [blame] | 522 | return -EINVAL; |
James Courtier-Dutton | 6129daa | 2006-04-09 13:01:34 +0100 | [diff] [blame] | 523 | if (ogain != ngain) { |
| 524 | if (emu->i2c_capture_source == source_id) |
| 525 | snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff) ); |
| 526 | emu->i2c_capture_volume[source_id][0] = ucontrol->value.integer.value[0]; |
| 527 | change = 1; |
| 528 | } |
| 529 | ogain = emu->i2c_capture_volume[source_id][1]; /* Right */ |
| 530 | ngain = ucontrol->value.integer.value[1]; |
| 531 | if (ngain > 0xff) |
Takashi Iwai | 5fe619f | 2007-11-15 14:42:34 +0100 | [diff] [blame] | 532 | return -EINVAL; |
James Courtier-Dutton | 6129daa | 2006-04-09 13:01:34 +0100 | [diff] [blame] | 533 | if (ogain != ngain) { |
| 534 | if (emu->i2c_capture_source == source_id) |
| 535 | snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff)); |
| 536 | emu->i2c_capture_volume[source_id][1] = ucontrol->value.integer.value[1]; |
| 537 | change = 1; |
| 538 | } |
| 539 | |
| 540 | return change; |
| 541 | } |
| 542 | |
Trent Piepho | b18cd53 | 2007-07-24 12:06:16 +0200 | [diff] [blame] | 543 | #define spi_mute_info snd_ctl_boolean_mono_info |
| 544 | |
| 545 | static int spi_mute_get(struct snd_kcontrol *kcontrol, |
| 546 | struct snd_ctl_elem_value *ucontrol) |
| 547 | { |
| 548 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
| 549 | unsigned int reg = kcontrol->private_value >> SPI_REG_SHIFT; |
| 550 | unsigned int bit = kcontrol->private_value & SPI_REG_MASK; |
| 551 | |
| 552 | ucontrol->value.integer.value[0] = !(emu->spi_dac_reg[reg] & bit); |
| 553 | return 0; |
| 554 | } |
| 555 | |
| 556 | static int spi_mute_put(struct snd_kcontrol *kcontrol, |
| 557 | struct snd_ctl_elem_value *ucontrol) |
| 558 | { |
| 559 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
| 560 | unsigned int reg = kcontrol->private_value >> SPI_REG_SHIFT; |
| 561 | unsigned int bit = kcontrol->private_value & SPI_REG_MASK; |
| 562 | int ret; |
| 563 | |
| 564 | ret = emu->spi_dac_reg[reg] & bit; |
| 565 | if (ucontrol->value.integer.value[0]) { |
| 566 | if (!ret) /* bit already cleared, do nothing */ |
| 567 | return 0; |
| 568 | emu->spi_dac_reg[reg] &= ~bit; |
| 569 | } else { |
| 570 | if (ret) /* bit already set, do nothing */ |
| 571 | return 0; |
| 572 | emu->spi_dac_reg[reg] |= bit; |
| 573 | } |
| 574 | |
| 575 | ret = snd_ca0106_spi_write(emu, emu->spi_dac_reg[reg]); |
Takashi Iwai | 5fe619f | 2007-11-15 14:42:34 +0100 | [diff] [blame] | 576 | return ret ? -EINVAL : 1; |
Trent Piepho | b18cd53 | 2007-07-24 12:06:16 +0200 | [diff] [blame] | 577 | } |
| 578 | |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 579 | #define CA_VOLUME(xname,chid,reg) \ |
| 580 | { \ |
| 581 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 582 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ |
| 583 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ |
James Courtier-Dutton | 6129daa | 2006-04-09 13:01:34 +0100 | [diff] [blame] | 584 | .info = snd_ca0106_volume_info, \ |
| 585 | .get = snd_ca0106_volume_get, \ |
| 586 | .put = snd_ca0106_volume_put, \ |
Takashi Iwai | 7cf0a95 | 2006-08-17 16:23:07 +0200 | [diff] [blame] | 587 | .tlv = { .p = snd_ca0106_db_scale1 }, \ |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 588 | .private_value = ((chid) << 8) | (reg) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 591 | static struct snd_kcontrol_new snd_ca0106_volume_ctls[] __devinitdata = { |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 592 | CA_VOLUME("Analog Front Playback Volume", |
| 593 | CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME2), |
| 594 | CA_VOLUME("Analog Rear Playback Volume", |
| 595 | CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME2), |
| 596 | CA_VOLUME("Analog Center/LFE Playback Volume", |
| 597 | CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME2), |
| 598 | CA_VOLUME("Analog Side Playback Volume", |
| 599 | CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME2), |
| 600 | |
James Courtier-Dutton | 39596dc | 2005-12-16 21:59:59 +0100 | [diff] [blame] | 601 | CA_VOLUME("IEC958 Front Playback Volume", |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 602 | CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME1), |
James Courtier-Dutton | 39596dc | 2005-12-16 21:59:59 +0100 | [diff] [blame] | 603 | CA_VOLUME("IEC958 Rear Playback Volume", |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 604 | CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME1), |
James Courtier-Dutton | 39596dc | 2005-12-16 21:59:59 +0100 | [diff] [blame] | 605 | CA_VOLUME("IEC958 Center/LFE Playback Volume", |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 606 | CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME1), |
James Courtier-Dutton | 39596dc | 2005-12-16 21:59:59 +0100 | [diff] [blame] | 607 | CA_VOLUME("IEC958 Unknown Playback Volume", |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 608 | CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME1), |
| 609 | |
| 610 | CA_VOLUME("CAPTURE feedback Playback Volume", |
| 611 | 1, CAPTURE_CONTROL), |
| 612 | |
| 613 | { |
| 614 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 615 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 616 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), |
| 617 | .count = 4, |
| 618 | .info = snd_ca0106_spdif_info, |
| 619 | .get = snd_ca0106_spdif_get_mask |
| 620 | }, |
| 621 | { |
| 622 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
James Courtier-Dutton | 39596dc | 2005-12-16 21:59:59 +0100 | [diff] [blame] | 623 | .name = "IEC958 Playback Switch", |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 624 | .info = snd_ca0106_shared_spdif_info, |
| 625 | .get = snd_ca0106_shared_spdif_get, |
| 626 | .put = snd_ca0106_shared_spdif_put |
| 627 | }, |
| 628 | { |
| 629 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
James Courtier-Dutton | e6327cf | 2006-11-11 10:52:06 +0000 | [diff] [blame] | 630 | .name = "Digital Source Capture Enum", |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 631 | .info = snd_ca0106_capture_source_info, |
| 632 | .get = snd_ca0106_capture_source_get, |
| 633 | .put = snd_ca0106_capture_source_put |
| 634 | }, |
| 635 | { |
James Courtier-Dutton | 6129daa | 2006-04-09 13:01:34 +0100 | [diff] [blame] | 636 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
James Courtier-Dutton | e6327cf | 2006-11-11 10:52:06 +0000 | [diff] [blame] | 637 | .name = "Analog Source Capture Enum", |
James Courtier-Dutton | 6129daa | 2006-04-09 13:01:34 +0100 | [diff] [blame] | 638 | .info = snd_ca0106_i2c_capture_source_info, |
| 639 | .get = snd_ca0106_i2c_capture_source_get, |
| 640 | .put = snd_ca0106_i2c_capture_source_put |
| 641 | }, |
| 642 | { |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 643 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 644 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), |
| 645 | .count = 4, |
| 646 | .info = snd_ca0106_spdif_info, |
Takashi Iwai | 3d47582 | 2008-12-19 12:13:18 +0100 | [diff] [blame] | 647 | .get = snd_ca0106_spdif_get_default, |
| 648 | .put = snd_ca0106_spdif_put_default |
| 649 | }, |
| 650 | { |
| 651 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 652 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM), |
| 653 | .count = 4, |
| 654 | .info = snd_ca0106_spdif_info, |
| 655 | .get = snd_ca0106_spdif_get_stream, |
| 656 | .put = snd_ca0106_spdif_put_stream |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 657 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | }; |
| 659 | |
James Courtier-Dutton | 7c15706 | 2006-12-10 00:00:38 +0000 | [diff] [blame] | 660 | #define I2C_VOLUME(xname,chid) \ |
| 661 | { \ |
| 662 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 663 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ |
| 664 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ |
| 665 | .info = snd_ca0106_i2c_volume_info, \ |
| 666 | .get = snd_ca0106_i2c_volume_get, \ |
| 667 | .put = snd_ca0106_i2c_volume_put, \ |
| 668 | .tlv = { .p = snd_ca0106_db_scale2 }, \ |
| 669 | .private_value = chid \ |
| 670 | } |
| 671 | |
| 672 | static struct snd_kcontrol_new snd_ca0106_volume_i2c_adc_ctls[] __devinitdata = { |
| 673 | I2C_VOLUME("Phone Capture Volume", 0), |
| 674 | I2C_VOLUME("Mic Capture Volume", 1), |
| 675 | I2C_VOLUME("Line in Capture Volume", 2), |
| 676 | I2C_VOLUME("Aux Capture Volume", 3), |
| 677 | }; |
| 678 | |
Trent Piepho | b18cd53 | 2007-07-24 12:06:16 +0200 | [diff] [blame] | 679 | #define SPI_SWITCH(xname,reg,bit) \ |
| 680 | { \ |
| 681 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 682 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \ |
| 683 | .info = spi_mute_info, \ |
| 684 | .get = spi_mute_get, \ |
| 685 | .put = spi_mute_put, \ |
Trent Piepho | 18b5d32 | 2007-07-25 18:40:39 +0200 | [diff] [blame] | 686 | .private_value = (reg<<SPI_REG_SHIFT) | (bit) \ |
Trent Piepho | b18cd53 | 2007-07-24 12:06:16 +0200 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | static struct snd_kcontrol_new snd_ca0106_volume_spi_dac_ctls[] |
| 690 | __devinitdata = { |
| 691 | SPI_SWITCH("Analog Front Playback Switch", |
| 692 | SPI_DMUTE4_REG, SPI_DMUTE4_BIT), |
| 693 | SPI_SWITCH("Analog Rear Playback Switch", |
| 694 | SPI_DMUTE0_REG, SPI_DMUTE0_BIT), |
| 695 | SPI_SWITCH("Analog Center/LFE Playback Switch", |
| 696 | SPI_DMUTE2_REG, SPI_DMUTE2_BIT), |
| 697 | SPI_SWITCH("Analog Side Playback Switch", |
| 698 | SPI_DMUTE1_REG, SPI_DMUTE1_BIT), |
| 699 | }; |
| 700 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 701 | static int __devinit remove_ctl(struct snd_card *card, const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 703 | struct snd_ctl_elem_id id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | memset(&id, 0, sizeof(id)); |
| 705 | strcpy(id.name, name); |
| 706 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 707 | return snd_ctl_remove_id(card, &id); |
| 708 | } |
| 709 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 710 | 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] | 711 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 712 | struct snd_ctl_elem_id sid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | memset(&sid, 0, sizeof(sid)); |
| 714 | /* FIXME: strcpy is bad. */ |
| 715 | strcpy(sid.name, name); |
| 716 | sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 717 | return snd_ctl_find_id(card, &sid); |
| 718 | } |
| 719 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 720 | 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] | 721 | { |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 722 | struct snd_kcontrol *kctl = ctl_find(card, src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | if (kctl) { |
| 724 | strcpy(kctl->id.name, dst); |
| 725 | return 0; |
| 726 | } |
| 727 | return -ENOENT; |
| 728 | } |
| 729 | |
Trent Piepho | fca7f38 | 2007-07-24 12:10:34 +0200 | [diff] [blame] | 730 | #define ADD_CTLS(emu, ctls) \ |
| 731 | do { \ |
Harvey Harrison | bed515b | 2008-02-28 12:02:56 +0100 | [diff] [blame] | 732 | int i, _err; \ |
Trent Piepho | fca7f38 | 2007-07-24 12:10:34 +0200 | [diff] [blame] | 733 | for (i = 0; i < ARRAY_SIZE(ctls); i++) { \ |
Harvey Harrison | bed515b | 2008-02-28 12:02:56 +0100 | [diff] [blame] | 734 | _err = snd_ctl_add(card, snd_ctl_new1(&ctls[i], emu)); \ |
| 735 | if (_err < 0) \ |
| 736 | return _err; \ |
Trent Piepho | fca7f38 | 2007-07-24 12:10:34 +0200 | [diff] [blame] | 737 | } \ |
| 738 | } while (0) |
| 739 | |
Takashi Iwai | 49c88b8 | 2008-02-18 13:06:49 +0100 | [diff] [blame] | 740 | static __devinitdata |
Takashi Iwai | c486567 | 2009-06-08 12:57:17 +0200 | [diff] [blame] | 741 | DECLARE_TLV_DB_SCALE(snd_ca0106_master_db_scale, -6375, 25, 1); |
Takashi Iwai | 49c88b8 | 2008-02-18 13:06:49 +0100 | [diff] [blame] | 742 | |
| 743 | static char *slave_vols[] __devinitdata = { |
| 744 | "Analog Front Playback Volume", |
| 745 | "Analog Rear Playback Volume", |
| 746 | "Analog Center/LFE Playback Volume", |
| 747 | "Analog Side Playback Volume", |
| 748 | "IEC958 Front Playback Volume", |
| 749 | "IEC958 Rear Playback Volume", |
| 750 | "IEC958 Center/LFE Playback Volume", |
| 751 | "IEC958 Unknown Playback Volume", |
| 752 | "CAPTURE feedback Playback Volume", |
| 753 | NULL |
| 754 | }; |
| 755 | |
| 756 | static char *slave_sws[] __devinitdata = { |
| 757 | "Analog Front Playback Switch", |
| 758 | "Analog Rear Playback Switch", |
| 759 | "Analog Center/LFE Playback Switch", |
| 760 | "Analog Side Playback Switch", |
| 761 | "IEC958 Playback Switch", |
| 762 | NULL |
| 763 | }; |
| 764 | |
| 765 | static void __devinit add_slaves(struct snd_card *card, |
| 766 | struct snd_kcontrol *master, char **list) |
| 767 | { |
| 768 | for (; *list; list++) { |
| 769 | struct snd_kcontrol *slave = ctl_find(card, *list); |
| 770 | if (slave) |
| 771 | snd_ctl_add_slave(master, slave); |
| 772 | } |
| 773 | } |
| 774 | |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 775 | int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
Trent Piepho | fca7f38 | 2007-07-24 12:10:34 +0200 | [diff] [blame] | 777 | int err; |
Takashi Iwai | e4a3d14 | 2005-11-17 14:55:40 +0100 | [diff] [blame] | 778 | struct snd_card *card = emu->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | char **c; |
Takashi Iwai | 49c88b8 | 2008-02-18 13:06:49 +0100 | [diff] [blame] | 780 | struct snd_kcontrol *vmaster; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | static char *ca0106_remove_ctls[] = { |
| 782 | "Master Mono Playback Switch", |
| 783 | "Master Mono Playback Volume", |
| 784 | "3D Control - Switch", |
| 785 | "3D Control Sigmatel - Depth", |
| 786 | "PCM Playback Switch", |
| 787 | "PCM Playback Volume", |
| 788 | "CD Playback Switch", |
| 789 | "CD Playback Volume", |
| 790 | "Phone Playback Switch", |
| 791 | "Phone Playback Volume", |
| 792 | "Video Playback Switch", |
| 793 | "Video Playback Volume", |
Jaroslav Kysela | d355c82a | 2009-11-03 15:47:25 +0100 | [diff] [blame] | 794 | "Beep Playback Switch", |
| 795 | "Beep Playback Volume", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | "Mono Output Select", |
| 797 | "Capture Source", |
| 798 | "Capture Switch", |
| 799 | "Capture Volume", |
| 800 | "External Amplifier", |
| 801 | "Sigmatel 4-Speaker Stereo Playback Switch", |
Andreas Mohr | afe6d7e | 2009-05-22 17:48:58 +0200 | [diff] [blame] | 802 | "Surround Phase Inversion Playback Switch", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | NULL |
| 804 | }; |
| 805 | static char *ca0106_rename_ctls[] = { |
| 806 | "Master Playback Switch", "Capture Switch", |
| 807 | "Master Playback Volume", "Capture Volume", |
| 808 | "Line Playback Switch", "AC97 Line Capture Switch", |
| 809 | "Line Playback Volume", "AC97 Line Capture Volume", |
| 810 | "Aux Playback Switch", "AC97 Aux Capture Switch", |
| 811 | "Aux Playback Volume", "AC97 Aux Capture Volume", |
| 812 | "Mic Playback Switch", "AC97 Mic Capture Switch", |
| 813 | "Mic Playback Volume", "AC97 Mic Capture Volume", |
| 814 | "Mic Select", "AC97 Mic Select", |
| 815 | "Mic Boost (+20dB)", "AC97 Mic Boost (+20dB)", |
| 816 | NULL |
| 817 | }; |
| 818 | #if 1 |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 819 | for (c = ca0106_remove_ctls; *c; c++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | remove_ctl(card, *c); |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 821 | for (c = ca0106_rename_ctls; *c; c += 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | rename_ctl(card, c[0], c[1]); |
| 823 | #endif |
| 824 | |
Trent Piepho | fca7f38 | 2007-07-24 12:10:34 +0200 | [diff] [blame] | 825 | ADD_CTLS(emu, snd_ca0106_volume_ctls); |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 826 | if (emu->details->i2c_adc == 1) { |
Trent Piepho | fca7f38 | 2007-07-24 12:10:34 +0200 | [diff] [blame] | 827 | ADD_CTLS(emu, snd_ca0106_volume_i2c_adc_ctls); |
James Courtier-Dutton | be0b7b0 | 2006-04-09 20:48:44 +0100 | [diff] [blame] | 828 | if (emu->details->gpio_type == 1) |
| 829 | err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_mic_line_in, emu)); |
| 830 | else /* gpio_type == 2 */ |
| 831 | err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_line_in_side_out, emu)); |
Takashi Iwai | 95a9826 | 2005-11-17 10:40:18 +0100 | [diff] [blame] | 832 | if (err < 0) |
| 833 | return err; |
| 834 | } |
Trent Piepho | fca7f38 | 2007-07-24 12:10:34 +0200 | [diff] [blame] | 835 | if (emu->details->spi_dac == 1) |
| 836 | ADD_CTLS(emu, snd_ca0106_volume_spi_dac_ctls); |
Takashi Iwai | 49c88b8 | 2008-02-18 13:06:49 +0100 | [diff] [blame] | 837 | |
| 838 | /* Create virtual master controls */ |
| 839 | vmaster = snd_ctl_make_virtual_master("Master Playback Volume", |
| 840 | snd_ca0106_master_db_scale); |
| 841 | if (!vmaster) |
| 842 | return -ENOMEM; |
Takashi Iwai | 601e1cc | 2009-06-02 11:37:01 +0200 | [diff] [blame] | 843 | err = snd_ctl_add(card, vmaster); |
| 844 | if (err < 0) |
| 845 | return err; |
Takashi Iwai | 49c88b8 | 2008-02-18 13:06:49 +0100 | [diff] [blame] | 846 | add_slaves(card, vmaster, slave_vols); |
| 847 | |
| 848 | if (emu->details->spi_dac == 1) { |
| 849 | vmaster = snd_ctl_make_virtual_master("Master Playback Switch", |
| 850 | NULL); |
| 851 | if (!vmaster) |
| 852 | return -ENOMEM; |
Takashi Iwai | 601e1cc | 2009-06-02 11:37:01 +0200 | [diff] [blame] | 853 | err = snd_ctl_add(card, vmaster); |
| 854 | if (err < 0) |
| 855 | return err; |
Takashi Iwai | 49c88b8 | 2008-02-18 13:06:49 +0100 | [diff] [blame] | 856 | add_slaves(card, vmaster, slave_sws); |
| 857 | } |
Takashi Iwai | eeaf100 | 2009-06-02 16:06:02 +0200 | [diff] [blame] | 858 | |
| 859 | strcpy(card->mixername, "CA0106"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | return 0; |
| 861 | } |
| 862 | |
Takashi Iwai | 5da9527 | 2008-11-24 14:06:08 +0100 | [diff] [blame] | 863 | #ifdef CONFIG_PM |
| 864 | struct ca0106_vol_tbl { |
Takashi Iwai | 5da9527 | 2008-11-24 14:06:08 +0100 | [diff] [blame] | 865 | unsigned int channel_id; |
Takashi Iwai | 8df0f70 | 2008-12-19 13:55:17 +0100 | [diff] [blame] | 866 | unsigned int reg; |
Takashi Iwai | 5da9527 | 2008-11-24 14:06:08 +0100 | [diff] [blame] | 867 | }; |
| 868 | |
| 869 | static struct ca0106_vol_tbl saved_volumes[NUM_SAVED_VOLUMES] = { |
| 870 | { CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME2 }, |
| 871 | { CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME2 }, |
| 872 | { CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME2 }, |
| 873 | { CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME2 }, |
| 874 | { CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME1 }, |
| 875 | { CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME1 }, |
| 876 | { CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME1 }, |
| 877 | { CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME1 }, |
| 878 | { 1, CAPTURE_CONTROL }, |
| 879 | }; |
| 880 | |
| 881 | void snd_ca0106_mixer_suspend(struct snd_ca0106 *chip) |
| 882 | { |
| 883 | int i; |
| 884 | |
| 885 | /* save volumes */ |
| 886 | for (i = 0; i < NUM_SAVED_VOLUMES; i++) |
| 887 | chip->saved_vol[i] = |
| 888 | snd_ca0106_ptr_read(chip, saved_volumes[i].reg, |
| 889 | saved_volumes[i].channel_id); |
| 890 | } |
| 891 | |
| 892 | void snd_ca0106_mixer_resume(struct snd_ca0106 *chip) |
| 893 | { |
| 894 | int i; |
| 895 | |
| 896 | for (i = 0; i < NUM_SAVED_VOLUMES; i++) |
| 897 | snd_ca0106_ptr_write(chip, saved_volumes[i].reg, |
| 898 | saved_volumes[i].channel_id, |
| 899 | chip->saved_vol[i]); |
| 900 | |
| 901 | ca0106_spdif_enable(chip); |
| 902 | ca0106_set_capture_source(chip); |
| 903 | ca0106_set_i2c_capture_source(chip, chip->i2c_capture_source, 1); |
| 904 | for (i = 0; i < 4; i++) |
| 905 | ca0106_set_spdif_bits(chip, i); |
| 906 | if (chip->details->i2c_adc) |
| 907 | ca0106_set_capture_mic_line_in(chip); |
| 908 | } |
| 909 | #endif /* CONFIG_PM */ |