2 * Copyright (c) by Jaroslav Kysela <perex@suse.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 <sound/driver.h>
28 #include <linux/delay.h>
30 #include <linux/init.h>
31 #include <linux/interrupt.h>
32 #include <linux/slab.h>
33 #include <linux/ioport.h>
34 #include <sound/core.h>
35 #include <sound/cs4231.h>
36 #include <sound/pcm_params.h>
42 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
43 MODULE_DESCRIPTION("Routines for control of CS4231(A)/CS4232/InterWave & compatible chips");
44 MODULE_LICENSE("GPL");
46 #define chip_t cs4231_t
49 #define SNDRV_DEBUG_MCE
56 static unsigned char freq_bits[14] = {
57 /* 5510 */ 0x00 | CS4231_XTAL2,
58 /* 6620 */ 0x0E | CS4231_XTAL2,
59 /* 8000 */ 0x00 | CS4231_XTAL1,
60 /* 9600 */ 0x0E | CS4231_XTAL1,
61 /* 11025 */ 0x02 | CS4231_XTAL2,
62 /* 16000 */ 0x02 | CS4231_XTAL1,
63 /* 18900 */ 0x04 | CS4231_XTAL2,
64 /* 22050 */ 0x06 | CS4231_XTAL2,
65 /* 27042 */ 0x04 | CS4231_XTAL1,
66 /* 32000 */ 0x06 | CS4231_XTAL1,
67 /* 33075 */ 0x0C | CS4231_XTAL2,
68 /* 37800 */ 0x08 | CS4231_XTAL2,
69 /* 44100 */ 0x0A | CS4231_XTAL2,
70 /* 48000 */ 0x0C | CS4231_XTAL1
73 static unsigned int rates[14] = {
74 5510, 6620, 8000, 9600, 11025, 16000, 18900, 22050,
75 27042, 32000, 33075, 37800, 44100, 48000
78 static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
84 static int snd_cs4231_xrate(snd_pcm_runtime_t *runtime)
86 return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
89 static unsigned char snd_cs4231_original_image[32] =
91 0x00, /* 00/00 - lic */
92 0x00, /* 01/01 - ric */
93 0x9f, /* 02/02 - la1ic */
94 0x9f, /* 03/03 - ra1ic */
95 0x9f, /* 04/04 - la2ic */
96 0x9f, /* 05/05 - ra2ic */
97 0xbf, /* 06/06 - loc */
98 0xbf, /* 07/07 - roc */
99 0x20, /* 08/08 - pdfr */
100 CS4231_AUTOCALIB, /* 09/09 - ic */
101 0x00, /* 0a/10 - pc */
102 0x00, /* 0b/11 - ti */
103 CS4231_MODE2, /* 0c/12 - mi */
104 0xfc, /* 0d/13 - lbc */
105 0x00, /* 0e/14 - pbru */
106 0x00, /* 0f/15 - pbrl */
107 0x80, /* 10/16 - afei */
108 0x01, /* 11/17 - afeii */
109 0x9f, /* 12/18 - llic */
110 0x9f, /* 13/19 - rlic */
111 0x00, /* 14/20 - tlb */
112 0x00, /* 15/21 - thb */
113 0x00, /* 16/22 - la3mic/reserved */
114 0x00, /* 17/23 - ra3mic/reserved */
115 0x00, /* 18/24 - afs */
116 0x00, /* 19/25 - lamoc/version */
117 0xcf, /* 1a/26 - mioc */
118 0x00, /* 1b/27 - ramoc/reserved */
119 0x20, /* 1c/28 - cdfr */
120 0x00, /* 1d/29 - res4 */
121 0x00, /* 1e/30 - cbru */
122 0x00, /* 1f/31 - cbrl */
126 * Basic I/O functions
129 #if !defined(EBUS_SUPPORT) && !defined(SBUS_SUPPORT)
130 #define __CS4231_INLINE__ inline
132 #define __CS4231_INLINE__ /* nothing */
135 static __CS4231_INLINE__ void cs4231_outb(cs4231_t *chip, u8 offset, u8 val)
138 if (chip->ebus->flag) {
139 writeb(val, chip->port + (offset << 2));
143 sbus_writeb(val, chip->port + (offset << 2));
148 #ifdef LEGACY_SUPPORT
149 outb(val, chip->port + offset);
153 static __CS4231_INLINE__ u8 cs4231_inb(cs4231_t *chip, u8 offset)
156 if (chip->ebus_flag) {
157 return readb(chip->port + (offset << 2));
161 return sbus_readb(chip->port + (offset << 2));
166 #ifdef LEGACY_SUPPORT
167 return inb(chip->port + offset);
171 void snd_cs4231_outm(cs4231_t *chip, unsigned char reg,
172 unsigned char mask, unsigned char value)
178 timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
181 #ifdef CONFIG_SND_DEBUG
182 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
183 snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
185 if (chip->calibrate_mute) {
186 chip->image[reg] &= mask;
187 chip->image[reg] |= value;
189 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
191 tmp = (chip->image[reg] & mask) | value;
192 cs4231_outb(chip, CS4231P(REG), tmp);
193 chip->image[reg] = tmp;
198 static void snd_cs4231_dout(cs4231_t *chip, unsigned char reg, unsigned char value)
203 timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
206 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
207 cs4231_outb(chip, CS4231P(REG), value);
211 void snd_cs4231_out(cs4231_t *chip, unsigned char reg, unsigned char value)
216 timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
219 #ifdef CONFIG_SND_DEBUG
220 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
221 snd_printk("out: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
223 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
224 cs4231_outb(chip, CS4231P(REG), value);
225 chip->image[reg] = value;
228 printk("codec out - reg 0x%x = 0x%x\n", chip->mce_bit | reg, value);
232 unsigned char snd_cs4231_in(cs4231_t *chip, unsigned char reg)
237 timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
240 #ifdef CONFIG_SND_DEBUG
241 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
242 snd_printk("in: auto calibration time out - reg = 0x%x\n", reg);
244 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
246 return cs4231_inb(chip, CS4231P(REG));
249 void snd_cs4236_ext_out(cs4231_t *chip, unsigned char reg, unsigned char val)
251 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | 0x17);
252 cs4231_outb(chip, CS4231P(REG), reg | (chip->image[CS4236_EXT_REG] & 0x01));
253 cs4231_outb(chip, CS4231P(REG), val);
254 chip->eimage[CS4236_REG(reg)] = val;
256 printk("ext out : reg = 0x%x, val = 0x%x\n", reg, val);
260 unsigned char snd_cs4236_ext_in(cs4231_t *chip, unsigned char reg)
262 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | 0x17);
263 cs4231_outb(chip, CS4231P(REG), reg | (chip->image[CS4236_EXT_REG] & 0x01));
265 return cs4231_inb(chip, CS4231P(REG));
269 res = cs4231_inb(chip, CS4231P(REG));
270 printk("ext in : reg = 0x%x, val = 0x%x\n", reg, res);
276 #ifdef CONFIG_SND_DEBUG
278 void snd_cs4231_debug(cs4231_t *chip)
280 printk("CS4231 REGS: INDEX = 0x%02x ", cs4231_inb(chip, CS4231P(REGSEL)));
281 printk(" STATUS = 0x%02x\n", cs4231_inb(chip, CS4231P(STATUS)));
282 printk(" 0x00: left input = 0x%02x ", snd_cs4231_in(chip, 0x00));
283 printk(" 0x10: alt 1 (CFIG 2) = 0x%02x\n", snd_cs4231_in(chip, 0x10));
284 printk(" 0x01: right input = 0x%02x ", snd_cs4231_in(chip, 0x01));
285 printk(" 0x11: alt 2 (CFIG 3) = 0x%02x\n", snd_cs4231_in(chip, 0x11));
286 printk(" 0x02: GF1 left input = 0x%02x ", snd_cs4231_in(chip, 0x02));
287 printk(" 0x12: left line in = 0x%02x\n", snd_cs4231_in(chip, 0x12));
288 printk(" 0x03: GF1 right input = 0x%02x ", snd_cs4231_in(chip, 0x03));
289 printk(" 0x13: right line in = 0x%02x\n", snd_cs4231_in(chip, 0x13));
290 printk(" 0x04: CD left input = 0x%02x ", snd_cs4231_in(chip, 0x04));
291 printk(" 0x14: timer low = 0x%02x\n", snd_cs4231_in(chip, 0x14));
292 printk(" 0x05: CD right input = 0x%02x ", snd_cs4231_in(chip, 0x05));
293 printk(" 0x15: timer high = 0x%02x\n", snd_cs4231_in(chip, 0x15));
294 printk(" 0x06: left output = 0x%02x ", snd_cs4231_in(chip, 0x06));
295 printk(" 0x16: left MIC (PnP) = 0x%02x\n", snd_cs4231_in(chip, 0x16));
296 printk(" 0x07: right output = 0x%02x ", snd_cs4231_in(chip, 0x07));
297 printk(" 0x17: right MIC (PnP) = 0x%02x\n", snd_cs4231_in(chip, 0x17));
298 printk(" 0x08: playback format = 0x%02x ", snd_cs4231_in(chip, 0x08));
299 printk(" 0x18: IRQ status = 0x%02x\n", snd_cs4231_in(chip, 0x18));
300 printk(" 0x09: iface (CFIG 1) = 0x%02x ", snd_cs4231_in(chip, 0x09));
301 printk(" 0x19: left line out = 0x%02x\n", snd_cs4231_in(chip, 0x19));
302 printk(" 0x0a: pin control = 0x%02x ", snd_cs4231_in(chip, 0x0a));
303 printk(" 0x1a: mono control = 0x%02x\n", snd_cs4231_in(chip, 0x1a));
304 printk(" 0x0b: init & status = 0x%02x ", snd_cs4231_in(chip, 0x0b));
305 printk(" 0x1b: right line out = 0x%02x\n", snd_cs4231_in(chip, 0x1b));
306 printk(" 0x0c: revision & mode = 0x%02x ", snd_cs4231_in(chip, 0x0c));
307 printk(" 0x1c: record format = 0x%02x\n", snd_cs4231_in(chip, 0x1c));
308 printk(" 0x0d: loopback = 0x%02x ", snd_cs4231_in(chip, 0x0d));
309 printk(" 0x1d: var freq (PnP) = 0x%02x\n", snd_cs4231_in(chip, 0x1d));
310 printk(" 0x0e: ply upr count = 0x%02x ", snd_cs4231_in(chip, 0x0e));
311 printk(" 0x1e: ply lwr count = 0x%02x\n", snd_cs4231_in(chip, 0x1e));
312 printk(" 0x0f: rec upr count = 0x%02x ", snd_cs4231_in(chip, 0x0f));
313 printk(" 0x1f: rec lwr count = 0x%02x\n", snd_cs4231_in(chip, 0x1f));
319 * CS4231 detection / MCE routines
322 static void snd_cs4231_busy_wait(cs4231_t *chip)
326 /* huh.. looks like this sequence is proper for CS4231A chip (GUS MAX) */
327 for (timeout = 5; timeout > 0; timeout--)
328 cs4231_inb(chip, CS4231P(REGSEL));
329 /* end of cleanup sequence */
331 timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
336 void snd_cs4231_mce_up(cs4231_t *chip)
341 for (timeout = 250; timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT); timeout--)
343 #ifdef CONFIG_SND_DEBUG
344 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
345 snd_printk("mce_up - auto calibration time out (0)\n");
347 spin_lock_irqsave(&chip->reg_lock, flags);
348 chip->mce_bit |= CS4231_MCE;
349 timeout = cs4231_inb(chip, CS4231P(REGSEL));
351 snd_printk("mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port);
352 if (!(timeout & CS4231_MCE))
353 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
354 spin_unlock_irqrestore(&chip->reg_lock, flags);
357 void snd_cs4231_mce_down(cs4231_t *chip)
363 snd_cs4231_busy_wait(chip);
365 printk("(1) timeout = %i\n", timeout);
367 #ifdef CONFIG_SND_DEBUG
368 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
369 snd_printk("mce_down [0x%lx] - auto calibration time out (0)\n", (long)CS4231P(REGSEL));
371 spin_lock_irqsave(&chip->reg_lock, flags);
372 chip->mce_bit &= ~CS4231_MCE;
373 timeout = cs4231_inb(chip, CS4231P(REGSEL));
374 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
375 spin_unlock_irqrestore(&chip->reg_lock, flags);
377 snd_printk("mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port);
378 if ((timeout & CS4231_MCE) == 0 ||
379 !(chip->hardware & (CS4231_HW_CS4231_MASK | CS4231_HW_CS4232_MASK))) {
382 snd_cs4231_busy_wait(chip);
384 /* calibration process */
386 for (timeout = 500; timeout > 0 && (snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) == 0; timeout--)
388 if ((snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) == 0) {
389 snd_printd("cs4231_mce_down - auto calibration time out (1)\n");
393 printk("(2) timeout = %i, jiffies = %li\n", timeout, jiffies);
395 timeout = HZ / 4 / 2;
397 while (snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) {
398 set_current_state(TASK_INTERRUPTIBLE);
399 time = schedule_timeout(time);
404 snd_printk("mce_down - auto calibration time out (2)\n");
409 printk("(3) jiffies = %li\n", jiffies);
411 timeout = HZ / 10 / 2;
413 while (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) {
414 set_current_state(TASK_INTERRUPTIBLE);
415 time = schedule_timeout(time);
420 snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n");
425 printk("(4) jiffies = %li\n", jiffies);
426 snd_printk("mce_down - exit = 0x%x\n", cs4231_inb(chip, CS4231P(REGSEL)));
430 static unsigned int snd_cs4231_get_count(unsigned char format, unsigned int size)
432 switch (format & 0xe0) {
433 case CS4231_LINEAR_16:
434 case CS4231_LINEAR_16_BIG:
437 case CS4231_ADPCM_16:
440 if (format & CS4231_STEREO)
445 static int snd_cs4231_trigger(snd_pcm_substream_t *substream,
448 cs4231_t *chip = snd_pcm_substream_chip(substream);
451 struct list_head *pos;
452 snd_pcm_substream_t *s;
456 printk("codec trigger!!! - what = %i, enable = %i, status = 0x%x\n", what, enable, cs4231_inb(chip, CS4231P(STATUS)));
460 case SNDRV_PCM_TRIGGER_START:
461 case SNDRV_PCM_TRIGGER_RESUME:
463 case SNDRV_PCM_TRIGGER_STOP:
464 case SNDRV_PCM_TRIGGER_SUSPEND:
471 snd_pcm_group_for_each(pos, substream) {
472 s = snd_pcm_group_substream_entry(pos);
473 if (s == chip->playback_substream) {
474 what |= CS4231_PLAYBACK_ENABLE;
475 snd_pcm_trigger_done(s, substream);
476 } else if (s == chip->capture_substream) {
477 what |= CS4231_RECORD_ENABLE;
478 snd_pcm_trigger_done(s, substream);
481 spin_lock(&chip->reg_lock);
483 chip->image[CS4231_IFACE_CTRL] |= what;
485 chip->trigger(chip, what, 1);
487 chip->image[CS4231_IFACE_CTRL] &= ~what;
489 chip->trigger(chip, what, 0);
491 snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
492 spin_unlock(&chip->reg_lock);
494 snd_cs4231_debug(chip);
503 static unsigned char snd_cs4231_get_rate(unsigned int rate)
507 for (i = 0; i < 14; i++)
508 if (rate == rates[i])
511 return freq_bits[13];
514 static unsigned char snd_cs4231_get_format(cs4231_t *chip,
518 unsigned char rformat;
520 rformat = CS4231_LINEAR_8;
522 case SNDRV_PCM_FORMAT_MU_LAW: rformat = CS4231_ULAW_8; break;
523 case SNDRV_PCM_FORMAT_A_LAW: rformat = CS4231_ALAW_8; break;
524 case SNDRV_PCM_FORMAT_S16_LE: rformat = CS4231_LINEAR_16; break;
525 case SNDRV_PCM_FORMAT_S16_BE: rformat = CS4231_LINEAR_16_BIG; break;
526 case SNDRV_PCM_FORMAT_IMA_ADPCM: rformat = CS4231_ADPCM_16; break;
529 rformat |= CS4231_STEREO;
531 snd_printk("get_format: 0x%x (mode=0x%x)\n", format, mode);
536 static void snd_cs4231_calibrate_mute(cs4231_t *chip, int mute)
541 spin_lock_irqsave(&chip->reg_lock, flags);
542 if (chip->calibrate_mute == mute) {
543 spin_unlock_irqrestore(&chip->reg_lock, flags);
547 snd_cs4231_dout(chip, CS4231_LEFT_INPUT, chip->image[CS4231_LEFT_INPUT]);
548 snd_cs4231_dout(chip, CS4231_RIGHT_INPUT, chip->image[CS4231_RIGHT_INPUT]);
549 snd_cs4231_dout(chip, CS4231_LOOPBACK, chip->image[CS4231_LOOPBACK]);
551 snd_cs4231_dout(chip, CS4231_AUX1_LEFT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX1_LEFT_INPUT]);
552 snd_cs4231_dout(chip, CS4231_AUX1_RIGHT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX1_RIGHT_INPUT]);
553 snd_cs4231_dout(chip, CS4231_AUX2_LEFT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX2_LEFT_INPUT]);
554 snd_cs4231_dout(chip, CS4231_AUX2_RIGHT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX2_RIGHT_INPUT]);
555 snd_cs4231_dout(chip, CS4231_LEFT_OUTPUT, mute ? 0x80 : chip->image[CS4231_LEFT_OUTPUT]);
556 snd_cs4231_dout(chip, CS4231_RIGHT_OUTPUT, mute ? 0x80 : chip->image[CS4231_RIGHT_OUTPUT]);
557 snd_cs4231_dout(chip, CS4231_LEFT_LINE_IN, mute ? 0x80 : chip->image[CS4231_LEFT_LINE_IN]);
558 snd_cs4231_dout(chip, CS4231_RIGHT_LINE_IN, mute ? 0x80 : chip->image[CS4231_RIGHT_LINE_IN]);
559 snd_cs4231_dout(chip, CS4231_MONO_CTRL, mute ? 0xc0 : chip->image[CS4231_MONO_CTRL]);
560 if (chip->hardware == CS4231_HW_INTERWAVE) {
561 snd_cs4231_dout(chip, CS4231_LEFT_MIC_INPUT, mute ? 0x80 : chip->image[CS4231_LEFT_MIC_INPUT]);
562 snd_cs4231_dout(chip, CS4231_RIGHT_MIC_INPUT, mute ? 0x80 : chip->image[CS4231_RIGHT_MIC_INPUT]);
563 snd_cs4231_dout(chip, CS4231_LINE_LEFT_OUTPUT, mute ? 0x80 : chip->image[CS4231_LINE_LEFT_OUTPUT]);
564 snd_cs4231_dout(chip, CS4231_LINE_RIGHT_OUTPUT, mute ? 0x80 : chip->image[CS4231_LINE_RIGHT_OUTPUT]);
566 chip->calibrate_mute = mute;
567 spin_unlock_irqrestore(&chip->reg_lock, flags);
570 static void snd_cs4231_playback_format(cs4231_t *chip,
571 snd_pcm_hw_params_t *params,
577 down(&chip->mce_mutex);
578 snd_cs4231_calibrate_mute(chip, 1);
579 if (chip->hardware == CS4231_HW_CS4231A ||
580 (chip->hardware & CS4231_HW_CS4232_MASK)) {
581 spin_lock_irqsave(&chip->reg_lock, flags);
582 if ((chip->image[CS4231_PLAYBK_FORMAT] & 0x0f) == (pdfr & 0x0f)) { /* rate is same? */
583 snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x10);
584 snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, chip->image[CS4231_PLAYBK_FORMAT] = pdfr);
585 snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] &= ~0x10);
586 udelay(100); /* Fixes audible clicks at least on GUS MAX */
589 spin_unlock_irqrestore(&chip->reg_lock, flags);
592 snd_cs4231_mce_up(chip);
593 spin_lock_irqsave(&chip->reg_lock, flags);
594 if (chip->hardware != CS4231_HW_INTERWAVE && !chip->single_dma) {
595 snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT,
596 (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) ?
597 (pdfr & 0xf0) | (chip->image[CS4231_REC_FORMAT] & 0x0f) :
600 snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, chip->image[CS4231_PLAYBK_FORMAT] = pdfr);
602 spin_unlock_irqrestore(&chip->reg_lock, flags);
603 snd_cs4231_mce_down(chip);
605 snd_cs4231_calibrate_mute(chip, 0);
606 up(&chip->mce_mutex);
609 static void snd_cs4231_capture_format(cs4231_t *chip,
610 snd_pcm_hw_params_t *params,
616 down(&chip->mce_mutex);
617 snd_cs4231_calibrate_mute(chip, 1);
618 if (chip->hardware == CS4231_HW_CS4231A ||
619 (chip->hardware & CS4231_HW_CS4232_MASK)) {
620 spin_lock_irqsave(&chip->reg_lock, flags);
621 if ((chip->image[CS4231_PLAYBK_FORMAT] & 0x0f) == (cdfr & 0x0f) || /* rate is same? */
622 (chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) {
623 snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x20);
624 snd_cs4231_out(chip, CS4231_REC_FORMAT, chip->image[CS4231_REC_FORMAT] = cdfr);
625 snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] &= ~0x20);
628 spin_unlock_irqrestore(&chip->reg_lock, flags);
631 snd_cs4231_mce_up(chip);
632 spin_lock_irqsave(&chip->reg_lock, flags);
633 if (chip->hardware != CS4231_HW_INTERWAVE) {
634 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) {
635 snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT,
636 ((chip->single_dma ? cdfr : chip->image[CS4231_PLAYBK_FORMAT]) & 0xf0) |
638 spin_unlock_irqrestore(&chip->reg_lock, flags);
639 snd_cs4231_mce_down(chip);
640 snd_cs4231_mce_up(chip);
641 spin_lock_irqsave(&chip->reg_lock, flags);
644 snd_cs4231_out(chip, CS4231_REC_FORMAT, cdfr);
645 spin_unlock_irqrestore(&chip->reg_lock, flags);
646 snd_cs4231_mce_down(chip);
648 snd_cs4231_calibrate_mute(chip, 0);
649 up(&chip->mce_mutex);
656 static unsigned long snd_cs4231_timer_resolution(snd_timer_t * timer)
658 cs4231_t *chip = snd_timer_chip(timer);
659 if (chip->hardware & CS4231_HW_CS4236B_MASK)
662 return chip->image[CS4231_PLAYBK_FORMAT] & 1 ? 9969 : 9920;
665 static int snd_cs4231_timer_start(snd_timer_t * timer)
669 cs4231_t *chip = snd_timer_chip(timer);
670 spin_lock_irqsave(&chip->reg_lock, flags);
671 ticks = timer->sticks;
672 if ((chip->image[CS4231_ALT_FEATURE_1] & CS4231_TIMER_ENABLE) == 0 ||
673 (unsigned char)(ticks >> 8) != chip->image[CS4231_TIMER_HIGH] ||
674 (unsigned char)ticks != chip->image[CS4231_TIMER_LOW]) {
675 snd_cs4231_out(chip, CS4231_TIMER_HIGH, chip->image[CS4231_TIMER_HIGH] = (unsigned char) (ticks >> 8));
676 snd_cs4231_out(chip, CS4231_TIMER_LOW, chip->image[CS4231_TIMER_LOW] = (unsigned char) ticks);
677 snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | CS4231_TIMER_ENABLE);
679 spin_unlock_irqrestore(&chip->reg_lock, flags);
683 static int snd_cs4231_timer_stop(snd_timer_t * timer)
686 cs4231_t *chip = snd_timer_chip(timer);
687 spin_lock_irqsave(&chip->reg_lock, flags);
688 snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] &= ~CS4231_TIMER_ENABLE);
689 spin_unlock_irqrestore(&chip->reg_lock, flags);
693 static void snd_cs4231_init(cs4231_t *chip)
697 snd_cs4231_mce_down(chip);
699 #ifdef SNDRV_DEBUGq_MCE
700 snd_printk("init: (1)\n");
702 snd_cs4231_mce_up(chip);
703 spin_lock_irqsave(&chip->reg_lock, flags);
704 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO |
705 CS4231_RECORD_ENABLE | CS4231_RECORD_PIO |
707 chip->image[CS4231_IFACE_CTRL] |= CS4231_AUTOCALIB;
708 snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
709 spin_unlock_irqrestore(&chip->reg_lock, flags);
710 snd_cs4231_mce_down(chip);
712 #ifdef SNDRV_DEBUG_MCE
713 snd_printk("init: (2)\n");
716 snd_cs4231_mce_up(chip);
717 spin_lock_irqsave(&chip->reg_lock, flags);
718 snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1]);
719 spin_unlock_irqrestore(&chip->reg_lock, flags);
720 snd_cs4231_mce_down(chip);
722 #ifdef SNDRV_DEBUG_MCE
723 snd_printk("init: (3) - afei = 0x%x\n", chip->image[CS4231_ALT_FEATURE_1]);
726 spin_lock_irqsave(&chip->reg_lock, flags);
727 snd_cs4231_out(chip, CS4231_ALT_FEATURE_2, chip->image[CS4231_ALT_FEATURE_2]);
728 spin_unlock_irqrestore(&chip->reg_lock, flags);
730 snd_cs4231_mce_up(chip);
731 spin_lock_irqsave(&chip->reg_lock, flags);
732 snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, chip->image[CS4231_PLAYBK_FORMAT]);
733 spin_unlock_irqrestore(&chip->reg_lock, flags);
734 snd_cs4231_mce_down(chip);
736 #ifdef SNDRV_DEBUG_MCE
737 snd_printk("init: (4)\n");
740 snd_cs4231_mce_up(chip);
741 spin_lock_irqsave(&chip->reg_lock, flags);
742 snd_cs4231_out(chip, CS4231_REC_FORMAT, chip->image[CS4231_REC_FORMAT]);
743 spin_unlock_irqrestore(&chip->reg_lock, flags);
744 snd_cs4231_mce_down(chip);
746 #ifdef SNDRV_DEBUG_MCE
747 snd_printk("init: (5)\n");
751 static int snd_cs4231_open(cs4231_t *chip, unsigned int mode)
755 down(&chip->open_mutex);
756 if ((chip->mode & mode) ||
757 ((chip->mode & CS4231_MODE_OPEN) && chip->single_dma)) {
758 up(&chip->open_mutex);
761 if (chip->mode & CS4231_MODE_OPEN) {
763 up(&chip->open_mutex);
766 /* ok. now enable and ack CODEC IRQ */
767 spin_lock_irqsave(&chip->reg_lock, flags);
768 snd_cs4231_out(chip, CS4231_IRQ_STATUS, CS4231_PLAYBACK_IRQ |
771 snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
772 cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
773 cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
774 chip->image[CS4231_PIN_CTRL] |= CS4231_IRQ_ENABLE;
775 snd_cs4231_out(chip, CS4231_PIN_CTRL, chip->image[CS4231_PIN_CTRL]);
776 snd_cs4231_out(chip, CS4231_IRQ_STATUS, CS4231_PLAYBACK_IRQ |
779 snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
780 spin_unlock_irqrestore(&chip->reg_lock, flags);
783 up(&chip->open_mutex);
787 static void snd_cs4231_close(cs4231_t *chip, unsigned int mode)
791 down(&chip->open_mutex);
793 if (chip->mode & CS4231_MODE_OPEN) {
794 up(&chip->open_mutex);
797 snd_cs4231_calibrate_mute(chip, 1);
800 spin_lock_irqsave(&chip->reg_lock, flags);
801 snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
802 cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
803 cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
804 chip->image[CS4231_PIN_CTRL] &= ~CS4231_IRQ_ENABLE;
805 snd_cs4231_out(chip, CS4231_PIN_CTRL, chip->image[CS4231_PIN_CTRL]);
807 /* now disable record & playback */
809 if (chip->image[CS4231_IFACE_CTRL] & (CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO |
810 CS4231_RECORD_ENABLE | CS4231_RECORD_PIO)) {
811 spin_unlock_irqrestore(&chip->reg_lock, flags);
812 snd_cs4231_mce_up(chip);
813 spin_lock_irqsave(&chip->reg_lock, flags);
814 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO |
815 CS4231_RECORD_ENABLE | CS4231_RECORD_PIO);
816 snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
817 spin_unlock_irqrestore(&chip->reg_lock, flags);
818 snd_cs4231_mce_down(chip);
819 spin_lock_irqsave(&chip->reg_lock, flags);
822 /* clear IRQ again */
823 snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
824 cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
825 cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
826 spin_unlock_irqrestore(&chip->reg_lock, flags);
828 snd_cs4231_calibrate_mute(chip, 0);
831 up(&chip->open_mutex);
838 static int snd_cs4231_timer_open(snd_timer_t * timer)
840 cs4231_t *chip = snd_timer_chip(timer);
841 snd_cs4231_open(chip, CS4231_MODE_TIMER);
845 static int snd_cs4231_timer_close(snd_timer_t * timer)
847 cs4231_t *chip = snd_timer_chip(timer);
848 snd_cs4231_close(chip, CS4231_MODE_TIMER);
852 static struct _snd_timer_hardware snd_cs4231_timer_table =
854 .flags = SNDRV_TIMER_HW_AUTO,
857 .open = snd_cs4231_timer_open,
858 .close = snd_cs4231_timer_close,
859 .c_resolution = snd_cs4231_timer_resolution,
860 .start = snd_cs4231_timer_start,
861 .stop = snd_cs4231_timer_stop,
865 * ok.. exported functions..
868 static int snd_cs4231_playback_hw_params(snd_pcm_substream_t * substream,
869 snd_pcm_hw_params_t * hw_params)
871 cs4231_t *chip = snd_pcm_substream_chip(substream);
872 unsigned char new_pdfr;
875 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
877 new_pdfr = snd_cs4231_get_format(chip, params_format(hw_params), params_channels(hw_params)) |
878 snd_cs4231_get_rate(params_rate(hw_params));
879 chip->set_playback_format(chip, hw_params, new_pdfr);
883 static int snd_cs4231_playback_hw_free(snd_pcm_substream_t * substream)
885 return snd_pcm_lib_free_pages(substream);
888 #ifdef LEGACY_SUPPORT
889 static int snd_cs4231_playback_prepare(snd_pcm_substream_t * substream)
891 cs4231_t *chip = snd_pcm_substream_chip(substream);
892 snd_pcm_runtime_t *runtime = substream->runtime;
894 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
895 unsigned int count = snd_pcm_lib_period_bytes(substream);
897 spin_lock_irqsave(&chip->reg_lock, flags);
898 chip->p_dma_size = size;
899 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO);
900 snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
901 count = snd_cs4231_get_count(chip->image[CS4231_PLAYBK_FORMAT], count) - 1;
902 snd_cs4231_out(chip, CS4231_PLY_LWR_CNT, (unsigned char) count);
903 snd_cs4231_out(chip, CS4231_PLY_UPR_CNT, (unsigned char) (count >> 8));
904 spin_unlock_irqrestore(&chip->reg_lock, flags);
906 snd_cs4231_debug(chip);
910 #endif /* LEGACY_SUPPORT */
912 static int snd_cs4231_capture_hw_params(snd_pcm_substream_t * substream,
913 snd_pcm_hw_params_t * hw_params)
915 cs4231_t *chip = snd_pcm_substream_chip(substream);
916 unsigned char new_cdfr;
919 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
921 new_cdfr = snd_cs4231_get_format(chip, params_format(hw_params), params_channels(hw_params)) |
922 snd_cs4231_get_rate(params_rate(hw_params));
923 chip->set_capture_format(chip, hw_params, new_cdfr);
927 static int snd_cs4231_capture_hw_free(snd_pcm_substream_t * substream)
929 return snd_pcm_lib_free_pages(substream);
932 #ifdef LEGACY_SUPPORT
933 static int snd_cs4231_capture_prepare(snd_pcm_substream_t * substream)
935 cs4231_t *chip = snd_pcm_substream_chip(substream);
936 snd_pcm_runtime_t *runtime = substream->runtime;
938 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
939 unsigned int count = snd_pcm_lib_period_bytes(substream);
941 spin_lock_irqsave(&chip->reg_lock, flags);
942 chip->c_dma_size = size;
943 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_RECORD_ENABLE | CS4231_RECORD_PIO);
944 snd_dma_program(chip->dma2, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
945 count = snd_cs4231_get_count(chip->image[CS4231_REC_FORMAT], count) - 1;
946 if (chip->single_dma && chip->hardware != CS4231_HW_INTERWAVE) {
947 snd_cs4231_out(chip, CS4231_PLY_LWR_CNT, (unsigned char) count);
948 snd_cs4231_out(chip, CS4231_PLY_UPR_CNT, (unsigned char) (count >> 8));
950 snd_cs4231_out(chip, CS4231_REC_LWR_CNT, (unsigned char) count);
951 snd_cs4231_out(chip, CS4231_REC_UPR_CNT, (unsigned char) (count >> 8));
953 spin_unlock_irqrestore(&chip->reg_lock, flags);
958 static void snd_cs4231_overrange(cs4231_t *chip)
963 spin_lock_irqsave(&chip->reg_lock, flags);
964 res = snd_cs4231_in(chip, CS4231_TEST_INIT);
965 spin_unlock_irqrestore(&chip->reg_lock, flags);
966 if (res & (0x08 | 0x02)) /* detect overrange only above 0dB; may be user selectable? */
967 chip->capture_substream->runtime->overrange++;
970 irqreturn_t snd_cs4231_interrupt(int irq, void *dev_id, struct pt_regs *regs)
972 cs4231_t *chip = snd_magic_cast(cs4231_t, dev_id, return IRQ_NONE);
973 unsigned char status;
975 status = snd_cs4231_in(chip, CS4231_IRQ_STATUS);
976 if (status & CS4231_TIMER_IRQ) {
978 snd_timer_interrupt(chip->timer, chip->timer->sticks);
980 if (chip->single_dma && chip->hardware != CS4231_HW_INTERWAVE) {
981 if (status & CS4231_PLAYBACK_IRQ) {
982 if (chip->mode & CS4231_MODE_PLAY)
983 snd_pcm_period_elapsed(chip->playback_substream);
984 if (chip->mode & CS4231_MODE_RECORD) {
985 snd_cs4231_overrange(chip);
986 snd_pcm_period_elapsed(chip->capture_substream);
990 if (status & CS4231_PLAYBACK_IRQ)
991 snd_pcm_period_elapsed(chip->playback_substream);
992 if (status & CS4231_RECORD_IRQ) {
993 snd_cs4231_overrange(chip);
994 snd_pcm_period_elapsed(chip->capture_substream);
998 spin_lock(&chip->reg_lock);
999 snd_cs4231_outm(chip, CS4231_IRQ_STATUS, ~CS4231_ALL_IRQS | ~status, 0);
1000 spin_unlock(&chip->reg_lock);
1004 #ifdef LEGACY_SUPPORT
1005 static snd_pcm_uframes_t snd_cs4231_playback_pointer(snd_pcm_substream_t * substream)
1007 cs4231_t *chip = snd_pcm_substream_chip(substream);
1010 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE))
1012 ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size);
1013 return bytes_to_frames(substream->runtime, ptr);
1016 static snd_pcm_uframes_t snd_cs4231_capture_pointer(snd_pcm_substream_t * substream)
1018 cs4231_t *chip = snd_pcm_substream_chip(substream);
1021 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE))
1023 ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size);
1024 return bytes_to_frames(substream->runtime, ptr);
1026 #endif /* LEGACY_SUPPORT */
1032 int snd_cs4231_probe(cs4231_t *chip)
1034 unsigned long flags;
1040 snd_cs4231_debug(chip);
1043 for (i = 0; i < 50; i++) {
1045 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
1048 spin_lock_irqsave(&chip->reg_lock, flags);
1049 snd_cs4231_out(chip, CS4231_MISC_INFO, CS4231_MODE2);
1050 id = snd_cs4231_in(chip, CS4231_MISC_INFO) & 0x0f;
1051 spin_unlock_irqrestore(&chip->reg_lock, flags);
1053 break; /* this is valid value */
1056 snd_printdd("cs4231: port = 0x%lx, id = 0x%x\n", chip->port, id);
1058 return -ENODEV; /* no valid device found */
1060 if (((hw = chip->hardware) & CS4231_HW_TYPE_MASK) == CS4231_HW_DETECT) {
1061 rev = snd_cs4231_in(chip, CS4231_VERSION) & 0xe7;
1062 snd_printdd("CS4231: VERSION (I25) = 0x%x\n", rev);
1064 unsigned char tmp = snd_cs4231_in(chip, 23);
1065 snd_cs4231_out(chip, 23, ~tmp);
1066 if (snd_cs4231_in(chip, 23) != tmp)
1067 chip->hardware = CS4231_HW_AD1845;
1069 chip->hardware = CS4231_HW_CS4231;
1070 } else if (rev == 0xa0) {
1071 chip->hardware = CS4231_HW_CS4231A;
1072 } else if (rev == 0xa2) {
1073 chip->hardware = CS4231_HW_CS4232;
1074 } else if (rev == 0xb2) {
1075 chip->hardware = CS4231_HW_CS4232A;
1076 } else if (rev == 0x83) {
1077 chip->hardware = CS4231_HW_CS4236;
1078 } else if (rev == 0x03) {
1079 chip->hardware = CS4231_HW_CS4236B;
1081 snd_printk("unknown CS chip with version 0x%x\n", rev);
1082 return -ENODEV; /* unknown CS4231 chip? */
1085 spin_lock_irqsave(&chip->reg_lock, flags);
1086 cs4231_inb(chip, CS4231P(STATUS)); /* clear any pendings IRQ */
1087 cs4231_outb(chip, CS4231P(STATUS), 0);
1089 spin_unlock_irqrestore(&chip->reg_lock, flags);
1091 chip->image[CS4231_MISC_INFO] = CS4231_MODE2;
1092 switch (chip->hardware) {
1093 case CS4231_HW_INTERWAVE:
1094 chip->image[CS4231_MISC_INFO] = CS4231_IW_MODE3;
1096 case CS4231_HW_CS4235:
1097 case CS4231_HW_CS4236B:
1098 case CS4231_HW_CS4237B:
1099 case CS4231_HW_CS4238B:
1100 case CS4231_HW_CS4239:
1101 if (hw == CS4231_HW_DETECT3)
1102 chip->image[CS4231_MISC_INFO] = CS4231_4236_MODE3;
1104 chip->hardware = CS4231_HW_CS4236;
1108 chip->image[CS4231_IFACE_CTRL] =
1109 (chip->image[CS4231_IFACE_CTRL] & ~CS4231_SINGLE_DMA) |
1110 (chip->single_dma ? CS4231_SINGLE_DMA : 0);
1111 chip->image[CS4231_ALT_FEATURE_1] = 0x80;
1112 chip->image[CS4231_ALT_FEATURE_2] = chip->hardware == CS4231_HW_INTERWAVE ? 0xc2 : 0x01;
1113 ptr = (unsigned char *) &chip->image;
1114 snd_cs4231_mce_down(chip);
1115 spin_lock_irqsave(&chip->reg_lock, flags);
1116 for (i = 0; i < 32; i++) /* ok.. fill all CS4231 registers */
1117 snd_cs4231_out(chip, i, *ptr++);
1118 spin_unlock_irqrestore(&chip->reg_lock, flags);
1119 snd_cs4231_mce_up(chip);
1120 snd_cs4231_mce_down(chip);
1124 /* ok.. try check hardware version for CS4236+ chips */
1125 if ((hw & CS4231_HW_TYPE_MASK) == CS4231_HW_DETECT) {
1126 if (chip->hardware == CS4231_HW_CS4236B) {
1127 rev = snd_cs4236_ext_in(chip, CS4236_VERSION);
1128 snd_cs4236_ext_out(chip, CS4236_VERSION, 0xff);
1129 id = snd_cs4236_ext_in(chip, CS4236_VERSION);
1130 snd_cs4236_ext_out(chip, CS4236_VERSION, rev);
1131 snd_printdd("CS4231: ext version; rev = 0x%x, id = 0x%x\n", rev, id);
1132 if ((id & 0x1f) == 0x1d) { /* CS4235 */
1133 chip->hardware = CS4231_HW_CS4235;
1140 snd_printk("unknown CS4235 chip (enhanced version = 0x%x)\n", id);
1142 } else if ((id & 0x1f) == 0x0b) { /* CS4236/B */
1148 chip->hardware = CS4231_HW_CS4236B;
1151 snd_printk("unknown CS4236 chip (enhanced version = 0x%x)\n", id);
1153 } else if ((id & 0x1f) == 0x08) { /* CS4237B */
1154 chip->hardware = CS4231_HW_CS4237B;
1162 snd_printk("unknown CS4237B chip (enhanced version = 0x%x)\n", id);
1164 } else if ((id & 0x1f) == 0x09) { /* CS4238B */
1165 chip->hardware = CS4231_HW_CS4238B;
1172 snd_printk("unknown CS4238B chip (enhanced version = 0x%x)\n", id);
1174 } else if ((id & 0x1f) == 0x1e) { /* CS4239 */
1175 chip->hardware = CS4231_HW_CS4239;
1182 snd_printk("unknown CS4239 chip (enhanced version = 0x%x)\n", id);
1185 snd_printk("unknown CS4236/CS423xB chip (enhanced version = 0x%x)\n", id);
1189 return 0; /* all things are ok.. */
1196 static snd_pcm_hardware_t snd_cs4231_playback =
1198 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1199 SNDRV_PCM_INFO_MMAP_VALID |
1200 SNDRV_PCM_INFO_RESUME |
1201 SNDRV_PCM_INFO_SYNC_START),
1202 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
1203 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
1204 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
1209 .buffer_bytes_max = (128*1024),
1210 .period_bytes_min = 64,
1211 .period_bytes_max = (128*1024),
1213 .periods_max = 1024,
1217 static snd_pcm_hardware_t snd_cs4231_capture =
1219 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1220 SNDRV_PCM_INFO_MMAP_VALID |
1221 SNDRV_PCM_INFO_RESUME |
1222 SNDRV_PCM_INFO_SYNC_START),
1223 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
1224 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
1225 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
1230 .buffer_bytes_max = (128*1024),
1231 .period_bytes_min = 64,
1232 .period_bytes_max = (128*1024),
1234 .periods_max = 1024,
1242 static int snd_cs4231_playback_open(snd_pcm_substream_t * substream)
1244 cs4231_t *chip = snd_pcm_substream_chip(substream);
1245 snd_pcm_runtime_t *runtime = substream->runtime;
1248 runtime->hw = snd_cs4231_playback;
1250 /* hardware bug in InterWave chipset */
1251 if (chip->hardware == CS4231_HW_INTERWAVE && chip->dma1 > 3)
1252 runtime->hw.formats &= ~SNDRV_PCM_FMTBIT_MU_LAW;
1254 /* hardware limitation of cheap chips */
1255 if (chip->hardware == CS4231_HW_CS4235 ||
1256 chip->hardware == CS4231_HW_CS4239)
1257 runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE;
1259 #ifdef LEGACY_SUPPORT
1260 snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max);
1261 snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.period_bytes_max);
1263 if (chip->claim_dma) {
1264 if ((err = chip->claim_dma(chip, chip->dma_private_data, chip->dma1)) < 0)
1269 if ((err = snd_cs4231_open(chip, CS4231_MODE_PLAY)) < 0) {
1270 #ifdef LEGACY_SUPPORT
1271 if (chip->release_dma)
1272 chip->release_dma(chip, chip->dma_private_data, chip->dma1);
1274 snd_free_pages(runtime->dma_area, runtime->dma_bytes);
1277 chip->playback_substream = substream;
1278 #if defined(SBUS_SUPPORT) || defined(EBUS_SUPPORT)
1279 chip->p_periods_sent = 0;
1281 snd_pcm_set_sync(substream);
1282 chip->rate_constraint(runtime);
1286 static int snd_cs4231_capture_open(snd_pcm_substream_t * substream)
1288 cs4231_t *chip = snd_pcm_substream_chip(substream);
1289 snd_pcm_runtime_t *runtime = substream->runtime;
1292 runtime->hw = snd_cs4231_capture;
1294 /* hardware limitation of cheap chips */
1295 if (chip->hardware == CS4231_HW_CS4235 ||
1296 chip->hardware == CS4231_HW_CS4239)
1297 runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE;
1299 #ifdef LEGACY_SUPPORT
1300 snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max);
1301 snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.period_bytes_max);
1303 if (chip->claim_dma) {
1304 if ((err = chip->claim_dma(chip, chip->dma_private_data, chip->dma2)) < 0)
1309 if ((err = snd_cs4231_open(chip, CS4231_MODE_RECORD)) < 0) {
1310 #ifdef LEGACY_SUPPORT
1311 if (chip->release_dma)
1312 chip->release_dma(chip, chip->dma_private_data, chip->dma2);
1314 snd_free_pages(runtime->dma_area, runtime->dma_bytes);
1317 chip->capture_substream = substream;
1318 #if defined(SBUS_SUPPORT) || defined(EBUS_SUPPORT)
1319 chip->c_periods_sent = 0;
1321 snd_pcm_set_sync(substream);
1322 chip->rate_constraint(runtime);
1326 static int snd_cs4231_playback_close(snd_pcm_substream_t * substream)
1328 cs4231_t *chip = snd_pcm_substream_chip(substream);
1330 chip->playback_substream = NULL;
1331 snd_cs4231_close(chip, CS4231_MODE_PLAY);
1335 static int snd_cs4231_capture_close(snd_pcm_substream_t * substream)
1337 cs4231_t *chip = snd_pcm_substream_chip(substream);
1339 chip->capture_substream = NULL;
1340 snd_cs4231_close(chip, CS4231_MODE_RECORD);
1346 static void snd_cs4231_suspend(cs4231_t *chip)
1349 unsigned long flags;
1351 spin_lock_irqsave(&chip->reg_lock, flags);
1352 for (reg = 0; reg < 32; reg++)
1353 chip->image[reg] = snd_cs4231_in(chip, reg);
1354 spin_unlock_irqrestore(&chip->reg_lock, flags);
1357 static void snd_cs4231_resume(cs4231_t *chip)
1360 unsigned long flags;
1363 snd_cs4231_mce_up(chip);
1364 spin_lock_irqsave(&chip->reg_lock, flags);
1365 for (reg = 0; reg < 32; reg++) {
1367 case CS4231_VERSION:
1370 snd_cs4231_out(chip, reg, chip->image[reg]);
1374 spin_unlock_irqrestore(&chip->reg_lock, flags);
1376 snd_cs4231_mce_down(chip);
1378 /* The following is a workaround to avoid freeze after resume on TP600E.
1379 This is the first half of copy of snd_cs4231_mce_down(), but doesn't
1380 include rescheduling. -- iwai
1382 snd_cs4231_busy_wait(chip);
1383 spin_lock_irqsave(&chip->reg_lock, flags);
1384 chip->mce_bit &= ~CS4231_MCE;
1385 timeout = cs4231_inb(chip, CS4231P(REGSEL));
1386 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
1387 spin_unlock_irqrestore(&chip->reg_lock, flags);
1388 if (timeout == 0x80)
1389 snd_printk("down [0x%lx]: serious init problem - codec still busy\n", chip->port);
1390 if ((timeout & CS4231_MCE) == 0 ||
1391 !(chip->hardware & (CS4231_HW_CS4231_MASK | CS4231_HW_CS4232_MASK))) {
1394 snd_cs4231_busy_wait(chip);
1398 static int snd_cs4231_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data)
1400 cs4231_t *chip = snd_magic_cast(cs4231_t, dev->data, return 0);
1404 if (chip->suspend) {
1405 snd_pcm_suspend_all(chip->pcm);
1406 (*chip->suspend)(chip);
1411 (*chip->resume)(chip);
1417 #endif /* CONFIG_PM */
1419 #ifdef LEGACY_SUPPORT
1421 static int snd_cs4231_free(cs4231_t *chip)
1423 if (chip->res_port) {
1424 release_resource(chip->res_port);
1425 kfree_nocheck(chip->res_port);
1427 if (chip->res_cport) {
1428 release_resource(chip->res_cport);
1429 kfree_nocheck(chip->res_cport);
1431 if (chip->irq >= 0) {
1432 disable_irq(chip->irq);
1433 if (!(chip->hwshare & CS4231_HWSHARE_IRQ))
1434 free_irq(chip->irq, (void *) chip);
1436 if (!(chip->hwshare & CS4231_HWSHARE_DMA1) && chip->dma1 >= 0) {
1437 snd_dma_disable(chip->dma1);
1438 free_dma(chip->dma1);
1440 if (!(chip->hwshare & CS4231_HWSHARE_DMA2) && chip->dma2 >= 0 && chip->dma2 != chip->dma1) {
1441 snd_dma_disable(chip->dma2);
1442 free_dma(chip->dma2);
1446 pm_unregister(chip->pm_dev);
1449 snd_device_free(chip->card, chip->timer);
1450 snd_magic_kfree(chip);
1454 static int snd_cs4231_dev_free(snd_device_t *device)
1456 cs4231_t *chip = snd_magic_cast(cs4231_t, device->device_data, return -ENXIO);
1457 return snd_cs4231_free(chip);
1460 #endif /* LEGACY_SUPPORT */
1462 const char *snd_cs4231_chip_id(cs4231_t *chip)
1464 switch (chip->hardware) {
1465 case CS4231_HW_CS4231: return "CS4231";
1466 case CS4231_HW_CS4231A: return "CS4231A";
1467 case CS4231_HW_CS4232: return "CS4232";
1468 case CS4231_HW_CS4232A: return "CS4232A";
1469 case CS4231_HW_CS4235: return "CS4235";
1470 case CS4231_HW_CS4236: return "CS4236";
1471 case CS4231_HW_CS4236B: return "CS4236B";
1472 case CS4231_HW_CS4237B: return "CS4237B";
1473 case CS4231_HW_CS4238B: return "CS4238B";
1474 case CS4231_HW_CS4239: return "CS4239";
1475 case CS4231_HW_INTERWAVE: return "AMD InterWave";
1476 case CS4231_HW_OPL3SA2: return chip->card->shortname;
1477 case CS4231_HW_AD1845: return "AD1845";
1478 default: return "???";
1482 static int snd_cs4231_new(snd_card_t * card,
1483 unsigned short hardware,
1484 unsigned short hwshare,
1490 chip = snd_magic_kcalloc(cs4231_t, 0, GFP_KERNEL);
1493 chip->hardware = hardware;
1494 chip->hwshare = hwshare;
1496 spin_lock_init(&chip->reg_lock);
1497 init_MUTEX(&chip->mce_mutex);
1498 init_MUTEX(&chip->open_mutex);
1500 chip->rate_constraint = snd_cs4231_xrate;
1501 chip->set_playback_format = snd_cs4231_playback_format;
1502 chip->set_capture_format = snd_cs4231_capture_format;
1503 memcpy(&chip->image, &snd_cs4231_original_image, sizeof(snd_cs4231_original_image));
1509 #ifdef LEGACY_SUPPORT
1511 int snd_cs4231_create(snd_card_t * card,
1513 unsigned long cport,
1514 int irq, int dma1, int dma2,
1515 unsigned short hardware,
1516 unsigned short hwshare,
1519 static snd_device_ops_t ops = {
1520 .dev_free = snd_cs4231_dev_free,
1525 err = snd_cs4231_new(card, hardware, hwshare, &chip);
1533 if ((chip->res_port = request_region(port, 4, "CS4231")) == NULL) {
1534 snd_printk(KERN_ERR "cs4231: can't grab port 0x%lx\n", port);
1535 snd_cs4231_free(chip);
1539 if ((long)cport >= 0 && (chip->res_cport = request_region(cport, 8, "CS4232 Control")) == NULL) {
1540 snd_printk(KERN_ERR "cs4231: can't grab control port 0x%lx\n", cport);
1541 snd_cs4231_free(chip);
1544 chip->cport = cport;
1545 if (!(hwshare & CS4231_HWSHARE_IRQ) && request_irq(irq, snd_cs4231_interrupt, SA_INTERRUPT, "CS4231", (void *) chip)) {
1546 snd_printk(KERN_ERR "cs4231: can't grab IRQ %d\n", irq);
1547 snd_cs4231_free(chip);
1551 if (!(hwshare & CS4231_HWSHARE_DMA1) && request_dma(dma1, "CS4231 - 1")) {
1552 snd_printk(KERN_ERR "cs4231: can't grab DMA1 %d\n", dma1);
1553 snd_cs4231_free(chip);
1557 if (!(hwshare & CS4231_HWSHARE_DMA2) && dma1 != dma2 && dma2 >= 0 && request_dma(dma2, "CS4231 - 2")) {
1558 snd_printk(KERN_ERR "cs4231: can't grab DMA2 %d\n", dma2);
1559 snd_cs4231_free(chip);
1562 if (dma1 == dma2 || dma2 < 0) {
1563 chip->single_dma = 1;
1564 chip->dma2 = chip->dma1;
1569 if (snd_cs4231_probe(chip) < 0) {
1570 snd_cs4231_free(chip);
1573 snd_cs4231_init(chip);
1575 if (chip->hardware & CS4231_HW_CS4232_MASK) {
1576 if (chip->res_cport == NULL)
1577 snd_printk("CS4232 control port features are not accessible\n");
1580 /* Register device */
1581 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1582 snd_cs4231_free(chip);
1587 /* Power Management */
1588 chip->suspend = snd_cs4231_suspend;
1589 chip->resume = snd_cs4231_resume;
1590 chip->pm_dev = pm_register(PM_ISA_DEV, 0, snd_cs4231_pm_callback);
1592 chip->pm_dev->data = chip;
1599 #endif /* LEGACY_SUPPORT */
1601 static snd_pcm_ops_t snd_cs4231_playback_ops = {
1602 .open = snd_cs4231_playback_open,
1603 .close = snd_cs4231_playback_close,
1604 .ioctl = snd_pcm_lib_ioctl,
1605 .hw_params = snd_cs4231_playback_hw_params,
1606 .hw_free = snd_cs4231_playback_hw_free,
1607 .prepare = snd_cs4231_playback_prepare,
1608 .trigger = snd_cs4231_trigger,
1609 .pointer = snd_cs4231_playback_pointer,
1612 static snd_pcm_ops_t snd_cs4231_capture_ops = {
1613 .open = snd_cs4231_capture_open,
1614 .close = snd_cs4231_capture_close,
1615 .ioctl = snd_pcm_lib_ioctl,
1616 .hw_params = snd_cs4231_capture_hw_params,
1617 .hw_free = snd_cs4231_capture_hw_free,
1618 .prepare = snd_cs4231_capture_prepare,
1619 .trigger = snd_cs4231_trigger,
1620 .pointer = snd_cs4231_capture_pointer,
1623 static void snd_cs4231_pcm_free(snd_pcm_t *pcm)
1625 cs4231_t *chip = snd_magic_cast(cs4231_t, pcm->private_data, return);
1627 snd_pcm_lib_preallocate_free_for_all(pcm);
1630 int snd_cs4231_pcm(cs4231_t *chip, int device, snd_pcm_t **rpcm)
1635 if ((err = snd_pcm_new(chip->card, "CS4231", device, 1, 1, &pcm)) < 0)
1638 spin_lock_init(&chip->reg_lock);
1639 init_MUTEX(&chip->mce_mutex);
1640 init_MUTEX(&chip->open_mutex);
1642 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs4231_playback_ops);
1643 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cs4231_capture_ops);
1646 pcm->private_data = chip;
1647 pcm->private_free = snd_cs4231_pcm_free;
1648 pcm->info_flags = 0;
1649 if (chip->single_dma)
1650 pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX;
1651 if (chip->hardware != CS4231_HW_INTERWAVE)
1652 pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX;
1653 strcpy(pcm->name, snd_cs4231_chip_id(chip));
1655 #ifdef LEGACY_SUPPORT
1656 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1658 64*1024, chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024);
1660 # ifdef EBUS_SUPPORT
1661 if (chip->ebus_flag) {
1662 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_PCI,
1667 # ifdef SBUS_SUPPORT
1668 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_SBUS,
1672 # ifdef EBUS_SUPPORT
1683 static void snd_cs4231_timer_free(snd_timer_t *timer)
1685 cs4231_t *chip = snd_magic_cast(cs4231_t, timer->private_data, return);
1689 int snd_cs4231_timer(cs4231_t *chip, int device, snd_timer_t **rtimer)
1695 /* Timer initialization */
1696 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
1697 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
1698 tid.card = chip->card->number;
1699 tid.device = device;
1701 if ((err = snd_timer_new(chip->card, "CS4231", &tid, &timer)) < 0)
1703 strcpy(timer->name, snd_cs4231_chip_id(chip));
1704 timer->private_data = chip;
1705 timer->private_free = snd_cs4231_timer_free;
1706 timer->hw = snd_cs4231_timer_table;
1707 chip->timer = timer;
1717 static int snd_cs4231_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1719 static char *texts[4] = {
1720 "Line", "Aux", "Mic", "Mix"
1722 static char *opl3sa_texts[4] = {
1723 "Line", "CD", "Mic", "Mix"
1725 static char *gusmax_texts[4] = {
1726 "Line", "Synth", "Mic", "Mix"
1728 char **ptexts = texts;
1729 cs4231_t *chip = snd_kcontrol_chip(kcontrol);
1731 snd_assert(chip->card != NULL, return -EINVAL);
1732 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1734 uinfo->value.enumerated.items = 4;
1735 if (uinfo->value.enumerated.item > 3)
1736 uinfo->value.enumerated.item = 3;
1737 if (!strcmp(chip->card->driver, "GUS MAX"))
1738 ptexts = gusmax_texts;
1739 switch (chip->hardware) {
1740 case CS4231_HW_INTERWAVE: ptexts = gusmax_texts; break;
1741 case CS4231_HW_OPL3SA2: ptexts = opl3sa_texts; break;
1743 strcpy(uinfo->value.enumerated.name, ptexts[uinfo->value.enumerated.item]);
1747 static int snd_cs4231_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1749 cs4231_t *chip = snd_kcontrol_chip(kcontrol);
1750 unsigned long flags;
1752 spin_lock_irqsave(&chip->reg_lock, flags);
1753 ucontrol->value.enumerated.item[0] = (chip->image[CS4231_LEFT_INPUT] & CS4231_MIXS_ALL) >> 6;
1754 ucontrol->value.enumerated.item[1] = (chip->image[CS4231_RIGHT_INPUT] & CS4231_MIXS_ALL) >> 6;
1755 spin_unlock_irqrestore(&chip->reg_lock, flags);
1759 static int snd_cs4231_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1761 cs4231_t *chip = snd_kcontrol_chip(kcontrol);
1762 unsigned long flags;
1763 unsigned short left, right;
1766 if (ucontrol->value.enumerated.item[0] > 3 ||
1767 ucontrol->value.enumerated.item[1] > 3)
1769 left = ucontrol->value.enumerated.item[0] << 6;
1770 right = ucontrol->value.enumerated.item[1] << 6;
1771 spin_lock_irqsave(&chip->reg_lock, flags);
1772 left = (chip->image[CS4231_LEFT_INPUT] & ~CS4231_MIXS_ALL) | left;
1773 right = (chip->image[CS4231_RIGHT_INPUT] & ~CS4231_MIXS_ALL) | right;
1774 change = left != chip->image[CS4231_LEFT_INPUT] ||
1775 right != chip->image[CS4231_RIGHT_INPUT];
1776 snd_cs4231_out(chip, CS4231_LEFT_INPUT, left);
1777 snd_cs4231_out(chip, CS4231_RIGHT_INPUT, right);
1778 spin_unlock_irqrestore(&chip->reg_lock, flags);
1782 int snd_cs4231_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1784 int mask = (kcontrol->private_value >> 16) & 0xff;
1786 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1788 uinfo->value.integer.min = 0;
1789 uinfo->value.integer.max = mask;
1793 int snd_cs4231_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1795 cs4231_t *chip = snd_kcontrol_chip(kcontrol);
1796 unsigned long flags;
1797 int reg = kcontrol->private_value & 0xff;
1798 int shift = (kcontrol->private_value >> 8) & 0xff;
1799 int mask = (kcontrol->private_value >> 16) & 0xff;
1800 int invert = (kcontrol->private_value >> 24) & 0xff;
1802 spin_lock_irqsave(&chip->reg_lock, flags);
1803 ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask;
1804 spin_unlock_irqrestore(&chip->reg_lock, flags);
1806 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1810 int snd_cs4231_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1812 cs4231_t *chip = snd_kcontrol_chip(kcontrol);
1813 unsigned long flags;
1814 int reg = kcontrol->private_value & 0xff;
1815 int shift = (kcontrol->private_value >> 8) & 0xff;
1816 int mask = (kcontrol->private_value >> 16) & 0xff;
1817 int invert = (kcontrol->private_value >> 24) & 0xff;
1821 val = (ucontrol->value.integer.value[0] & mask);
1825 spin_lock_irqsave(&chip->reg_lock, flags);
1826 val = (chip->image[reg] & ~(mask << shift)) | val;
1827 change = val != chip->image[reg];
1828 snd_cs4231_out(chip, reg, val);
1829 spin_unlock_irqrestore(&chip->reg_lock, flags);
1833 int snd_cs4231_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1835 int mask = (kcontrol->private_value >> 24) & 0xff;
1837 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1839 uinfo->value.integer.min = 0;
1840 uinfo->value.integer.max = mask;
1844 int snd_cs4231_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1846 cs4231_t *chip = snd_kcontrol_chip(kcontrol);
1847 unsigned long flags;
1848 int left_reg = kcontrol->private_value & 0xff;
1849 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1850 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1851 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1852 int mask = (kcontrol->private_value >> 24) & 0xff;
1853 int invert = (kcontrol->private_value >> 22) & 1;
1855 spin_lock_irqsave(&chip->reg_lock, flags);
1856 ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
1857 ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask;
1858 spin_unlock_irqrestore(&chip->reg_lock, flags);
1860 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1861 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
1866 int snd_cs4231_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1868 cs4231_t *chip = snd_kcontrol_chip(kcontrol);
1869 unsigned long flags;
1870 int left_reg = kcontrol->private_value & 0xff;
1871 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1872 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1873 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1874 int mask = (kcontrol->private_value >> 24) & 0xff;
1875 int invert = (kcontrol->private_value >> 22) & 1;
1877 unsigned short val1, val2;
1879 val1 = ucontrol->value.integer.value[0] & mask;
1880 val2 = ucontrol->value.integer.value[1] & mask;
1885 val1 <<= shift_left;
1886 val2 <<= shift_right;
1887 spin_lock_irqsave(&chip->reg_lock, flags);
1888 val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
1889 val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2;
1890 change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg];
1891 snd_cs4231_out(chip, left_reg, val1);
1892 snd_cs4231_out(chip, right_reg, val2);
1893 spin_unlock_irqrestore(&chip->reg_lock, flags);
1897 #define CS4231_CONTROLS (sizeof(snd_cs4231_controls)/sizeof(snd_kcontrol_new_t))
1899 static snd_kcontrol_new_t snd_cs4231_controls[] = {
1900 CS4231_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
1901 CS4231_DOUBLE("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
1902 CS4231_DOUBLE("Line Playback Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
1903 CS4231_DOUBLE("Line Playback Volume", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1),
1904 CS4231_DOUBLE("Aux Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
1905 CS4231_DOUBLE("Aux Playback Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
1906 CS4231_DOUBLE("Aux Playback Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
1907 CS4231_DOUBLE("Aux Playback Volume", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
1908 CS4231_SINGLE("Mono Playback Switch", 0, CS4231_MONO_CTRL, 7, 1, 1),
1909 CS4231_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1),
1910 CS4231_SINGLE("Mono Output Playback Switch", 0, CS4231_MONO_CTRL, 6, 1, 1),
1911 CS4231_SINGLE("Mono Output Playback Bypass", 0, CS4231_MONO_CTRL, 5, 1, 0),
1912 CS4231_DOUBLE("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
1914 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1915 .name = "Capture Source",
1916 .info = snd_cs4231_info_mux,
1917 .get = snd_cs4231_get_mux,
1918 .put = snd_cs4231_put_mux,
1920 CS4231_DOUBLE("Mic Boost", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
1921 CS4231_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK, 0, 1, 0),
1922 CS4231_SINGLE("Loopback Capture Volume", 0, CS4231_LOOPBACK, 2, 63, 1)
1925 int snd_cs4231_mixer(cs4231_t *chip)
1931 snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL);
1935 strcpy(card->mixername, chip->pcm->name);
1937 for (idx = 0; idx < CS4231_CONTROLS; idx++) {
1938 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4231_controls[idx], chip))) < 0)
1944 EXPORT_SYMBOL(snd_cs4231_out);
1945 EXPORT_SYMBOL(snd_cs4231_in);
1946 EXPORT_SYMBOL(snd_cs4231_outm);
1947 EXPORT_SYMBOL(snd_cs4236_ext_out);
1948 EXPORT_SYMBOL(snd_cs4236_ext_in);
1949 EXPORT_SYMBOL(snd_cs4231_mce_up);
1950 EXPORT_SYMBOL(snd_cs4231_mce_down);
1951 EXPORT_SYMBOL(snd_cs4231_interrupt);
1952 EXPORT_SYMBOL(snd_cs4231_chip_id);
1953 EXPORT_SYMBOL(snd_cs4231_create);
1954 EXPORT_SYMBOL(snd_cs4231_pcm);
1955 EXPORT_SYMBOL(snd_cs4231_mixer);
1956 EXPORT_SYMBOL(snd_cs4231_timer);
1957 EXPORT_SYMBOL(snd_cs4231_info_single);
1958 EXPORT_SYMBOL(snd_cs4231_get_single);
1959 EXPORT_SYMBOL(snd_cs4231_put_single);
1960 EXPORT_SYMBOL(snd_cs4231_info_double);
1961 EXPORT_SYMBOL(snd_cs4231_get_double);
1962 EXPORT_SYMBOL(snd_cs4231_put_double);
1968 static int __init alsa_cs4231_init(void)
1973 static void __exit alsa_cs4231_exit(void)
1977 module_init(alsa_cs4231_init)
1978 module_exit(alsa_cs4231_exit)