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 control of CS4235/4236B/4237B/4238B/4239 chips |
| 4 | * |
| 5 | * Note: |
| 6 | * ----- |
| 7 | * |
| 8 | * Bugs: |
| 9 | * ----- |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | /* |
| 28 | * Indirect control registers (CS4236B+) |
| 29 | * |
| 30 | * C0 |
| 31 | * D8: WSS reset (all chips) |
| 32 | * |
| 33 | * C1 (all chips except CS4236) |
| 34 | * D7-D5: version |
| 35 | * D4-D0: chip id |
| 36 | * 11101 - CS4235 |
| 37 | * 01011 - CS4236B |
| 38 | * 01000 - CS4237B |
| 39 | * 01001 - CS4238B |
| 40 | * 11110 - CS4239 |
| 41 | * |
| 42 | * C2 |
| 43 | * D7-D4: 3D Space (CS4235,CS4237B,CS4238B,CS4239) |
| 44 | * D3-D0: 3D Center (CS4237B); 3D Volume (CS4238B) |
| 45 | * |
| 46 | * C3 |
| 47 | * D7: 3D Enable (CS4237B) |
| 48 | * D6: 3D Mono Enable (CS4237B) |
| 49 | * D5: 3D Serial Output (CS4237B,CS4238B) |
| 50 | * D4: 3D Enable (CS4235,CS4238B,CS4239) |
| 51 | * |
| 52 | * C4 |
| 53 | * D7: consumer serial port enable (CS4237B,CS4238B) |
| 54 | * D6: channels status block reset (CS4237B,CS4238B) |
| 55 | * D5: user bit in sub-frame of digital audio data (CS4237B,CS4238B) |
| 56 | * D4: validity bit bit in sub-frame of digital audio data (CS4237B,CS4238B) |
| 57 | * |
| 58 | * C5 lower channel status (digital serial data description) (CS4237B,CS4238B) |
| 59 | * D7-D6: first two bits of category code |
| 60 | * D5: lock |
| 61 | * D4-D3: pre-emphasis (0 = none, 1 = 50/15us) |
| 62 | * D2: copy/copyright (0 = copy inhibited) |
| 63 | * D1: 0 = digital audio / 1 = non-digital audio |
| 64 | * |
| 65 | * C6 upper channel status (digital serial data description) (CS4237B,CS4238B) |
| 66 | * D7-D6: sample frequency (0 = 44.1kHz) |
| 67 | * D5: generation status (0 = no indication, 1 = original/commercially precaptureed data) |
| 68 | * D4-D0: category code (upper bits) |
| 69 | * |
| 70 | * C7 reserved (must write 0) |
| 71 | * |
| 72 | * C8 wavetable control |
| 73 | * D7: volume control interrupt enable (CS4235,CS4239) |
| 74 | * D6: hardware volume control format (CS4235,CS4239) |
| 75 | * D3: wavetable serial port enable (all chips) |
| 76 | * D2: DSP serial port switch (all chips) |
| 77 | * D1: disable MCLK (all chips) |
| 78 | * D0: force BRESET low (all chips) |
| 79 | * |
| 80 | */ |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | #include <asm/io.h> |
| 83 | #include <linux/delay.h> |
| 84 | #include <linux/init.h> |
| 85 | #include <linux/time.h> |
| 86 | #include <linux/wait.h> |
| 87 | #include <sound/core.h> |
Krzysztof Helt | 61ef19d | 2008-07-31 21:02:42 +0200 | [diff] [blame] | 88 | #include <sound/wss.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | #include <sound/asoundef.h> |
| 90 | |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 91 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | MODULE_DESCRIPTION("Routines for control of CS4235/4236B/4237B/4238B/4239 chips"); |
| 93 | MODULE_LICENSE("GPL"); |
| 94 | |
| 95 | /* |
| 96 | * |
| 97 | */ |
| 98 | |
| 99 | static unsigned char snd_cs4236_ext_map[18] = { |
| 100 | /* CS4236_LEFT_LINE */ 0xff, |
| 101 | /* CS4236_RIGHT_LINE */ 0xff, |
| 102 | /* CS4236_LEFT_MIC */ 0xdf, |
| 103 | /* CS4236_RIGHT_MIC */ 0xdf, |
| 104 | /* CS4236_LEFT_MIX_CTRL */ 0xe0 | 0x18, |
| 105 | /* CS4236_RIGHT_MIX_CTRL */ 0xe0, |
| 106 | /* CS4236_LEFT_FM */ 0xbf, |
| 107 | /* CS4236_RIGHT_FM */ 0xbf, |
| 108 | /* CS4236_LEFT_DSP */ 0xbf, |
| 109 | /* CS4236_RIGHT_DSP */ 0xbf, |
| 110 | /* CS4236_RIGHT_LOOPBACK */ 0xbf, |
| 111 | /* CS4236_DAC_MUTE */ 0xe0, |
| 112 | /* CS4236_ADC_RATE */ 0x01, /* 48kHz */ |
| 113 | /* CS4236_DAC_RATE */ 0x01, /* 48kHz */ |
| 114 | /* CS4236_LEFT_MASTER */ 0xbf, |
| 115 | /* CS4236_RIGHT_MASTER */ 0xbf, |
| 116 | /* CS4236_LEFT_WAVE */ 0xbf, |
| 117 | /* CS4236_RIGHT_WAVE */ 0xbf |
| 118 | }; |
| 119 | |
| 120 | /* |
| 121 | * |
| 122 | */ |
| 123 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 124 | static void snd_cs4236_ctrl_out(struct snd_wss *chip, |
| 125 | unsigned char reg, unsigned char val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
| 127 | outb(reg, chip->cport + 3); |
| 128 | outb(chip->cimage[reg] = val, chip->cport + 4); |
| 129 | } |
| 130 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 131 | static unsigned char snd_cs4236_ctrl_in(struct snd_wss *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { |
| 133 | outb(reg, chip->cport + 3); |
| 134 | return inb(chip->cport + 4); |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * PCM |
| 139 | */ |
| 140 | |
| 141 | #define CLOCKS 8 |
| 142 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 143 | static struct snd_ratnum clocks[CLOCKS] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { .num = 16934400, .den_min = 353, .den_max = 353, .den_step = 1 }, |
| 145 | { .num = 16934400, .den_min = 529, .den_max = 529, .den_step = 1 }, |
| 146 | { .num = 16934400, .den_min = 617, .den_max = 617, .den_step = 1 }, |
| 147 | { .num = 16934400, .den_min = 1058, .den_max = 1058, .den_step = 1 }, |
| 148 | { .num = 16934400, .den_min = 1764, .den_max = 1764, .den_step = 1 }, |
| 149 | { .num = 16934400, .den_min = 2117, .den_max = 2117, .den_step = 1 }, |
| 150 | { .num = 16934400, .den_min = 2558, .den_max = 2558, .den_step = 1 }, |
| 151 | { .num = 16934400/16, .den_min = 21, .den_max = 192, .den_step = 1 } |
| 152 | }; |
| 153 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 154 | static struct snd_pcm_hw_constraint_ratnums hw_constraints_clocks = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | .nrats = CLOCKS, |
| 156 | .rats = clocks, |
| 157 | }; |
| 158 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 159 | static int snd_cs4236_xrate(struct snd_pcm_runtime *runtime) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | { |
| 161 | return snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 162 | &hw_constraints_clocks); |
| 163 | } |
| 164 | |
| 165 | static unsigned char divisor_to_rate_register(unsigned int divisor) |
| 166 | { |
| 167 | switch (divisor) { |
| 168 | case 353: return 1; |
| 169 | case 529: return 2; |
| 170 | case 617: return 3; |
| 171 | case 1058: return 4; |
| 172 | case 1764: return 5; |
| 173 | case 2117: return 6; |
| 174 | case 2558: return 7; |
| 175 | default: |
Takashi Iwai | 7c22f1a | 2005-10-10 11:46:31 +0200 | [diff] [blame] | 176 | if (divisor < 21 || divisor > 192) { |
| 177 | snd_BUG(); |
| 178 | return 192; |
| 179 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | return divisor; |
| 181 | } |
| 182 | } |
| 183 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 184 | static void snd_cs4236_playback_format(struct snd_wss *chip, |
| 185 | struct snd_pcm_hw_params *params, |
| 186 | unsigned char pdfr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
| 188 | unsigned long flags; |
| 189 | unsigned char rate = divisor_to_rate_register(params->rate_den); |
| 190 | |
| 191 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 192 | /* set fast playback format change and clean playback FIFO */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 193 | snd_wss_out(chip, CS4231_ALT_FEATURE_1, |
| 194 | chip->image[CS4231_ALT_FEATURE_1] | 0x10); |
| 195 | snd_wss_out(chip, CS4231_PLAYBK_FORMAT, pdfr & 0xf0); |
| 196 | snd_wss_out(chip, CS4231_ALT_FEATURE_1, |
| 197 | chip->image[CS4231_ALT_FEATURE_1] & ~0x10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | snd_cs4236_ext_out(chip, CS4236_DAC_RATE, rate); |
| 199 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 200 | } |
| 201 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 202 | static void snd_cs4236_capture_format(struct snd_wss *chip, |
| 203 | struct snd_pcm_hw_params *params, |
| 204 | unsigned char cdfr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { |
| 206 | unsigned long flags; |
| 207 | unsigned char rate = divisor_to_rate_register(params->rate_den); |
| 208 | |
| 209 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 210 | /* set fast capture format change and clean capture FIFO */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 211 | snd_wss_out(chip, CS4231_ALT_FEATURE_1, |
| 212 | chip->image[CS4231_ALT_FEATURE_1] | 0x20); |
| 213 | snd_wss_out(chip, CS4231_REC_FORMAT, cdfr & 0xf0); |
| 214 | snd_wss_out(chip, CS4231_ALT_FEATURE_1, |
| 215 | chip->image[CS4231_ALT_FEATURE_1] & ~0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | snd_cs4236_ext_out(chip, CS4236_ADC_RATE, rate); |
| 217 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 218 | } |
| 219 | |
| 220 | #ifdef CONFIG_PM |
| 221 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 222 | static void snd_cs4236_suspend(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | { |
| 224 | int reg; |
| 225 | unsigned long flags; |
| 226 | |
| 227 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 228 | for (reg = 0; reg < 32; reg++) |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 229 | chip->image[reg] = snd_wss_in(chip, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | for (reg = 0; reg < 18; reg++) |
| 231 | chip->eimage[reg] = snd_cs4236_ext_in(chip, CS4236_I23VAL(reg)); |
| 232 | for (reg = 2; reg < 9; reg++) |
| 233 | chip->cimage[reg] = snd_cs4236_ctrl_in(chip, reg); |
| 234 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 235 | } |
| 236 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 237 | static void snd_cs4236_resume(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
| 239 | int reg; |
| 240 | unsigned long flags; |
| 241 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 242 | snd_wss_mce_up(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 244 | for (reg = 0; reg < 32; reg++) { |
| 245 | switch (reg) { |
| 246 | case CS4236_EXT_REG: |
| 247 | case CS4231_VERSION: |
| 248 | case 27: /* why? CS4235 - master left */ |
| 249 | case 29: /* why? CS4235 - master right */ |
| 250 | break; |
| 251 | default: |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 252 | snd_wss_out(chip, reg, chip->image[reg]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | break; |
| 254 | } |
| 255 | } |
| 256 | for (reg = 0; reg < 18; reg++) |
| 257 | snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), chip->eimage[reg]); |
| 258 | for (reg = 2; reg < 9; reg++) { |
| 259 | switch (reg) { |
| 260 | case 7: |
| 261 | break; |
| 262 | default: |
| 263 | snd_cs4236_ctrl_out(chip, reg, chip->cimage[reg]); |
| 264 | } |
| 265 | } |
| 266 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 267 | snd_wss_mce_down(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | #endif /* CONFIG_PM */ |
| 271 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 272 | int snd_cs4236_create(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | unsigned long port, |
| 274 | unsigned long cport, |
| 275 | int irq, int dma1, int dma2, |
| 276 | unsigned short hardware, |
| 277 | unsigned short hwshare, |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 278 | struct snd_wss **rchip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 280 | struct snd_wss *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | unsigned char ver1, ver2; |
| 282 | unsigned int reg; |
| 283 | int err; |
| 284 | |
| 285 | *rchip = NULL; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 286 | if (hardware == WSS_HW_DETECT) |
| 287 | hardware = WSS_HW_DETECT3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | if (cport < 0x100) { |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame^] | 289 | snd_printk(KERN_ERR "please, specify control port " |
| 290 | "for CS4236+ chips\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | return -ENODEV; |
| 292 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 293 | err = snd_wss_create(card, port, cport, |
| 294 | irq, dma1, dma2, hardware, hwshare, &chip); |
| 295 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | return err; |
| 297 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 298 | if (!(chip->hardware & WSS_HW_CS4236B_MASK)) { |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame^] | 299 | snd_printk(KERN_ERR "CS4236+: MODE3 and extended registers " |
| 300 | "not available, hardware=0x%x\n", chip->hardware); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | snd_device_free(card, chip); |
| 302 | return -ENODEV; |
| 303 | } |
| 304 | #if 0 |
| 305 | { |
| 306 | int idx; |
| 307 | for (idx = 0; idx < 8; idx++) |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame^] | 308 | snd_printk(KERN_DEBUG "CD%i = 0x%x\n", |
| 309 | idx, inb(chip->cport + idx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | for (idx = 0; idx < 9; idx++) |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame^] | 311 | snd_printk(KERN_DEBUG "C%i = 0x%x\n", |
| 312 | idx, snd_cs4236_ctrl_in(chip, idx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | #endif |
| 315 | ver1 = snd_cs4236_ctrl_in(chip, 1); |
| 316 | ver2 = snd_cs4236_ext_in(chip, CS4236_VERSION); |
| 317 | snd_printdd("CS4236: [0x%lx] C1 (version) = 0x%x, ext = 0x%x\n", cport, ver1, ver2); |
| 318 | if (ver1 != ver2) { |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame^] | 319 | snd_printk(KERN_ERR "CS4236+ chip detected, but " |
| 320 | "control port 0x%lx is not valid\n", cport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | snd_device_free(card, chip); |
| 322 | return -ENODEV; |
| 323 | } |
| 324 | snd_cs4236_ctrl_out(chip, 0, 0x00); |
| 325 | snd_cs4236_ctrl_out(chip, 2, 0xff); |
| 326 | snd_cs4236_ctrl_out(chip, 3, 0x00); |
| 327 | snd_cs4236_ctrl_out(chip, 4, 0x80); |
| 328 | snd_cs4236_ctrl_out(chip, 5, ((IEC958_AES1_CON_PCM_CODER & 3) << 6) | IEC958_AES0_CON_EMPHASIS_NONE); |
| 329 | snd_cs4236_ctrl_out(chip, 6, IEC958_AES1_CON_PCM_CODER >> 2); |
| 330 | snd_cs4236_ctrl_out(chip, 7, 0x00); |
| 331 | /* 0x8c for C8 is valid for Turtle Beach Malibu - the IEC-958 output */ |
| 332 | /* is working with this setup, other hardware should have */ |
| 333 | /* different signal paths and this value should be selectable */ |
| 334 | /* in the future */ |
| 335 | snd_cs4236_ctrl_out(chip, 8, 0x8c); |
| 336 | chip->rate_constraint = snd_cs4236_xrate; |
| 337 | chip->set_playback_format = snd_cs4236_playback_format; |
| 338 | chip->set_capture_format = snd_cs4236_capture_format; |
| 339 | #ifdef CONFIG_PM |
| 340 | chip->suspend = snd_cs4236_suspend; |
| 341 | chip->resume = snd_cs4236_resume; |
| 342 | #endif |
| 343 | |
| 344 | /* initialize extended registers */ |
| 345 | for (reg = 0; reg < sizeof(snd_cs4236_ext_map); reg++) |
| 346 | snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), snd_cs4236_ext_map[reg]); |
| 347 | |
| 348 | /* initialize compatible but more featured registers */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 349 | snd_wss_out(chip, CS4231_LEFT_INPUT, 0x40); |
| 350 | snd_wss_out(chip, CS4231_RIGHT_INPUT, 0x40); |
| 351 | snd_wss_out(chip, CS4231_AUX1_LEFT_INPUT, 0xff); |
| 352 | snd_wss_out(chip, CS4231_AUX1_RIGHT_INPUT, 0xff); |
| 353 | snd_wss_out(chip, CS4231_AUX2_LEFT_INPUT, 0xdf); |
| 354 | snd_wss_out(chip, CS4231_AUX2_RIGHT_INPUT, 0xdf); |
| 355 | snd_wss_out(chip, CS4231_RIGHT_LINE_IN, 0xff); |
| 356 | snd_wss_out(chip, CS4231_LEFT_LINE_IN, 0xff); |
| 357 | snd_wss_out(chip, CS4231_RIGHT_LINE_IN, 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | switch (chip->hardware) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 359 | case WSS_HW_CS4235: |
| 360 | case WSS_HW_CS4239: |
| 361 | snd_wss_out(chip, CS4235_LEFT_MASTER, 0xff); |
| 362 | snd_wss_out(chip, CS4235_RIGHT_MASTER, 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | break; |
| 364 | } |
| 365 | |
| 366 | *rchip = chip; |
| 367 | return 0; |
| 368 | } |
| 369 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 370 | int snd_cs4236_pcm(struct snd_wss *chip, int device, struct snd_pcm **rpcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 372 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | int err; |
| 374 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 375 | err = snd_wss_pcm(chip, device, &pcm); |
| 376 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | return err; |
| 378 | pcm->info_flags &= ~SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 379 | if (rpcm) |
| 380 | *rpcm = pcm; |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | /* |
| 385 | * MIXER |
| 386 | */ |
| 387 | |
| 388 | #define CS4236_SINGLE(xname, xindex, reg, shift, mask, invert) \ |
| 389 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 390 | .info = snd_cs4236_info_single, \ |
| 391 | .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \ |
| 392 | .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } |
| 393 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 394 | static int snd_cs4236_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | { |
| 396 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 397 | |
| 398 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 399 | uinfo->count = 1; |
| 400 | uinfo->value.integer.min = 0; |
| 401 | uinfo->value.integer.max = mask; |
| 402 | return 0; |
| 403 | } |
| 404 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 405 | static int snd_cs4236_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 407 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | unsigned long flags; |
| 409 | int reg = kcontrol->private_value & 0xff; |
| 410 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 411 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 412 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 413 | |
| 414 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 415 | ucontrol->value.integer.value[0] = (chip->eimage[CS4236_REG(reg)] >> shift) & mask; |
| 416 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 417 | if (invert) |
| 418 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 419 | return 0; |
| 420 | } |
| 421 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 422 | static int snd_cs4236_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 424 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | unsigned long flags; |
| 426 | int reg = kcontrol->private_value & 0xff; |
| 427 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 428 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 429 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 430 | int change; |
| 431 | unsigned short val; |
| 432 | |
| 433 | val = (ucontrol->value.integer.value[0] & mask); |
| 434 | if (invert) |
| 435 | val = mask - val; |
| 436 | val <<= shift; |
| 437 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 438 | val = (chip->eimage[CS4236_REG(reg)] & ~(mask << shift)) | val; |
| 439 | change = val != chip->eimage[CS4236_REG(reg)]; |
| 440 | snd_cs4236_ext_out(chip, reg, val); |
| 441 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 442 | return change; |
| 443 | } |
| 444 | |
| 445 | #define CS4236_SINGLEC(xname, xindex, reg, shift, mask, invert) \ |
| 446 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 447 | .info = snd_cs4236_info_single, \ |
| 448 | .get = snd_cs4236_get_singlec, .put = snd_cs4236_put_singlec, \ |
| 449 | .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } |
| 450 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 451 | static int snd_cs4236_get_singlec(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 453 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | unsigned long flags; |
| 455 | int reg = kcontrol->private_value & 0xff; |
| 456 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 457 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 458 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 459 | |
| 460 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 461 | ucontrol->value.integer.value[0] = (chip->cimage[reg] >> shift) & mask; |
| 462 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 463 | if (invert) |
| 464 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 465 | return 0; |
| 466 | } |
| 467 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 468 | static int snd_cs4236_put_singlec(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 470 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | unsigned long flags; |
| 472 | int reg = kcontrol->private_value & 0xff; |
| 473 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 474 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 475 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 476 | int change; |
| 477 | unsigned short val; |
| 478 | |
| 479 | val = (ucontrol->value.integer.value[0] & mask); |
| 480 | if (invert) |
| 481 | val = mask - val; |
| 482 | val <<= shift; |
| 483 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 484 | val = (chip->cimage[reg] & ~(mask << shift)) | val; |
| 485 | change = val != chip->cimage[reg]; |
| 486 | snd_cs4236_ctrl_out(chip, reg, val); |
| 487 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 488 | return change; |
| 489 | } |
| 490 | |
| 491 | #define CS4236_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ |
| 492 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 493 | .info = snd_cs4236_info_double, \ |
| 494 | .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \ |
| 495 | .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } |
| 496 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 497 | static int snd_cs4236_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | { |
| 499 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 500 | |
| 501 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 502 | uinfo->count = 2; |
| 503 | uinfo->value.integer.min = 0; |
| 504 | uinfo->value.integer.max = mask; |
| 505 | return 0; |
| 506 | } |
| 507 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 508 | static int snd_cs4236_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 510 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | unsigned long flags; |
| 512 | int left_reg = kcontrol->private_value & 0xff; |
| 513 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 514 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 515 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 516 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 517 | int invert = (kcontrol->private_value >> 22) & 1; |
| 518 | |
| 519 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 520 | ucontrol->value.integer.value[0] = (chip->eimage[CS4236_REG(left_reg)] >> shift_left) & mask; |
| 521 | ucontrol->value.integer.value[1] = (chip->eimage[CS4236_REG(right_reg)] >> shift_right) & mask; |
| 522 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 523 | if (invert) { |
| 524 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 525 | ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; |
| 526 | } |
| 527 | return 0; |
| 528 | } |
| 529 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 530 | static int snd_cs4236_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 532 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | unsigned long flags; |
| 534 | int left_reg = kcontrol->private_value & 0xff; |
| 535 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 536 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 537 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 538 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 539 | int invert = (kcontrol->private_value >> 22) & 1; |
| 540 | int change; |
| 541 | unsigned short val1, val2; |
| 542 | |
| 543 | val1 = ucontrol->value.integer.value[0] & mask; |
| 544 | val2 = ucontrol->value.integer.value[1] & mask; |
| 545 | if (invert) { |
| 546 | val1 = mask - val1; |
| 547 | val2 = mask - val2; |
| 548 | } |
| 549 | val1 <<= shift_left; |
| 550 | val2 <<= shift_right; |
| 551 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 552 | if (left_reg != right_reg) { |
| 553 | val1 = (chip->eimage[CS4236_REG(left_reg)] & ~(mask << shift_left)) | val1; |
| 554 | val2 = (chip->eimage[CS4236_REG(right_reg)] & ~(mask << shift_right)) | val2; |
| 555 | change = val1 != chip->eimage[CS4236_REG(left_reg)] || val2 != chip->eimage[CS4236_REG(right_reg)]; |
| 556 | snd_cs4236_ext_out(chip, left_reg, val1); |
| 557 | snd_cs4236_ext_out(chip, right_reg, val2); |
| 558 | } else { |
| 559 | val1 = (chip->eimage[CS4236_REG(left_reg)] & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2; |
| 560 | change = val1 != chip->eimage[CS4236_REG(left_reg)]; |
| 561 | snd_cs4236_ext_out(chip, left_reg, val1); |
| 562 | } |
| 563 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 564 | return change; |
| 565 | } |
| 566 | |
| 567 | #define CS4236_DOUBLE1(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ |
| 568 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 569 | .info = snd_cs4236_info_double, \ |
| 570 | .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \ |
| 571 | .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } |
| 572 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 573 | static int snd_cs4236_get_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 575 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | unsigned long flags; |
| 577 | int left_reg = kcontrol->private_value & 0xff; |
| 578 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 579 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 580 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 581 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 582 | int invert = (kcontrol->private_value >> 22) & 1; |
| 583 | |
| 584 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 585 | ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask; |
| 586 | ucontrol->value.integer.value[1] = (chip->eimage[CS4236_REG(right_reg)] >> shift_right) & mask; |
| 587 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 588 | if (invert) { |
| 589 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 590 | ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; |
| 591 | } |
| 592 | return 0; |
| 593 | } |
| 594 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 595 | static int snd_cs4236_put_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 597 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | unsigned long flags; |
| 599 | int left_reg = kcontrol->private_value & 0xff; |
| 600 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 601 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 602 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 603 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 604 | int invert = (kcontrol->private_value >> 22) & 1; |
| 605 | int change; |
| 606 | unsigned short val1, val2; |
| 607 | |
| 608 | val1 = ucontrol->value.integer.value[0] & mask; |
| 609 | val2 = ucontrol->value.integer.value[1] & mask; |
| 610 | if (invert) { |
| 611 | val1 = mask - val1; |
| 612 | val2 = mask - val2; |
| 613 | } |
| 614 | val1 <<= shift_left; |
| 615 | val2 <<= shift_right; |
| 616 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 617 | val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1; |
| 618 | val2 = (chip->eimage[CS4236_REG(right_reg)] & ~(mask << shift_right)) | val2; |
| 619 | change = val1 != chip->image[left_reg] || val2 != chip->eimage[CS4236_REG(right_reg)]; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 620 | snd_wss_out(chip, left_reg, val1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | snd_cs4236_ext_out(chip, right_reg, val2); |
| 622 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 623 | return change; |
| 624 | } |
| 625 | |
| 626 | #define CS4236_MASTER_DIGITAL(xname, xindex) \ |
| 627 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 628 | .info = snd_cs4236_info_double, \ |
| 629 | .get = snd_cs4236_get_master_digital, .put = snd_cs4236_put_master_digital, \ |
| 630 | .private_value = 71 << 24 } |
| 631 | |
| 632 | static inline int snd_cs4236_mixer_master_digital_invert_volume(int vol) |
| 633 | { |
| 634 | return (vol < 64) ? 63 - vol : 64 + (71 - vol); |
| 635 | } |
| 636 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 637 | static int snd_cs4236_get_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 639 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | unsigned long flags; |
| 641 | |
| 642 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 643 | ucontrol->value.integer.value[0] = snd_cs4236_mixer_master_digital_invert_volume(chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] & 0x7f); |
| 644 | ucontrol->value.integer.value[1] = snd_cs4236_mixer_master_digital_invert_volume(chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)] & 0x7f); |
| 645 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 646 | return 0; |
| 647 | } |
| 648 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 649 | static int snd_cs4236_put_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 651 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | unsigned long flags; |
| 653 | int change; |
| 654 | unsigned short val1, val2; |
| 655 | |
| 656 | val1 = snd_cs4236_mixer_master_digital_invert_volume(ucontrol->value.integer.value[0] & 0x7f); |
| 657 | val2 = snd_cs4236_mixer_master_digital_invert_volume(ucontrol->value.integer.value[1] & 0x7f); |
| 658 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 659 | val1 = (chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] & ~0x7f) | val1; |
| 660 | val2 = (chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)] & ~0x7f) | val2; |
| 661 | change = val1 != chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] || val2 != chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)]; |
| 662 | snd_cs4236_ext_out(chip, CS4236_LEFT_MASTER, val1); |
Takashi Iwai | a5a6bbd | 2006-02-27 17:20:41 +0100 | [diff] [blame] | 663 | snd_cs4236_ext_out(chip, CS4236_RIGHT_MASTER, val2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 665 | return change; |
| 666 | } |
| 667 | |
| 668 | #define CS4235_OUTPUT_ACCU(xname, xindex) \ |
| 669 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 670 | .info = snd_cs4236_info_double, \ |
| 671 | .get = snd_cs4235_get_output_accu, .put = snd_cs4235_put_output_accu, \ |
| 672 | .private_value = 3 << 24 } |
| 673 | |
| 674 | static inline int snd_cs4235_mixer_output_accu_get_volume(int vol) |
| 675 | { |
| 676 | switch ((vol >> 5) & 3) { |
| 677 | case 0: return 1; |
| 678 | case 1: return 3; |
| 679 | case 2: return 2; |
| 680 | case 3: return 0; |
| 681 | } |
| 682 | return 3; |
| 683 | } |
| 684 | |
| 685 | static inline int snd_cs4235_mixer_output_accu_set_volume(int vol) |
| 686 | { |
| 687 | switch (vol & 3) { |
| 688 | case 0: return 3 << 5; |
| 689 | case 1: return 0 << 5; |
| 690 | case 2: return 2 << 5; |
| 691 | case 3: return 1 << 5; |
| 692 | } |
| 693 | return 1 << 5; |
| 694 | } |
| 695 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 696 | static int snd_cs4235_get_output_accu(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 698 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | unsigned long flags; |
| 700 | |
| 701 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 702 | ucontrol->value.integer.value[0] = snd_cs4235_mixer_output_accu_get_volume(chip->image[CS4235_LEFT_MASTER]); |
| 703 | ucontrol->value.integer.value[1] = snd_cs4235_mixer_output_accu_get_volume(chip->image[CS4235_RIGHT_MASTER]); |
| 704 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 705 | return 0; |
| 706 | } |
| 707 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 708 | static int snd_cs4235_put_output_accu(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 710 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | unsigned long flags; |
| 712 | int change; |
| 713 | unsigned short val1, val2; |
| 714 | |
| 715 | val1 = snd_cs4235_mixer_output_accu_set_volume(ucontrol->value.integer.value[0]); |
| 716 | val2 = snd_cs4235_mixer_output_accu_set_volume(ucontrol->value.integer.value[1]); |
| 717 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 718 | val1 = (chip->image[CS4235_LEFT_MASTER] & ~(3 << 5)) | val1; |
| 719 | val2 = (chip->image[CS4235_RIGHT_MASTER] & ~(3 << 5)) | val2; |
| 720 | change = val1 != chip->image[CS4235_LEFT_MASTER] || val2 != chip->image[CS4235_RIGHT_MASTER]; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 721 | snd_wss_out(chip, CS4235_LEFT_MASTER, val1); |
| 722 | snd_wss_out(chip, CS4235_RIGHT_MASTER, val2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 724 | return change; |
| 725 | } |
| 726 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 727 | static struct snd_kcontrol_new snd_cs4236_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 729 | CS4236_DOUBLE("Master Digital Playback Switch", 0, |
| 730 | CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1), |
| 731 | CS4236_DOUBLE("Master Digital Capture Switch", 0, |
| 732 | CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | CS4236_MASTER_DIGITAL("Master Digital Volume", 0), |
| 734 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 735 | CS4236_DOUBLE("Capture Boost Volume", 0, |
| 736 | CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 738 | WSS_DOUBLE("PCM Playback Switch", 0, |
| 739 | CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), |
| 740 | WSS_DOUBLE("PCM Playback Volume", 0, |
| 741 | CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 743 | CS4236_DOUBLE("DSP Playback Switch", 0, |
| 744 | CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1), |
| 745 | CS4236_DOUBLE("DSP Playback Volume", 0, |
| 746 | CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 0, 0, 63, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 748 | CS4236_DOUBLE("FM Playback Switch", 0, |
| 749 | CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1), |
| 750 | CS4236_DOUBLE("FM Playback Volume", 0, |
| 751 | CS4236_LEFT_FM, CS4236_RIGHT_FM, 0, 0, 63, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 753 | CS4236_DOUBLE("Wavetable Playback Switch", 0, |
| 754 | CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1), |
| 755 | CS4236_DOUBLE("Wavetable Playback Volume", 0, |
| 756 | CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 0, 0, 63, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 758 | WSS_DOUBLE("Synth Playback Switch", 0, |
| 759 | CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), |
| 760 | WSS_DOUBLE("Synth Volume", 0, |
| 761 | CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1), |
| 762 | WSS_DOUBLE("Synth Capture Switch", 0, |
| 763 | CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1), |
| 764 | WSS_DOUBLE("Synth Capture Bypass", 0, |
| 765 | CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 5, 5, 1, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 767 | CS4236_DOUBLE("Mic Playback Switch", 0, |
| 768 | CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1), |
| 769 | CS4236_DOUBLE("Mic Capture Switch", 0, |
| 770 | CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | CS4236_DOUBLE("Mic Volume", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 0, 0, 31, 1), |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 772 | CS4236_DOUBLE("Mic Playback Boost", 0, |
| 773 | CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 5, 5, 1, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 775 | WSS_DOUBLE("Line Playback Switch", 0, |
| 776 | CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), |
| 777 | WSS_DOUBLE("Line Volume", 0, |
| 778 | CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1), |
| 779 | WSS_DOUBLE("Line Capture Switch", 0, |
| 780 | CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1), |
| 781 | WSS_DOUBLE("Line Capture Bypass", 0, |
| 782 | CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 5, 5, 1, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 784 | WSS_DOUBLE("CD Playback Switch", 0, |
| 785 | CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), |
| 786 | WSS_DOUBLE("CD Volume", 0, |
| 787 | CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1), |
| 788 | WSS_DOUBLE("CD Capture Switch", 0, |
| 789 | CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 791 | CS4236_DOUBLE1("Mono Output Playback Switch", 0, |
| 792 | CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1), |
| 793 | CS4236_DOUBLE1("Mono Playback Switch", 0, |
| 794 | CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1), |
| 795 | WSS_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1), |
| 796 | WSS_SINGLE("Mono Playback Bypass", 0, CS4231_MONO_CTRL, 5, 1, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 798 | WSS_DOUBLE("Capture Volume", 0, |
| 799 | CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0), |
| 800 | WSS_DOUBLE("Analog Loopback Capture Switch", 0, |
| 801 | CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 803 | WSS_SINGLE("Digital Loopback Playback Switch", 0, CS4231_LOOPBACK, 0, 1, 0), |
| 804 | CS4236_DOUBLE1("Digital Loopback Playback Volume", 0, |
| 805 | CS4231_LOOPBACK, CS4236_RIGHT_LOOPBACK, 2, 0, 63, 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | }; |
| 807 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 808 | static struct snd_kcontrol_new snd_cs4235_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 810 | WSS_DOUBLE("Master Switch", 0, |
| 811 | CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 7, 7, 1, 1), |
| 812 | WSS_DOUBLE("Master Volume", 0, |
| 813 | CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 0, 0, 31, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
| 815 | CS4235_OUTPUT_ACCU("Playback Volume", 0), |
| 816 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 817 | CS4236_DOUBLE("Master Digital Playback Switch", 0, |
| 818 | CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1), |
| 819 | CS4236_DOUBLE("Master Digital Capture Switch", 0, |
| 820 | CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | CS4236_MASTER_DIGITAL("Master Digital Volume", 0), |
| 822 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 823 | WSS_DOUBLE("Master Digital Playback Switch", 1, |
| 824 | CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), |
| 825 | WSS_DOUBLE("Master Digital Capture Switch", 1, |
| 826 | CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1), |
| 827 | WSS_DOUBLE("Master Digital Volume", 1, |
| 828 | CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 830 | CS4236_DOUBLE("Capture Volume", 0, |
| 831 | CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 833 | WSS_DOUBLE("PCM Switch", 0, |
| 834 | CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), |
| 835 | WSS_DOUBLE("PCM Volume", 0, |
| 836 | CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
| 838 | CS4236_DOUBLE("DSP Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1), |
| 839 | |
| 840 | CS4236_DOUBLE("FM Switch", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1), |
| 841 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 842 | CS4236_DOUBLE("Wavetable Switch", 0, |
| 843 | CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 845 | CS4236_DOUBLE("Mic Capture Switch", 0, |
| 846 | CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1), |
| 847 | CS4236_DOUBLE("Mic Playback Switch", 0, |
| 848 | CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | CS4236_SINGLE("Mic Volume", 0, CS4236_LEFT_MIC, 0, 31, 1), |
| 850 | CS4236_SINGLE("Mic Playback Boost", 0, CS4236_LEFT_MIC, 5, 1, 0), |
| 851 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 852 | WSS_DOUBLE("Aux Playback Switch", 0, |
| 853 | CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), |
| 854 | WSS_DOUBLE("Aux Capture Switch", 0, |
| 855 | CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1), |
| 856 | WSS_DOUBLE("Aux Volume", 0, |
| 857 | CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 859 | WSS_DOUBLE("Aux Playback Switch", 1, |
| 860 | CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), |
| 861 | WSS_DOUBLE("Aux Capture Switch", 1, |
| 862 | CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1), |
| 863 | WSS_DOUBLE("Aux Volume", 1, |
| 864 | CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 866 | CS4236_DOUBLE1("Master Mono Switch", 0, |
| 867 | CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 869 | CS4236_DOUBLE1("Mono Switch", 0, |
| 870 | CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1), |
| 871 | WSS_SINGLE("Mono Volume", 0, CS4231_MONO_CTRL, 0, 15, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 873 | WSS_DOUBLE("Analog Loopback Switch", 0, |
| 874 | CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | }; |
| 876 | |
| 877 | #define CS4236_IEC958_ENABLE(xname, xindex) \ |
| 878 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 879 | .info = snd_cs4236_info_single, \ |
| 880 | .get = snd_cs4236_get_iec958_switch, .put = snd_cs4236_put_iec958_switch, \ |
| 881 | .private_value = 1 << 16 } |
| 882 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 883 | static int snd_cs4236_get_iec958_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 885 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | unsigned long flags; |
| 887 | |
| 888 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 889 | ucontrol->value.integer.value[0] = chip->image[CS4231_ALT_FEATURE_1] & 0x02 ? 1 : 0; |
| 890 | #if 0 |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame^] | 891 | printk(KERN_DEBUG "get valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, " |
| 892 | "C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n", |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 893 | snd_wss_in(chip, CS4231_ALT_FEATURE_1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | snd_cs4236_ctrl_in(chip, 3), |
| 895 | snd_cs4236_ctrl_in(chip, 4), |
| 896 | snd_cs4236_ctrl_in(chip, 5), |
| 897 | snd_cs4236_ctrl_in(chip, 6), |
| 898 | snd_cs4236_ctrl_in(chip, 8)); |
| 899 | #endif |
| 900 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 901 | return 0; |
| 902 | } |
| 903 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 904 | static int snd_cs4236_put_iec958_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 906 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | unsigned long flags; |
| 908 | int change; |
| 909 | unsigned short enable, val; |
| 910 | |
| 911 | enable = ucontrol->value.integer.value[0] & 1; |
| 912 | |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 913 | mutex_lock(&chip->mce_mutex); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 914 | snd_wss_mce_up(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 916 | val = (chip->image[CS4231_ALT_FEATURE_1] & ~0x0e) | (0<<2) | (enable << 1); |
| 917 | change = val != chip->image[CS4231_ALT_FEATURE_1]; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 918 | snd_wss_out(chip, CS4231_ALT_FEATURE_1, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | val = snd_cs4236_ctrl_in(chip, 4) | 0xc0; |
| 920 | snd_cs4236_ctrl_out(chip, 4, val); |
| 921 | udelay(100); |
| 922 | val &= ~0x40; |
| 923 | snd_cs4236_ctrl_out(chip, 4, val); |
| 924 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 925 | snd_wss_mce_down(chip); |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 926 | mutex_unlock(&chip->mce_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | |
| 928 | #if 0 |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame^] | 929 | printk(KERN_DEBUG "set valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, " |
| 930 | "C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n", |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 931 | snd_wss_in(chip, CS4231_ALT_FEATURE_1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | snd_cs4236_ctrl_in(chip, 3), |
| 933 | snd_cs4236_ctrl_in(chip, 4), |
| 934 | snd_cs4236_ctrl_in(chip, 5), |
| 935 | snd_cs4236_ctrl_in(chip, 6), |
| 936 | snd_cs4236_ctrl_in(chip, 8)); |
| 937 | #endif |
| 938 | return change; |
| 939 | } |
| 940 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 941 | static struct snd_kcontrol_new snd_cs4236_iec958_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | CS4236_IEC958_ENABLE("IEC958 Output Enable", 0), |
| 943 | CS4236_SINGLEC("IEC958 Output Validity", 0, 4, 4, 1, 0), |
| 944 | CS4236_SINGLEC("IEC958 Output User", 0, 4, 5, 1, 0), |
| 945 | CS4236_SINGLEC("IEC958 Output CSBR", 0, 4, 6, 1, 0), |
| 946 | CS4236_SINGLEC("IEC958 Output Channel Status Low", 0, 5, 1, 127, 0), |
| 947 | CS4236_SINGLEC("IEC958 Output Channel Status High", 0, 6, 0, 255, 0) |
| 948 | }; |
| 949 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 950 | static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4235[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | CS4236_SINGLEC("3D Control - Switch", 0, 3, 4, 1, 0), |
| 952 | CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1) |
| 953 | }; |
| 954 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 955 | static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4237[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | CS4236_SINGLEC("3D Control - Switch", 0, 3, 7, 1, 0), |
| 957 | CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1), |
| 958 | CS4236_SINGLEC("3D Control - Center", 0, 2, 0, 15, 1), |
| 959 | CS4236_SINGLEC("3D Control - Mono", 0, 3, 6, 1, 0), |
| 960 | CS4236_SINGLEC("3D Control - IEC958", 0, 3, 5, 1, 0) |
| 961 | }; |
| 962 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 963 | static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4238[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | CS4236_SINGLEC("3D Control - Switch", 0, 3, 4, 1, 0), |
| 965 | CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1), |
| 966 | CS4236_SINGLEC("3D Control - Volume", 0, 2, 0, 15, 1), |
| 967 | CS4236_SINGLEC("3D Control - IEC958", 0, 3, 5, 1, 0) |
| 968 | }; |
| 969 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 970 | int snd_cs4236_mixer(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | { |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 972 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | unsigned int idx, count; |
| 974 | int err; |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 975 | struct snd_kcontrol_new *kcontrol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
Takashi Iwai | 622207d | 2008-08-08 17:11:45 +0200 | [diff] [blame] | 977 | if (snd_BUG_ON(!chip || !chip->card)) |
| 978 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | card = chip->card; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 980 | strcpy(card->mixername, snd_wss_chip_id(chip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 982 | if (chip->hardware == WSS_HW_CS4235 || |
| 983 | chip->hardware == WSS_HW_CS4239) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | for (idx = 0; idx < ARRAY_SIZE(snd_cs4235_controls); idx++) { |
| 985 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4235_controls[idx], chip))) < 0) |
| 986 | return err; |
| 987 | } |
| 988 | } else { |
| 989 | for (idx = 0; idx < ARRAY_SIZE(snd_cs4236_controls); idx++) { |
| 990 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4236_controls[idx], chip))) < 0) |
| 991 | return err; |
| 992 | } |
| 993 | } |
| 994 | switch (chip->hardware) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 995 | case WSS_HW_CS4235: |
| 996 | case WSS_HW_CS4239: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4235); |
| 998 | kcontrol = snd_cs4236_3d_controls_cs4235; |
| 999 | break; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1000 | case WSS_HW_CS4237B: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4237); |
| 1002 | kcontrol = snd_cs4236_3d_controls_cs4237; |
| 1003 | break; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1004 | case WSS_HW_CS4238B: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4238); |
| 1006 | kcontrol = snd_cs4236_3d_controls_cs4238; |
| 1007 | break; |
| 1008 | default: |
| 1009 | count = 0; |
| 1010 | kcontrol = NULL; |
| 1011 | } |
| 1012 | for (idx = 0; idx < count; idx++, kcontrol++) { |
| 1013 | if ((err = snd_ctl_add(card, snd_ctl_new1(kcontrol, chip))) < 0) |
| 1014 | return err; |
| 1015 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1016 | if (chip->hardware == WSS_HW_CS4237B || |
| 1017 | chip->hardware == WSS_HW_CS4238B) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | for (idx = 0; idx < ARRAY_SIZE(snd_cs4236_iec958_controls); idx++) { |
| 1019 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4236_iec958_controls[idx], chip))) < 0) |
| 1020 | return err; |
| 1021 | } |
| 1022 | } |
| 1023 | return 0; |
| 1024 | } |
| 1025 | |
| 1026 | EXPORT_SYMBOL(snd_cs4236_create); |
| 1027 | EXPORT_SYMBOL(snd_cs4236_pcm); |
| 1028 | EXPORT_SYMBOL(snd_cs4236_mixer); |
| 1029 | |
| 1030 | /* |
| 1031 | * INIT part |
| 1032 | */ |
| 1033 | |
| 1034 | static int __init alsa_cs4236_init(void) |
| 1035 | { |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
| 1039 | static void __exit alsa_cs4236_exit(void) |
| 1040 | { |
| 1041 | } |
| 1042 | |
| 1043 | module_init(alsa_cs4236_init) |
| 1044 | module_exit(alsa_cs4236_exit) |