Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 2 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Routines for Sound Blaster mixer control |
| 4 | * |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | */ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/io.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/time.h> |
| 25 | #include <sound/core.h> |
| 26 | #include <sound/sb.h> |
| 27 | #include <sound/control.h> |
| 28 | |
| 29 | #undef IO_DEBUG |
| 30 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 31 | void snd_sbmixer_write(struct snd_sb *chip, unsigned char reg, unsigned char data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { |
| 33 | outb(reg, SBP(chip, MIXER_ADDR)); |
| 34 | udelay(10); |
| 35 | outb(data, SBP(chip, MIXER_DATA)); |
| 36 | udelay(10); |
| 37 | #ifdef IO_DEBUG |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 38 | snd_printk(KERN_DEBUG "mixer_write 0x%x 0x%x\n", reg, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #endif |
| 40 | } |
| 41 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 42 | unsigned char snd_sbmixer_read(struct snd_sb *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
| 44 | unsigned char result; |
| 45 | |
| 46 | outb(reg, SBP(chip, MIXER_ADDR)); |
| 47 | udelay(10); |
| 48 | result = inb(SBP(chip, MIXER_DATA)); |
| 49 | udelay(10); |
| 50 | #ifdef IO_DEBUG |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 51 | snd_printk(KERN_DEBUG "mixer_read 0x%x 0x%x\n", reg, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #endif |
| 53 | return result; |
| 54 | } |
| 55 | |
| 56 | /* |
| 57 | * Single channel mixer element |
| 58 | */ |
| 59 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 60 | static int snd_sbmixer_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
| 62 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 63 | |
| 64 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 65 | uinfo->count = 1; |
| 66 | uinfo->value.integer.min = 0; |
| 67 | uinfo->value.integer.max = mask; |
| 68 | return 0; |
| 69 | } |
| 70 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 71 | static int snd_sbmixer_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 73 | struct snd_sb *sb = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | unsigned long flags; |
| 75 | int reg = kcontrol->private_value & 0xff; |
| 76 | int shift = (kcontrol->private_value >> 16) & 0xff; |
| 77 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 78 | unsigned char val; |
| 79 | |
| 80 | spin_lock_irqsave(&sb->mixer_lock, flags); |
| 81 | val = (snd_sbmixer_read(sb, reg) >> shift) & mask; |
| 82 | spin_unlock_irqrestore(&sb->mixer_lock, flags); |
| 83 | ucontrol->value.integer.value[0] = val; |
| 84 | return 0; |
| 85 | } |
| 86 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 87 | static int snd_sbmixer_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 89 | struct snd_sb *sb = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | unsigned long flags; |
| 91 | int reg = kcontrol->private_value & 0xff; |
| 92 | int shift = (kcontrol->private_value >> 16) & 0x07; |
| 93 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 94 | int change; |
| 95 | unsigned char val, oval; |
| 96 | |
| 97 | val = (ucontrol->value.integer.value[0] & mask) << shift; |
| 98 | spin_lock_irqsave(&sb->mixer_lock, flags); |
| 99 | oval = snd_sbmixer_read(sb, reg); |
| 100 | val = (oval & ~(mask << shift)) | val; |
| 101 | change = val != oval; |
| 102 | if (change) |
| 103 | snd_sbmixer_write(sb, reg, val); |
| 104 | spin_unlock_irqrestore(&sb->mixer_lock, flags); |
| 105 | return change; |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | * Double channel mixer element |
| 110 | */ |
| 111 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 112 | static int snd_sbmixer_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { |
| 114 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 115 | |
| 116 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 117 | uinfo->count = 2; |
| 118 | uinfo->value.integer.min = 0; |
| 119 | uinfo->value.integer.max = mask; |
| 120 | return 0; |
| 121 | } |
| 122 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 123 | static int snd_sbmixer_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 125 | struct snd_sb *sb = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | unsigned long flags; |
| 127 | int left_reg = kcontrol->private_value & 0xff; |
| 128 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 129 | int left_shift = (kcontrol->private_value >> 16) & 0x07; |
| 130 | int right_shift = (kcontrol->private_value >> 19) & 0x07; |
| 131 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 132 | unsigned char left, right; |
| 133 | |
| 134 | spin_lock_irqsave(&sb->mixer_lock, flags); |
| 135 | left = (snd_sbmixer_read(sb, left_reg) >> left_shift) & mask; |
| 136 | right = (snd_sbmixer_read(sb, right_reg) >> right_shift) & mask; |
| 137 | spin_unlock_irqrestore(&sb->mixer_lock, flags); |
| 138 | ucontrol->value.integer.value[0] = left; |
| 139 | ucontrol->value.integer.value[1] = right; |
| 140 | return 0; |
| 141 | } |
| 142 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 143 | static int snd_sbmixer_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 145 | struct snd_sb *sb = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | unsigned long flags; |
| 147 | int left_reg = kcontrol->private_value & 0xff; |
| 148 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 149 | int left_shift = (kcontrol->private_value >> 16) & 0x07; |
| 150 | int right_shift = (kcontrol->private_value >> 19) & 0x07; |
| 151 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 152 | int change; |
| 153 | unsigned char left, right, oleft, oright; |
| 154 | |
| 155 | left = (ucontrol->value.integer.value[0] & mask) << left_shift; |
| 156 | right = (ucontrol->value.integer.value[1] & mask) << right_shift; |
| 157 | spin_lock_irqsave(&sb->mixer_lock, flags); |
| 158 | if (left_reg == right_reg) { |
| 159 | oleft = snd_sbmixer_read(sb, left_reg); |
| 160 | left = (oleft & ~((mask << left_shift) | (mask << right_shift))) | left | right; |
| 161 | change = left != oleft; |
| 162 | if (change) |
| 163 | snd_sbmixer_write(sb, left_reg, left); |
| 164 | } else { |
| 165 | oleft = snd_sbmixer_read(sb, left_reg); |
| 166 | oright = snd_sbmixer_read(sb, right_reg); |
| 167 | left = (oleft & ~(mask << left_shift)) | left; |
| 168 | right = (oright & ~(mask << right_shift)) | right; |
| 169 | change = left != oleft || right != oright; |
| 170 | if (change) { |
| 171 | snd_sbmixer_write(sb, left_reg, left); |
| 172 | snd_sbmixer_write(sb, right_reg, right); |
| 173 | } |
| 174 | } |
| 175 | spin_unlock_irqrestore(&sb->mixer_lock, flags); |
| 176 | return change; |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * DT-019x / ALS-007 capture/input switch |
| 181 | */ |
| 182 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 183 | static int snd_dt019x_input_sw_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
| 185 | static char *texts[5] = { |
| 186 | "CD", "Mic", "Line", "Synth", "Master" |
| 187 | }; |
| 188 | |
| 189 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 190 | uinfo->count = 1; |
| 191 | uinfo->value.enumerated.items = 5; |
| 192 | if (uinfo->value.enumerated.item > 4) |
| 193 | uinfo->value.enumerated.item = 4; |
| 194 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 195 | return 0; |
| 196 | } |
| 197 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 198 | static int snd_dt019x_input_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 200 | struct snd_sb *sb = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | unsigned long flags; |
| 202 | unsigned char oval; |
| 203 | |
| 204 | spin_lock_irqsave(&sb->mixer_lock, flags); |
| 205 | oval = snd_sbmixer_read(sb, SB_DT019X_CAPTURE_SW); |
| 206 | spin_unlock_irqrestore(&sb->mixer_lock, flags); |
| 207 | switch (oval & 0x07) { |
| 208 | case SB_DT019X_CAP_CD: |
| 209 | ucontrol->value.enumerated.item[0] = 0; |
| 210 | break; |
| 211 | case SB_DT019X_CAP_MIC: |
| 212 | ucontrol->value.enumerated.item[0] = 1; |
| 213 | break; |
| 214 | case SB_DT019X_CAP_LINE: |
| 215 | ucontrol->value.enumerated.item[0] = 2; |
| 216 | break; |
| 217 | case SB_DT019X_CAP_MAIN: |
| 218 | ucontrol->value.enumerated.item[0] = 4; |
| 219 | break; |
| 220 | /* To record the synth on these cards you must record the main. */ |
| 221 | /* Thus SB_DT019X_CAP_SYNTH == SB_DT019X_CAP_MAIN and would cause */ |
| 222 | /* duplicate case labels if left uncommented. */ |
| 223 | /* case SB_DT019X_CAP_SYNTH: |
| 224 | * ucontrol->value.enumerated.item[0] = 3; |
| 225 | * break; |
| 226 | */ |
| 227 | default: |
| 228 | ucontrol->value.enumerated.item[0] = 4; |
| 229 | break; |
| 230 | } |
| 231 | return 0; |
| 232 | } |
| 233 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 234 | static int snd_dt019x_input_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 236 | struct snd_sb *sb = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | unsigned long flags; |
| 238 | int change; |
| 239 | unsigned char nval, oval; |
| 240 | |
| 241 | if (ucontrol->value.enumerated.item[0] > 4) |
| 242 | return -EINVAL; |
| 243 | switch (ucontrol->value.enumerated.item[0]) { |
| 244 | case 0: |
| 245 | nval = SB_DT019X_CAP_CD; |
| 246 | break; |
| 247 | case 1: |
| 248 | nval = SB_DT019X_CAP_MIC; |
| 249 | break; |
| 250 | case 2: |
| 251 | nval = SB_DT019X_CAP_LINE; |
| 252 | break; |
| 253 | case 3: |
| 254 | nval = SB_DT019X_CAP_SYNTH; |
| 255 | break; |
| 256 | case 4: |
| 257 | nval = SB_DT019X_CAP_MAIN; |
| 258 | break; |
| 259 | default: |
| 260 | nval = SB_DT019X_CAP_MAIN; |
| 261 | } |
| 262 | spin_lock_irqsave(&sb->mixer_lock, flags); |
| 263 | oval = snd_sbmixer_read(sb, SB_DT019X_CAPTURE_SW); |
| 264 | change = nval != oval; |
| 265 | if (change) |
| 266 | snd_sbmixer_write(sb, SB_DT019X_CAPTURE_SW, nval); |
| 267 | spin_unlock_irqrestore(&sb->mixer_lock, flags); |
| 268 | return change; |
| 269 | } |
| 270 | |
| 271 | /* |
| 272 | * SBPRO input multiplexer |
| 273 | */ |
| 274 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 275 | static int snd_sb8mixer_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | { |
| 277 | static char *texts[3] = { |
| 278 | "Mic", "CD", "Line" |
| 279 | }; |
| 280 | |
| 281 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 282 | uinfo->count = 1; |
| 283 | uinfo->value.enumerated.items = 3; |
| 284 | if (uinfo->value.enumerated.item > 2) |
| 285 | uinfo->value.enumerated.item = 2; |
| 286 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 291 | static int snd_sb8mixer_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 293 | struct snd_sb *sb = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | unsigned long flags; |
| 295 | unsigned char oval; |
| 296 | |
| 297 | spin_lock_irqsave(&sb->mixer_lock, flags); |
| 298 | oval = snd_sbmixer_read(sb, SB_DSP_CAPTURE_SOURCE); |
| 299 | spin_unlock_irqrestore(&sb->mixer_lock, flags); |
| 300 | switch ((oval >> 0x01) & 0x03) { |
| 301 | case SB_DSP_MIXS_CD: |
| 302 | ucontrol->value.enumerated.item[0] = 1; |
| 303 | break; |
| 304 | case SB_DSP_MIXS_LINE: |
| 305 | ucontrol->value.enumerated.item[0] = 2; |
| 306 | break; |
| 307 | default: |
| 308 | ucontrol->value.enumerated.item[0] = 0; |
| 309 | break; |
| 310 | } |
| 311 | return 0; |
| 312 | } |
| 313 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 314 | static int snd_sb8mixer_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | { |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 316 | struct snd_sb *sb = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | unsigned long flags; |
| 318 | int change; |
| 319 | unsigned char nval, oval; |
| 320 | |
| 321 | if (ucontrol->value.enumerated.item[0] > 2) |
| 322 | return -EINVAL; |
| 323 | switch (ucontrol->value.enumerated.item[0]) { |
| 324 | case 1: |
| 325 | nval = SB_DSP_MIXS_CD; |
| 326 | break; |
| 327 | case 2: |
| 328 | nval = SB_DSP_MIXS_LINE; |
| 329 | break; |
| 330 | default: |
| 331 | nval = SB_DSP_MIXS_MIC; |
| 332 | } |
| 333 | nval <<= 1; |
| 334 | spin_lock_irqsave(&sb->mixer_lock, flags); |
| 335 | oval = snd_sbmixer_read(sb, SB_DSP_CAPTURE_SOURCE); |
| 336 | nval |= oval & ~0x06; |
| 337 | change = nval != oval; |
| 338 | if (change) |
| 339 | snd_sbmixer_write(sb, SB_DSP_CAPTURE_SOURCE, nval); |
| 340 | spin_unlock_irqrestore(&sb->mixer_lock, flags); |
| 341 | return change; |
| 342 | } |
| 343 | |
| 344 | /* |
| 345 | * SB16 input switch |
| 346 | */ |
| 347 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 348 | static int snd_sb16mixer_info_input_sw(struct snd_kcontrol *kcontrol, 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_BOOLEAN; |
| 351 | uinfo->count = 4; |
| 352 | uinfo->value.integer.min = 0; |
| 353 | uinfo->value.integer.max = 1; |
| 354 | return 0; |
| 355 | } |
| 356 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 357 | static int snd_sb16mixer_get_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | { |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 359 | struct snd_sb *sb = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | unsigned long flags; |
| 361 | int reg1 = kcontrol->private_value & 0xff; |
| 362 | int reg2 = (kcontrol->private_value >> 8) & 0xff; |
| 363 | int left_shift = (kcontrol->private_value >> 16) & 0x0f; |
| 364 | int right_shift = (kcontrol->private_value >> 24) & 0x0f; |
| 365 | unsigned char val1, val2; |
| 366 | |
| 367 | spin_lock_irqsave(&sb->mixer_lock, flags); |
| 368 | val1 = snd_sbmixer_read(sb, reg1); |
| 369 | val2 = snd_sbmixer_read(sb, reg2); |
| 370 | spin_unlock_irqrestore(&sb->mixer_lock, flags); |
| 371 | ucontrol->value.integer.value[0] = (val1 >> left_shift) & 0x01; |
| 372 | ucontrol->value.integer.value[1] = (val2 >> left_shift) & 0x01; |
| 373 | ucontrol->value.integer.value[2] = (val1 >> right_shift) & 0x01; |
| 374 | ucontrol->value.integer.value[3] = (val2 >> right_shift) & 0x01; |
| 375 | return 0; |
| 376 | } |
| 377 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 378 | static int snd_sb16mixer_put_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 380 | struct snd_sb *sb = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | unsigned long flags; |
| 382 | int reg1 = kcontrol->private_value & 0xff; |
| 383 | int reg2 = (kcontrol->private_value >> 8) & 0xff; |
| 384 | int left_shift = (kcontrol->private_value >> 16) & 0x0f; |
| 385 | int right_shift = (kcontrol->private_value >> 24) & 0x0f; |
| 386 | int change; |
| 387 | unsigned char val1, val2, oval1, oval2; |
| 388 | |
| 389 | spin_lock_irqsave(&sb->mixer_lock, flags); |
| 390 | oval1 = snd_sbmixer_read(sb, reg1); |
| 391 | oval2 = snd_sbmixer_read(sb, reg2); |
| 392 | val1 = oval1 & ~((1 << left_shift) | (1 << right_shift)); |
| 393 | val2 = oval2 & ~((1 << left_shift) | (1 << right_shift)); |
| 394 | val1 |= (ucontrol->value.integer.value[0] & 1) << left_shift; |
| 395 | val2 |= (ucontrol->value.integer.value[1] & 1) << left_shift; |
| 396 | val1 |= (ucontrol->value.integer.value[2] & 1) << right_shift; |
| 397 | val2 |= (ucontrol->value.integer.value[3] & 1) << right_shift; |
| 398 | change = val1 != oval1 || val2 != oval2; |
| 399 | if (change) { |
| 400 | snd_sbmixer_write(sb, reg1, val1); |
| 401 | snd_sbmixer_write(sb, reg2, val2); |
| 402 | } |
| 403 | spin_unlock_irqrestore(&sb->mixer_lock, flags); |
| 404 | return change; |
| 405 | } |
| 406 | |
| 407 | |
| 408 | /* |
| 409 | */ |
| 410 | /* |
| 411 | */ |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 412 | int snd_sbmixer_add_ctl(struct snd_sb *chip, const char *name, int index, int type, unsigned long value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | { |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 414 | static struct snd_kcontrol_new newctls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | [SB_MIX_SINGLE] = { |
| 416 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 417 | .info = snd_sbmixer_info_single, |
| 418 | .get = snd_sbmixer_get_single, |
| 419 | .put = snd_sbmixer_put_single, |
| 420 | }, |
| 421 | [SB_MIX_DOUBLE] = { |
| 422 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 423 | .info = snd_sbmixer_info_double, |
| 424 | .get = snd_sbmixer_get_double, |
| 425 | .put = snd_sbmixer_put_double, |
| 426 | }, |
| 427 | [SB_MIX_INPUT_SW] = { |
| 428 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 429 | .info = snd_sb16mixer_info_input_sw, |
| 430 | .get = snd_sb16mixer_get_input_sw, |
| 431 | .put = snd_sb16mixer_put_input_sw, |
| 432 | }, |
| 433 | [SB_MIX_CAPTURE_PRO] = { |
| 434 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 435 | .info = snd_sb8mixer_info_mux, |
| 436 | .get = snd_sb8mixer_get_mux, |
| 437 | .put = snd_sb8mixer_put_mux, |
| 438 | }, |
| 439 | [SB_MIX_CAPTURE_DT019X] = { |
| 440 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 441 | .info = snd_dt019x_input_sw_info, |
| 442 | .get = snd_dt019x_input_sw_get, |
| 443 | .put = snd_dt019x_input_sw_put, |
| 444 | }, |
| 445 | }; |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 446 | struct snd_kcontrol *ctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | int err; |
| 448 | |
| 449 | ctl = snd_ctl_new1(&newctls[type], chip); |
| 450 | if (! ctl) |
| 451 | return -ENOMEM; |
| 452 | strlcpy(ctl->id.name, name, sizeof(ctl->id.name)); |
| 453 | ctl->id.index = index; |
| 454 | ctl->private_value = value; |
Dave Jones | bcc54f9 | 2006-03-06 13:28:34 +0100 | [diff] [blame] | 455 | if ((err = snd_ctl_add(chip->card, ctl)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | /* |
| 461 | * SB 2.0 specific mixer elements |
| 462 | */ |
| 463 | |
| 464 | static struct sbmix_elem snd_sb20_ctl_master_play_vol = |
| 465 | SB_SINGLE("Master Playback Volume", SB_DSP20_MASTER_DEV, 1, 7); |
| 466 | static struct sbmix_elem snd_sb20_ctl_pcm_play_vol = |
| 467 | SB_SINGLE("PCM Playback Volume", SB_DSP20_PCM_DEV, 1, 3); |
| 468 | static struct sbmix_elem snd_sb20_ctl_synth_play_vol = |
| 469 | SB_SINGLE("Synth Playback Volume", SB_DSP20_FM_DEV, 1, 7); |
| 470 | static struct sbmix_elem snd_sb20_ctl_cd_play_vol = |
| 471 | SB_SINGLE("CD Playback Volume", SB_DSP20_CD_DEV, 1, 7); |
| 472 | |
| 473 | static struct sbmix_elem *snd_sb20_controls[] = { |
| 474 | &snd_sb20_ctl_master_play_vol, |
| 475 | &snd_sb20_ctl_pcm_play_vol, |
| 476 | &snd_sb20_ctl_synth_play_vol, |
| 477 | &snd_sb20_ctl_cd_play_vol |
| 478 | }; |
| 479 | |
| 480 | static unsigned char snd_sb20_init_values[][2] = { |
| 481 | { SB_DSP20_MASTER_DEV, 0 }, |
| 482 | { SB_DSP20_FM_DEV, 0 }, |
| 483 | }; |
| 484 | |
| 485 | /* |
| 486 | * SB Pro specific mixer elements |
| 487 | */ |
| 488 | static struct sbmix_elem snd_sbpro_ctl_master_play_vol = |
| 489 | SB_DOUBLE("Master Playback Volume", SB_DSP_MASTER_DEV, SB_DSP_MASTER_DEV, 5, 1, 7); |
| 490 | static struct sbmix_elem snd_sbpro_ctl_pcm_play_vol = |
| 491 | SB_DOUBLE("PCM Playback Volume", SB_DSP_PCM_DEV, SB_DSP_PCM_DEV, 5, 1, 7); |
| 492 | static struct sbmix_elem snd_sbpro_ctl_pcm_play_filter = |
| 493 | SB_SINGLE("PCM Playback Filter", SB_DSP_PLAYBACK_FILT, 5, 1); |
| 494 | static struct sbmix_elem snd_sbpro_ctl_synth_play_vol = |
| 495 | SB_DOUBLE("Synth Playback Volume", SB_DSP_FM_DEV, SB_DSP_FM_DEV, 5, 1, 7); |
| 496 | static struct sbmix_elem snd_sbpro_ctl_cd_play_vol = |
| 497 | SB_DOUBLE("CD Playback Volume", SB_DSP_CD_DEV, SB_DSP_CD_DEV, 5, 1, 7); |
| 498 | static struct sbmix_elem snd_sbpro_ctl_line_play_vol = |
| 499 | SB_DOUBLE("Line Playback Volume", SB_DSP_LINE_DEV, SB_DSP_LINE_DEV, 5, 1, 7); |
| 500 | static struct sbmix_elem snd_sbpro_ctl_mic_play_vol = |
| 501 | SB_SINGLE("Mic Playback Volume", SB_DSP_MIC_DEV, 1, 3); |
| 502 | static struct sbmix_elem snd_sbpro_ctl_capture_source = |
| 503 | { |
| 504 | .name = "Capture Source", |
| 505 | .type = SB_MIX_CAPTURE_PRO |
| 506 | }; |
| 507 | static struct sbmix_elem snd_sbpro_ctl_capture_filter = |
| 508 | SB_SINGLE("Capture Filter", SB_DSP_CAPTURE_FILT, 5, 1); |
| 509 | static struct sbmix_elem snd_sbpro_ctl_capture_low_filter = |
| 510 | SB_SINGLE("Capture Low-Pass Filter", SB_DSP_CAPTURE_FILT, 3, 1); |
| 511 | |
| 512 | static struct sbmix_elem *snd_sbpro_controls[] = { |
| 513 | &snd_sbpro_ctl_master_play_vol, |
| 514 | &snd_sbpro_ctl_pcm_play_vol, |
| 515 | &snd_sbpro_ctl_pcm_play_filter, |
| 516 | &snd_sbpro_ctl_synth_play_vol, |
| 517 | &snd_sbpro_ctl_cd_play_vol, |
| 518 | &snd_sbpro_ctl_line_play_vol, |
| 519 | &snd_sbpro_ctl_mic_play_vol, |
| 520 | &snd_sbpro_ctl_capture_source, |
| 521 | &snd_sbpro_ctl_capture_filter, |
| 522 | &snd_sbpro_ctl_capture_low_filter |
| 523 | }; |
| 524 | |
| 525 | static unsigned char snd_sbpro_init_values[][2] = { |
| 526 | { SB_DSP_MASTER_DEV, 0 }, |
| 527 | { SB_DSP_PCM_DEV, 0 }, |
| 528 | { SB_DSP_FM_DEV, 0 }, |
| 529 | }; |
| 530 | |
| 531 | /* |
| 532 | * SB16 specific mixer elements |
| 533 | */ |
| 534 | static struct sbmix_elem snd_sb16_ctl_master_play_vol = |
| 535 | SB_DOUBLE("Master Playback Volume", SB_DSP4_MASTER_DEV, (SB_DSP4_MASTER_DEV + 1), 3, 3, 31); |
| 536 | static struct sbmix_elem snd_sb16_ctl_3d_enhance_switch = |
| 537 | SB_SINGLE("3D Enhancement Switch", SB_DSP4_3DSE, 0, 1); |
| 538 | static struct sbmix_elem snd_sb16_ctl_tone_bass = |
| 539 | SB_DOUBLE("Tone Control - Bass", SB_DSP4_BASS_DEV, (SB_DSP4_BASS_DEV + 1), 4, 4, 15); |
| 540 | static struct sbmix_elem snd_sb16_ctl_tone_treble = |
| 541 | SB_DOUBLE("Tone Control - Treble", SB_DSP4_TREBLE_DEV, (SB_DSP4_TREBLE_DEV + 1), 4, 4, 15); |
| 542 | static struct sbmix_elem snd_sb16_ctl_pcm_play_vol = |
| 543 | SB_DOUBLE("PCM Playback Volume", SB_DSP4_PCM_DEV, (SB_DSP4_PCM_DEV + 1), 3, 3, 31); |
| 544 | static struct sbmix_elem snd_sb16_ctl_synth_capture_route = |
| 545 | SB16_INPUT_SW("Synth Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 6, 5); |
| 546 | static struct sbmix_elem snd_sb16_ctl_synth_play_vol = |
| 547 | SB_DOUBLE("Synth Playback Volume", SB_DSP4_SYNTH_DEV, (SB_DSP4_SYNTH_DEV + 1), 3, 3, 31); |
| 548 | static struct sbmix_elem snd_sb16_ctl_cd_capture_route = |
| 549 | SB16_INPUT_SW("CD Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 2, 1); |
| 550 | static struct sbmix_elem snd_sb16_ctl_cd_play_switch = |
| 551 | SB_DOUBLE("CD Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1); |
| 552 | static struct sbmix_elem snd_sb16_ctl_cd_play_vol = |
| 553 | SB_DOUBLE("CD Playback Volume", SB_DSP4_CD_DEV, (SB_DSP4_CD_DEV + 1), 3, 3, 31); |
| 554 | static struct sbmix_elem snd_sb16_ctl_line_capture_route = |
| 555 | SB16_INPUT_SW("Line Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 4, 3); |
| 556 | static struct sbmix_elem snd_sb16_ctl_line_play_switch = |
| 557 | SB_DOUBLE("Line Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1); |
| 558 | static struct sbmix_elem snd_sb16_ctl_line_play_vol = |
| 559 | SB_DOUBLE("Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31); |
| 560 | static struct sbmix_elem snd_sb16_ctl_mic_capture_route = |
| 561 | SB16_INPUT_SW("Mic Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0); |
| 562 | static struct sbmix_elem snd_sb16_ctl_mic_play_switch = |
| 563 | SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1); |
| 564 | static struct sbmix_elem snd_sb16_ctl_mic_play_vol = |
| 565 | SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31); |
| 566 | static struct sbmix_elem snd_sb16_ctl_pc_speaker_vol = |
| 567 | SB_SINGLE("PC Speaker Volume", SB_DSP4_SPEAKER_DEV, 6, 3); |
| 568 | static struct sbmix_elem snd_sb16_ctl_capture_vol = |
| 569 | SB_DOUBLE("Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3); |
| 570 | static struct sbmix_elem snd_sb16_ctl_play_vol = |
| 571 | SB_DOUBLE("Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3); |
| 572 | static struct sbmix_elem snd_sb16_ctl_auto_mic_gain = |
| 573 | SB_SINGLE("Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1); |
| 574 | |
| 575 | static struct sbmix_elem *snd_sb16_controls[] = { |
| 576 | &snd_sb16_ctl_master_play_vol, |
| 577 | &snd_sb16_ctl_3d_enhance_switch, |
| 578 | &snd_sb16_ctl_tone_bass, |
| 579 | &snd_sb16_ctl_tone_treble, |
| 580 | &snd_sb16_ctl_pcm_play_vol, |
| 581 | &snd_sb16_ctl_synth_capture_route, |
| 582 | &snd_sb16_ctl_synth_play_vol, |
| 583 | &snd_sb16_ctl_cd_capture_route, |
| 584 | &snd_sb16_ctl_cd_play_switch, |
| 585 | &snd_sb16_ctl_cd_play_vol, |
| 586 | &snd_sb16_ctl_line_capture_route, |
| 587 | &snd_sb16_ctl_line_play_switch, |
| 588 | &snd_sb16_ctl_line_play_vol, |
| 589 | &snd_sb16_ctl_mic_capture_route, |
| 590 | &snd_sb16_ctl_mic_play_switch, |
| 591 | &snd_sb16_ctl_mic_play_vol, |
| 592 | &snd_sb16_ctl_pc_speaker_vol, |
| 593 | &snd_sb16_ctl_capture_vol, |
| 594 | &snd_sb16_ctl_play_vol, |
| 595 | &snd_sb16_ctl_auto_mic_gain |
| 596 | }; |
| 597 | |
| 598 | static unsigned char snd_sb16_init_values[][2] = { |
| 599 | { SB_DSP4_MASTER_DEV + 0, 0 }, |
| 600 | { SB_DSP4_MASTER_DEV + 1, 0 }, |
| 601 | { SB_DSP4_PCM_DEV + 0, 0 }, |
| 602 | { SB_DSP4_PCM_DEV + 1, 0 }, |
| 603 | { SB_DSP4_SYNTH_DEV + 0, 0 }, |
| 604 | { SB_DSP4_SYNTH_DEV + 1, 0 }, |
| 605 | { SB_DSP4_INPUT_LEFT, 0 }, |
| 606 | { SB_DSP4_INPUT_RIGHT, 0 }, |
| 607 | { SB_DSP4_OUTPUT_SW, 0 }, |
| 608 | { SB_DSP4_SPEAKER_DEV, 0 }, |
| 609 | }; |
| 610 | |
| 611 | /* |
| 612 | * DT019x specific mixer elements |
| 613 | */ |
| 614 | static struct sbmix_elem snd_dt019x_ctl_master_play_vol = |
| 615 | SB_DOUBLE("Master Playback Volume", SB_DT019X_MASTER_DEV, SB_DT019X_MASTER_DEV, 4,0, 15); |
| 616 | static struct sbmix_elem snd_dt019x_ctl_pcm_play_vol = |
| 617 | SB_DOUBLE("PCM Playback Volume", SB_DT019X_PCM_DEV, SB_DT019X_PCM_DEV, 4,0, 15); |
| 618 | static struct sbmix_elem snd_dt019x_ctl_synth_play_vol = |
| 619 | SB_DOUBLE("Synth Playback Volume", SB_DT019X_SYNTH_DEV, SB_DT019X_SYNTH_DEV, 4,0, 15); |
| 620 | static struct sbmix_elem snd_dt019x_ctl_cd_play_vol = |
| 621 | SB_DOUBLE("CD Playback Volume", SB_DT019X_CD_DEV, SB_DT019X_CD_DEV, 4,0, 15); |
| 622 | static struct sbmix_elem snd_dt019x_ctl_mic_play_vol = |
| 623 | SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7); |
| 624 | static struct sbmix_elem snd_dt019x_ctl_pc_speaker_vol = |
| 625 | SB_SINGLE("PC Speaker Volume", SB_DT019X_SPKR_DEV, 0, 7); |
| 626 | static struct sbmix_elem snd_dt019x_ctl_line_play_vol = |
| 627 | SB_DOUBLE("Line Playback Volume", SB_DT019X_LINE_DEV, SB_DT019X_LINE_DEV, 4,0, 15); |
| 628 | static struct sbmix_elem snd_dt019x_ctl_pcm_play_switch = |
| 629 | SB_DOUBLE("PCM Playback Switch", SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 2,1, 1); |
| 630 | static struct sbmix_elem snd_dt019x_ctl_synth_play_switch = |
| 631 | SB_DOUBLE("Synth Playback Switch", SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 4,3, 1); |
| 632 | static struct sbmix_elem snd_dt019x_ctl_capture_source = |
| 633 | { |
| 634 | .name = "Capture Source", |
| 635 | .type = SB_MIX_CAPTURE_DT019X |
| 636 | }; |
| 637 | |
| 638 | static struct sbmix_elem *snd_dt019x_controls[] = { |
| 639 | &snd_dt019x_ctl_master_play_vol, |
| 640 | &snd_dt019x_ctl_pcm_play_vol, |
| 641 | &snd_dt019x_ctl_synth_play_vol, |
| 642 | &snd_dt019x_ctl_cd_play_vol, |
| 643 | &snd_dt019x_ctl_mic_play_vol, |
| 644 | &snd_dt019x_ctl_pc_speaker_vol, |
| 645 | &snd_dt019x_ctl_line_play_vol, |
| 646 | &snd_sb16_ctl_mic_play_switch, |
| 647 | &snd_sb16_ctl_cd_play_switch, |
| 648 | &snd_sb16_ctl_line_play_switch, |
| 649 | &snd_dt019x_ctl_pcm_play_switch, |
| 650 | &snd_dt019x_ctl_synth_play_switch, |
| 651 | &snd_dt019x_ctl_capture_source |
| 652 | }; |
| 653 | |
| 654 | static unsigned char snd_dt019x_init_values[][2] = { |
| 655 | { SB_DT019X_MASTER_DEV, 0 }, |
| 656 | { SB_DT019X_PCM_DEV, 0 }, |
| 657 | { SB_DT019X_SYNTH_DEV, 0 }, |
| 658 | { SB_DT019X_CD_DEV, 0 }, |
| 659 | { SB_DT019X_MIC_DEV, 0 }, /* Includes PC-speaker in high nibble */ |
| 660 | { SB_DT019X_LINE_DEV, 0 }, |
| 661 | { SB_DSP4_OUTPUT_SW, 0 }, |
| 662 | { SB_DT019X_OUTPUT_SW2, 0 }, |
| 663 | { SB_DT019X_CAPTURE_SW, 0x06 }, |
| 664 | }; |
| 665 | |
| 666 | /* |
| 667 | * ALS4000 specific mixer elements |
| 668 | */ |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 669 | /* FIXME: SB_ALS4000_MONO_IO_CTRL needs output select ctrl! */ |
| 670 | static struct sbmix_elem snd_als4000_ctl_master_mono_playback_switch = |
| 671 | SB_SINGLE("Master Mono Playback Switch", SB_ALS4000_MONO_IO_CTRL, 5, 1); |
| 672 | static struct sbmix_elem snd_als4000_ctl_master_mono_capture_route = |
| 673 | SB_SINGLE("Master Mono Capture Route", SB_ALS4000_MONO_IO_CTRL, 6, 0x03); |
| 674 | /* FIXME: mono playback switch also available on DT019X? */ |
| 675 | static struct sbmix_elem snd_als4000_ctl_mono_playback_switch = |
| 676 | SB_SINGLE("Mono Playback Switch", SB_DT019X_OUTPUT_SW2, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | static struct sbmix_elem snd_als4000_ctl_mic_20db_boost = |
| 678 | SB_SINGLE("Mic Boost (+20dB)", SB_ALS4000_MIC_IN_GAIN, 0, 0x03); |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 679 | static struct sbmix_elem snd_als4000_ctl_mixer_loopback = |
| 680 | SB_SINGLE("Analog Loopback", SB_ALS4000_MIC_IN_GAIN, 7, 0x01); |
| 681 | /* FIXME: functionality of 3D controls might be swapped, I didn't find |
| 682 | * a description of how to identify what is supposed to be what */ |
| 683 | static struct sbmix_elem snd_als4000_3d_control_switch = |
| 684 | SB_SINGLE("3D Control - Switch", SB_ALS4000_3D_SND_FX, 6, 0x01); |
| 685 | static struct sbmix_elem snd_als4000_3d_control_ratio = |
| 686 | SB_SINGLE("3D Control - Level", SB_ALS4000_3D_SND_FX, 0, 0x07); |
| 687 | static struct sbmix_elem snd_als4000_3d_control_freq = |
| 688 | /* FIXME: maybe there's actually some standard 3D ctrl name for it?? */ |
| 689 | SB_SINGLE("3D Control - Freq", SB_ALS4000_3D_SND_FX, 4, 0x03); |
| 690 | static struct sbmix_elem snd_als4000_3d_control_delay = |
| 691 | /* FIXME: ALS4000a.pdf mentions BBD (Bucket Brigade Device) time delay, |
| 692 | * but what ALSA 3D attribute is that actually? "Center", "Depth", |
| 693 | * "Wide" or "Space" or even "Level"? Assuming "Wide" for now... */ |
| 694 | SB_SINGLE("3D Control - Wide", SB_ALS4000_3D_TIME_DELAY, 0, 0x0f); |
| 695 | static struct sbmix_elem snd_als4000_3d_control_poweroff_switch = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | SB_SINGLE("3D PowerOff Switch", SB_ALS4000_3D_TIME_DELAY, 4, 0x01); |
Olaf Hering | 44456d3 | 2005-07-27 11:45:17 -0700 | [diff] [blame] | 697 | #ifdef NOT_AVAILABLE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | static struct sbmix_elem snd_als4000_ctl_fmdac = |
| 699 | SB_SINGLE("FMDAC Switch (Option ?)", SB_ALS4000_FMDAC, 0, 0x01); |
| 700 | static struct sbmix_elem snd_als4000_ctl_qsound = |
| 701 | SB_SINGLE("QSound Mode", SB_ALS4000_QSOUND, 1, 0x1f); |
| 702 | #endif |
| 703 | |
| 704 | static struct sbmix_elem *snd_als4000_controls[] = { |
| 705 | &snd_sb16_ctl_master_play_vol, |
| 706 | &snd_dt019x_ctl_pcm_play_switch, |
| 707 | &snd_sb16_ctl_pcm_play_vol, |
| 708 | &snd_sb16_ctl_synth_capture_route, |
| 709 | &snd_dt019x_ctl_synth_play_switch, |
| 710 | &snd_sb16_ctl_synth_play_vol, |
| 711 | &snd_sb16_ctl_cd_capture_route, |
| 712 | &snd_sb16_ctl_cd_play_switch, |
| 713 | &snd_sb16_ctl_cd_play_vol, |
| 714 | &snd_sb16_ctl_line_capture_route, |
| 715 | &snd_sb16_ctl_line_play_switch, |
| 716 | &snd_sb16_ctl_line_play_vol, |
| 717 | &snd_sb16_ctl_mic_capture_route, |
| 718 | &snd_als4000_ctl_mic_20db_boost, |
| 719 | &snd_sb16_ctl_auto_mic_gain, |
| 720 | &snd_sb16_ctl_mic_play_switch, |
| 721 | &snd_sb16_ctl_mic_play_vol, |
| 722 | &snd_sb16_ctl_pc_speaker_vol, |
| 723 | &snd_sb16_ctl_capture_vol, |
| 724 | &snd_sb16_ctl_play_vol, |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 725 | &snd_als4000_ctl_master_mono_playback_switch, |
| 726 | &snd_als4000_ctl_master_mono_capture_route, |
| 727 | &snd_als4000_ctl_mono_playback_switch, |
| 728 | &snd_als4000_ctl_mixer_loopback, |
| 729 | &snd_als4000_3d_control_switch, |
| 730 | &snd_als4000_3d_control_ratio, |
| 731 | &snd_als4000_3d_control_freq, |
| 732 | &snd_als4000_3d_control_delay, |
| 733 | &snd_als4000_3d_control_poweroff_switch, |
Olaf Hering | 44456d3 | 2005-07-27 11:45:17 -0700 | [diff] [blame] | 734 | #ifdef NOT_AVAILABLE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | &snd_als4000_ctl_fmdac, |
| 736 | &snd_als4000_ctl_qsound, |
| 737 | #endif |
| 738 | }; |
| 739 | |
| 740 | static unsigned char snd_als4000_init_values[][2] = { |
| 741 | { SB_DSP4_MASTER_DEV + 0, 0 }, |
| 742 | { SB_DSP4_MASTER_DEV + 1, 0 }, |
| 743 | { SB_DSP4_PCM_DEV + 0, 0 }, |
| 744 | { SB_DSP4_PCM_DEV + 1, 0 }, |
| 745 | { SB_DSP4_SYNTH_DEV + 0, 0 }, |
| 746 | { SB_DSP4_SYNTH_DEV + 1, 0 }, |
| 747 | { SB_DSP4_SPEAKER_DEV, 0 }, |
| 748 | { SB_DSP4_OUTPUT_SW, 0 }, |
| 749 | { SB_DSP4_INPUT_LEFT, 0 }, |
| 750 | { SB_DSP4_INPUT_RIGHT, 0 }, |
| 751 | { SB_DT019X_OUTPUT_SW2, 0 }, |
| 752 | { SB_ALS4000_MIC_IN_GAIN, 0 }, |
| 753 | }; |
| 754 | |
| 755 | |
| 756 | /* |
| 757 | */ |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 758 | static int snd_sbmixer_init(struct snd_sb *chip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | struct sbmix_elem **controls, |
| 760 | int controls_count, |
| 761 | unsigned char map[][2], |
| 762 | int map_count, |
| 763 | char *name) |
| 764 | { |
| 765 | unsigned long flags; |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 766 | struct snd_card *card = chip->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | int idx, err; |
| 768 | |
| 769 | /* mixer reset */ |
| 770 | spin_lock_irqsave(&chip->mixer_lock, flags); |
| 771 | snd_sbmixer_write(chip, 0x00, 0x00); |
| 772 | spin_unlock_irqrestore(&chip->mixer_lock, flags); |
| 773 | |
| 774 | /* mute and zero volume channels */ |
| 775 | for (idx = 0; idx < map_count; idx++) { |
| 776 | spin_lock_irqsave(&chip->mixer_lock, flags); |
| 777 | snd_sbmixer_write(chip, map[idx][0], map[idx][1]); |
| 778 | spin_unlock_irqrestore(&chip->mixer_lock, flags); |
| 779 | } |
| 780 | |
| 781 | for (idx = 0; idx < controls_count; idx++) { |
| 782 | if ((err = snd_sbmixer_add_ctl_elem(chip, controls[idx])) < 0) |
| 783 | return err; |
| 784 | } |
| 785 | snd_component_add(card, name); |
| 786 | strcpy(card->mixername, name); |
| 787 | return 0; |
| 788 | } |
| 789 | |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 790 | int snd_sbmixer_new(struct snd_sb *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | { |
Takashi Iwai | 029d64b | 2005-11-17 14:34:36 +0100 | [diff] [blame] | 792 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | int err; |
| 794 | |
| 795 | snd_assert(chip != NULL && chip->card != NULL, return -EINVAL); |
| 796 | |
| 797 | card = chip->card; |
| 798 | |
| 799 | switch (chip->hardware) { |
| 800 | case SB_HW_10: |
| 801 | return 0; /* no mixer chip on SB1.x */ |
| 802 | case SB_HW_20: |
| 803 | case SB_HW_201: |
| 804 | if ((err = snd_sbmixer_init(chip, |
| 805 | snd_sb20_controls, |
| 806 | ARRAY_SIZE(snd_sb20_controls), |
| 807 | snd_sb20_init_values, |
| 808 | ARRAY_SIZE(snd_sb20_init_values), |
| 809 | "CTL1335")) < 0) |
| 810 | return err; |
| 811 | break; |
| 812 | case SB_HW_PRO: |
| 813 | if ((err = snd_sbmixer_init(chip, |
| 814 | snd_sbpro_controls, |
| 815 | ARRAY_SIZE(snd_sbpro_controls), |
| 816 | snd_sbpro_init_values, |
| 817 | ARRAY_SIZE(snd_sbpro_init_values), |
| 818 | "CTL1345")) < 0) |
| 819 | return err; |
| 820 | break; |
| 821 | case SB_HW_16: |
| 822 | case SB_HW_ALS100: |
Takashi Iwai | 621887a | 2007-05-24 18:46:54 +0200 | [diff] [blame] | 823 | case SB_HW_CS5530: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | if ((err = snd_sbmixer_init(chip, |
| 825 | snd_sb16_controls, |
| 826 | ARRAY_SIZE(snd_sb16_controls), |
| 827 | snd_sb16_init_values, |
| 828 | ARRAY_SIZE(snd_sb16_init_values), |
| 829 | "CTL1745")) < 0) |
| 830 | return err; |
| 831 | break; |
| 832 | case SB_HW_ALS4000: |
| 833 | if ((err = snd_sbmixer_init(chip, |
| 834 | snd_als4000_controls, |
| 835 | ARRAY_SIZE(snd_als4000_controls), |
| 836 | snd_als4000_init_values, |
| 837 | ARRAY_SIZE(snd_als4000_init_values), |
| 838 | "ALS4000")) < 0) |
| 839 | return err; |
| 840 | break; |
| 841 | case SB_HW_DT019X: |
| 842 | if ((err = snd_sbmixer_init(chip, |
| 843 | snd_dt019x_controls, |
| 844 | ARRAY_SIZE(snd_dt019x_controls), |
| 845 | snd_dt019x_init_values, |
| 846 | ARRAY_SIZE(snd_dt019x_init_values), |
| 847 | "DT019X")) < 0) |
| 848 | break; |
| 849 | default: |
| 850 | strcpy(card->mixername, "???"); |
| 851 | } |
| 852 | return 0; |
| 853 | } |
Takashi Iwai | 5bdb6a1 | 2005-11-17 16:16:10 +0100 | [diff] [blame] | 854 | |
| 855 | #ifdef CONFIG_PM |
| 856 | static unsigned char sb20_saved_regs[] = { |
| 857 | SB_DSP20_MASTER_DEV, |
| 858 | SB_DSP20_PCM_DEV, |
| 859 | SB_DSP20_FM_DEV, |
| 860 | SB_DSP20_CD_DEV, |
| 861 | }; |
| 862 | |
| 863 | static unsigned char sbpro_saved_regs[] = { |
| 864 | SB_DSP_MASTER_DEV, |
| 865 | SB_DSP_PCM_DEV, |
| 866 | SB_DSP_PLAYBACK_FILT, |
| 867 | SB_DSP_FM_DEV, |
| 868 | SB_DSP_CD_DEV, |
| 869 | SB_DSP_LINE_DEV, |
| 870 | SB_DSP_MIC_DEV, |
| 871 | SB_DSP_CAPTURE_SOURCE, |
| 872 | SB_DSP_CAPTURE_FILT, |
| 873 | }; |
| 874 | |
| 875 | static unsigned char sb16_saved_regs[] = { |
| 876 | SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1, |
| 877 | SB_DSP4_3DSE, |
| 878 | SB_DSP4_BASS_DEV, SB_DSP4_BASS_DEV + 1, |
| 879 | SB_DSP4_TREBLE_DEV, SB_DSP4_TREBLE_DEV + 1, |
| 880 | SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1, |
| 881 | SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, |
| 882 | SB_DSP4_SYNTH_DEV, SB_DSP4_SYNTH_DEV + 1, |
| 883 | SB_DSP4_OUTPUT_SW, |
| 884 | SB_DSP4_CD_DEV, SB_DSP4_CD_DEV + 1, |
| 885 | SB_DSP4_LINE_DEV, SB_DSP4_LINE_DEV + 1, |
| 886 | SB_DSP4_MIC_DEV, |
| 887 | SB_DSP4_SPEAKER_DEV, |
| 888 | SB_DSP4_IGAIN_DEV, SB_DSP4_IGAIN_DEV + 1, |
| 889 | SB_DSP4_OGAIN_DEV, SB_DSP4_OGAIN_DEV + 1, |
| 890 | SB_DSP4_MIC_AGC |
| 891 | }; |
| 892 | |
| 893 | static unsigned char dt019x_saved_regs[] = { |
| 894 | SB_DT019X_MASTER_DEV, |
| 895 | SB_DT019X_PCM_DEV, |
| 896 | SB_DT019X_SYNTH_DEV, |
| 897 | SB_DT019X_CD_DEV, |
| 898 | SB_DT019X_MIC_DEV, |
| 899 | SB_DT019X_SPKR_DEV, |
| 900 | SB_DT019X_LINE_DEV, |
| 901 | SB_DSP4_OUTPUT_SW, |
| 902 | SB_DT019X_OUTPUT_SW2, |
| 903 | SB_DT019X_CAPTURE_SW, |
| 904 | }; |
| 905 | |
| 906 | static unsigned char als4000_saved_regs[] = { |
| 907 | SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1, |
| 908 | SB_DSP4_OUTPUT_SW, |
| 909 | SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1, |
| 910 | SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, |
| 911 | SB_DSP4_SYNTH_DEV, SB_DSP4_SYNTH_DEV + 1, |
| 912 | SB_DSP4_CD_DEV, SB_DSP4_CD_DEV + 1, |
| 913 | SB_DSP4_MIC_AGC, |
| 914 | SB_DSP4_MIC_DEV, |
| 915 | SB_DSP4_SPEAKER_DEV, |
| 916 | SB_DSP4_IGAIN_DEV, SB_DSP4_IGAIN_DEV + 1, |
| 917 | SB_DSP4_OGAIN_DEV, SB_DSP4_OGAIN_DEV + 1, |
| 918 | SB_DT019X_OUTPUT_SW2, |
| 919 | SB_ALS4000_MONO_IO_CTRL, |
| 920 | SB_ALS4000_MIC_IN_GAIN, |
| 921 | SB_ALS4000_3D_SND_FX, |
| 922 | SB_ALS4000_3D_TIME_DELAY, |
| 923 | }; |
| 924 | |
| 925 | static void save_mixer(struct snd_sb *chip, unsigned char *regs, int num_regs) |
| 926 | { |
| 927 | unsigned char *val = chip->saved_regs; |
| 928 | snd_assert(num_regs > ARRAY_SIZE(chip->saved_regs), return); |
| 929 | for (; num_regs; num_regs--) |
| 930 | *val++ = snd_sbmixer_read(chip, *regs++); |
| 931 | } |
| 932 | |
| 933 | static void restore_mixer(struct snd_sb *chip, unsigned char *regs, int num_regs) |
| 934 | { |
| 935 | unsigned char *val = chip->saved_regs; |
| 936 | snd_assert(num_regs > ARRAY_SIZE(chip->saved_regs), return); |
| 937 | for (; num_regs; num_regs--) |
| 938 | snd_sbmixer_write(chip, *regs++, *val++); |
| 939 | } |
| 940 | |
| 941 | void snd_sbmixer_suspend(struct snd_sb *chip) |
| 942 | { |
| 943 | switch (chip->hardware) { |
| 944 | case SB_HW_20: |
| 945 | case SB_HW_201: |
| 946 | save_mixer(chip, sb20_saved_regs, ARRAY_SIZE(sb20_saved_regs)); |
| 947 | break; |
| 948 | case SB_HW_PRO: |
| 949 | save_mixer(chip, sbpro_saved_regs, ARRAY_SIZE(sbpro_saved_regs)); |
| 950 | break; |
| 951 | case SB_HW_16: |
| 952 | case SB_HW_ALS100: |
Takashi Iwai | 621887a | 2007-05-24 18:46:54 +0200 | [diff] [blame] | 953 | case SB_HW_CS5530: |
Takashi Iwai | 5bdb6a1 | 2005-11-17 16:16:10 +0100 | [diff] [blame] | 954 | save_mixer(chip, sb16_saved_regs, ARRAY_SIZE(sb16_saved_regs)); |
| 955 | break; |
| 956 | case SB_HW_ALS4000: |
| 957 | save_mixer(chip, als4000_saved_regs, ARRAY_SIZE(als4000_saved_regs)); |
| 958 | break; |
| 959 | case SB_HW_DT019X: |
| 960 | save_mixer(chip, dt019x_saved_regs, ARRAY_SIZE(dt019x_saved_regs)); |
| 961 | break; |
| 962 | default: |
| 963 | break; |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | void snd_sbmixer_resume(struct snd_sb *chip) |
| 968 | { |
| 969 | switch (chip->hardware) { |
| 970 | case SB_HW_20: |
| 971 | case SB_HW_201: |
| 972 | restore_mixer(chip, sb20_saved_regs, ARRAY_SIZE(sb20_saved_regs)); |
| 973 | break; |
| 974 | case SB_HW_PRO: |
| 975 | restore_mixer(chip, sbpro_saved_regs, ARRAY_SIZE(sbpro_saved_regs)); |
| 976 | break; |
| 977 | case SB_HW_16: |
| 978 | case SB_HW_ALS100: |
Takashi Iwai | 621887a | 2007-05-24 18:46:54 +0200 | [diff] [blame] | 979 | case SB_HW_CS5530: |
Takashi Iwai | 5bdb6a1 | 2005-11-17 16:16:10 +0100 | [diff] [blame] | 980 | restore_mixer(chip, sb16_saved_regs, ARRAY_SIZE(sb16_saved_regs)); |
| 981 | break; |
| 982 | case SB_HW_ALS4000: |
| 983 | restore_mixer(chip, als4000_saved_regs, ARRAY_SIZE(als4000_saved_regs)); |
| 984 | break; |
| 985 | case SB_HW_DT019X: |
| 986 | restore_mixer(chip, dt019x_saved_regs, ARRAY_SIZE(dt019x_saved_regs)); |
| 987 | break; |
| 988 | default: |
| 989 | break; |
| 990 | } |
| 991 | } |
| 992 | #endif |