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 */
122 static unsigned char snd_opti93x_original_image
[32] =
124 0x00, /* 00/00 - l_mixout_outctrl */
125 0x00, /* 01/01 - r_mixout_outctrl */
126 0x88, /* 02/02 - l_cd_inctrl */
127 0x88, /* 03/03 - r_cd_inctrl */
128 0x88, /* 04/04 - l_a1/fm_inctrl */
129 0x88, /* 05/05 - r_a1/fm_inctrl */
130 0x80, /* 06/06 - l_dac_inctrl */
131 0x80, /* 07/07 - r_dac_inctrl */
132 0x00, /* 08/08 - ply_dataform_reg */
133 0x00, /* 09/09 - if_conf */
134 0x00, /* 0a/10 - pin_ctrl */
135 0x00, /* 0b/11 - err_init_reg */
136 0x0a, /* 0c/12 - id_reg */
137 0x00, /* 0d/13 - reserved */
138 0x00, /* 0e/14 - ply_upcount_reg */
139 0x00, /* 0f/15 - ply_lowcount_reg */
140 0x88, /* 10/16 - reserved/l_a1_inctrl */
141 0x88, /* 11/17 - reserved/r_a1_inctrl */
142 0x88, /* 12/18 - l_line_inctrl */
143 0x88, /* 13/19 - r_line_inctrl */
144 0x88, /* 14/20 - l_mic_inctrl */
145 0x88, /* 15/21 - r_mic_inctrl */
146 0x80, /* 16/22 - l_out_outctrl */
147 0x80, /* 17/23 - r_out_outctrl */
148 0x00, /* 18/24 - reserved */
149 0x00, /* 19/25 - reserved */
150 0x00, /* 1a/26 - reserved */
151 0x00, /* 1b/27 - reserved */
152 0x00, /* 1c/28 - cap_dataform_reg */
153 0x00, /* 1d/29 - reserved */
154 0x00, /* 1e/30 - cap_upcount_reg */
155 0x00 /* 1f/31 - cap_lowcount_reg */
159 * Basic I/O functions
162 static inline void cs4231_outb(struct snd_cs4231
*chip
, u8 offset
, u8 val
)
164 outb(val
, chip
->port
+ offset
);
167 static inline u8
cs4231_inb(struct snd_cs4231
*chip
, u8 offset
)
169 return inb(chip
->port
+ offset
);
172 static void snd_cs4231_wait(struct snd_cs4231
*chip
)
177 timeout
> 0 && (cs4231_inb(chip
, CS4231P(REGSEL
)) & CS4231_INIT
);
182 static void snd_cs4231_outm(struct snd_cs4231
*chip
, unsigned char reg
,
183 unsigned char mask
, unsigned char value
)
185 unsigned char tmp
= (chip
->image
[reg
] & mask
) | value
;
187 snd_cs4231_wait(chip
);
188 #ifdef CONFIG_SND_DEBUG
189 if (cs4231_inb(chip
, CS4231P(REGSEL
)) & CS4231_INIT
)
190 snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg
, value
);
192 chip
->image
[reg
] = tmp
;
193 if (!chip
->calibrate_mute
) {
194 cs4231_outb(chip
, CS4231P(REGSEL
), chip
->mce_bit
| reg
);
196 cs4231_outb(chip
, CS4231P(REG
), tmp
);
201 static void snd_cs4231_dout(struct snd_cs4231
*chip
, unsigned char reg
, unsigned char value
)
206 timeout
> 0 && (cs4231_inb(chip
, CS4231P(REGSEL
)) & CS4231_INIT
);
209 cs4231_outb(chip
, CS4231P(REGSEL
), chip
->mce_bit
| reg
);
210 cs4231_outb(chip
, CS4231P(REG
), value
);
214 void snd_cs4231_out(struct snd_cs4231
*chip
, unsigned char reg
, unsigned char value
)
216 snd_cs4231_wait(chip
);
217 #ifdef CONFIG_SND_DEBUG
218 if (cs4231_inb(chip
, CS4231P(REGSEL
)) & CS4231_INIT
)
219 snd_printk("out: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg
, value
);
221 cs4231_outb(chip
, CS4231P(REGSEL
), chip
->mce_bit
| reg
);
222 cs4231_outb(chip
, CS4231P(REG
), value
);
223 chip
->image
[reg
] = value
;
225 snd_printdd("codec out - reg 0x%x = 0x%x\n",
226 chip
->mce_bit
| reg
, value
);
229 unsigned char snd_cs4231_in(struct snd_cs4231
*chip
, unsigned char reg
)
231 snd_cs4231_wait(chip
);
232 #ifdef CONFIG_SND_DEBUG
233 if (cs4231_inb(chip
, CS4231P(REGSEL
)) & CS4231_INIT
)
234 snd_printk("in: auto calibration time out - reg = 0x%x\n", reg
);
236 cs4231_outb(chip
, CS4231P(REGSEL
), chip
->mce_bit
| reg
);
238 return cs4231_inb(chip
, CS4231P(REG
));
241 void snd_cs4236_ext_out(struct snd_cs4231
*chip
, unsigned char reg
, unsigned char val
)
243 cs4231_outb(chip
, CS4231P(REGSEL
), chip
->mce_bit
| 0x17);
244 cs4231_outb(chip
, CS4231P(REG
), reg
| (chip
->image
[CS4236_EXT_REG
] & 0x01));
245 cs4231_outb(chip
, CS4231P(REG
), val
);
246 chip
->eimage
[CS4236_REG(reg
)] = val
;
248 printk("ext out : reg = 0x%x, val = 0x%x\n", reg
, val
);
252 unsigned char snd_cs4236_ext_in(struct snd_cs4231
*chip
, unsigned char reg
)
254 cs4231_outb(chip
, CS4231P(REGSEL
), chip
->mce_bit
| 0x17);
255 cs4231_outb(chip
, CS4231P(REG
), reg
| (chip
->image
[CS4236_EXT_REG
] & 0x01));
257 return cs4231_inb(chip
, CS4231P(REG
));
261 res
= cs4231_inb(chip
, CS4231P(REG
));
262 printk("ext in : reg = 0x%x, val = 0x%x\n", reg
, res
);
270 static void snd_cs4231_debug(struct snd_cs4231
*chip
)
272 printk("CS4231 REGS: INDEX = 0x%02x ", cs4231_inb(chip
, CS4231P(REGSEL
)));
273 printk(" STATUS = 0x%02x\n", cs4231_inb(chip
, CS4231P(STATUS
)));
274 printk(" 0x00: left input = 0x%02x ", snd_cs4231_in(chip
, 0x00));
275 printk(" 0x10: alt 1 (CFIG 2) = 0x%02x\n", snd_cs4231_in(chip
, 0x10));
276 printk(" 0x01: right input = 0x%02x ", snd_cs4231_in(chip
, 0x01));
277 printk(" 0x11: alt 2 (CFIG 3) = 0x%02x\n", snd_cs4231_in(chip
, 0x11));
278 printk(" 0x02: GF1 left input = 0x%02x ", snd_cs4231_in(chip
, 0x02));
279 printk(" 0x12: left line in = 0x%02x\n", snd_cs4231_in(chip
, 0x12));
280 printk(" 0x03: GF1 right input = 0x%02x ", snd_cs4231_in(chip
, 0x03));
281 printk(" 0x13: right line in = 0x%02x\n", snd_cs4231_in(chip
, 0x13));
282 printk(" 0x04: CD left input = 0x%02x ", snd_cs4231_in(chip
, 0x04));
283 printk(" 0x14: timer low = 0x%02x\n", snd_cs4231_in(chip
, 0x14));
284 printk(" 0x05: CD right input = 0x%02x ", snd_cs4231_in(chip
, 0x05));
285 printk(" 0x15: timer high = 0x%02x\n", snd_cs4231_in(chip
, 0x15));
286 printk(" 0x06: left output = 0x%02x ", snd_cs4231_in(chip
, 0x06));
287 printk(" 0x16: left MIC (PnP) = 0x%02x\n", snd_cs4231_in(chip
, 0x16));
288 printk(" 0x07: right output = 0x%02x ", snd_cs4231_in(chip
, 0x07));
289 printk(" 0x17: right MIC (PnP) = 0x%02x\n", snd_cs4231_in(chip
, 0x17));
290 printk(" 0x08: playback format = 0x%02x ", snd_cs4231_in(chip
, 0x08));
291 printk(" 0x18: IRQ status = 0x%02x\n", snd_cs4231_in(chip
, 0x18));
292 printk(" 0x09: iface (CFIG 1) = 0x%02x ", snd_cs4231_in(chip
, 0x09));
293 printk(" 0x19: left line out = 0x%02x\n", snd_cs4231_in(chip
, 0x19));
294 printk(" 0x0a: pin control = 0x%02x ", snd_cs4231_in(chip
, 0x0a));
295 printk(" 0x1a: mono control = 0x%02x\n", snd_cs4231_in(chip
, 0x1a));
296 printk(" 0x0b: init & status = 0x%02x ", snd_cs4231_in(chip
, 0x0b));
297 printk(" 0x1b: right line out = 0x%02x\n", snd_cs4231_in(chip
, 0x1b));
298 printk(" 0x0c: revision & mode = 0x%02x ", snd_cs4231_in(chip
, 0x0c));
299 printk(" 0x1c: record format = 0x%02x\n", snd_cs4231_in(chip
, 0x1c));
300 printk(" 0x0d: loopback = 0x%02x ", snd_cs4231_in(chip
, 0x0d));
301 printk(" 0x1d: var freq (PnP) = 0x%02x\n", snd_cs4231_in(chip
, 0x1d));
302 printk(" 0x0e: ply upr count = 0x%02x ", snd_cs4231_in(chip
, 0x0e));
303 printk(" 0x1e: ply lwr count = 0x%02x\n", snd_cs4231_in(chip
, 0x1e));
304 printk(" 0x0f: rec upr count = 0x%02x ", snd_cs4231_in(chip
, 0x0f));
305 printk(" 0x1f: rec lwr count = 0x%02x\n", snd_cs4231_in(chip
, 0x1f));
311 * CS4231 detection / MCE routines
314 static void snd_cs4231_busy_wait(struct snd_cs4231
*chip
)
318 /* huh.. looks like this sequence is proper for CS4231A chip (GUS MAX) */
319 for (timeout
= 5; timeout
> 0; timeout
--)
320 cs4231_inb(chip
, CS4231P(REGSEL
));
321 /* end of cleanup sequence */
323 timeout
> 0 && (cs4231_inb(chip
, CS4231P(REGSEL
)) & CS4231_INIT
);
328 void snd_cs4231_mce_up(struct snd_cs4231
*chip
)
333 snd_cs4231_wait(chip
);
334 #ifdef CONFIG_SND_DEBUG
335 if (cs4231_inb(chip
, CS4231P(REGSEL
)) & CS4231_INIT
)
336 snd_printk("mce_up - auto calibration time out (0)\n");
338 spin_lock_irqsave(&chip
->reg_lock
, flags
);
339 chip
->mce_bit
|= CS4231_MCE
;
340 timeout
= cs4231_inb(chip
, CS4231P(REGSEL
));
342 snd_printk("mce_up [0x%lx]: serious init problem - codec still busy\n", chip
->port
);
343 if (!(timeout
& CS4231_MCE
))
344 cs4231_outb(chip
, CS4231P(REGSEL
), chip
->mce_bit
| (timeout
& 0x1f));
345 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
348 void snd_cs4231_mce_down(struct snd_cs4231
*chip
)
351 unsigned long end_time
;
354 snd_cs4231_busy_wait(chip
);
356 #ifdef CONFIG_SND_DEBUG
357 if (cs4231_inb(chip
, CS4231P(REGSEL
)) & CS4231_INIT
)
358 snd_printk("mce_down [0x%lx] - auto calibration time out (0)\n", (long)CS4231P(REGSEL
));
360 spin_lock_irqsave(&chip
->reg_lock
, flags
);
361 chip
->mce_bit
&= ~CS4231_MCE
;
362 timeout
= cs4231_inb(chip
, CS4231P(REGSEL
));
363 cs4231_outb(chip
, CS4231P(REGSEL
), chip
->mce_bit
| (timeout
& 0x1f));
364 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
366 snd_printk("mce_down [0x%lx]: serious init problem - codec still busy\n", chip
->port
);
367 if ((timeout
& CS4231_MCE
) == 0 ||
368 !(chip
->hardware
& (CS4231_HW_CS4231_MASK
| CS4231_HW_CS4232_MASK
))) {
373 * Wait for (possible -- during init auto-calibration may not be set)
374 * calibration process to start. Needs upto 5 sample periods on AD1848
375 * which at the slowest possible rate of 5.5125 kHz means 907 us.
379 snd_printdd("(1) jiffies = %lu\n", jiffies
);
381 /* check condition up to 250 ms */
382 end_time
= jiffies
+ msecs_to_jiffies(250);
383 while (snd_cs4231_in(chip
, CS4231_TEST_INIT
) &
384 CS4231_CALIB_IN_PROGRESS
) {
386 if (time_after(jiffies
, end_time
)) {
387 snd_printk(KERN_ERR
"mce_down - "
388 "auto calibration time out (2)\n");
394 snd_printdd("(2) jiffies = %lu\n", jiffies
);
396 /* check condition up to 100 ms */
397 end_time
= jiffies
+ msecs_to_jiffies(100);
398 while (cs4231_inb(chip
, CS4231P(REGSEL
)) & CS4231_INIT
) {
399 if (time_after(jiffies
, end_time
)) {
400 snd_printk(KERN_ERR
"mce_down - auto calibration time out (3)\n");
406 snd_printdd("(3) jiffies = %lu\n", jiffies
);
407 snd_printd("mce_down - exit = 0x%x\n", cs4231_inb(chip
, CS4231P(REGSEL
)));
410 static unsigned int snd_cs4231_get_count(unsigned char format
, unsigned int size
)
412 switch (format
& 0xe0) {
413 case CS4231_LINEAR_16
:
414 case CS4231_LINEAR_16_BIG
:
417 case CS4231_ADPCM_16
:
420 if (format
& CS4231_STEREO
)
425 static int snd_cs4231_trigger(struct snd_pcm_substream
*substream
,
428 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
431 struct snd_pcm_substream
*s
;
435 printk("codec trigger!!! - what = %i, enable = %i, status = 0x%x\n", what
, enable
, cs4231_inb(chip
, CS4231P(STATUS
)));
439 case SNDRV_PCM_TRIGGER_START
:
440 case SNDRV_PCM_TRIGGER_RESUME
:
442 case SNDRV_PCM_TRIGGER_STOP
:
443 case SNDRV_PCM_TRIGGER_SUSPEND
:
450 snd_pcm_group_for_each_entry(s
, substream
) {
451 if (s
== chip
->playback_substream
) {
452 what
|= CS4231_PLAYBACK_ENABLE
;
453 snd_pcm_trigger_done(s
, substream
);
454 } else if (s
== chip
->capture_substream
) {
455 what
|= CS4231_RECORD_ENABLE
;
456 snd_pcm_trigger_done(s
, substream
);
459 spin_lock(&chip
->reg_lock
);
461 chip
->image
[CS4231_IFACE_CTRL
] |= what
;
463 chip
->trigger(chip
, what
, 1);
465 chip
->image
[CS4231_IFACE_CTRL
] &= ~what
;
467 chip
->trigger(chip
, what
, 0);
469 snd_cs4231_out(chip
, CS4231_IFACE_CTRL
, chip
->image
[CS4231_IFACE_CTRL
]);
470 spin_unlock(&chip
->reg_lock
);
472 snd_cs4231_debug(chip
);
481 static unsigned char snd_cs4231_get_rate(unsigned int rate
)
485 for (i
= 0; i
< ARRAY_SIZE(rates
); i
++)
486 if (rate
== rates
[i
])
489 return freq_bits
[ARRAY_SIZE(rates
) - 1];
492 static unsigned char snd_cs4231_get_format(struct snd_cs4231
*chip
,
496 unsigned char rformat
;
498 rformat
= CS4231_LINEAR_8
;
500 case SNDRV_PCM_FORMAT_MU_LAW
: rformat
= CS4231_ULAW_8
; break;
501 case SNDRV_PCM_FORMAT_A_LAW
: rformat
= CS4231_ALAW_8
; break;
502 case SNDRV_PCM_FORMAT_S16_LE
: rformat
= CS4231_LINEAR_16
; break;
503 case SNDRV_PCM_FORMAT_S16_BE
: rformat
= CS4231_LINEAR_16_BIG
; break;
504 case SNDRV_PCM_FORMAT_IMA_ADPCM
: rformat
= CS4231_ADPCM_16
; break;
507 rformat
|= CS4231_STEREO
;
509 snd_printk("get_format: 0x%x (mode=0x%x)\n", format
, mode
);
514 static void snd_cs4231_calibrate_mute(struct snd_cs4231
*chip
, int mute
)
519 spin_lock_irqsave(&chip
->reg_lock
, flags
);
520 if (chip
->calibrate_mute
== mute
) {
521 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
525 snd_cs4231_dout(chip
, CS4231_LEFT_INPUT
, chip
->image
[CS4231_LEFT_INPUT
]);
526 snd_cs4231_dout(chip
, CS4231_RIGHT_INPUT
, chip
->image
[CS4231_RIGHT_INPUT
]);
527 snd_cs4231_dout(chip
, CS4231_LOOPBACK
, chip
->image
[CS4231_LOOPBACK
]);
529 snd_cs4231_dout(chip
, CS4231_AUX1_LEFT_INPUT
, mute
? 0x80 : chip
->image
[CS4231_AUX1_LEFT_INPUT
]);
530 snd_cs4231_dout(chip
, CS4231_AUX1_RIGHT_INPUT
, mute
? 0x80 : chip
->image
[CS4231_AUX1_RIGHT_INPUT
]);
531 snd_cs4231_dout(chip
, CS4231_AUX2_LEFT_INPUT
, mute
? 0x80 : chip
->image
[CS4231_AUX2_LEFT_INPUT
]);
532 snd_cs4231_dout(chip
, CS4231_AUX2_RIGHT_INPUT
, mute
? 0x80 : chip
->image
[CS4231_AUX2_RIGHT_INPUT
]);
533 snd_cs4231_dout(chip
, CS4231_LEFT_OUTPUT
, mute
? 0x80 : chip
->image
[CS4231_LEFT_OUTPUT
]);
534 snd_cs4231_dout(chip
, CS4231_RIGHT_OUTPUT
, mute
? 0x80 : chip
->image
[CS4231_RIGHT_OUTPUT
]);
535 snd_cs4231_dout(chip
, CS4231_LEFT_LINE_IN
, mute
? 0x80 : chip
->image
[CS4231_LEFT_LINE_IN
]);
536 snd_cs4231_dout(chip
, CS4231_RIGHT_LINE_IN
, mute
? 0x80 : chip
->image
[CS4231_RIGHT_LINE_IN
]);
537 snd_cs4231_dout(chip
, CS4231_MONO_CTRL
, mute
? 0xc0 : chip
->image
[CS4231_MONO_CTRL
]);
538 if (chip
->hardware
== CS4231_HW_INTERWAVE
) {
539 snd_cs4231_dout(chip
, CS4231_LEFT_MIC_INPUT
, mute
? 0x80 : chip
->image
[CS4231_LEFT_MIC_INPUT
]);
540 snd_cs4231_dout(chip
, CS4231_RIGHT_MIC_INPUT
, mute
? 0x80 : chip
->image
[CS4231_RIGHT_MIC_INPUT
]);
541 snd_cs4231_dout(chip
, CS4231_LINE_LEFT_OUTPUT
, mute
? 0x80 : chip
->image
[CS4231_LINE_LEFT_OUTPUT
]);
542 snd_cs4231_dout(chip
, CS4231_LINE_RIGHT_OUTPUT
, mute
? 0x80 : chip
->image
[CS4231_LINE_RIGHT_OUTPUT
]);
544 chip
->calibrate_mute
= mute
;
545 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
548 static void snd_cs4231_playback_format(struct snd_cs4231
*chip
,
549 struct snd_pcm_hw_params
*params
,
555 mutex_lock(&chip
->mce_mutex
);
556 snd_cs4231_calibrate_mute(chip
, 1);
557 if (chip
->hardware
== CS4231_HW_CS4231A
||
558 (chip
->hardware
& CS4231_HW_CS4232_MASK
)) {
559 spin_lock_irqsave(&chip
->reg_lock
, flags
);
560 if ((chip
->image
[CS4231_PLAYBK_FORMAT
] & 0x0f) == (pdfr
& 0x0f)) { /* rate is same? */
561 snd_cs4231_out(chip
, CS4231_ALT_FEATURE_1
, chip
->image
[CS4231_ALT_FEATURE_1
] | 0x10);
562 snd_cs4231_out(chip
, CS4231_PLAYBK_FORMAT
, chip
->image
[CS4231_PLAYBK_FORMAT
] = pdfr
);
563 snd_cs4231_out(chip
, CS4231_ALT_FEATURE_1
, chip
->image
[CS4231_ALT_FEATURE_1
] &= ~0x10);
564 udelay(100); /* Fixes audible clicks at least on GUS MAX */
567 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
570 snd_cs4231_mce_up(chip
);
571 spin_lock_irqsave(&chip
->reg_lock
, flags
);
572 if (chip
->hardware
!= CS4231_HW_INTERWAVE
&& !chip
->single_dma
) {
573 snd_cs4231_out(chip
, CS4231_PLAYBK_FORMAT
,
574 (chip
->image
[CS4231_IFACE_CTRL
] & CS4231_RECORD_ENABLE
) ?
575 (pdfr
& 0xf0) | (chip
->image
[CS4231_REC_FORMAT
] & 0x0f) :
578 snd_cs4231_out(chip
, CS4231_PLAYBK_FORMAT
, chip
->image
[CS4231_PLAYBK_FORMAT
] = pdfr
);
580 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
581 if (chip
->hardware
== CS4231_HW_OPL3SA2
)
582 udelay(100); /* this seems to help */
583 snd_cs4231_mce_down(chip
);
585 snd_cs4231_calibrate_mute(chip
, 0);
586 mutex_unlock(&chip
->mce_mutex
);
589 static void snd_cs4231_capture_format(struct snd_cs4231
*chip
,
590 struct snd_pcm_hw_params
*params
,
596 mutex_lock(&chip
->mce_mutex
);
597 snd_cs4231_calibrate_mute(chip
, 1);
598 if (chip
->hardware
== CS4231_HW_CS4231A
||
599 (chip
->hardware
& CS4231_HW_CS4232_MASK
)) {
600 spin_lock_irqsave(&chip
->reg_lock
, flags
);
601 if ((chip
->image
[CS4231_PLAYBK_FORMAT
] & 0x0f) == (cdfr
& 0x0f) || /* rate is same? */
602 (chip
->image
[CS4231_IFACE_CTRL
] & CS4231_PLAYBACK_ENABLE
)) {
603 snd_cs4231_out(chip
, CS4231_ALT_FEATURE_1
, chip
->image
[CS4231_ALT_FEATURE_1
] | 0x20);
604 snd_cs4231_out(chip
, CS4231_REC_FORMAT
, chip
->image
[CS4231_REC_FORMAT
] = cdfr
);
605 snd_cs4231_out(chip
, CS4231_ALT_FEATURE_1
, chip
->image
[CS4231_ALT_FEATURE_1
] &= ~0x20);
608 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
611 snd_cs4231_mce_up(chip
);
612 spin_lock_irqsave(&chip
->reg_lock
, flags
);
613 if (chip
->hardware
!= CS4231_HW_INTERWAVE
) {
614 if (!(chip
->image
[CS4231_IFACE_CTRL
] & CS4231_PLAYBACK_ENABLE
)) {
615 snd_cs4231_out(chip
, CS4231_PLAYBK_FORMAT
,
616 ((chip
->single_dma
? cdfr
: chip
->image
[CS4231_PLAYBK_FORMAT
]) & 0xf0) |
618 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
619 snd_cs4231_mce_down(chip
);
620 snd_cs4231_mce_up(chip
);
621 spin_lock_irqsave(&chip
->reg_lock
, flags
);
624 snd_cs4231_out(chip
, CS4231_REC_FORMAT
, cdfr
);
625 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
626 snd_cs4231_mce_down(chip
);
628 snd_cs4231_calibrate_mute(chip
, 0);
629 mutex_unlock(&chip
->mce_mutex
);
636 static unsigned long snd_cs4231_timer_resolution(struct snd_timer
* timer
)
638 struct snd_cs4231
*chip
= snd_timer_chip(timer
);
639 if (chip
->hardware
& CS4231_HW_CS4236B_MASK
)
642 return chip
->image
[CS4231_PLAYBK_FORMAT
] & 1 ? 9969 : 9920;
645 static int snd_cs4231_timer_start(struct snd_timer
* timer
)
649 struct snd_cs4231
*chip
= snd_timer_chip(timer
);
650 spin_lock_irqsave(&chip
->reg_lock
, flags
);
651 ticks
= timer
->sticks
;
652 if ((chip
->image
[CS4231_ALT_FEATURE_1
] & CS4231_TIMER_ENABLE
) == 0 ||
653 (unsigned char)(ticks
>> 8) != chip
->image
[CS4231_TIMER_HIGH
] ||
654 (unsigned char)ticks
!= chip
->image
[CS4231_TIMER_LOW
]) {
655 snd_cs4231_out(chip
, CS4231_TIMER_HIGH
, chip
->image
[CS4231_TIMER_HIGH
] = (unsigned char) (ticks
>> 8));
656 snd_cs4231_out(chip
, CS4231_TIMER_LOW
, chip
->image
[CS4231_TIMER_LOW
] = (unsigned char) ticks
);
657 snd_cs4231_out(chip
, CS4231_ALT_FEATURE_1
, chip
->image
[CS4231_ALT_FEATURE_1
] | CS4231_TIMER_ENABLE
);
659 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
663 static int snd_cs4231_timer_stop(struct snd_timer
* timer
)
666 struct snd_cs4231
*chip
= snd_timer_chip(timer
);
667 spin_lock_irqsave(&chip
->reg_lock
, flags
);
668 snd_cs4231_out(chip
, CS4231_ALT_FEATURE_1
, chip
->image
[CS4231_ALT_FEATURE_1
] &= ~CS4231_TIMER_ENABLE
);
669 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
673 static void snd_cs4231_init(struct snd_cs4231
*chip
)
677 snd_cs4231_mce_down(chip
);
679 #ifdef SNDRV_DEBUG_MCE
680 snd_printk("init: (1)\n");
682 snd_cs4231_mce_up(chip
);
683 spin_lock_irqsave(&chip
->reg_lock
, flags
);
684 chip
->image
[CS4231_IFACE_CTRL
] &= ~(CS4231_PLAYBACK_ENABLE
| CS4231_PLAYBACK_PIO
|
685 CS4231_RECORD_ENABLE
| CS4231_RECORD_PIO
|
687 chip
->image
[CS4231_IFACE_CTRL
] |= CS4231_AUTOCALIB
;
688 snd_cs4231_out(chip
, CS4231_IFACE_CTRL
, chip
->image
[CS4231_IFACE_CTRL
]);
689 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
690 snd_cs4231_mce_down(chip
);
692 #ifdef SNDRV_DEBUG_MCE
693 snd_printk("init: (2)\n");
696 snd_cs4231_mce_up(chip
);
697 spin_lock_irqsave(&chip
->reg_lock
, flags
);
698 snd_cs4231_out(chip
, CS4231_ALT_FEATURE_1
, chip
->image
[CS4231_ALT_FEATURE_1
]);
699 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
700 snd_cs4231_mce_down(chip
);
702 #ifdef SNDRV_DEBUG_MCE
703 snd_printk("init: (3) - afei = 0x%x\n", chip
->image
[CS4231_ALT_FEATURE_1
]);
706 spin_lock_irqsave(&chip
->reg_lock
, flags
);
707 snd_cs4231_out(chip
, CS4231_ALT_FEATURE_2
, chip
->image
[CS4231_ALT_FEATURE_2
]);
708 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
710 snd_cs4231_mce_up(chip
);
711 spin_lock_irqsave(&chip
->reg_lock
, flags
);
712 snd_cs4231_out(chip
, CS4231_PLAYBK_FORMAT
, chip
->image
[CS4231_PLAYBK_FORMAT
]);
713 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
714 snd_cs4231_mce_down(chip
);
716 #ifdef SNDRV_DEBUG_MCE
717 snd_printk("init: (4)\n");
720 snd_cs4231_mce_up(chip
);
721 spin_lock_irqsave(&chip
->reg_lock
, flags
);
722 snd_cs4231_out(chip
, CS4231_REC_FORMAT
, chip
->image
[CS4231_REC_FORMAT
]);
723 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
724 snd_cs4231_mce_down(chip
);
726 #ifdef SNDRV_DEBUG_MCE
727 snd_printk("init: (5)\n");
731 static int snd_cs4231_open(struct snd_cs4231
*chip
, unsigned int mode
)
735 mutex_lock(&chip
->open_mutex
);
736 if ((chip
->mode
& mode
) ||
737 ((chip
->mode
& CS4231_MODE_OPEN
) && chip
->single_dma
)) {
738 mutex_unlock(&chip
->open_mutex
);
741 if (chip
->mode
& CS4231_MODE_OPEN
) {
743 mutex_unlock(&chip
->open_mutex
);
746 /* ok. now enable and ack CODEC IRQ */
747 spin_lock_irqsave(&chip
->reg_lock
, flags
);
748 snd_cs4231_out(chip
, CS4231_IRQ_STATUS
, CS4231_PLAYBACK_IRQ
|
751 snd_cs4231_out(chip
, CS4231_IRQ_STATUS
, 0);
752 cs4231_outb(chip
, CS4231P(STATUS
), 0); /* clear IRQ */
753 cs4231_outb(chip
, CS4231P(STATUS
), 0); /* clear IRQ */
754 chip
->image
[CS4231_PIN_CTRL
] |= CS4231_IRQ_ENABLE
;
755 snd_cs4231_out(chip
, CS4231_PIN_CTRL
, chip
->image
[CS4231_PIN_CTRL
]);
756 snd_cs4231_out(chip
, CS4231_IRQ_STATUS
, CS4231_PLAYBACK_IRQ
|
759 snd_cs4231_out(chip
, CS4231_IRQ_STATUS
, 0);
760 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
763 mutex_unlock(&chip
->open_mutex
);
767 static void snd_cs4231_close(struct snd_cs4231
*chip
, unsigned int mode
)
771 mutex_lock(&chip
->open_mutex
);
773 if (chip
->mode
& CS4231_MODE_OPEN
) {
774 mutex_unlock(&chip
->open_mutex
);
777 snd_cs4231_calibrate_mute(chip
, 1);
780 spin_lock_irqsave(&chip
->reg_lock
, flags
);
781 snd_cs4231_out(chip
, CS4231_IRQ_STATUS
, 0);
782 cs4231_outb(chip
, CS4231P(STATUS
), 0); /* clear IRQ */
783 cs4231_outb(chip
, CS4231P(STATUS
), 0); /* clear IRQ */
784 chip
->image
[CS4231_PIN_CTRL
] &= ~CS4231_IRQ_ENABLE
;
785 snd_cs4231_out(chip
, CS4231_PIN_CTRL
, chip
->image
[CS4231_PIN_CTRL
]);
787 /* now disable record & playback */
789 if (chip
->image
[CS4231_IFACE_CTRL
] & (CS4231_PLAYBACK_ENABLE
| CS4231_PLAYBACK_PIO
|
790 CS4231_RECORD_ENABLE
| CS4231_RECORD_PIO
)) {
791 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
792 snd_cs4231_mce_up(chip
);
793 spin_lock_irqsave(&chip
->reg_lock
, flags
);
794 chip
->image
[CS4231_IFACE_CTRL
] &= ~(CS4231_PLAYBACK_ENABLE
| CS4231_PLAYBACK_PIO
|
795 CS4231_RECORD_ENABLE
| CS4231_RECORD_PIO
);
796 snd_cs4231_out(chip
, CS4231_IFACE_CTRL
, chip
->image
[CS4231_IFACE_CTRL
]);
797 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
798 snd_cs4231_mce_down(chip
);
799 spin_lock_irqsave(&chip
->reg_lock
, flags
);
802 /* clear IRQ again */
803 snd_cs4231_out(chip
, CS4231_IRQ_STATUS
, 0);
804 cs4231_outb(chip
, CS4231P(STATUS
), 0); /* clear IRQ */
805 cs4231_outb(chip
, CS4231P(STATUS
), 0); /* clear IRQ */
806 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
808 snd_cs4231_calibrate_mute(chip
, 0);
811 mutex_unlock(&chip
->open_mutex
);
818 static int snd_cs4231_timer_open(struct snd_timer
* timer
)
820 struct snd_cs4231
*chip
= snd_timer_chip(timer
);
821 snd_cs4231_open(chip
, CS4231_MODE_TIMER
);
825 static int snd_cs4231_timer_close(struct snd_timer
* timer
)
827 struct snd_cs4231
*chip
= snd_timer_chip(timer
);
828 snd_cs4231_close(chip
, CS4231_MODE_TIMER
);
832 static struct snd_timer_hardware snd_cs4231_timer_table
=
834 .flags
= SNDRV_TIMER_HW_AUTO
,
837 .open
= snd_cs4231_timer_open
,
838 .close
= snd_cs4231_timer_close
,
839 .c_resolution
= snd_cs4231_timer_resolution
,
840 .start
= snd_cs4231_timer_start
,
841 .stop
= snd_cs4231_timer_stop
,
845 * ok.. exported functions..
848 static int snd_cs4231_playback_hw_params(struct snd_pcm_substream
*substream
,
849 struct snd_pcm_hw_params
*hw_params
)
851 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
852 unsigned char new_pdfr
;
855 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
857 new_pdfr
= snd_cs4231_get_format(chip
, params_format(hw_params
), params_channels(hw_params
)) |
858 snd_cs4231_get_rate(params_rate(hw_params
));
859 chip
->set_playback_format(chip
, hw_params
, new_pdfr
);
863 static int snd_cs4231_playback_hw_free(struct snd_pcm_substream
*substream
)
865 return snd_pcm_lib_free_pages(substream
);
868 static int snd_cs4231_playback_prepare(struct snd_pcm_substream
*substream
)
870 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
871 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
873 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
874 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
876 spin_lock_irqsave(&chip
->reg_lock
, flags
);
877 chip
->p_dma_size
= size
;
878 chip
->image
[CS4231_IFACE_CTRL
] &= ~(CS4231_PLAYBACK_ENABLE
| CS4231_PLAYBACK_PIO
);
879 snd_dma_program(chip
->dma1
, runtime
->dma_addr
, size
, DMA_MODE_WRITE
| DMA_AUTOINIT
);
880 count
= snd_cs4231_get_count(chip
->image
[CS4231_PLAYBK_FORMAT
], count
) - 1;
881 snd_cs4231_out(chip
, CS4231_PLY_LWR_CNT
, (unsigned char) count
);
882 snd_cs4231_out(chip
, CS4231_PLY_UPR_CNT
, (unsigned char) (count
>> 8));
883 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
885 snd_cs4231_debug(chip
);
890 static int snd_cs4231_capture_hw_params(struct snd_pcm_substream
*substream
,
891 struct snd_pcm_hw_params
*hw_params
)
893 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
894 unsigned char new_cdfr
;
897 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
899 new_cdfr
= snd_cs4231_get_format(chip
, params_format(hw_params
), params_channels(hw_params
)) |
900 snd_cs4231_get_rate(params_rate(hw_params
));
901 chip
->set_capture_format(chip
, hw_params
, new_cdfr
);
905 static int snd_cs4231_capture_hw_free(struct snd_pcm_substream
*substream
)
907 return snd_pcm_lib_free_pages(substream
);
910 static int snd_cs4231_capture_prepare(struct snd_pcm_substream
*substream
)
912 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
913 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
915 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
916 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
918 spin_lock_irqsave(&chip
->reg_lock
, flags
);
919 chip
->c_dma_size
= size
;
920 chip
->image
[CS4231_IFACE_CTRL
] &= ~(CS4231_RECORD_ENABLE
| CS4231_RECORD_PIO
);
921 snd_dma_program(chip
->dma2
, runtime
->dma_addr
, size
, DMA_MODE_READ
| DMA_AUTOINIT
);
922 count
= snd_cs4231_get_count(chip
->image
[CS4231_REC_FORMAT
], count
) - 1;
923 if (chip
->single_dma
&& chip
->hardware
!= CS4231_HW_INTERWAVE
) {
924 snd_cs4231_out(chip
, CS4231_PLY_LWR_CNT
, (unsigned char) count
);
925 snd_cs4231_out(chip
, CS4231_PLY_UPR_CNT
, (unsigned char) (count
>> 8));
927 snd_cs4231_out(chip
, CS4231_REC_LWR_CNT
, (unsigned char) count
);
928 snd_cs4231_out(chip
, CS4231_REC_UPR_CNT
, (unsigned char) (count
>> 8));
930 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
934 void snd_cs4231_overrange(struct snd_cs4231
*chip
)
939 spin_lock_irqsave(&chip
->reg_lock
, flags
);
940 res
= snd_cs4231_in(chip
, CS4231_TEST_INIT
);
941 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
942 if (res
& (0x08 | 0x02)) /* detect overrange only above 0dB; may be user selectable? */
943 chip
->capture_substream
->runtime
->overrange
++;
946 irqreturn_t
snd_cs4231_interrupt(int irq
, void *dev_id
)
948 struct snd_cs4231
*chip
= dev_id
;
949 unsigned char status
;
951 status
= snd_cs4231_in(chip
, CS4231_IRQ_STATUS
);
952 if (status
& CS4231_TIMER_IRQ
) {
954 snd_timer_interrupt(chip
->timer
, chip
->timer
->sticks
);
956 if (chip
->single_dma
&& chip
->hardware
!= CS4231_HW_INTERWAVE
) {
957 if (status
& CS4231_PLAYBACK_IRQ
) {
958 if (chip
->mode
& CS4231_MODE_PLAY
) {
959 if (chip
->playback_substream
)
960 snd_pcm_period_elapsed(chip
->playback_substream
);
962 if (chip
->mode
& CS4231_MODE_RECORD
) {
963 if (chip
->capture_substream
) {
964 snd_cs4231_overrange(chip
);
965 snd_pcm_period_elapsed(chip
->capture_substream
);
970 if (status
& CS4231_PLAYBACK_IRQ
) {
971 if (chip
->playback_substream
)
972 snd_pcm_period_elapsed(chip
->playback_substream
);
974 if (status
& CS4231_RECORD_IRQ
) {
975 if (chip
->capture_substream
) {
976 snd_cs4231_overrange(chip
);
977 snd_pcm_period_elapsed(chip
->capture_substream
);
982 spin_lock(&chip
->reg_lock
);
983 snd_cs4231_outm(chip
, CS4231_IRQ_STATUS
, ~CS4231_ALL_IRQS
| ~status
, 0);
984 spin_unlock(&chip
->reg_lock
);
988 static snd_pcm_uframes_t
snd_cs4231_playback_pointer(struct snd_pcm_substream
*substream
)
990 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
993 if (!(chip
->image
[CS4231_IFACE_CTRL
] & CS4231_PLAYBACK_ENABLE
))
995 ptr
= snd_dma_pointer(chip
->dma1
, chip
->p_dma_size
);
996 return bytes_to_frames(substream
->runtime
, ptr
);
999 static snd_pcm_uframes_t
snd_cs4231_capture_pointer(struct snd_pcm_substream
*substream
)
1001 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
1004 if (!(chip
->image
[CS4231_IFACE_CTRL
] & CS4231_RECORD_ENABLE
))
1006 ptr
= snd_dma_pointer(chip
->dma2
, chip
->c_dma_size
);
1007 return bytes_to_frames(substream
->runtime
, ptr
);
1014 static int snd_cs4231_probe(struct snd_cs4231
*chip
)
1016 unsigned long flags
;
1022 snd_cs4231_debug(chip
);
1025 for (i
= 0; i
< 50; i
++) {
1027 if (cs4231_inb(chip
, CS4231P(REGSEL
)) & CS4231_INIT
)
1030 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1031 snd_cs4231_out(chip
, CS4231_MISC_INFO
, CS4231_MODE2
);
1032 id
= snd_cs4231_in(chip
, CS4231_MISC_INFO
) & 0x0f;
1033 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1035 break; /* this is valid value */
1038 snd_printdd("cs4231: port = 0x%lx, id = 0x%x\n", chip
->port
, id
);
1040 return -ENODEV
; /* no valid device found */
1042 if (((hw
= chip
->hardware
) & CS4231_HW_TYPE_MASK
) == CS4231_HW_DETECT
) {
1043 rev
= snd_cs4231_in(chip
, CS4231_VERSION
) & 0xe7;
1044 snd_printdd("CS4231: VERSION (I25) = 0x%x\n", rev
);
1046 unsigned char tmp
= snd_cs4231_in(chip
, 23);
1047 snd_cs4231_out(chip
, 23, ~tmp
);
1048 if (snd_cs4231_in(chip
, 23) != tmp
)
1049 chip
->hardware
= CS4231_HW_AD1845
;
1051 chip
->hardware
= CS4231_HW_CS4231
;
1052 } else if (rev
== 0xa0) {
1053 chip
->hardware
= CS4231_HW_CS4231A
;
1054 } else if (rev
== 0xa2) {
1055 chip
->hardware
= CS4231_HW_CS4232
;
1056 } else if (rev
== 0xb2) {
1057 chip
->hardware
= CS4231_HW_CS4232A
;
1058 } else if (rev
== 0x83) {
1059 chip
->hardware
= CS4231_HW_CS4236
;
1060 } else if (rev
== 0x03) {
1061 chip
->hardware
= CS4231_HW_CS4236B
;
1063 snd_printk("unknown CS chip with version 0x%x\n", rev
);
1064 return -ENODEV
; /* unknown CS4231 chip? */
1067 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1068 cs4231_inb(chip
, CS4231P(STATUS
)); /* clear any pendings IRQ */
1069 cs4231_outb(chip
, CS4231P(STATUS
), 0);
1071 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1073 chip
->image
[CS4231_MISC_INFO
] = CS4231_MODE2
;
1074 switch (chip
->hardware
) {
1075 case CS4231_HW_INTERWAVE
:
1076 chip
->image
[CS4231_MISC_INFO
] = CS4231_IW_MODE3
;
1078 case CS4231_HW_CS4235
:
1079 case CS4231_HW_CS4236B
:
1080 case CS4231_HW_CS4237B
:
1081 case CS4231_HW_CS4238B
:
1082 case CS4231_HW_CS4239
:
1083 if (hw
== CS4231_HW_DETECT3
)
1084 chip
->image
[CS4231_MISC_INFO
] = CS4231_4236_MODE3
;
1086 chip
->hardware
= CS4231_HW_CS4236
;
1090 chip
->image
[CS4231_IFACE_CTRL
] =
1091 (chip
->image
[CS4231_IFACE_CTRL
] & ~CS4231_SINGLE_DMA
) |
1092 (chip
->single_dma
? CS4231_SINGLE_DMA
: 0);
1093 if (chip
->hardware
!= CS4231_HW_OPTI93X
) {
1094 chip
->image
[CS4231_ALT_FEATURE_1
] = 0x80;
1095 chip
->image
[CS4231_ALT_FEATURE_2
] =
1096 chip
->hardware
== CS4231_HW_INTERWAVE
? 0xc2 : 0x01;
1098 ptr
= (unsigned char *) &chip
->image
;
1099 snd_cs4231_mce_down(chip
);
1100 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1101 for (i
= 0; i
< 32; i
++) /* ok.. fill all CS4231 registers */
1102 snd_cs4231_out(chip
, i
, *ptr
++);
1103 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1104 snd_cs4231_mce_up(chip
);
1105 snd_cs4231_mce_down(chip
);
1109 /* ok.. try check hardware version for CS4236+ chips */
1110 if ((hw
& CS4231_HW_TYPE_MASK
) == CS4231_HW_DETECT
) {
1111 if (chip
->hardware
== CS4231_HW_CS4236B
) {
1112 rev
= snd_cs4236_ext_in(chip
, CS4236_VERSION
);
1113 snd_cs4236_ext_out(chip
, CS4236_VERSION
, 0xff);
1114 id
= snd_cs4236_ext_in(chip
, CS4236_VERSION
);
1115 snd_cs4236_ext_out(chip
, CS4236_VERSION
, rev
);
1116 snd_printdd("CS4231: ext version; rev = 0x%x, id = 0x%x\n", rev
, id
);
1117 if ((id
& 0x1f) == 0x1d) { /* CS4235 */
1118 chip
->hardware
= CS4231_HW_CS4235
;
1125 snd_printk("unknown CS4235 chip (enhanced version = 0x%x)\n", id
);
1127 } else if ((id
& 0x1f) == 0x0b) { /* CS4236/B */
1133 chip
->hardware
= CS4231_HW_CS4236B
;
1136 snd_printk("unknown CS4236 chip (enhanced version = 0x%x)\n", id
);
1138 } else if ((id
& 0x1f) == 0x08) { /* CS4237B */
1139 chip
->hardware
= CS4231_HW_CS4237B
;
1147 snd_printk("unknown CS4237B chip (enhanced version = 0x%x)\n", id
);
1149 } else if ((id
& 0x1f) == 0x09) { /* CS4238B */
1150 chip
->hardware
= CS4231_HW_CS4238B
;
1157 snd_printk("unknown CS4238B chip (enhanced version = 0x%x)\n", id
);
1159 } else if ((id
& 0x1f) == 0x1e) { /* CS4239 */
1160 chip
->hardware
= CS4231_HW_CS4239
;
1167 snd_printk("unknown CS4239 chip (enhanced version = 0x%x)\n", id
);
1170 snd_printk("unknown CS4236/CS423xB chip (enhanced version = 0x%x)\n", id
);
1174 return 0; /* all things are ok.. */
1181 static struct snd_pcm_hardware snd_cs4231_playback
=
1183 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1184 SNDRV_PCM_INFO_MMAP_VALID
|
1185 SNDRV_PCM_INFO_RESUME
|
1186 SNDRV_PCM_INFO_SYNC_START
),
1187 .formats
= (SNDRV_PCM_FMTBIT_MU_LAW
| SNDRV_PCM_FMTBIT_A_LAW
| SNDRV_PCM_FMTBIT_IMA_ADPCM
|
1188 SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S16_BE
),
1189 .rates
= SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_8000_48000
,
1194 .buffer_bytes_max
= (128*1024),
1195 .period_bytes_min
= 64,
1196 .period_bytes_max
= (128*1024),
1198 .periods_max
= 1024,
1202 static struct snd_pcm_hardware snd_cs4231_capture
=
1204 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1205 SNDRV_PCM_INFO_MMAP_VALID
|
1206 SNDRV_PCM_INFO_RESUME
|
1207 SNDRV_PCM_INFO_SYNC_START
),
1208 .formats
= (SNDRV_PCM_FMTBIT_MU_LAW
| SNDRV_PCM_FMTBIT_A_LAW
| SNDRV_PCM_FMTBIT_IMA_ADPCM
|
1209 SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S16_BE
),
1210 .rates
= SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_8000_48000
,
1215 .buffer_bytes_max
= (128*1024),
1216 .period_bytes_min
= 64,
1217 .period_bytes_max
= (128*1024),
1219 .periods_max
= 1024,
1227 static int snd_cs4231_playback_open(struct snd_pcm_substream
*substream
)
1229 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
1230 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1233 runtime
->hw
= snd_cs4231_playback
;
1235 /* hardware bug in InterWave chipset */
1236 if (chip
->hardware
== CS4231_HW_INTERWAVE
&& chip
->dma1
> 3)
1237 runtime
->hw
.formats
&= ~SNDRV_PCM_FMTBIT_MU_LAW
;
1239 /* hardware limitation of cheap chips */
1240 if (chip
->hardware
== CS4231_HW_CS4235
||
1241 chip
->hardware
== CS4231_HW_CS4239
)
1242 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
;
1244 snd_pcm_limit_isa_dma_size(chip
->dma1
, &runtime
->hw
.buffer_bytes_max
);
1245 snd_pcm_limit_isa_dma_size(chip
->dma1
, &runtime
->hw
.period_bytes_max
);
1247 if (chip
->claim_dma
) {
1248 if ((err
= chip
->claim_dma(chip
, chip
->dma_private_data
, chip
->dma1
)) < 0)
1252 if ((err
= snd_cs4231_open(chip
, CS4231_MODE_PLAY
)) < 0) {
1253 if (chip
->release_dma
)
1254 chip
->release_dma(chip
, chip
->dma_private_data
, chip
->dma1
);
1255 snd_free_pages(runtime
->dma_area
, runtime
->dma_bytes
);
1258 chip
->playback_substream
= substream
;
1259 snd_pcm_set_sync(substream
);
1260 chip
->rate_constraint(runtime
);
1264 static int snd_cs4231_capture_open(struct snd_pcm_substream
*substream
)
1266 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
1267 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1270 runtime
->hw
= snd_cs4231_capture
;
1272 /* hardware limitation of cheap chips */
1273 if (chip
->hardware
== CS4231_HW_CS4235
||
1274 chip
->hardware
== CS4231_HW_CS4239
)
1275 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
;
1277 snd_pcm_limit_isa_dma_size(chip
->dma2
, &runtime
->hw
.buffer_bytes_max
);
1278 snd_pcm_limit_isa_dma_size(chip
->dma2
, &runtime
->hw
.period_bytes_max
);
1280 if (chip
->claim_dma
) {
1281 if ((err
= chip
->claim_dma(chip
, chip
->dma_private_data
, chip
->dma2
)) < 0)
1285 if ((err
= snd_cs4231_open(chip
, CS4231_MODE_RECORD
)) < 0) {
1286 if (chip
->release_dma
)
1287 chip
->release_dma(chip
, chip
->dma_private_data
, chip
->dma2
);
1288 snd_free_pages(runtime
->dma_area
, runtime
->dma_bytes
);
1291 chip
->capture_substream
= substream
;
1292 snd_pcm_set_sync(substream
);
1293 chip
->rate_constraint(runtime
);
1297 static int snd_cs4231_playback_close(struct snd_pcm_substream
*substream
)
1299 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
1301 chip
->playback_substream
= NULL
;
1302 snd_cs4231_close(chip
, CS4231_MODE_PLAY
);
1306 static int snd_cs4231_capture_close(struct snd_pcm_substream
*substream
)
1308 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
1310 chip
->capture_substream
= NULL
;
1311 snd_cs4231_close(chip
, CS4231_MODE_RECORD
);
1317 /* lowlevel suspend callback for CS4231 */
1318 static void snd_cs4231_suspend(struct snd_cs4231
*chip
)
1321 unsigned long flags
;
1323 snd_pcm_suspend_all(chip
->pcm
);
1324 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1325 for (reg
= 0; reg
< 32; reg
++)
1326 chip
->image
[reg
] = snd_cs4231_in(chip
, reg
);
1327 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1330 /* lowlevel resume callback for CS4231 */
1331 static void snd_cs4231_resume(struct snd_cs4231
*chip
)
1334 unsigned long flags
;
1337 snd_cs4231_mce_up(chip
);
1338 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1339 for (reg
= 0; reg
< 32; reg
++) {
1341 case CS4231_VERSION
:
1344 snd_cs4231_out(chip
, reg
, chip
->image
[reg
]);
1348 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1350 snd_cs4231_mce_down(chip
);
1352 /* The following is a workaround to avoid freeze after resume on TP600E.
1353 This is the first half of copy of snd_cs4231_mce_down(), but doesn't
1354 include rescheduling. -- iwai
1356 snd_cs4231_busy_wait(chip
);
1357 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1358 chip
->mce_bit
&= ~CS4231_MCE
;
1359 timeout
= cs4231_inb(chip
, CS4231P(REGSEL
));
1360 cs4231_outb(chip
, CS4231P(REGSEL
), chip
->mce_bit
| (timeout
& 0x1f));
1361 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1362 if (timeout
== 0x80)
1363 snd_printk("down [0x%lx]: serious init problem - codec still busy\n", chip
->port
);
1364 if ((timeout
& CS4231_MCE
) == 0 ||
1365 !(chip
->hardware
& (CS4231_HW_CS4231_MASK
| CS4231_HW_CS4232_MASK
))) {
1368 snd_cs4231_busy_wait(chip
);
1371 #endif /* CONFIG_PM */
1373 static int snd_cs4231_free(struct snd_cs4231
*chip
)
1375 release_and_free_resource(chip
->res_port
);
1376 release_and_free_resource(chip
->res_cport
);
1377 if (chip
->irq
>= 0) {
1378 disable_irq(chip
->irq
);
1379 if (!(chip
->hwshare
& CS4231_HWSHARE_IRQ
))
1380 free_irq(chip
->irq
, (void *) chip
);
1382 if (!(chip
->hwshare
& CS4231_HWSHARE_DMA1
) && chip
->dma1
>= 0) {
1383 snd_dma_disable(chip
->dma1
);
1384 free_dma(chip
->dma1
);
1386 if (!(chip
->hwshare
& CS4231_HWSHARE_DMA2
) && chip
->dma2
>= 0 && chip
->dma2
!= chip
->dma1
) {
1387 snd_dma_disable(chip
->dma2
);
1388 free_dma(chip
->dma2
);
1391 snd_device_free(chip
->card
, chip
->timer
);
1396 static int snd_cs4231_dev_free(struct snd_device
*device
)
1398 struct snd_cs4231
*chip
= device
->device_data
;
1399 return snd_cs4231_free(chip
);
1402 const char *snd_cs4231_chip_id(struct snd_cs4231
*chip
)
1404 switch (chip
->hardware
) {
1405 case CS4231_HW_CS4231
: return "CS4231";
1406 case CS4231_HW_CS4231A
: return "CS4231A";
1407 case CS4231_HW_CS4232
: return "CS4232";
1408 case CS4231_HW_CS4232A
: return "CS4232A";
1409 case CS4231_HW_CS4235
: return "CS4235";
1410 case CS4231_HW_CS4236
: return "CS4236";
1411 case CS4231_HW_CS4236B
: return "CS4236B";
1412 case CS4231_HW_CS4237B
: return "CS4237B";
1413 case CS4231_HW_CS4238B
: return "CS4238B";
1414 case CS4231_HW_CS4239
: return "CS4239";
1415 case CS4231_HW_INTERWAVE
: return "AMD InterWave";
1416 case CS4231_HW_OPL3SA2
: return chip
->card
->shortname
;
1417 case CS4231_HW_AD1845
: return "AD1845";
1418 case CS4231_HW_OPTI93X
: return "OPTi 93x";
1419 default: return "???";
1423 static int snd_cs4231_new(struct snd_card
*card
,
1424 unsigned short hardware
,
1425 unsigned short hwshare
,
1426 struct snd_cs4231
** rchip
)
1428 struct snd_cs4231
*chip
;
1431 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
1434 chip
->hardware
= hardware
;
1435 chip
->hwshare
= hwshare
;
1437 spin_lock_init(&chip
->reg_lock
);
1438 mutex_init(&chip
->mce_mutex
);
1439 mutex_init(&chip
->open_mutex
);
1441 chip
->rate_constraint
= snd_cs4231_xrate
;
1442 chip
->set_playback_format
= snd_cs4231_playback_format
;
1443 chip
->set_capture_format
= snd_cs4231_capture_format
;
1444 if (chip
->hardware
== CS4231_HW_OPTI93X
)
1445 memcpy(&chip
->image
, &snd_opti93x_original_image
,
1446 sizeof(snd_opti93x_original_image
));
1448 memcpy(&chip
->image
, &snd_cs4231_original_image
,
1449 sizeof(snd_cs4231_original_image
));
1455 int snd_cs4231_create(struct snd_card
*card
,
1457 unsigned long cport
,
1458 int irq
, int dma1
, int dma2
,
1459 unsigned short hardware
,
1460 unsigned short hwshare
,
1461 struct snd_cs4231
** rchip
)
1463 static struct snd_device_ops ops
= {
1464 .dev_free
= snd_cs4231_dev_free
,
1466 struct snd_cs4231
*chip
;
1469 err
= snd_cs4231_new(card
, hardware
, hwshare
, &chip
);
1477 if ((chip
->res_port
= request_region(port
, 4, "CS4231")) == NULL
) {
1478 snd_printk(KERN_ERR
"cs4231: can't grab port 0x%lx\n", port
);
1479 snd_cs4231_free(chip
);
1483 if ((long)cport
>= 0 && (chip
->res_cport
= request_region(cport
, 8, "CS4232 Control")) == NULL
) {
1484 snd_printk(KERN_ERR
"cs4231: can't grab control port 0x%lx\n", cport
);
1485 snd_cs4231_free(chip
);
1488 chip
->cport
= cport
;
1489 if (!(hwshare
& CS4231_HWSHARE_IRQ
) && request_irq(irq
, snd_cs4231_interrupt
, IRQF_DISABLED
, "CS4231", (void *) chip
)) {
1490 snd_printk(KERN_ERR
"cs4231: can't grab IRQ %d\n", irq
);
1491 snd_cs4231_free(chip
);
1495 if (!(hwshare
& CS4231_HWSHARE_DMA1
) && request_dma(dma1
, "CS4231 - 1")) {
1496 snd_printk(KERN_ERR
"cs4231: can't grab DMA1 %d\n", dma1
);
1497 snd_cs4231_free(chip
);
1501 if (!(hwshare
& CS4231_HWSHARE_DMA2
) && dma1
!= dma2
&& dma2
>= 0 && request_dma(dma2
, "CS4231 - 2")) {
1502 snd_printk(KERN_ERR
"cs4231: can't grab DMA2 %d\n", dma2
);
1503 snd_cs4231_free(chip
);
1506 if (dma1
== dma2
|| dma2
< 0) {
1507 chip
->single_dma
= 1;
1508 chip
->dma2
= chip
->dma1
;
1513 if (snd_cs4231_probe(chip
) < 0) {
1514 snd_cs4231_free(chip
);
1517 snd_cs4231_init(chip
);
1520 if (chip
->hardware
& CS4231_HW_CS4232_MASK
) {
1521 if (chip
->res_cport
== NULL
)
1522 snd_printk("CS4232 control port features are not accessible\n");
1526 /* Register device */
1527 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
)) < 0) {
1528 snd_cs4231_free(chip
);
1533 /* Power Management */
1534 chip
->suspend
= snd_cs4231_suspend
;
1535 chip
->resume
= snd_cs4231_resume
;
1542 static struct snd_pcm_ops snd_cs4231_playback_ops
= {
1543 .open
= snd_cs4231_playback_open
,
1544 .close
= snd_cs4231_playback_close
,
1545 .ioctl
= snd_pcm_lib_ioctl
,
1546 .hw_params
= snd_cs4231_playback_hw_params
,
1547 .hw_free
= snd_cs4231_playback_hw_free
,
1548 .prepare
= snd_cs4231_playback_prepare
,
1549 .trigger
= snd_cs4231_trigger
,
1550 .pointer
= snd_cs4231_playback_pointer
,
1553 static struct snd_pcm_ops snd_cs4231_capture_ops
= {
1554 .open
= snd_cs4231_capture_open
,
1555 .close
= snd_cs4231_capture_close
,
1556 .ioctl
= snd_pcm_lib_ioctl
,
1557 .hw_params
= snd_cs4231_capture_hw_params
,
1558 .hw_free
= snd_cs4231_capture_hw_free
,
1559 .prepare
= snd_cs4231_capture_prepare
,
1560 .trigger
= snd_cs4231_trigger
,
1561 .pointer
= snd_cs4231_capture_pointer
,
1564 int snd_cs4231_pcm(struct snd_cs4231
*chip
, int device
, struct snd_pcm
**rpcm
)
1566 struct snd_pcm
*pcm
;
1569 if ((err
= snd_pcm_new(chip
->card
, "CS4231", device
, 1, 1, &pcm
)) < 0)
1572 spin_lock_init(&chip
->reg_lock
);
1573 mutex_init(&chip
->mce_mutex
);
1574 mutex_init(&chip
->open_mutex
);
1576 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_cs4231_playback_ops
);
1577 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_cs4231_capture_ops
);
1580 pcm
->private_data
= chip
;
1581 pcm
->info_flags
= 0;
1582 if (chip
->single_dma
)
1583 pcm
->info_flags
|= SNDRV_PCM_INFO_HALF_DUPLEX
;
1584 if (chip
->hardware
!= CS4231_HW_INTERWAVE
)
1585 pcm
->info_flags
|= SNDRV_PCM_INFO_JOINT_DUPLEX
;
1586 strcpy(pcm
->name
, snd_cs4231_chip_id(chip
));
1588 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1590 64*1024, chip
->dma1
> 3 || chip
->dma2
> 3 ? 128*1024 : 64*1024);
1598 static void snd_cs4231_timer_free(struct snd_timer
*timer
)
1600 struct snd_cs4231
*chip
= timer
->private_data
;
1604 int snd_cs4231_timer(struct snd_cs4231
*chip
, int device
, struct snd_timer
**rtimer
)
1606 struct snd_timer
*timer
;
1607 struct snd_timer_id tid
;
1610 /* Timer initialization */
1611 tid
.dev_class
= SNDRV_TIMER_CLASS_CARD
;
1612 tid
.dev_sclass
= SNDRV_TIMER_SCLASS_NONE
;
1613 tid
.card
= chip
->card
->number
;
1614 tid
.device
= device
;
1616 if ((err
= snd_timer_new(chip
->card
, "CS4231", &tid
, &timer
)) < 0)
1618 strcpy(timer
->name
, snd_cs4231_chip_id(chip
));
1619 timer
->private_data
= chip
;
1620 timer
->private_free
= snd_cs4231_timer_free
;
1621 timer
->hw
= snd_cs4231_timer_table
;
1622 chip
->timer
= timer
;
1632 static int snd_cs4231_info_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1634 static char *texts
[4] = {
1635 "Line", "Aux", "Mic", "Mix"
1637 static char *opl3sa_texts
[4] = {
1638 "Line", "CD", "Mic", "Mix"
1640 static char *gusmax_texts
[4] = {
1641 "Line", "Synth", "Mic", "Mix"
1643 char **ptexts
= texts
;
1644 struct snd_cs4231
*chip
= snd_kcontrol_chip(kcontrol
);
1646 snd_assert(chip
->card
!= NULL
, return -EINVAL
);
1647 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1649 uinfo
->value
.enumerated
.items
= 4;
1650 if (uinfo
->value
.enumerated
.item
> 3)
1651 uinfo
->value
.enumerated
.item
= 3;
1652 if (!strcmp(chip
->card
->driver
, "GUS MAX"))
1653 ptexts
= gusmax_texts
;
1654 switch (chip
->hardware
) {
1655 case CS4231_HW_INTERWAVE
: ptexts
= gusmax_texts
; break;
1656 case CS4231_HW_OPL3SA2
: ptexts
= opl3sa_texts
; break;
1658 strcpy(uinfo
->value
.enumerated
.name
, ptexts
[uinfo
->value
.enumerated
.item
]);
1662 static int snd_cs4231_get_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1664 struct snd_cs4231
*chip
= snd_kcontrol_chip(kcontrol
);
1665 unsigned long flags
;
1667 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1668 ucontrol
->value
.enumerated
.item
[0] = (chip
->image
[CS4231_LEFT_INPUT
] & CS4231_MIXS_ALL
) >> 6;
1669 ucontrol
->value
.enumerated
.item
[1] = (chip
->image
[CS4231_RIGHT_INPUT
] & CS4231_MIXS_ALL
) >> 6;
1670 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1674 static int snd_cs4231_put_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1676 struct snd_cs4231
*chip
= snd_kcontrol_chip(kcontrol
);
1677 unsigned long flags
;
1678 unsigned short left
, right
;
1681 if (ucontrol
->value
.enumerated
.item
[0] > 3 ||
1682 ucontrol
->value
.enumerated
.item
[1] > 3)
1684 left
= ucontrol
->value
.enumerated
.item
[0] << 6;
1685 right
= ucontrol
->value
.enumerated
.item
[1] << 6;
1686 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1687 left
= (chip
->image
[CS4231_LEFT_INPUT
] & ~CS4231_MIXS_ALL
) | left
;
1688 right
= (chip
->image
[CS4231_RIGHT_INPUT
] & ~CS4231_MIXS_ALL
) | right
;
1689 change
= left
!= chip
->image
[CS4231_LEFT_INPUT
] ||
1690 right
!= chip
->image
[CS4231_RIGHT_INPUT
];
1691 snd_cs4231_out(chip
, CS4231_LEFT_INPUT
, left
);
1692 snd_cs4231_out(chip
, CS4231_RIGHT_INPUT
, right
);
1693 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1697 int snd_cs4231_info_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1699 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1701 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1703 uinfo
->value
.integer
.min
= 0;
1704 uinfo
->value
.integer
.max
= mask
;
1708 int snd_cs4231_get_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1710 struct snd_cs4231
*chip
= snd_kcontrol_chip(kcontrol
);
1711 unsigned long flags
;
1712 int reg
= kcontrol
->private_value
& 0xff;
1713 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1714 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1715 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1717 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1718 ucontrol
->value
.integer
.value
[0] = (chip
->image
[reg
] >> shift
) & mask
;
1719 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1721 ucontrol
->value
.integer
.value
[0] = mask
- ucontrol
->value
.integer
.value
[0];
1725 int snd_cs4231_put_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1727 struct snd_cs4231
*chip
= snd_kcontrol_chip(kcontrol
);
1728 unsigned long flags
;
1729 int reg
= kcontrol
->private_value
& 0xff;
1730 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1731 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1732 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1736 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1740 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1741 val
= (chip
->image
[reg
] & ~(mask
<< shift
)) | val
;
1742 change
= val
!= chip
->image
[reg
];
1743 snd_cs4231_out(chip
, reg
, val
);
1744 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1748 int snd_cs4231_info_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1750 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1752 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1754 uinfo
->value
.integer
.min
= 0;
1755 uinfo
->value
.integer
.max
= mask
;
1759 int snd_cs4231_get_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1761 struct snd_cs4231
*chip
= snd_kcontrol_chip(kcontrol
);
1762 unsigned long flags
;
1763 int left_reg
= kcontrol
->private_value
& 0xff;
1764 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
1765 int shift_left
= (kcontrol
->private_value
>> 16) & 0x07;
1766 int shift_right
= (kcontrol
->private_value
>> 19) & 0x07;
1767 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1768 int invert
= (kcontrol
->private_value
>> 22) & 1;
1770 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1771 ucontrol
->value
.integer
.value
[0] = (chip
->image
[left_reg
] >> shift_left
) & mask
;
1772 ucontrol
->value
.integer
.value
[1] = (chip
->image
[right_reg
] >> shift_right
) & mask
;
1773 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1775 ucontrol
->value
.integer
.value
[0] = mask
- ucontrol
->value
.integer
.value
[0];
1776 ucontrol
->value
.integer
.value
[1] = mask
- ucontrol
->value
.integer
.value
[1];
1781 int snd_cs4231_put_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1783 struct snd_cs4231
*chip
= snd_kcontrol_chip(kcontrol
);
1784 unsigned long flags
;
1785 int left_reg
= kcontrol
->private_value
& 0xff;
1786 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
1787 int shift_left
= (kcontrol
->private_value
>> 16) & 0x07;
1788 int shift_right
= (kcontrol
->private_value
>> 19) & 0x07;
1789 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1790 int invert
= (kcontrol
->private_value
>> 22) & 1;
1792 unsigned short val1
, val2
;
1794 val1
= ucontrol
->value
.integer
.value
[0] & mask
;
1795 val2
= ucontrol
->value
.integer
.value
[1] & mask
;
1800 val1
<<= shift_left
;
1801 val2
<<= shift_right
;
1802 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1803 val1
= (chip
->image
[left_reg
] & ~(mask
<< shift_left
)) | val1
;
1804 val2
= (chip
->image
[right_reg
] & ~(mask
<< shift_right
)) | val2
;
1805 change
= val1
!= chip
->image
[left_reg
] || val2
!= chip
->image
[right_reg
];
1806 snd_cs4231_out(chip
, left_reg
, val1
);
1807 snd_cs4231_out(chip
, right_reg
, val2
);
1808 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1812 static struct snd_kcontrol_new snd_cs4231_controls
[] = {
1813 CS4231_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT
, CS4231_RIGHT_OUTPUT
, 7, 7, 1, 1),
1814 CS4231_DOUBLE("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT
, CS4231_RIGHT_OUTPUT
, 0, 0, 63, 1),
1815 CS4231_DOUBLE("Line Playback Switch", 0, CS4231_LEFT_LINE_IN
, CS4231_RIGHT_LINE_IN
, 7, 7, 1, 1),
1816 CS4231_DOUBLE("Line Playback Volume", 0, CS4231_LEFT_LINE_IN
, CS4231_RIGHT_LINE_IN
, 0, 0, 31, 1),
1817 CS4231_DOUBLE("Aux Playback Switch", 0, CS4231_AUX1_LEFT_INPUT
, CS4231_AUX1_RIGHT_INPUT
, 7, 7, 1, 1),
1818 CS4231_DOUBLE("Aux Playback Volume", 0, CS4231_AUX1_LEFT_INPUT
, CS4231_AUX1_RIGHT_INPUT
, 0, 0, 31, 1),
1819 CS4231_DOUBLE("Aux Playback Switch", 1, CS4231_AUX2_LEFT_INPUT
, CS4231_AUX2_RIGHT_INPUT
, 7, 7, 1, 1),
1820 CS4231_DOUBLE("Aux Playback Volume", 1, CS4231_AUX2_LEFT_INPUT
, CS4231_AUX2_RIGHT_INPUT
, 0, 0, 31, 1),
1821 CS4231_SINGLE("Mono Playback Switch", 0, CS4231_MONO_CTRL
, 7, 1, 1),
1822 CS4231_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL
, 0, 15, 1),
1823 CS4231_SINGLE("Mono Output Playback Switch", 0, CS4231_MONO_CTRL
, 6, 1, 1),
1824 CS4231_SINGLE("Mono Output Playback Bypass", 0, CS4231_MONO_CTRL
, 5, 1, 0),
1825 CS4231_DOUBLE("Capture Volume", 0, CS4231_LEFT_INPUT
, CS4231_RIGHT_INPUT
, 0, 0, 15, 0),
1827 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1828 .name
= "Capture Source",
1829 .info
= snd_cs4231_info_mux
,
1830 .get
= snd_cs4231_get_mux
,
1831 .put
= snd_cs4231_put_mux
,
1833 CS4231_DOUBLE("Mic Boost", 0, CS4231_LEFT_INPUT
, CS4231_RIGHT_INPUT
, 5, 5, 1, 0),
1834 CS4231_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK
, 0, 1, 0),
1835 CS4231_SINGLE("Loopback Capture Volume", 0, CS4231_LOOPBACK
, 2, 63, 1)
1838 static struct snd_kcontrol_new snd_opti93x_controls
[] = {
1839 CS4231_DOUBLE("Master Playback Switch", 0,
1840 OPTi93X_OUT_LEFT
, OPTi93X_OUT_RIGHT
, 7, 7, 1, 1),
1841 CS4231_DOUBLE("Master Playback Volume", 0,
1842 OPTi93X_OUT_LEFT
, OPTi93X_OUT_RIGHT
, 1, 1, 31, 1),
1843 CS4231_DOUBLE("PCM Playback Switch", 0,
1844 CS4231_LEFT_OUTPUT
, CS4231_RIGHT_OUTPUT
, 7, 7, 1, 1),
1845 CS4231_DOUBLE("PCM Playback Volume", 0,
1846 CS4231_LEFT_OUTPUT
, CS4231_RIGHT_OUTPUT
, 0, 0, 31, 1),
1847 CS4231_DOUBLE("FM Playback Switch", 0,
1848 CS4231_AUX2_LEFT_INPUT
, CS4231_AUX2_RIGHT_INPUT
, 7, 7, 1, 1),
1849 CS4231_DOUBLE("FM Playback Volume", 0,
1850 CS4231_AUX2_LEFT_INPUT
, CS4231_AUX2_RIGHT_INPUT
, 1, 1, 15, 1),
1851 CS4231_DOUBLE("Line Playback Switch", 0,
1852 CS4231_LEFT_LINE_IN
, CS4231_RIGHT_LINE_IN
, 7, 7, 1, 1),
1853 CS4231_DOUBLE("Line Playback Volume", 0,
1854 CS4231_LEFT_LINE_IN
, CS4231_RIGHT_LINE_IN
, 0, 0, 15, 1),
1855 CS4231_DOUBLE("Mic Playback Switch", 0,
1856 OPTi93X_MIC_LEFT_INPUT
, OPTi93X_MIC_RIGHT_INPUT
, 7, 7, 1, 1),
1857 CS4231_DOUBLE("Mic Playback Volume", 0,
1858 OPTi93X_MIC_LEFT_INPUT
, OPTi93X_MIC_RIGHT_INPUT
, 1, 1, 15, 1),
1859 CS4231_DOUBLE("Mic Boost", 0,
1860 CS4231_LEFT_INPUT
, CS4231_RIGHT_INPUT
, 5, 5, 1, 0),
1861 CS4231_DOUBLE("CD Playback Switch", 0,
1862 CS4231_AUX1_LEFT_INPUT
, CS4231_AUX1_RIGHT_INPUT
, 7, 7, 1, 1),
1863 CS4231_DOUBLE("CD Playback Volume", 0,
1864 CS4231_AUX1_LEFT_INPUT
, CS4231_AUX1_RIGHT_INPUT
, 1, 1, 15, 1),
1865 CS4231_DOUBLE("Aux Playback Switch", 0,
1866 OPTi931_AUX_LEFT_INPUT
, OPTi931_AUX_RIGHT_INPUT
, 7, 7, 1, 1),
1867 CS4231_DOUBLE("Aux Playback Volume", 0,
1868 OPTi931_AUX_LEFT_INPUT
, OPTi931_AUX_RIGHT_INPUT
, 1, 1, 15, 1),
1869 CS4231_DOUBLE("Capture Volume", 0,
1870 CS4231_LEFT_INPUT
, CS4231_RIGHT_INPUT
, 0, 0, 15, 0),
1872 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1873 .name
= "Capture Source",
1874 .info
= snd_cs4231_info_mux
,
1875 .get
= snd_cs4231_get_mux
,
1876 .put
= snd_cs4231_put_mux
,
1880 int snd_cs4231_mixer(struct snd_cs4231
*chip
)
1882 struct snd_card
*card
;
1886 snd_assert(chip
!= NULL
&& chip
->pcm
!= NULL
, return -EINVAL
);
1890 strcpy(card
->mixername
, chip
->pcm
->name
);
1892 if (chip
->hardware
== CS4231_HW_OPTI93X
)
1893 for (idx
= 0; idx
< ARRAY_SIZE(snd_opti93x_controls
); idx
++) {
1894 err
= snd_ctl_add(card
,
1895 snd_ctl_new1(&snd_opti93x_controls
[idx
],
1901 for (idx
= 0; idx
< ARRAY_SIZE(snd_cs4231_controls
); idx
++) {
1902 err
= snd_ctl_add(card
,
1903 snd_ctl_new1(&snd_cs4231_controls
[idx
],
1911 EXPORT_SYMBOL(snd_cs4231_out
);
1912 EXPORT_SYMBOL(snd_cs4231_in
);
1913 EXPORT_SYMBOL(snd_cs4236_ext_out
);
1914 EXPORT_SYMBOL(snd_cs4236_ext_in
);
1915 EXPORT_SYMBOL(snd_cs4231_mce_up
);
1916 EXPORT_SYMBOL(snd_cs4231_mce_down
);
1917 EXPORT_SYMBOL(snd_cs4231_overrange
);
1918 EXPORT_SYMBOL(snd_cs4231_interrupt
);
1919 EXPORT_SYMBOL(snd_cs4231_chip_id
);
1920 EXPORT_SYMBOL(snd_cs4231_create
);
1921 EXPORT_SYMBOL(snd_cs4231_pcm
);
1922 EXPORT_SYMBOL(snd_cs4231_mixer
);
1923 EXPORT_SYMBOL(snd_cs4231_timer
);
1924 EXPORT_SYMBOL(snd_cs4231_info_single
);
1925 EXPORT_SYMBOL(snd_cs4231_get_single
);
1926 EXPORT_SYMBOL(snd_cs4231_put_single
);
1927 EXPORT_SYMBOL(snd_cs4231_info_double
);
1928 EXPORT_SYMBOL(snd_cs4231_get_double
);
1929 EXPORT_SYMBOL(snd_cs4231_put_double
);
1935 static int __init
alsa_cs4231_init(void)
1940 static void __exit
alsa_cs4231_exit(void)
1944 module_init(alsa_cs4231_init
)
1945 module_exit(alsa_cs4231_exit
)