2 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
3 * Routines for control of CS4231(A)/CS4232/InterWave & compatible chips
6 * - sometimes record brokes playback with WSS portion of
8 * - CS4231 (GUS MAX) - still trouble with occasional noises
9 * - broken initialization?
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.
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.
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
27 #include <linux/delay.h>
29 #include <linux/init.h>
30 #include <linux/interrupt.h>
31 #include <linux/slab.h>
32 #include <linux/ioport.h>
33 #include <sound/core.h>
34 #include <sound/cs4231.h>
35 #include <sound/pcm_params.h>
41 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
42 MODULE_DESCRIPTION("Routines for control of CS4231(A)/CS4232/InterWave & compatible chips");
43 MODULE_LICENSE("GPL");
46 #define SNDRV_DEBUG_MCE
53 static unsigned char freq_bits[14] = {
54 /* 5510 */ 0x00 | CS4231_XTAL2,
55 /* 6620 */ 0x0E | CS4231_XTAL2,
56 /* 8000 */ 0x00 | CS4231_XTAL1,
57 /* 9600 */ 0x0E | CS4231_XTAL1,
58 /* 11025 */ 0x02 | CS4231_XTAL2,
59 /* 16000 */ 0x02 | CS4231_XTAL1,
60 /* 18900 */ 0x04 | CS4231_XTAL2,
61 /* 22050 */ 0x06 | CS4231_XTAL2,
62 /* 27042 */ 0x04 | CS4231_XTAL1,
63 /* 32000 */ 0x06 | CS4231_XTAL1,
64 /* 33075 */ 0x0C | CS4231_XTAL2,
65 /* 37800 */ 0x08 | CS4231_XTAL2,
66 /* 44100 */ 0x0A | CS4231_XTAL2,
67 /* 48000 */ 0x0C | CS4231_XTAL1
70 static unsigned int rates[14] = {
71 5510, 6620, 8000, 9600, 11025, 16000, 18900, 22050,
72 27042, 32000, 33075, 37800, 44100, 48000
75 static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
76 .count = ARRAY_SIZE(rates),
81 static int snd_cs4231_xrate(struct snd_pcm_runtime *runtime)
83 return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
86 static unsigned char snd_cs4231_original_image[32] =
88 0x00, /* 00/00 - lic */
89 0x00, /* 01/01 - ric */
90 0x9f, /* 02/02 - la1ic */
91 0x9f, /* 03/03 - ra1ic */
92 0x9f, /* 04/04 - la2ic */
93 0x9f, /* 05/05 - ra2ic */
94 0xbf, /* 06/06 - loc */
95 0xbf, /* 07/07 - roc */
96 0x20, /* 08/08 - pdfr */
97 CS4231_AUTOCALIB, /* 09/09 - ic */
98 0x00, /* 0a/10 - pc */
99 0x00, /* 0b/11 - ti */
100 CS4231_MODE2, /* 0c/12 - mi */
101 0xfc, /* 0d/13 - lbc */
102 0x00, /* 0e/14 - pbru */
103 0x00, /* 0f/15 - pbrl */
104 0x80, /* 10/16 - afei */
105 0x01, /* 11/17 - afeii */
106 0x9f, /* 12/18 - llic */
107 0x9f, /* 13/19 - rlic */
108 0x00, /* 14/20 - tlb */
109 0x00, /* 15/21 - thb */
110 0x00, /* 16/22 - la3mic/reserved */
111 0x00, /* 17/23 - ra3mic/reserved */
112 0x00, /* 18/24 - afs */
113 0x00, /* 19/25 - lamoc/version */
114 0xcf, /* 1a/26 - mioc */
115 0x00, /* 1b/27 - ramoc/reserved */
116 0x20, /* 1c/28 - cdfr */
117 0x00, /* 1d/29 - res4 */
118 0x00, /* 1e/30 - cbru */
119 0x00, /* 1f/31 - cbrl */
123 * Basic I/O functions
126 static inline void cs4231_outb(struct snd_cs4231 *chip, u8 offset, u8 val)
128 outb(val, chip->port + offset);
131 static inline u8 cs4231_inb(struct snd_cs4231 *chip, u8 offset)
133 return inb(chip->port + offset);
136 static void snd_cs4231_wait(struct snd_cs4231 *chip)
141 timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
146 static void snd_cs4231_outm(struct snd_cs4231 *chip, unsigned char reg,
147 unsigned char mask, unsigned char value)
149 unsigned char tmp = (chip->image[reg] & mask) | value;
151 snd_cs4231_wait(chip);
152 #ifdef CONFIG_SND_DEBUG
153 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
154 snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
156 chip->image[reg] = tmp;
157 if (!chip->calibrate_mute) {
158 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
160 cs4231_outb(chip, CS4231P(REG), tmp);
165 static void snd_cs4231_dout(struct snd_cs4231 *chip, unsigned char reg, unsigned char value)
170 timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
173 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
174 cs4231_outb(chip, CS4231P(REG), value);
178 void snd_cs4231_out(struct snd_cs4231 *chip, unsigned char reg, unsigned char value)
180 snd_cs4231_wait(chip);
181 #ifdef CONFIG_SND_DEBUG
182 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
183 snd_printk("out: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
185 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
186 cs4231_outb(chip, CS4231P(REG), value);
187 chip->image[reg] = value;
189 snd_printdd("codec out - reg 0x%x = 0x%x\n",
190 chip->mce_bit | reg, value);
193 unsigned char snd_cs4231_in(struct snd_cs4231 *chip, unsigned char reg)
195 snd_cs4231_wait(chip);
196 #ifdef CONFIG_SND_DEBUG
197 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
198 snd_printk("in: auto calibration time out - reg = 0x%x\n", reg);
200 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
202 return cs4231_inb(chip, CS4231P(REG));
205 void snd_cs4236_ext_out(struct snd_cs4231 *chip, unsigned char reg, unsigned char val)
207 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | 0x17);
208 cs4231_outb(chip, CS4231P(REG), reg | (chip->image[CS4236_EXT_REG] & 0x01));
209 cs4231_outb(chip, CS4231P(REG), val);
210 chip->eimage[CS4236_REG(reg)] = val;
212 printk("ext out : reg = 0x%x, val = 0x%x\n", reg, val);
216 unsigned char snd_cs4236_ext_in(struct snd_cs4231 *chip, unsigned char reg)
218 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | 0x17);
219 cs4231_outb(chip, CS4231P(REG), reg | (chip->image[CS4236_EXT_REG] & 0x01));
221 return cs4231_inb(chip, CS4231P(REG));
225 res = cs4231_inb(chip, CS4231P(REG));
226 printk("ext in : reg = 0x%x, val = 0x%x\n", reg, res);
234 static void snd_cs4231_debug(struct snd_cs4231 *chip)
236 printk("CS4231 REGS: INDEX = 0x%02x ", cs4231_inb(chip, CS4231P(REGSEL)));
237 printk(" STATUS = 0x%02x\n", cs4231_inb(chip, CS4231P(STATUS)));
238 printk(" 0x00: left input = 0x%02x ", snd_cs4231_in(chip, 0x00));
239 printk(" 0x10: alt 1 (CFIG 2) = 0x%02x\n", snd_cs4231_in(chip, 0x10));
240 printk(" 0x01: right input = 0x%02x ", snd_cs4231_in(chip, 0x01));
241 printk(" 0x11: alt 2 (CFIG 3) = 0x%02x\n", snd_cs4231_in(chip, 0x11));
242 printk(" 0x02: GF1 left input = 0x%02x ", snd_cs4231_in(chip, 0x02));
243 printk(" 0x12: left line in = 0x%02x\n", snd_cs4231_in(chip, 0x12));
244 printk(" 0x03: GF1 right input = 0x%02x ", snd_cs4231_in(chip, 0x03));
245 printk(" 0x13: right line in = 0x%02x\n", snd_cs4231_in(chip, 0x13));
246 printk(" 0x04: CD left input = 0x%02x ", snd_cs4231_in(chip, 0x04));
247 printk(" 0x14: timer low = 0x%02x\n", snd_cs4231_in(chip, 0x14));
248 printk(" 0x05: CD right input = 0x%02x ", snd_cs4231_in(chip, 0x05));
249 printk(" 0x15: timer high = 0x%02x\n", snd_cs4231_in(chip, 0x15));
250 printk(" 0x06: left output = 0x%02x ", snd_cs4231_in(chip, 0x06));
251 printk(" 0x16: left MIC (PnP) = 0x%02x\n", snd_cs4231_in(chip, 0x16));
252 printk(" 0x07: right output = 0x%02x ", snd_cs4231_in(chip, 0x07));
253 printk(" 0x17: right MIC (PnP) = 0x%02x\n", snd_cs4231_in(chip, 0x17));
254 printk(" 0x08: playback format = 0x%02x ", snd_cs4231_in(chip, 0x08));
255 printk(" 0x18: IRQ status = 0x%02x\n", snd_cs4231_in(chip, 0x18));
256 printk(" 0x09: iface (CFIG 1) = 0x%02x ", snd_cs4231_in(chip, 0x09));
257 printk(" 0x19: left line out = 0x%02x\n", snd_cs4231_in(chip, 0x19));
258 printk(" 0x0a: pin control = 0x%02x ", snd_cs4231_in(chip, 0x0a));
259 printk(" 0x1a: mono control = 0x%02x\n", snd_cs4231_in(chip, 0x1a));
260 printk(" 0x0b: init & status = 0x%02x ", snd_cs4231_in(chip, 0x0b));
261 printk(" 0x1b: right line out = 0x%02x\n", snd_cs4231_in(chip, 0x1b));
262 printk(" 0x0c: revision & mode = 0x%02x ", snd_cs4231_in(chip, 0x0c));
263 printk(" 0x1c: record format = 0x%02x\n", snd_cs4231_in(chip, 0x1c));
264 printk(" 0x0d: loopback = 0x%02x ", snd_cs4231_in(chip, 0x0d));
265 printk(" 0x1d: var freq (PnP) = 0x%02x\n", snd_cs4231_in(chip, 0x1d));
266 printk(" 0x0e: ply upr count = 0x%02x ", snd_cs4231_in(chip, 0x0e));
267 printk(" 0x1e: ply lwr count = 0x%02x\n", snd_cs4231_in(chip, 0x1e));
268 printk(" 0x0f: rec upr count = 0x%02x ", snd_cs4231_in(chip, 0x0f));
269 printk(" 0x1f: rec lwr count = 0x%02x\n", snd_cs4231_in(chip, 0x1f));
275 * CS4231 detection / MCE routines
278 static void snd_cs4231_busy_wait(struct snd_cs4231 *chip)
282 /* huh.. looks like this sequence is proper for CS4231A chip (GUS MAX) */
283 for (timeout = 5; timeout > 0; timeout--)
284 cs4231_inb(chip, CS4231P(REGSEL));
285 /* end of cleanup sequence */
287 timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
292 void snd_cs4231_mce_up(struct snd_cs4231 *chip)
297 snd_cs4231_wait(chip);
298 #ifdef CONFIG_SND_DEBUG
299 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
300 snd_printk("mce_up - auto calibration time out (0)\n");
302 spin_lock_irqsave(&chip->reg_lock, flags);
303 chip->mce_bit |= CS4231_MCE;
304 timeout = cs4231_inb(chip, CS4231P(REGSEL));
306 snd_printk("mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port);
307 if (!(timeout & CS4231_MCE))
308 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
309 spin_unlock_irqrestore(&chip->reg_lock, flags);
312 void snd_cs4231_mce_down(struct snd_cs4231 *chip)
315 unsigned long end_time;
318 snd_cs4231_busy_wait(chip);
320 #ifdef CONFIG_SND_DEBUG
321 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
322 snd_printk("mce_down [0x%lx] - auto calibration time out (0)\n", (long)CS4231P(REGSEL));
324 spin_lock_irqsave(&chip->reg_lock, flags);
325 chip->mce_bit &= ~CS4231_MCE;
326 timeout = cs4231_inb(chip, CS4231P(REGSEL));
327 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
328 spin_unlock_irqrestore(&chip->reg_lock, flags);
330 snd_printk("mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port);
331 if ((timeout & CS4231_MCE) == 0 ||
332 !(chip->hardware & (CS4231_HW_CS4231_MASK | CS4231_HW_CS4232_MASK))) {
335 snd_cs4231_busy_wait(chip);
338 * Wait for (possible -- during init auto-calibration may not be set)
339 * calibration process to start. Needs upto 5 sample periods on AD1848
340 * which at the slowest possible rate of 5.5125 kHz means 907 us.
344 snd_printdd("(1) jiffies = %lu\n", jiffies);
346 /* check condition up to 250 ms */
347 end_time = jiffies + msecs_to_jiffies(250);
348 while (snd_cs4231_in(chip, CS4231_TEST_INIT) &
349 CS4231_CALIB_IN_PROGRESS) {
351 if (time_after(jiffies, end_time)) {
352 snd_printk(KERN_ERR "mce_down - "
353 "auto calibration time out (2)\n");
359 snd_printdd("(2) jiffies = %lu\n", jiffies);
361 /* check condition up to 100 ms */
362 end_time = jiffies + msecs_to_jiffies(100);
363 while (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) {
364 if (time_after(jiffies, end_time)) {
365 snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n");
371 snd_printdd("(3) jiffies = %lu\n", jiffies);
372 snd_printd("mce_down - exit = 0x%x\n", cs4231_inb(chip, CS4231P(REGSEL)));
375 static unsigned int snd_cs4231_get_count(unsigned char format, unsigned int size)
377 switch (format & 0xe0) {
378 case CS4231_LINEAR_16:
379 case CS4231_LINEAR_16_BIG:
382 case CS4231_ADPCM_16:
385 if (format & CS4231_STEREO)
390 static int snd_cs4231_trigger(struct snd_pcm_substream *substream,
393 struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
396 struct snd_pcm_substream *s;
400 printk("codec trigger!!! - what = %i, enable = %i, status = 0x%x\n", what, enable, cs4231_inb(chip, CS4231P(STATUS)));
404 case SNDRV_PCM_TRIGGER_START:
405 case SNDRV_PCM_TRIGGER_RESUME:
407 case SNDRV_PCM_TRIGGER_STOP:
408 case SNDRV_PCM_TRIGGER_SUSPEND:
415 snd_pcm_group_for_each_entry(s, substream) {
416 if (s == chip->playback_substream) {
417 what |= CS4231_PLAYBACK_ENABLE;
418 snd_pcm_trigger_done(s, substream);
419 } else if (s == chip->capture_substream) {
420 what |= CS4231_RECORD_ENABLE;
421 snd_pcm_trigger_done(s, substream);
424 spin_lock(&chip->reg_lock);
426 chip->image[CS4231_IFACE_CTRL] |= what;
428 chip->trigger(chip, what, 1);
430 chip->image[CS4231_IFACE_CTRL] &= ~what;
432 chip->trigger(chip, what, 0);
434 snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
435 spin_unlock(&chip->reg_lock);
437 snd_cs4231_debug(chip);
446 static unsigned char snd_cs4231_get_rate(unsigned int rate)
450 for (i = 0; i < ARRAY_SIZE(rates); i++)
451 if (rate == rates[i])
454 return freq_bits[ARRAY_SIZE(rates) - 1];
457 static unsigned char snd_cs4231_get_format(struct snd_cs4231 *chip,
461 unsigned char rformat;
463 rformat = CS4231_LINEAR_8;
465 case SNDRV_PCM_FORMAT_MU_LAW: rformat = CS4231_ULAW_8; break;
466 case SNDRV_PCM_FORMAT_A_LAW: rformat = CS4231_ALAW_8; break;
467 case SNDRV_PCM_FORMAT_S16_LE: rformat = CS4231_LINEAR_16; break;
468 case SNDRV_PCM_FORMAT_S16_BE: rformat = CS4231_LINEAR_16_BIG; break;
469 case SNDRV_PCM_FORMAT_IMA_ADPCM: rformat = CS4231_ADPCM_16; break;
472 rformat |= CS4231_STEREO;
474 snd_printk("get_format: 0x%x (mode=0x%x)\n", format, mode);
479 static void snd_cs4231_calibrate_mute(struct snd_cs4231 *chip, int mute)
484 spin_lock_irqsave(&chip->reg_lock, flags);
485 if (chip->calibrate_mute == mute) {
486 spin_unlock_irqrestore(&chip->reg_lock, flags);
490 snd_cs4231_dout(chip, CS4231_LEFT_INPUT, chip->image[CS4231_LEFT_INPUT]);
491 snd_cs4231_dout(chip, CS4231_RIGHT_INPUT, chip->image[CS4231_RIGHT_INPUT]);
492 snd_cs4231_dout(chip, CS4231_LOOPBACK, chip->image[CS4231_LOOPBACK]);
494 snd_cs4231_dout(chip, CS4231_AUX1_LEFT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX1_LEFT_INPUT]);
495 snd_cs4231_dout(chip, CS4231_AUX1_RIGHT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX1_RIGHT_INPUT]);
496 snd_cs4231_dout(chip, CS4231_AUX2_LEFT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX2_LEFT_INPUT]);
497 snd_cs4231_dout(chip, CS4231_AUX2_RIGHT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX2_RIGHT_INPUT]);
498 snd_cs4231_dout(chip, CS4231_LEFT_OUTPUT, mute ? 0x80 : chip->image[CS4231_LEFT_OUTPUT]);
499 snd_cs4231_dout(chip, CS4231_RIGHT_OUTPUT, mute ? 0x80 : chip->image[CS4231_RIGHT_OUTPUT]);
500 snd_cs4231_dout(chip, CS4231_LEFT_LINE_IN, mute ? 0x80 : chip->image[CS4231_LEFT_LINE_IN]);
501 snd_cs4231_dout(chip, CS4231_RIGHT_LINE_IN, mute ? 0x80 : chip->image[CS4231_RIGHT_LINE_IN]);
502 snd_cs4231_dout(chip, CS4231_MONO_CTRL, mute ? 0xc0 : chip->image[CS4231_MONO_CTRL]);
503 if (chip->hardware == CS4231_HW_INTERWAVE) {
504 snd_cs4231_dout(chip, CS4231_LEFT_MIC_INPUT, mute ? 0x80 : chip->image[CS4231_LEFT_MIC_INPUT]);
505 snd_cs4231_dout(chip, CS4231_RIGHT_MIC_INPUT, mute ? 0x80 : chip->image[CS4231_RIGHT_MIC_INPUT]);
506 snd_cs4231_dout(chip, CS4231_LINE_LEFT_OUTPUT, mute ? 0x80 : chip->image[CS4231_LINE_LEFT_OUTPUT]);
507 snd_cs4231_dout(chip, CS4231_LINE_RIGHT_OUTPUT, mute ? 0x80 : chip->image[CS4231_LINE_RIGHT_OUTPUT]);
509 chip->calibrate_mute = mute;
510 spin_unlock_irqrestore(&chip->reg_lock, flags);
513 static void snd_cs4231_playback_format(struct snd_cs4231 *chip,
514 struct snd_pcm_hw_params *params,
520 mutex_lock(&chip->mce_mutex);
521 snd_cs4231_calibrate_mute(chip, 1);
522 if (chip->hardware == CS4231_HW_CS4231A ||
523 (chip->hardware & CS4231_HW_CS4232_MASK)) {
524 spin_lock_irqsave(&chip->reg_lock, flags);
525 if ((chip->image[CS4231_PLAYBK_FORMAT] & 0x0f) == (pdfr & 0x0f)) { /* rate is same? */
526 snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x10);
527 snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, chip->image[CS4231_PLAYBK_FORMAT] = pdfr);
528 snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] &= ~0x10);
529 udelay(100); /* Fixes audible clicks at least on GUS MAX */
532 spin_unlock_irqrestore(&chip->reg_lock, flags);
535 snd_cs4231_mce_up(chip);
536 spin_lock_irqsave(&chip->reg_lock, flags);
537 if (chip->hardware != CS4231_HW_INTERWAVE && !chip->single_dma) {
538 snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT,
539 (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) ?
540 (pdfr & 0xf0) | (chip->image[CS4231_REC_FORMAT] & 0x0f) :
543 snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, chip->image[CS4231_PLAYBK_FORMAT] = pdfr);
545 spin_unlock_irqrestore(&chip->reg_lock, flags);
546 if (chip->hardware == CS4231_HW_OPL3SA2)
547 udelay(100); /* this seems to help */
548 snd_cs4231_mce_down(chip);
550 snd_cs4231_calibrate_mute(chip, 0);
551 mutex_unlock(&chip->mce_mutex);
554 static void snd_cs4231_capture_format(struct snd_cs4231 *chip,
555 struct snd_pcm_hw_params *params,
561 mutex_lock(&chip->mce_mutex);
562 snd_cs4231_calibrate_mute(chip, 1);
563 if (chip->hardware == CS4231_HW_CS4231A ||
564 (chip->hardware & CS4231_HW_CS4232_MASK)) {
565 spin_lock_irqsave(&chip->reg_lock, flags);
566 if ((chip->image[CS4231_PLAYBK_FORMAT] & 0x0f) == (cdfr & 0x0f) || /* rate is same? */
567 (chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) {
568 snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x20);
569 snd_cs4231_out(chip, CS4231_REC_FORMAT, chip->image[CS4231_REC_FORMAT] = cdfr);
570 snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] &= ~0x20);
573 spin_unlock_irqrestore(&chip->reg_lock, flags);
576 snd_cs4231_mce_up(chip);
577 spin_lock_irqsave(&chip->reg_lock, flags);
578 if (chip->hardware != CS4231_HW_INTERWAVE) {
579 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) {
580 snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT,
581 ((chip->single_dma ? cdfr : chip->image[CS4231_PLAYBK_FORMAT]) & 0xf0) |
583 spin_unlock_irqrestore(&chip->reg_lock, flags);
584 snd_cs4231_mce_down(chip);
585 snd_cs4231_mce_up(chip);
586 spin_lock_irqsave(&chip->reg_lock, flags);
589 snd_cs4231_out(chip, CS4231_REC_FORMAT, cdfr);
590 spin_unlock_irqrestore(&chip->reg_lock, flags);
591 snd_cs4231_mce_down(chip);
593 snd_cs4231_calibrate_mute(chip, 0);
594 mutex_unlock(&chip->mce_mutex);
601 static unsigned long snd_cs4231_timer_resolution(struct snd_timer * timer)
603 struct snd_cs4231 *chip = snd_timer_chip(timer);
604 if (chip->hardware & CS4231_HW_CS4236B_MASK)
607 return chip->image[CS4231_PLAYBK_FORMAT] & 1 ? 9969 : 9920;
610 static int snd_cs4231_timer_start(struct snd_timer * timer)
614 struct snd_cs4231 *chip = snd_timer_chip(timer);
615 spin_lock_irqsave(&chip->reg_lock, flags);
616 ticks = timer->sticks;
617 if ((chip->image[CS4231_ALT_FEATURE_1] & CS4231_TIMER_ENABLE) == 0 ||
618 (unsigned char)(ticks >> 8) != chip->image[CS4231_TIMER_HIGH] ||
619 (unsigned char)ticks != chip->image[CS4231_TIMER_LOW]) {
620 snd_cs4231_out(chip, CS4231_TIMER_HIGH, chip->image[CS4231_TIMER_HIGH] = (unsigned char) (ticks >> 8));
621 snd_cs4231_out(chip, CS4231_TIMER_LOW, chip->image[CS4231_TIMER_LOW] = (unsigned char) ticks);
622 snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | CS4231_TIMER_ENABLE);
624 spin_unlock_irqrestore(&chip->reg_lock, flags);
628 static int snd_cs4231_timer_stop(struct snd_timer * timer)
631 struct snd_cs4231 *chip = snd_timer_chip(timer);
632 spin_lock_irqsave(&chip->reg_lock, flags);
633 snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] &= ~CS4231_TIMER_ENABLE);
634 spin_unlock_irqrestore(&chip->reg_lock, flags);
638 static void snd_cs4231_init(struct snd_cs4231 *chip)
642 snd_cs4231_mce_down(chip);
644 #ifdef SNDRV_DEBUG_MCE
645 snd_printk("init: (1)\n");
647 snd_cs4231_mce_up(chip);
648 spin_lock_irqsave(&chip->reg_lock, flags);
649 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO |
650 CS4231_RECORD_ENABLE | CS4231_RECORD_PIO |
652 chip->image[CS4231_IFACE_CTRL] |= CS4231_AUTOCALIB;
653 snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
654 spin_unlock_irqrestore(&chip->reg_lock, flags);
655 snd_cs4231_mce_down(chip);
657 #ifdef SNDRV_DEBUG_MCE
658 snd_printk("init: (2)\n");
661 snd_cs4231_mce_up(chip);
662 spin_lock_irqsave(&chip->reg_lock, flags);
663 snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1]);
664 spin_unlock_irqrestore(&chip->reg_lock, flags);
665 snd_cs4231_mce_down(chip);
667 #ifdef SNDRV_DEBUG_MCE
668 snd_printk("init: (3) - afei = 0x%x\n", chip->image[CS4231_ALT_FEATURE_1]);
671 spin_lock_irqsave(&chip->reg_lock, flags);
672 snd_cs4231_out(chip, CS4231_ALT_FEATURE_2, chip->image[CS4231_ALT_FEATURE_2]);
673 spin_unlock_irqrestore(&chip->reg_lock, flags);
675 snd_cs4231_mce_up(chip);
676 spin_lock_irqsave(&chip->reg_lock, flags);
677 snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, chip->image[CS4231_PLAYBK_FORMAT]);
678 spin_unlock_irqrestore(&chip->reg_lock, flags);
679 snd_cs4231_mce_down(chip);
681 #ifdef SNDRV_DEBUG_MCE
682 snd_printk("init: (4)\n");
685 snd_cs4231_mce_up(chip);
686 spin_lock_irqsave(&chip->reg_lock, flags);
687 snd_cs4231_out(chip, CS4231_REC_FORMAT, chip->image[CS4231_REC_FORMAT]);
688 spin_unlock_irqrestore(&chip->reg_lock, flags);
689 snd_cs4231_mce_down(chip);
691 #ifdef SNDRV_DEBUG_MCE
692 snd_printk("init: (5)\n");
696 static int snd_cs4231_open(struct snd_cs4231 *chip, unsigned int mode)
700 mutex_lock(&chip->open_mutex);
701 if ((chip->mode & mode) ||
702 ((chip->mode & CS4231_MODE_OPEN) && chip->single_dma)) {
703 mutex_unlock(&chip->open_mutex);
706 if (chip->mode & CS4231_MODE_OPEN) {
708 mutex_unlock(&chip->open_mutex);
711 /* ok. now enable and ack CODEC IRQ */
712 spin_lock_irqsave(&chip->reg_lock, flags);
713 snd_cs4231_out(chip, CS4231_IRQ_STATUS, CS4231_PLAYBACK_IRQ |
716 snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
717 cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
718 cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
719 chip->image[CS4231_PIN_CTRL] |= CS4231_IRQ_ENABLE;
720 snd_cs4231_out(chip, CS4231_PIN_CTRL, chip->image[CS4231_PIN_CTRL]);
721 snd_cs4231_out(chip, CS4231_IRQ_STATUS, CS4231_PLAYBACK_IRQ |
724 snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
725 spin_unlock_irqrestore(&chip->reg_lock, flags);
728 mutex_unlock(&chip->open_mutex);
732 static void snd_cs4231_close(struct snd_cs4231 *chip, unsigned int mode)
736 mutex_lock(&chip->open_mutex);
738 if (chip->mode & CS4231_MODE_OPEN) {
739 mutex_unlock(&chip->open_mutex);
742 snd_cs4231_calibrate_mute(chip, 1);
745 spin_lock_irqsave(&chip->reg_lock, flags);
746 snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
747 cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
748 cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
749 chip->image[CS4231_PIN_CTRL] &= ~CS4231_IRQ_ENABLE;
750 snd_cs4231_out(chip, CS4231_PIN_CTRL, chip->image[CS4231_PIN_CTRL]);
752 /* now disable record & playback */
754 if (chip->image[CS4231_IFACE_CTRL] & (CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO |
755 CS4231_RECORD_ENABLE | CS4231_RECORD_PIO)) {
756 spin_unlock_irqrestore(&chip->reg_lock, flags);
757 snd_cs4231_mce_up(chip);
758 spin_lock_irqsave(&chip->reg_lock, flags);
759 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO |
760 CS4231_RECORD_ENABLE | CS4231_RECORD_PIO);
761 snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
762 spin_unlock_irqrestore(&chip->reg_lock, flags);
763 snd_cs4231_mce_down(chip);
764 spin_lock_irqsave(&chip->reg_lock, flags);
767 /* clear IRQ again */
768 snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
769 cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
770 cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
771 spin_unlock_irqrestore(&chip->reg_lock, flags);
773 snd_cs4231_calibrate_mute(chip, 0);
776 mutex_unlock(&chip->open_mutex);
783 static int snd_cs4231_timer_open(struct snd_timer * timer)
785 struct snd_cs4231 *chip = snd_timer_chip(timer);
786 snd_cs4231_open(chip, CS4231_MODE_TIMER);
790 static int snd_cs4231_timer_close(struct snd_timer * timer)
792 struct snd_cs4231 *chip = snd_timer_chip(timer);
793 snd_cs4231_close(chip, CS4231_MODE_TIMER);
797 static struct snd_timer_hardware snd_cs4231_timer_table =
799 .flags = SNDRV_TIMER_HW_AUTO,
802 .open = snd_cs4231_timer_open,
803 .close = snd_cs4231_timer_close,
804 .c_resolution = snd_cs4231_timer_resolution,
805 .start = snd_cs4231_timer_start,
806 .stop = snd_cs4231_timer_stop,
810 * ok.. exported functions..
813 static int snd_cs4231_playback_hw_params(struct snd_pcm_substream *substream,
814 struct snd_pcm_hw_params *hw_params)
816 struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
817 unsigned char new_pdfr;
820 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
822 new_pdfr = snd_cs4231_get_format(chip, params_format(hw_params), params_channels(hw_params)) |
823 snd_cs4231_get_rate(params_rate(hw_params));
824 chip->set_playback_format(chip, hw_params, new_pdfr);
828 static int snd_cs4231_playback_hw_free(struct snd_pcm_substream *substream)
830 return snd_pcm_lib_free_pages(substream);
833 static int snd_cs4231_playback_prepare(struct snd_pcm_substream *substream)
835 struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
836 struct snd_pcm_runtime *runtime = substream->runtime;
838 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
839 unsigned int count = snd_pcm_lib_period_bytes(substream);
841 spin_lock_irqsave(&chip->reg_lock, flags);
842 chip->p_dma_size = size;
843 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO);
844 snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
845 count = snd_cs4231_get_count(chip->image[CS4231_PLAYBK_FORMAT], count) - 1;
846 snd_cs4231_out(chip, CS4231_PLY_LWR_CNT, (unsigned char) count);
847 snd_cs4231_out(chip, CS4231_PLY_UPR_CNT, (unsigned char) (count >> 8));
848 spin_unlock_irqrestore(&chip->reg_lock, flags);
850 snd_cs4231_debug(chip);
855 static int snd_cs4231_capture_hw_params(struct snd_pcm_substream *substream,
856 struct snd_pcm_hw_params *hw_params)
858 struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
859 unsigned char new_cdfr;
862 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
864 new_cdfr = snd_cs4231_get_format(chip, params_format(hw_params), params_channels(hw_params)) |
865 snd_cs4231_get_rate(params_rate(hw_params));
866 chip->set_capture_format(chip, hw_params, new_cdfr);
870 static int snd_cs4231_capture_hw_free(struct snd_pcm_substream *substream)
872 return snd_pcm_lib_free_pages(substream);
875 static int snd_cs4231_capture_prepare(struct snd_pcm_substream *substream)
877 struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
878 struct snd_pcm_runtime *runtime = substream->runtime;
880 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
881 unsigned int count = snd_pcm_lib_period_bytes(substream);
883 spin_lock_irqsave(&chip->reg_lock, flags);
884 chip->c_dma_size = size;
885 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_RECORD_ENABLE | CS4231_RECORD_PIO);
886 snd_dma_program(chip->dma2, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
887 count = snd_cs4231_get_count(chip->image[CS4231_REC_FORMAT], count) - 1;
888 if (chip->single_dma && chip->hardware != CS4231_HW_INTERWAVE) {
889 snd_cs4231_out(chip, CS4231_PLY_LWR_CNT, (unsigned char) count);
890 snd_cs4231_out(chip, CS4231_PLY_UPR_CNT, (unsigned char) (count >> 8));
892 snd_cs4231_out(chip, CS4231_REC_LWR_CNT, (unsigned char) count);
893 snd_cs4231_out(chip, CS4231_REC_UPR_CNT, (unsigned char) (count >> 8));
895 spin_unlock_irqrestore(&chip->reg_lock, flags);
899 static void snd_cs4231_overrange(struct snd_cs4231 *chip)
904 spin_lock_irqsave(&chip->reg_lock, flags);
905 res = snd_cs4231_in(chip, CS4231_TEST_INIT);
906 spin_unlock_irqrestore(&chip->reg_lock, flags);
907 if (res & (0x08 | 0x02)) /* detect overrange only above 0dB; may be user selectable? */
908 chip->capture_substream->runtime->overrange++;
911 irqreturn_t snd_cs4231_interrupt(int irq, void *dev_id)
913 struct snd_cs4231 *chip = dev_id;
914 unsigned char status;
916 status = snd_cs4231_in(chip, CS4231_IRQ_STATUS);
917 if (status & CS4231_TIMER_IRQ) {
919 snd_timer_interrupt(chip->timer, chip->timer->sticks);
921 if (chip->single_dma && chip->hardware != CS4231_HW_INTERWAVE) {
922 if (status & CS4231_PLAYBACK_IRQ) {
923 if (chip->mode & CS4231_MODE_PLAY) {
924 if (chip->playback_substream)
925 snd_pcm_period_elapsed(chip->playback_substream);
927 if (chip->mode & CS4231_MODE_RECORD) {
928 if (chip->capture_substream) {
929 snd_cs4231_overrange(chip);
930 snd_pcm_period_elapsed(chip->capture_substream);
935 if (status & CS4231_PLAYBACK_IRQ) {
936 if (chip->playback_substream)
937 snd_pcm_period_elapsed(chip->playback_substream);
939 if (status & CS4231_RECORD_IRQ) {
940 if (chip->capture_substream) {
941 snd_cs4231_overrange(chip);
942 snd_pcm_period_elapsed(chip->capture_substream);
947 spin_lock(&chip->reg_lock);
948 snd_cs4231_outm(chip, CS4231_IRQ_STATUS, ~CS4231_ALL_IRQS | ~status, 0);
949 spin_unlock(&chip->reg_lock);
953 static snd_pcm_uframes_t snd_cs4231_playback_pointer(struct snd_pcm_substream *substream)
955 struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
958 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE))
960 ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size);
961 return bytes_to_frames(substream->runtime, ptr);
964 static snd_pcm_uframes_t snd_cs4231_capture_pointer(struct snd_pcm_substream *substream)
966 struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
969 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE))
971 ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size);
972 return bytes_to_frames(substream->runtime, ptr);
979 static int snd_cs4231_probe(struct snd_cs4231 *chip)
987 snd_cs4231_debug(chip);
990 for (i = 0; i < 50; i++) {
992 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
995 spin_lock_irqsave(&chip->reg_lock, flags);
996 snd_cs4231_out(chip, CS4231_MISC_INFO, CS4231_MODE2);
997 id = snd_cs4231_in(chip, CS4231_MISC_INFO) & 0x0f;
998 spin_unlock_irqrestore(&chip->reg_lock, flags);
1000 break; /* this is valid value */
1003 snd_printdd("cs4231: port = 0x%lx, id = 0x%x\n", chip->port, id);
1005 return -ENODEV; /* no valid device found */
1007 if (((hw = chip->hardware) & CS4231_HW_TYPE_MASK) == CS4231_HW_DETECT) {
1008 rev = snd_cs4231_in(chip, CS4231_VERSION) & 0xe7;
1009 snd_printdd("CS4231: VERSION (I25) = 0x%x\n", rev);
1011 unsigned char tmp = snd_cs4231_in(chip, 23);
1012 snd_cs4231_out(chip, 23, ~tmp);
1013 if (snd_cs4231_in(chip, 23) != tmp)
1014 chip->hardware = CS4231_HW_AD1845;
1016 chip->hardware = CS4231_HW_CS4231;
1017 } else if (rev == 0xa0) {
1018 chip->hardware = CS4231_HW_CS4231A;
1019 } else if (rev == 0xa2) {
1020 chip->hardware = CS4231_HW_CS4232;
1021 } else if (rev == 0xb2) {
1022 chip->hardware = CS4231_HW_CS4232A;
1023 } else if (rev == 0x83) {
1024 chip->hardware = CS4231_HW_CS4236;
1025 } else if (rev == 0x03) {
1026 chip->hardware = CS4231_HW_CS4236B;
1028 snd_printk("unknown CS chip with version 0x%x\n", rev);
1029 return -ENODEV; /* unknown CS4231 chip? */
1032 spin_lock_irqsave(&chip->reg_lock, flags);
1033 cs4231_inb(chip, CS4231P(STATUS)); /* clear any pendings IRQ */
1034 cs4231_outb(chip, CS4231P(STATUS), 0);
1036 spin_unlock_irqrestore(&chip->reg_lock, flags);
1038 chip->image[CS4231_MISC_INFO] = CS4231_MODE2;
1039 switch (chip->hardware) {
1040 case CS4231_HW_INTERWAVE:
1041 chip->image[CS4231_MISC_INFO] = CS4231_IW_MODE3;
1043 case CS4231_HW_CS4235:
1044 case CS4231_HW_CS4236B:
1045 case CS4231_HW_CS4237B:
1046 case CS4231_HW_CS4238B:
1047 case CS4231_HW_CS4239:
1048 if (hw == CS4231_HW_DETECT3)
1049 chip->image[CS4231_MISC_INFO] = CS4231_4236_MODE3;
1051 chip->hardware = CS4231_HW_CS4236;
1055 chip->image[CS4231_IFACE_CTRL] =
1056 (chip->image[CS4231_IFACE_CTRL] & ~CS4231_SINGLE_DMA) |
1057 (chip->single_dma ? CS4231_SINGLE_DMA : 0);
1058 chip->image[CS4231_ALT_FEATURE_1] = 0x80;
1059 chip->image[CS4231_ALT_FEATURE_2] = chip->hardware == CS4231_HW_INTERWAVE ? 0xc2 : 0x01;
1060 ptr = (unsigned char *) &chip->image;
1061 snd_cs4231_mce_down(chip);
1062 spin_lock_irqsave(&chip->reg_lock, flags);
1063 for (i = 0; i < 32; i++) /* ok.. fill all CS4231 registers */
1064 snd_cs4231_out(chip, i, *ptr++);
1065 spin_unlock_irqrestore(&chip->reg_lock, flags);
1066 snd_cs4231_mce_up(chip);
1067 snd_cs4231_mce_down(chip);
1071 /* ok.. try check hardware version for CS4236+ chips */
1072 if ((hw & CS4231_HW_TYPE_MASK) == CS4231_HW_DETECT) {
1073 if (chip->hardware == CS4231_HW_CS4236B) {
1074 rev = snd_cs4236_ext_in(chip, CS4236_VERSION);
1075 snd_cs4236_ext_out(chip, CS4236_VERSION, 0xff);
1076 id = snd_cs4236_ext_in(chip, CS4236_VERSION);
1077 snd_cs4236_ext_out(chip, CS4236_VERSION, rev);
1078 snd_printdd("CS4231: ext version; rev = 0x%x, id = 0x%x\n", rev, id);
1079 if ((id & 0x1f) == 0x1d) { /* CS4235 */
1080 chip->hardware = CS4231_HW_CS4235;
1087 snd_printk("unknown CS4235 chip (enhanced version = 0x%x)\n", id);
1089 } else if ((id & 0x1f) == 0x0b) { /* CS4236/B */
1095 chip->hardware = CS4231_HW_CS4236B;
1098 snd_printk("unknown CS4236 chip (enhanced version = 0x%x)\n", id);
1100 } else if ((id & 0x1f) == 0x08) { /* CS4237B */
1101 chip->hardware = CS4231_HW_CS4237B;
1109 snd_printk("unknown CS4237B chip (enhanced version = 0x%x)\n", id);
1111 } else if ((id & 0x1f) == 0x09) { /* CS4238B */
1112 chip->hardware = CS4231_HW_CS4238B;
1119 snd_printk("unknown CS4238B chip (enhanced version = 0x%x)\n", id);
1121 } else if ((id & 0x1f) == 0x1e) { /* CS4239 */
1122 chip->hardware = CS4231_HW_CS4239;
1129 snd_printk("unknown CS4239 chip (enhanced version = 0x%x)\n", id);
1132 snd_printk("unknown CS4236/CS423xB chip (enhanced version = 0x%x)\n", id);
1136 return 0; /* all things are ok.. */
1143 static struct snd_pcm_hardware snd_cs4231_playback =
1145 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1146 SNDRV_PCM_INFO_MMAP_VALID |
1147 SNDRV_PCM_INFO_RESUME |
1148 SNDRV_PCM_INFO_SYNC_START),
1149 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
1150 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
1151 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
1156 .buffer_bytes_max = (128*1024),
1157 .period_bytes_min = 64,
1158 .period_bytes_max = (128*1024),
1160 .periods_max = 1024,
1164 static struct snd_pcm_hardware snd_cs4231_capture =
1166 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1167 SNDRV_PCM_INFO_MMAP_VALID |
1168 SNDRV_PCM_INFO_RESUME |
1169 SNDRV_PCM_INFO_SYNC_START),
1170 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
1171 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
1172 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
1177 .buffer_bytes_max = (128*1024),
1178 .period_bytes_min = 64,
1179 .period_bytes_max = (128*1024),
1181 .periods_max = 1024,
1189 static int snd_cs4231_playback_open(struct snd_pcm_substream *substream)
1191 struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
1192 struct snd_pcm_runtime *runtime = substream->runtime;
1195 runtime->hw = snd_cs4231_playback;
1197 /* hardware bug in InterWave chipset */
1198 if (chip->hardware == CS4231_HW_INTERWAVE && chip->dma1 > 3)
1199 runtime->hw.formats &= ~SNDRV_PCM_FMTBIT_MU_LAW;
1201 /* hardware limitation of cheap chips */
1202 if (chip->hardware == CS4231_HW_CS4235 ||
1203 chip->hardware == CS4231_HW_CS4239)
1204 runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE;
1206 snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max);
1207 snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.period_bytes_max);
1209 if (chip->claim_dma) {
1210 if ((err = chip->claim_dma(chip, chip->dma_private_data, chip->dma1)) < 0)
1214 if ((err = snd_cs4231_open(chip, CS4231_MODE_PLAY)) < 0) {
1215 if (chip->release_dma)
1216 chip->release_dma(chip, chip->dma_private_data, chip->dma1);
1217 snd_free_pages(runtime->dma_area, runtime->dma_bytes);
1220 chip->playback_substream = substream;
1221 snd_pcm_set_sync(substream);
1222 chip->rate_constraint(runtime);
1226 static int snd_cs4231_capture_open(struct snd_pcm_substream *substream)
1228 struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
1229 struct snd_pcm_runtime *runtime = substream->runtime;
1232 runtime->hw = snd_cs4231_capture;
1234 /* hardware limitation of cheap chips */
1235 if (chip->hardware == CS4231_HW_CS4235 ||
1236 chip->hardware == CS4231_HW_CS4239)
1237 runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE;
1239 snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max);
1240 snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.period_bytes_max);
1242 if (chip->claim_dma) {
1243 if ((err = chip->claim_dma(chip, chip->dma_private_data, chip->dma2)) < 0)
1247 if ((err = snd_cs4231_open(chip, CS4231_MODE_RECORD)) < 0) {
1248 if (chip->release_dma)
1249 chip->release_dma(chip, chip->dma_private_data, chip->dma2);
1250 snd_free_pages(runtime->dma_area, runtime->dma_bytes);
1253 chip->capture_substream = substream;
1254 snd_pcm_set_sync(substream);
1255 chip->rate_constraint(runtime);
1259 static int snd_cs4231_playback_close(struct snd_pcm_substream *substream)
1261 struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
1263 chip->playback_substream = NULL;
1264 snd_cs4231_close(chip, CS4231_MODE_PLAY);
1268 static int snd_cs4231_capture_close(struct snd_pcm_substream *substream)
1270 struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
1272 chip->capture_substream = NULL;
1273 snd_cs4231_close(chip, CS4231_MODE_RECORD);
1279 /* lowlevel suspend callback for CS4231 */
1280 static void snd_cs4231_suspend(struct snd_cs4231 *chip)
1283 unsigned long flags;
1285 snd_pcm_suspend_all(chip->pcm);
1286 spin_lock_irqsave(&chip->reg_lock, flags);
1287 for (reg = 0; reg < 32; reg++)
1288 chip->image[reg] = snd_cs4231_in(chip, reg);
1289 spin_unlock_irqrestore(&chip->reg_lock, flags);
1292 /* lowlevel resume callback for CS4231 */
1293 static void snd_cs4231_resume(struct snd_cs4231 *chip)
1296 unsigned long flags;
1299 snd_cs4231_mce_up(chip);
1300 spin_lock_irqsave(&chip->reg_lock, flags);
1301 for (reg = 0; reg < 32; reg++) {
1303 case CS4231_VERSION:
1306 snd_cs4231_out(chip, reg, chip->image[reg]);
1310 spin_unlock_irqrestore(&chip->reg_lock, flags);
1312 snd_cs4231_mce_down(chip);
1314 /* The following is a workaround to avoid freeze after resume on TP600E.
1315 This is the first half of copy of snd_cs4231_mce_down(), but doesn't
1316 include rescheduling. -- iwai
1318 snd_cs4231_busy_wait(chip);
1319 spin_lock_irqsave(&chip->reg_lock, flags);
1320 chip->mce_bit &= ~CS4231_MCE;
1321 timeout = cs4231_inb(chip, CS4231P(REGSEL));
1322 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
1323 spin_unlock_irqrestore(&chip->reg_lock, flags);
1324 if (timeout == 0x80)
1325 snd_printk("down [0x%lx]: serious init problem - codec still busy\n", chip->port);
1326 if ((timeout & CS4231_MCE) == 0 ||
1327 !(chip->hardware & (CS4231_HW_CS4231_MASK | CS4231_HW_CS4232_MASK))) {
1330 snd_cs4231_busy_wait(chip);
1333 #endif /* CONFIG_PM */
1335 static int snd_cs4231_free(struct snd_cs4231 *chip)
1337 release_and_free_resource(chip->res_port);
1338 release_and_free_resource(chip->res_cport);
1339 if (chip->irq >= 0) {
1340 disable_irq(chip->irq);
1341 if (!(chip->hwshare & CS4231_HWSHARE_IRQ))
1342 free_irq(chip->irq, (void *) chip);
1344 if (!(chip->hwshare & CS4231_HWSHARE_DMA1) && chip->dma1 >= 0) {
1345 snd_dma_disable(chip->dma1);
1346 free_dma(chip->dma1);
1348 if (!(chip->hwshare & CS4231_HWSHARE_DMA2) && chip->dma2 >= 0 && chip->dma2 != chip->dma1) {
1349 snd_dma_disable(chip->dma2);
1350 free_dma(chip->dma2);
1353 snd_device_free(chip->card, chip->timer);
1358 static int snd_cs4231_dev_free(struct snd_device *device)
1360 struct snd_cs4231 *chip = device->device_data;
1361 return snd_cs4231_free(chip);
1364 const char *snd_cs4231_chip_id(struct snd_cs4231 *chip)
1366 switch (chip->hardware) {
1367 case CS4231_HW_CS4231: return "CS4231";
1368 case CS4231_HW_CS4231A: return "CS4231A";
1369 case CS4231_HW_CS4232: return "CS4232";
1370 case CS4231_HW_CS4232A: return "CS4232A";
1371 case CS4231_HW_CS4235: return "CS4235";
1372 case CS4231_HW_CS4236: return "CS4236";
1373 case CS4231_HW_CS4236B: return "CS4236B";
1374 case CS4231_HW_CS4237B: return "CS4237B";
1375 case CS4231_HW_CS4238B: return "CS4238B";
1376 case CS4231_HW_CS4239: return "CS4239";
1377 case CS4231_HW_INTERWAVE: return "AMD InterWave";
1378 case CS4231_HW_OPL3SA2: return chip->card->shortname;
1379 case CS4231_HW_AD1845: return "AD1845";
1380 default: return "???";
1384 static int snd_cs4231_new(struct snd_card *card,
1385 unsigned short hardware,
1386 unsigned short hwshare,
1387 struct snd_cs4231 ** rchip)
1389 struct snd_cs4231 *chip;
1392 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1395 chip->hardware = hardware;
1396 chip->hwshare = hwshare;
1398 spin_lock_init(&chip->reg_lock);
1399 mutex_init(&chip->mce_mutex);
1400 mutex_init(&chip->open_mutex);
1402 chip->rate_constraint = snd_cs4231_xrate;
1403 chip->set_playback_format = snd_cs4231_playback_format;
1404 chip->set_capture_format = snd_cs4231_capture_format;
1405 memcpy(&chip->image, &snd_cs4231_original_image, sizeof(snd_cs4231_original_image));
1411 int snd_cs4231_create(struct snd_card *card,
1413 unsigned long cport,
1414 int irq, int dma1, int dma2,
1415 unsigned short hardware,
1416 unsigned short hwshare,
1417 struct snd_cs4231 ** rchip)
1419 static struct snd_device_ops ops = {
1420 .dev_free = snd_cs4231_dev_free,
1422 struct snd_cs4231 *chip;
1425 err = snd_cs4231_new(card, hardware, hwshare, &chip);
1433 if ((chip->res_port = request_region(port, 4, "CS4231")) == NULL) {
1434 snd_printk(KERN_ERR "cs4231: can't grab port 0x%lx\n", port);
1435 snd_cs4231_free(chip);
1439 if ((long)cport >= 0 && (chip->res_cport = request_region(cport, 8, "CS4232 Control")) == NULL) {
1440 snd_printk(KERN_ERR "cs4231: can't grab control port 0x%lx\n", cport);
1441 snd_cs4231_free(chip);
1444 chip->cport = cport;
1445 if (!(hwshare & CS4231_HWSHARE_IRQ) && request_irq(irq, snd_cs4231_interrupt, IRQF_DISABLED, "CS4231", (void *) chip)) {
1446 snd_printk(KERN_ERR "cs4231: can't grab IRQ %d\n", irq);
1447 snd_cs4231_free(chip);
1451 if (!(hwshare & CS4231_HWSHARE_DMA1) && request_dma(dma1, "CS4231 - 1")) {
1452 snd_printk(KERN_ERR "cs4231: can't grab DMA1 %d\n", dma1);
1453 snd_cs4231_free(chip);
1457 if (!(hwshare & CS4231_HWSHARE_DMA2) && dma1 != dma2 && dma2 >= 0 && request_dma(dma2, "CS4231 - 2")) {
1458 snd_printk(KERN_ERR "cs4231: can't grab DMA2 %d\n", dma2);
1459 snd_cs4231_free(chip);
1462 if (dma1 == dma2 || dma2 < 0) {
1463 chip->single_dma = 1;
1464 chip->dma2 = chip->dma1;
1469 if (snd_cs4231_probe(chip) < 0) {
1470 snd_cs4231_free(chip);
1473 snd_cs4231_init(chip);
1476 if (chip->hardware & CS4231_HW_CS4232_MASK) {
1477 if (chip->res_cport == NULL)
1478 snd_printk("CS4232 control port features are not accessible\n");
1482 /* Register device */
1483 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1484 snd_cs4231_free(chip);
1489 /* Power Management */
1490 chip->suspend = snd_cs4231_suspend;
1491 chip->resume = snd_cs4231_resume;
1498 static struct snd_pcm_ops snd_cs4231_playback_ops = {
1499 .open = snd_cs4231_playback_open,
1500 .close = snd_cs4231_playback_close,
1501 .ioctl = snd_pcm_lib_ioctl,
1502 .hw_params = snd_cs4231_playback_hw_params,
1503 .hw_free = snd_cs4231_playback_hw_free,
1504 .prepare = snd_cs4231_playback_prepare,
1505 .trigger = snd_cs4231_trigger,
1506 .pointer = snd_cs4231_playback_pointer,
1509 static struct snd_pcm_ops snd_cs4231_capture_ops = {
1510 .open = snd_cs4231_capture_open,
1511 .close = snd_cs4231_capture_close,
1512 .ioctl = snd_pcm_lib_ioctl,
1513 .hw_params = snd_cs4231_capture_hw_params,
1514 .hw_free = snd_cs4231_capture_hw_free,
1515 .prepare = snd_cs4231_capture_prepare,
1516 .trigger = snd_cs4231_trigger,
1517 .pointer = snd_cs4231_capture_pointer,
1520 int snd_cs4231_pcm(struct snd_cs4231 *chip, int device, struct snd_pcm **rpcm)
1522 struct snd_pcm *pcm;
1525 if ((err = snd_pcm_new(chip->card, "CS4231", device, 1, 1, &pcm)) < 0)
1528 spin_lock_init(&chip->reg_lock);
1529 mutex_init(&chip->mce_mutex);
1530 mutex_init(&chip->open_mutex);
1532 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs4231_playback_ops);
1533 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cs4231_capture_ops);
1536 pcm->private_data = chip;
1537 pcm->info_flags = 0;
1538 if (chip->single_dma)
1539 pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX;
1540 if (chip->hardware != CS4231_HW_INTERWAVE)
1541 pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX;
1542 strcpy(pcm->name, snd_cs4231_chip_id(chip));
1544 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1546 64*1024, chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024);
1554 static void snd_cs4231_timer_free(struct snd_timer *timer)
1556 struct snd_cs4231 *chip = timer->private_data;
1560 int snd_cs4231_timer(struct snd_cs4231 *chip, int device, struct snd_timer **rtimer)
1562 struct snd_timer *timer;
1563 struct snd_timer_id tid;
1566 /* Timer initialization */
1567 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
1568 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
1569 tid.card = chip->card->number;
1570 tid.device = device;
1572 if ((err = snd_timer_new(chip->card, "CS4231", &tid, &timer)) < 0)
1574 strcpy(timer->name, snd_cs4231_chip_id(chip));
1575 timer->private_data = chip;
1576 timer->private_free = snd_cs4231_timer_free;
1577 timer->hw = snd_cs4231_timer_table;
1578 chip->timer = timer;
1588 static int snd_cs4231_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1590 static char *texts[4] = {
1591 "Line", "Aux", "Mic", "Mix"
1593 static char *opl3sa_texts[4] = {
1594 "Line", "CD", "Mic", "Mix"
1596 static char *gusmax_texts[4] = {
1597 "Line", "Synth", "Mic", "Mix"
1599 char **ptexts = texts;
1600 struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
1602 snd_assert(chip->card != NULL, return -EINVAL);
1603 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1605 uinfo->value.enumerated.items = 4;
1606 if (uinfo->value.enumerated.item > 3)
1607 uinfo->value.enumerated.item = 3;
1608 if (!strcmp(chip->card->driver, "GUS MAX"))
1609 ptexts = gusmax_texts;
1610 switch (chip->hardware) {
1611 case CS4231_HW_INTERWAVE: ptexts = gusmax_texts; break;
1612 case CS4231_HW_OPL3SA2: ptexts = opl3sa_texts; break;
1614 strcpy(uinfo->value.enumerated.name, ptexts[uinfo->value.enumerated.item]);
1618 static int snd_cs4231_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1620 struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
1621 unsigned long flags;
1623 spin_lock_irqsave(&chip->reg_lock, flags);
1624 ucontrol->value.enumerated.item[0] = (chip->image[CS4231_LEFT_INPUT] & CS4231_MIXS_ALL) >> 6;
1625 ucontrol->value.enumerated.item[1] = (chip->image[CS4231_RIGHT_INPUT] & CS4231_MIXS_ALL) >> 6;
1626 spin_unlock_irqrestore(&chip->reg_lock, flags);
1630 static int snd_cs4231_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1632 struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
1633 unsigned long flags;
1634 unsigned short left, right;
1637 if (ucontrol->value.enumerated.item[0] > 3 ||
1638 ucontrol->value.enumerated.item[1] > 3)
1640 left = ucontrol->value.enumerated.item[0] << 6;
1641 right = ucontrol->value.enumerated.item[1] << 6;
1642 spin_lock_irqsave(&chip->reg_lock, flags);
1643 left = (chip->image[CS4231_LEFT_INPUT] & ~CS4231_MIXS_ALL) | left;
1644 right = (chip->image[CS4231_RIGHT_INPUT] & ~CS4231_MIXS_ALL) | right;
1645 change = left != chip->image[CS4231_LEFT_INPUT] ||
1646 right != chip->image[CS4231_RIGHT_INPUT];
1647 snd_cs4231_out(chip, CS4231_LEFT_INPUT, left);
1648 snd_cs4231_out(chip, CS4231_RIGHT_INPUT, right);
1649 spin_unlock_irqrestore(&chip->reg_lock, flags);
1653 int snd_cs4231_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1655 int mask = (kcontrol->private_value >> 16) & 0xff;
1657 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1659 uinfo->value.integer.min = 0;
1660 uinfo->value.integer.max = mask;
1664 int snd_cs4231_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1666 struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
1667 unsigned long flags;
1668 int reg = kcontrol->private_value & 0xff;
1669 int shift = (kcontrol->private_value >> 8) & 0xff;
1670 int mask = (kcontrol->private_value >> 16) & 0xff;
1671 int invert = (kcontrol->private_value >> 24) & 0xff;
1673 spin_lock_irqsave(&chip->reg_lock, flags);
1674 ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask;
1675 spin_unlock_irqrestore(&chip->reg_lock, flags);
1677 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1681 int snd_cs4231_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1683 struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
1684 unsigned long flags;
1685 int reg = kcontrol->private_value & 0xff;
1686 int shift = (kcontrol->private_value >> 8) & 0xff;
1687 int mask = (kcontrol->private_value >> 16) & 0xff;
1688 int invert = (kcontrol->private_value >> 24) & 0xff;
1692 val = (ucontrol->value.integer.value[0] & mask);
1696 spin_lock_irqsave(&chip->reg_lock, flags);
1697 val = (chip->image[reg] & ~(mask << shift)) | val;
1698 change = val != chip->image[reg];
1699 snd_cs4231_out(chip, reg, val);
1700 spin_unlock_irqrestore(&chip->reg_lock, flags);
1704 int snd_cs4231_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1706 int mask = (kcontrol->private_value >> 24) & 0xff;
1708 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1710 uinfo->value.integer.min = 0;
1711 uinfo->value.integer.max = mask;
1715 int snd_cs4231_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1717 struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
1718 unsigned long flags;
1719 int left_reg = kcontrol->private_value & 0xff;
1720 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1721 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1722 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1723 int mask = (kcontrol->private_value >> 24) & 0xff;
1724 int invert = (kcontrol->private_value >> 22) & 1;
1726 spin_lock_irqsave(&chip->reg_lock, flags);
1727 ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
1728 ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask;
1729 spin_unlock_irqrestore(&chip->reg_lock, flags);
1731 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1732 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
1737 int snd_cs4231_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1739 struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
1740 unsigned long flags;
1741 int left_reg = kcontrol->private_value & 0xff;
1742 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1743 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1744 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1745 int mask = (kcontrol->private_value >> 24) & 0xff;
1746 int invert = (kcontrol->private_value >> 22) & 1;
1748 unsigned short val1, val2;
1750 val1 = ucontrol->value.integer.value[0] & mask;
1751 val2 = ucontrol->value.integer.value[1] & mask;
1756 val1 <<= shift_left;
1757 val2 <<= shift_right;
1758 spin_lock_irqsave(&chip->reg_lock, flags);
1759 val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
1760 val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2;
1761 change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg];
1762 snd_cs4231_out(chip, left_reg, val1);
1763 snd_cs4231_out(chip, right_reg, val2);
1764 spin_unlock_irqrestore(&chip->reg_lock, flags);
1768 static struct snd_kcontrol_new snd_cs4231_controls[] = {
1769 CS4231_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
1770 CS4231_DOUBLE("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
1771 CS4231_DOUBLE("Line Playback Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
1772 CS4231_DOUBLE("Line Playback Volume", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1),
1773 CS4231_DOUBLE("Aux Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
1774 CS4231_DOUBLE("Aux Playback Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
1775 CS4231_DOUBLE("Aux Playback Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
1776 CS4231_DOUBLE("Aux Playback Volume", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
1777 CS4231_SINGLE("Mono Playback Switch", 0, CS4231_MONO_CTRL, 7, 1, 1),
1778 CS4231_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1),
1779 CS4231_SINGLE("Mono Output Playback Switch", 0, CS4231_MONO_CTRL, 6, 1, 1),
1780 CS4231_SINGLE("Mono Output Playback Bypass", 0, CS4231_MONO_CTRL, 5, 1, 0),
1781 CS4231_DOUBLE("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
1783 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1784 .name = "Capture Source",
1785 .info = snd_cs4231_info_mux,
1786 .get = snd_cs4231_get_mux,
1787 .put = snd_cs4231_put_mux,
1789 CS4231_DOUBLE("Mic Boost", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
1790 CS4231_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK, 0, 1, 0),
1791 CS4231_SINGLE("Loopback Capture Volume", 0, CS4231_LOOPBACK, 2, 63, 1)
1794 int snd_cs4231_mixer(struct snd_cs4231 *chip)
1796 struct snd_card *card;
1800 snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL);
1804 strcpy(card->mixername, chip->pcm->name);
1806 for (idx = 0; idx < ARRAY_SIZE(snd_cs4231_controls); idx++) {
1807 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4231_controls[idx], chip))) < 0)
1813 EXPORT_SYMBOL(snd_cs4231_out);
1814 EXPORT_SYMBOL(snd_cs4231_in);
1815 EXPORT_SYMBOL(snd_cs4236_ext_out);
1816 EXPORT_SYMBOL(snd_cs4236_ext_in);
1817 EXPORT_SYMBOL(snd_cs4231_mce_up);
1818 EXPORT_SYMBOL(snd_cs4231_mce_down);
1819 EXPORT_SYMBOL(snd_cs4231_interrupt);
1820 EXPORT_SYMBOL(snd_cs4231_chip_id);
1821 EXPORT_SYMBOL(snd_cs4231_create);
1822 EXPORT_SYMBOL(snd_cs4231_pcm);
1823 EXPORT_SYMBOL(snd_cs4231_mixer);
1824 EXPORT_SYMBOL(snd_cs4231_timer);
1825 EXPORT_SYMBOL(snd_cs4231_info_single);
1826 EXPORT_SYMBOL(snd_cs4231_get_single);
1827 EXPORT_SYMBOL(snd_cs4231_put_single);
1828 EXPORT_SYMBOL(snd_cs4231_info_double);
1829 EXPORT_SYMBOL(snd_cs4231_get_double);
1830 EXPORT_SYMBOL(snd_cs4231_put_double);
1836 static int __init alsa_cs4231_init(void)
1841 static void __exit alsa_cs4231_exit(void)
1845 module_init(alsa_cs4231_init)
1846 module_exit(alsa_cs4231_exit)