Merge with Linux 2.5.48.
[linux-2.6/linux-mips.git] / sound / isa / ad1848 / ad1848_lib.c
blobd36d57a2efa904b39828e10e9caf9b573a0da591
1 /*
2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * Routines for control of AD1848/AD1847/CS4248
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define SNDRV_MAIN_OBJECT_FILE
23 #include <sound/driver.h>
24 #include <linux/delay.h>
25 #include <linux/init.h>
26 #include <linux/interrupt.h>
27 #include <linux/slab.h>
28 #include <linux/ioport.h>
29 #include <sound/core.h>
30 #include <sound/ad1848.h>
31 #include <sound/pcm_params.h>
33 #include <asm/io.h>
34 #include <asm/dma.h>
36 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
37 MODULE_DESCRIPTION("Routines for control of AD1848/AD1847/CS4248");
38 MODULE_LICENSE("GPL");
40 #define chip_t ad1848_t
42 #if 0
43 #define SNDRV_DEBUG_MCE
44 #endif
47 * Some variables
50 static unsigned char freq_bits[14] = {
51 /* 5510 */ 0x00 | AD1848_XTAL2,
52 /* 6620 */ 0x0E | AD1848_XTAL2,
53 /* 8000 */ 0x00 | AD1848_XTAL1,
54 /* 9600 */ 0x0E | AD1848_XTAL1,
55 /* 11025 */ 0x02 | AD1848_XTAL2,
56 /* 16000 */ 0x02 | AD1848_XTAL1,
57 /* 18900 */ 0x04 | AD1848_XTAL2,
58 /* 22050 */ 0x06 | AD1848_XTAL2,
59 /* 27042 */ 0x04 | AD1848_XTAL1,
60 /* 32000 */ 0x06 | AD1848_XTAL1,
61 /* 33075 */ 0x0C | AD1848_XTAL2,
62 /* 37800 */ 0x08 | AD1848_XTAL2,
63 /* 44100 */ 0x0A | AD1848_XTAL2,
64 /* 48000 */ 0x0C | AD1848_XTAL1
67 static unsigned int rates[14] = {
68 5510, 6620, 8000, 9600, 11025, 16000, 18900, 22050,
69 27042, 32000, 33075, 37800, 44100, 48000
72 static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
73 .count = 14,
74 .list = rates,
75 .mask = 0,
78 static unsigned char snd_ad1848_original_image[16] =
80 0x00, /* 00 - lic */
81 0x00, /* 01 - ric */
82 0x9f, /* 02 - la1ic */
83 0x9f, /* 03 - ra1ic */
84 0x9f, /* 04 - la2ic */
85 0x9f, /* 05 - ra2ic */
86 0xbf, /* 06 - loc */
87 0xbf, /* 07 - roc */
88 0x20, /* 08 - dfr */
89 AD1848_AUTOCALIB, /* 09 - ic */
90 0x00, /* 0a - pc */
91 0x00, /* 0b - ti */
92 0x00, /* 0c - mi */
93 0x00, /* 0d - lbc */
94 0x00, /* 0e - dru */
95 0x00, /* 0f - drl */
99 * Basic I/O functions
102 void snd_ad1848_out(ad1848_t *chip,
103 unsigned char reg,
104 unsigned char value)
106 int timeout;
108 for (timeout = 250; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--)
109 udelay(100);
110 #ifdef CONFIG_SND_DEBUG
111 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
112 snd_printk("auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
113 #endif
114 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
115 outb(chip->image[reg] = value, AD1848P(chip, REG));
116 mb();
117 #if 0
118 printk("codec out - reg 0x%x = 0x%x\n", chip->mce_bit | reg, value);
119 #endif
122 void snd_ad1848_dout(ad1848_t *chip,
123 unsigned char reg,
124 unsigned char value)
126 int timeout;
128 for (timeout = 250; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--)
129 udelay(100);
130 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
131 outb(value, AD1848P(chip, REG));
132 mb();
135 unsigned char snd_ad1848_in(ad1848_t *chip, unsigned char reg)
137 int timeout;
139 for (timeout = 250; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--)
140 udelay(100);
141 #ifdef CONFIG_SND_DEBUG
142 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
143 snd_printk("auto calibration time out - reg = 0x%x\n", reg);
144 #endif
145 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
146 mb();
147 return inb(AD1848P(chip, REG));
150 #ifdef CONFIG_SND_DEBUG
152 void snd_ad1848_debug(ad1848_t *chip)
154 printk("AD1848 REGS: INDEX = 0x%02x ", inb(AD1848P(chip, REGSEL)));
155 printk(" STATUS = 0x%02x\n", inb(AD1848P(chip, STATUS)));
156 printk(" 0x00: left input = 0x%02x ", snd_ad1848_in(chip, 0x00));
157 printk(" 0x08: playback format = 0x%02x\n", snd_ad1848_in(chip, 0x08));
158 printk(" 0x01: right input = 0x%02x ", snd_ad1848_in(chip, 0x01));
159 printk(" 0x09: iface (CFIG 1) = 0x%02x\n", snd_ad1848_in(chip, 0x09));
160 printk(" 0x02: AUXA left = 0x%02x ", snd_ad1848_in(chip, 0x02));
161 printk(" 0x0a: pin control = 0x%02x\n", snd_ad1848_in(chip, 0x0a));
162 printk(" 0x03: AUXA right = 0x%02x ", snd_ad1848_in(chip, 0x03));
163 printk(" 0x0b: init & status = 0x%02x\n", snd_ad1848_in(chip, 0x0b));
164 printk(" 0x04: AUXB left = 0x%02x ", snd_ad1848_in(chip, 0x04));
165 printk(" 0x0c: revision & mode = 0x%02x\n", snd_ad1848_in(chip, 0x0c));
166 printk(" 0x05: AUXB right = 0x%02x ", snd_ad1848_in(chip, 0x05));
167 printk(" 0x0d: loopback = 0x%02x\n", snd_ad1848_in(chip, 0x0d));
168 printk(" 0x06: left output = 0x%02x ", snd_ad1848_in(chip, 0x06));
169 printk(" 0x0e: data upr count = 0x%02x\n", snd_ad1848_in(chip, 0x0e));
170 printk(" 0x07: right output = 0x%02x ", snd_ad1848_in(chip, 0x07));
171 printk(" 0x0f: data lwr count = 0x%02x\n", snd_ad1848_in(chip, 0x0f));
174 #endif
177 * AD1848 detection / MCE routines
180 void snd_ad1848_mce_up(ad1848_t *chip)
182 unsigned long flags;
183 int timeout;
185 for (timeout = 250; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--)
186 udelay(100);
187 #ifdef CONFIG_SND_DEBUG
188 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
189 snd_printk("mce_up - auto calibration time out (0)\n");
190 #endif
191 spin_lock_irqsave(&chip->reg_lock, flags);
192 chip->mce_bit |= AD1848_MCE;
193 timeout = inb(AD1848P(chip, REGSEL));
194 if (timeout == 0x80)
195 snd_printk("mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port);
196 if (!(timeout & AD1848_MCE))
197 outb(chip->mce_bit | (timeout & 0x1f), AD1848P(chip, REGSEL));
198 spin_unlock_irqrestore(&chip->reg_lock, flags);
201 void snd_ad1848_mce_down(ad1848_t *chip)
203 unsigned long flags;
204 int timeout;
205 signed long time;
207 spin_lock_irqsave(&chip->reg_lock, flags);
208 for (timeout = 5; timeout > 0; timeout--)
209 inb(AD1848P(chip, REGSEL));
210 /* end of cleanup sequence */
211 for (timeout = 12000; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--)
212 udelay(100);
213 #if 0
214 printk("(1) timeout = %i\n", timeout);
215 #endif
216 #ifdef CONFIG_SND_DEBUG
217 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
218 snd_printk("mce_down [0x%lx] - auto calibration time out (0)\n", AD1848P(chip, REGSEL));
219 #endif
220 chip->mce_bit &= ~AD1848_MCE;
221 timeout = inb(AD1848P(chip, REGSEL));
222 outb(chip->mce_bit | (timeout & 0x1f), AD1848P(chip, REGSEL));
223 if (timeout == 0x80)
224 snd_printk("mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port);
225 if ((timeout & AD1848_MCE) == 0) {
226 spin_unlock_irqrestore(&chip->reg_lock, flags);
227 return;
229 /* calibration process */
231 for (timeout = 500; timeout > 0 && (snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) == 0; timeout--);
232 if ((snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) == 0) {
233 snd_printd("mce_down - auto calibration time out (1)\n");
234 spin_unlock_irqrestore(&chip->reg_lock, flags);
235 return;
237 #if 0
238 printk("(2) timeout = %i, jiffies = %li\n", timeout, jiffies);
239 #endif
240 time = HZ / 4;
241 while (snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) {
242 spin_unlock_irqrestore(&chip->reg_lock, flags);
243 if (time <= 0) {
244 snd_printk("mce_down - auto calibration time out (2)\n");
245 return;
247 set_current_state(TASK_INTERRUPTIBLE);
248 time = schedule_timeout(time);
249 spin_lock_irqsave(&chip->reg_lock, flags);
251 #if 0
252 printk("(3) jiffies = %li\n", jiffies);
253 #endif
254 time = HZ / 10;
255 while (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) {
256 spin_unlock_irqrestore(&chip->reg_lock, flags);
257 if (time <= 0) {
258 snd_printk("mce_down - auto calibration time out (3)\n");
259 return;
261 set_current_state(TASK_INTERRUPTIBLE);
262 time = schedule_timeout(time);
263 spin_lock_irqsave(&chip->reg_lock, flags);
265 spin_unlock_irqrestore(&chip->reg_lock, flags);
266 #if 0
267 printk("(4) jiffies = %li\n", jiffies);
268 snd_printk("mce_down - exit = 0x%x\n", inb(AD1848P(chip, REGSEL)));
269 #endif
272 static unsigned int snd_ad1848_get_count(unsigned char format,
273 unsigned int size)
275 switch (format & 0xe0) {
276 case AD1848_LINEAR_16:
277 size >>= 1;
278 break;
280 if (format & AD1848_STEREO)
281 size >>= 1;
282 return size;
285 static int snd_ad1848_trigger(ad1848_t *chip, unsigned char what,
286 int channel, int cmd)
288 int result = 0;
290 #if 0
291 printk("codec trigger!!! - what = %i, enable = %i, status = 0x%x\n", what, enable, inb(AD1848P(card, STATUS)));
292 #endif
293 spin_lock(&chip->reg_lock);
294 if (cmd == SNDRV_PCM_TRIGGER_START) {
295 if (chip->image[AD1848_IFACE_CTRL] & what) {
296 spin_unlock(&chip->reg_lock);
297 return 0;
299 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL] |= what);
300 chip->mode |= AD1848_MODE_RUNNING;
301 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
302 if (!(chip->image[AD1848_IFACE_CTRL] & what)) {
303 spin_unlock(&chip->reg_lock);
304 return 0;
306 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL] &= ~what);
307 chip->mode &= ~AD1848_MODE_RUNNING;
308 } else {
309 result = -EINVAL;
311 spin_unlock(&chip->reg_lock);
312 return result;
316 * CODEC I/O
319 static unsigned char snd_ad1848_get_rate(unsigned int rate)
321 int i;
323 for (i = 0; i < 14; i++)
324 if (rate == rates[i])
325 return freq_bits[i];
326 snd_BUG();
327 return freq_bits[13];
330 static int snd_ad1848_ioctl(snd_pcm_substream_t * substream,
331 unsigned int cmd, void *arg)
333 return snd_pcm_lib_ioctl(substream, cmd, arg);
336 static unsigned char snd_ad1848_get_format(int format, int channels)
338 unsigned char rformat;
340 rformat = AD1848_LINEAR_8;
341 switch (format) {
342 case SNDRV_PCM_FORMAT_A_LAW: rformat = AD1848_ALAW_8; break;
343 case SNDRV_PCM_FORMAT_MU_LAW: rformat = AD1848_ULAW_8; break;
344 case SNDRV_PCM_FORMAT_S16_LE: rformat = AD1848_LINEAR_16; break;
346 if (channels > 1)
347 rformat |= AD1848_STEREO;
348 #if 0
349 snd_printk("get_format: 0x%x (mode=0x%x)\n", format, mode);
350 #endif
351 return rformat;
354 static void snd_ad1848_calibrate_mute(ad1848_t *chip, int mute)
356 unsigned long flags;
358 mute = mute ? 1 : 0;
359 spin_lock_irqsave(&chip->reg_lock, flags);
360 if (chip->calibrate_mute == mute) {
361 spin_unlock_irqrestore(&chip->reg_lock, flags);
362 return;
364 if (!mute) {
365 snd_ad1848_dout(chip, AD1848_LEFT_INPUT, chip->image[AD1848_LEFT_INPUT]);
366 snd_ad1848_dout(chip, AD1848_RIGHT_INPUT, chip->image[AD1848_RIGHT_INPUT]);
368 snd_ad1848_dout(chip, AD1848_AUX1_LEFT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX1_LEFT_INPUT]);
369 snd_ad1848_dout(chip, AD1848_AUX1_RIGHT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX1_RIGHT_INPUT]);
370 snd_ad1848_dout(chip, AD1848_AUX2_LEFT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX2_LEFT_INPUT]);
371 snd_ad1848_dout(chip, AD1848_AUX2_RIGHT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX2_RIGHT_INPUT]);
372 snd_ad1848_dout(chip, AD1848_LEFT_OUTPUT, mute ? 0x80 : chip->image[AD1848_LEFT_OUTPUT]);
373 snd_ad1848_dout(chip, AD1848_RIGHT_OUTPUT, mute ? 0x80 : chip->image[AD1848_RIGHT_OUTPUT]);
374 chip->calibrate_mute = mute;
375 spin_unlock_irqrestore(&chip->reg_lock, flags);
378 static void snd_ad1848_set_data_format(ad1848_t *chip, snd_pcm_hw_params_t *hw_params)
380 if (hw_params == NULL) {
381 chip->image[AD1848_DATA_FORMAT] = 0x20;
382 } else {
383 chip->image[AD1848_DATA_FORMAT] =
384 snd_ad1848_get_format(params_format(hw_params), params_channels(hw_params)) |
385 snd_ad1848_get_rate(params_rate(hw_params));
387 // snd_printk(">>> pmode = 0x%x, dfr = 0x%x\n", pstr->mode, chip->image[AD1848_DATA_FORMAT]);
390 static int snd_ad1848_open(ad1848_t *chip, unsigned int mode)
392 unsigned long flags;
394 down(&chip->open_mutex);
395 if (chip->mode & AD1848_MODE_OPEN) {
396 up(&chip->open_mutex);
397 return -EAGAIN;
399 snd_ad1848_mce_down(chip);
401 #ifdef SNDRV_DEBUG_MCE
402 snd_printk("open: (1)\n");
403 #endif
404 snd_ad1848_mce_up(chip);
405 spin_lock_irqsave(&chip->reg_lock, flags);
406 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO |
407 AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO |
408 AD1848_CALIB_MODE);
409 chip->image[AD1848_IFACE_CTRL] |= AD1848_AUTOCALIB;
410 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL]);
411 spin_unlock_irqrestore(&chip->reg_lock, flags);
412 snd_ad1848_mce_down(chip);
414 #ifdef SNDRV_DEBUG_MCE
415 snd_printk("open: (2)\n");
416 #endif
418 snd_ad1848_set_data_format(chip, NULL);
420 snd_ad1848_mce_up(chip);
421 spin_lock_irqsave(&chip->reg_lock, flags);
422 snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
423 spin_unlock_irqrestore(&chip->reg_lock, flags);
424 snd_ad1848_mce_down(chip);
426 #ifdef SNDRV_DEBUG_MCE
427 snd_printk("open: (3)\n");
428 #endif
430 /* ok. now enable and ack CODEC IRQ */
431 spin_lock_irqsave(&chip->reg_lock, flags);
432 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
433 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
434 chip->image[AD1848_PIN_CTRL] |= AD1848_IRQ_ENABLE;
435 snd_ad1848_out(chip, AD1848_PIN_CTRL, chip->image[AD1848_PIN_CTRL]);
436 spin_unlock_irqrestore(&chip->reg_lock, flags);
438 chip->mode = mode;
439 up(&chip->open_mutex);
441 return 0;
444 static void snd_ad1848_close(ad1848_t *chip)
446 unsigned long flags;
448 down(&chip->open_mutex);
449 if (!chip->mode) {
450 up(&chip->open_mutex);
451 return;
453 /* disable IRQ */
454 spin_lock_irqsave(&chip->reg_lock, flags);
455 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
456 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
457 chip->image[AD1848_PIN_CTRL] &= ~AD1848_IRQ_ENABLE;
458 snd_ad1848_out(chip, AD1848_PIN_CTRL, chip->image[AD1848_PIN_CTRL]);
459 spin_unlock_irqrestore(&chip->reg_lock, flags);
461 /* now disable capture & playback */
463 snd_ad1848_mce_up(chip);
464 spin_lock_irqsave(&chip->reg_lock, flags);
465 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO |
466 AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO);
467 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL]);
468 spin_unlock_irqrestore(&chip->reg_lock, flags);
469 snd_ad1848_mce_down(chip);
471 /* clear IRQ again */
472 spin_lock_irqsave(&chip->reg_lock, flags);
473 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
474 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
475 spin_unlock_irqrestore(&chip->reg_lock, flags);
477 chip->mode = 0;
478 up(&chip->open_mutex);
482 * ok.. exported functions..
485 static int snd_ad1848_playback_trigger(snd_pcm_substream_t * substream,
486 int cmd)
488 ad1848_t *chip = snd_pcm_substream_chip(substream);
489 return snd_ad1848_trigger(chip, AD1848_PLAYBACK_ENABLE, SNDRV_PCM_STREAM_PLAYBACK, cmd);
492 static int snd_ad1848_capture_trigger(snd_pcm_substream_t * substream,
493 int cmd)
495 ad1848_t *chip = snd_pcm_substream_chip(substream);
496 return snd_ad1848_trigger(chip, AD1848_CAPTURE_ENABLE, SNDRV_PCM_STREAM_CAPTURE, cmd);
499 static int snd_ad1848_playback_hw_params(snd_pcm_substream_t * substream,
500 snd_pcm_hw_params_t * hw_params)
502 ad1848_t *chip = snd_pcm_substream_chip(substream);
503 unsigned long flags;
504 int err;
506 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
507 return err;
508 snd_ad1848_calibrate_mute(chip, 1);
509 snd_ad1848_set_data_format(chip, hw_params);
510 snd_ad1848_mce_up(chip);
511 spin_lock_irqsave(&chip->reg_lock, flags);
512 snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
513 spin_unlock_irqrestore(&chip->reg_lock, flags);
514 snd_ad1848_mce_down(chip);
515 snd_ad1848_calibrate_mute(chip, 0);
516 return 0;
519 static int snd_ad1848_playback_hw_free(snd_pcm_substream_t * substream)
521 return snd_pcm_lib_free_pages(substream);
524 static int snd_ad1848_playback_prepare(snd_pcm_substream_t * substream)
526 ad1848_t *chip = snd_pcm_substream_chip(substream);
527 snd_pcm_runtime_t *runtime = substream->runtime;
528 unsigned long flags;
529 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
530 unsigned int count = snd_pcm_lib_period_bytes(substream);
532 chip->dma_size = size;
533 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO);
534 snd_dma_program(chip->dma, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
535 count = snd_ad1848_get_count(chip->image[AD1848_DATA_FORMAT], count) - 1;
536 spin_lock_irqsave(&chip->reg_lock, flags);
537 snd_ad1848_out(chip, AD1848_DATA_LWR_CNT, (unsigned char) count);
538 snd_ad1848_out(chip, AD1848_DATA_UPR_CNT, (unsigned char) (count >> 8));
539 spin_unlock_irqrestore(&chip->reg_lock, flags);
540 return 0;
543 static int snd_ad1848_capture_hw_params(snd_pcm_substream_t * substream,
544 snd_pcm_hw_params_t * hw_params)
546 ad1848_t *chip = snd_pcm_substream_chip(substream);
547 unsigned long flags;
548 int err;
550 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
551 return err;
552 snd_ad1848_calibrate_mute(chip, 1);
553 snd_ad1848_set_data_format(chip, hw_params);
554 snd_ad1848_mce_up(chip);
555 spin_lock_irqsave(&chip->reg_lock, flags);
556 snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
557 spin_unlock_irqrestore(&chip->reg_lock, flags);
558 snd_ad1848_mce_down(chip);
559 snd_ad1848_calibrate_mute(chip, 0);
560 return 0;
563 static int snd_ad1848_capture_hw_free(snd_pcm_substream_t * substream)
565 return snd_pcm_lib_free_pages(substream);
568 static int snd_ad1848_capture_prepare(snd_pcm_substream_t * substream)
570 ad1848_t *chip = snd_pcm_substream_chip(substream);
571 snd_pcm_runtime_t *runtime = substream->runtime;
572 unsigned long flags;
573 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
574 unsigned int count = snd_pcm_lib_period_bytes(substream);
576 chip->dma_size = size;
577 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO);
578 snd_dma_program(chip->dma, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
579 count = snd_ad1848_get_count(chip->image[AD1848_DATA_FORMAT], count) - 1;
580 spin_lock_irqsave(&chip->reg_lock, flags);
581 snd_ad1848_out(chip, AD1848_DATA_LWR_CNT, (unsigned char) count);
582 snd_ad1848_out(chip, AD1848_DATA_UPR_CNT, (unsigned char) (count >> 8));
583 spin_unlock_irqrestore(&chip->reg_lock, flags);
584 return 0;
587 void snd_ad1848_interrupt(int irq, void *dev_id, struct pt_regs *regs)
589 ad1848_t *chip = snd_magic_cast(ad1848_t, dev_id, return);
591 if ((chip->mode & AD1848_MODE_PLAY) && chip->playback_substream &&
592 (chip->mode & AD1848_MODE_RUNNING))
593 snd_pcm_period_elapsed(chip->playback_substream);
594 if ((chip->mode & AD1848_MODE_CAPTURE) && chip->capture_substream &&
595 (chip->mode & AD1848_MODE_RUNNING))
596 snd_pcm_period_elapsed(chip->capture_substream);
597 outb(0, AD1848P(chip, STATUS)); /* clear global interrupt bit */
600 static snd_pcm_uframes_t snd_ad1848_playback_pointer(snd_pcm_substream_t * substream)
602 ad1848_t *chip = snd_pcm_substream_chip(substream);
603 size_t ptr;
605 if (!(chip->image[AD1848_IFACE_CTRL] & AD1848_PLAYBACK_ENABLE))
606 return 0;
607 ptr = chip->dma_size - snd_dma_residue(chip->dma);
608 return bytes_to_frames(substream->runtime, ptr);
611 static snd_pcm_uframes_t snd_ad1848_capture_pointer(snd_pcm_substream_t * substream)
613 ad1848_t *chip = snd_pcm_substream_chip(substream);
614 size_t ptr;
616 if (!(chip->image[AD1848_IFACE_CTRL] & AD1848_CAPTURE_ENABLE))
617 return 0;
618 ptr = chip->dma_size - snd_dma_residue(chip->dma);
619 return bytes_to_frames(substream->runtime, ptr);
626 static int snd_ad1848_probe(ad1848_t * chip)
628 unsigned long flags;
629 int i, id, rev, ad1847;
630 unsigned char *ptr;
632 #if 0
633 snd_ad1848_debug(chip);
634 #endif
635 id = ad1847 = 0;
636 for (i = 0; i < 1000; i++) {
637 mb();
638 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
639 udelay(500);
640 else {
641 spin_lock_irqsave(&chip->reg_lock, flags);
642 snd_ad1848_out(chip, AD1848_MISC_INFO, 0x00);
643 snd_ad1848_out(chip, AD1848_LEFT_INPUT, 0xaa);
644 snd_ad1848_out(chip, AD1848_RIGHT_INPUT, 0x45);
645 rev = snd_ad1848_in(chip, AD1848_RIGHT_INPUT);
646 if (rev == 0x65) {
647 id = 1;
648 ad1847 = 1;
649 break;
651 if (snd_ad1848_in(chip, AD1848_LEFT_INPUT) == 0xaa && rev == 0x45) {
652 id = 1;
653 break;
655 spin_unlock_irqrestore(&chip->reg_lock, flags);
658 if (id != 1)
659 return -ENODEV; /* no valid device found */
660 if (chip->hardware == AD1848_HW_DETECT) {
661 if (ad1847) {
662 chip->hardware = AD1848_HW_AD1847;
663 } else {
664 chip->hardware = AD1848_HW_AD1848;
665 rev = snd_ad1848_in(chip, AD1848_MISC_INFO);
666 if (rev & 0x80) {
667 chip->hardware = AD1848_HW_CS4248;
668 } else if ((rev & 0x0f) == 0x0a) {
669 snd_ad1848_out(chip, AD1848_MISC_INFO, 0x40);
670 for (i = 0; i < 16; ++i) {
671 if (snd_ad1848_in(chip, i) != snd_ad1848_in(chip, i + 16)) {
672 chip->hardware = AD1848_HW_CMI8330;
673 break;
676 snd_ad1848_out(chip, AD1848_MISC_INFO, 0x00);
680 spin_lock_irqsave(&chip->reg_lock, flags);
681 inb(AD1848P(chip, STATUS)); /* clear any pendings IRQ */
682 outb(0, AD1848P(chip, STATUS));
683 mb();
684 spin_unlock_irqrestore(&chip->reg_lock, flags);
686 chip->image[AD1848_MISC_INFO] = 0x00;
687 chip->image[AD1848_IFACE_CTRL] =
688 (chip->image[AD1848_IFACE_CTRL] & ~AD1848_SINGLE_DMA) | AD1848_SINGLE_DMA;
689 ptr = (unsigned char *) &chip->image;
690 snd_ad1848_mce_down(chip);
691 spin_lock_irqsave(&chip->reg_lock, flags);
692 for (i = 0; i < 16; i++) /* ok.. fill all AD1848 registers */
693 snd_ad1848_out(chip, i, *ptr++);
694 spin_unlock_irqrestore(&chip->reg_lock, flags);
695 snd_ad1848_mce_up(chip);
696 snd_ad1848_mce_down(chip);
697 return 0; /* all things are ok.. */
704 static snd_pcm_hardware_t snd_ad1848_playback =
706 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
707 SNDRV_PCM_INFO_MMAP_VALID),
708 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
709 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE),
710 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
711 .rate_min = 5510,
712 .rate_max = 48000,
713 .channels_min = 1,
714 .channels_max = 2,
715 .buffer_bytes_max = (128*1024),
716 .period_bytes_min = 64,
717 .period_bytes_max = (128*1024),
718 .periods_min = 1,
719 .periods_max = 1024,
720 .fifo_size = 0,
723 static snd_pcm_hardware_t snd_ad1848_capture =
725 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
726 SNDRV_PCM_INFO_MMAP_VALID),
727 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
728 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE),
729 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
730 .rate_min = 5510,
731 .rate_max = 48000,
732 .channels_min = 1,
733 .channels_max = 2,
734 .buffer_bytes_max = (128*1024),
735 .period_bytes_min = 64,
736 .period_bytes_max = (128*1024),
737 .periods_min = 1,
738 .periods_max = 1024,
739 .fifo_size = 0,
746 static int snd_ad1848_playback_open(snd_pcm_substream_t * substream)
748 ad1848_t *chip = snd_pcm_substream_chip(substream);
749 snd_pcm_runtime_t *runtime = substream->runtime;
750 int err;
752 if ((err = snd_ad1848_open(chip, AD1848_MODE_PLAY)) < 0)
753 return err;
754 chip->playback_substream = substream;
755 runtime->hw = snd_ad1848_playback;
756 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.buffer_bytes_max);
757 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.period_bytes_max);
758 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
759 return 0;
762 static int snd_ad1848_capture_open(snd_pcm_substream_t * substream)
764 ad1848_t *chip = snd_pcm_substream_chip(substream);
765 snd_pcm_runtime_t *runtime = substream->runtime;
766 int err;
768 if ((err = snd_ad1848_open(chip, AD1848_MODE_CAPTURE)) < 0)
769 return err;
770 chip->capture_substream = substream;
771 runtime->hw = snd_ad1848_capture;
772 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.buffer_bytes_max);
773 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.period_bytes_max);
774 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
775 return 0;
778 static int snd_ad1848_playback_close(snd_pcm_substream_t * substream)
780 ad1848_t *chip = snd_pcm_substream_chip(substream);
782 chip->mode &= ~AD1848_MODE_PLAY;
783 chip->playback_substream = NULL;
784 snd_ad1848_close(chip);
785 return 0;
788 static int snd_ad1848_capture_close(snd_pcm_substream_t * substream)
790 ad1848_t *chip = snd_pcm_substream_chip(substream);
792 chip->mode &= ~AD1848_MODE_CAPTURE;
793 chip->capture_substream = NULL;
794 snd_ad1848_close(chip);
795 return 0;
798 static int snd_ad1848_free(ad1848_t *chip)
800 if (chip->res_port) {
801 release_resource(chip->res_port);
802 kfree_nocheck(chip->res_port);
804 if (chip->irq >= 0)
805 free_irq(chip->irq, (void *) chip);
806 if (chip->dma >= 0) {
807 snd_dma_disable(chip->dma);
808 free_dma(chip->dma);
810 snd_magic_kfree(chip);
811 return 0;
814 static int snd_ad1848_dev_free(snd_device_t *device)
816 ad1848_t *chip = snd_magic_cast(ad1848_t, device->device_data, return -ENXIO);
817 return snd_ad1848_free(chip);
820 static const char *snd_ad1848_chip_id(ad1848_t *chip)
822 switch (chip->hardware) {
823 case AD1848_HW_AD1847: return "AD1847";
824 case AD1848_HW_AD1848: return "AD1848";
825 case AD1848_HW_CS4248: return "CS4248";
826 case AD1848_HW_CMI8330: return "CMI8330/C3D";
827 default: return "???";
831 int snd_ad1848_create(snd_card_t * card,
832 unsigned long port,
833 int irq, int dma,
834 unsigned short hardware,
835 ad1848_t ** rchip)
837 static snd_device_ops_t ops = {
838 .dev_free = snd_ad1848_dev_free,
840 ad1848_t *chip;
841 int err;
843 *rchip = NULL;
844 chip = snd_magic_kcalloc(ad1848_t, 0, GFP_KERNEL);
845 if (chip == NULL)
846 return -ENOMEM;
847 spin_lock_init(&chip->reg_lock);
848 init_MUTEX(&chip->open_mutex);
849 chip->card = card;
850 chip->port = port;
851 chip->irq = -1;
852 chip->dma = -1;
853 chip->hardware = hardware;
854 memcpy(&chip->image, &snd_ad1848_original_image, sizeof(snd_ad1848_original_image));
856 if ((chip->res_port = request_region(port, 4, "AD1848")) == NULL) {
857 snd_ad1848_free(chip);
858 return -EBUSY;
860 if (request_irq(irq, snd_ad1848_interrupt, SA_INTERRUPT, "AD1848", (void *) chip)) {
861 snd_ad1848_free(chip);
862 return -EBUSY;
864 chip->irq = irq;
865 if (request_dma(dma, "AD1848")) {
866 snd_ad1848_free(chip);
867 return -EBUSY;
869 chip->dma = dma;
871 if (snd_ad1848_probe(chip) < 0) {
872 snd_ad1848_free(chip);
873 return -ENODEV;
876 /* Register device */
877 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
878 snd_ad1848_free(chip);
879 return err;
882 *rchip = chip;
883 return 0;
886 static snd_pcm_ops_t snd_ad1848_playback_ops = {
887 .open = snd_ad1848_playback_open,
888 .close = snd_ad1848_playback_close,
889 .ioctl = snd_ad1848_ioctl,
890 .hw_params = snd_ad1848_playback_hw_params,
891 .hw_free = snd_ad1848_playback_hw_free,
892 .prepare = snd_ad1848_playback_prepare,
893 .trigger = snd_ad1848_playback_trigger,
894 .pointer = snd_ad1848_playback_pointer,
897 static snd_pcm_ops_t snd_ad1848_capture_ops = {
898 .open = snd_ad1848_capture_open,
899 .close = snd_ad1848_capture_close,
900 .ioctl = snd_ad1848_ioctl,
901 .hw_params = snd_ad1848_capture_hw_params,
902 .hw_free = snd_ad1848_capture_hw_free,
903 .prepare = snd_ad1848_capture_prepare,
904 .trigger = snd_ad1848_capture_trigger,
905 .pointer = snd_ad1848_capture_pointer,
908 static void snd_ad1848_pcm_free(snd_pcm_t *pcm)
910 ad1848_t *chip = snd_magic_cast(ad1848_t, pcm->private_data, return);
911 chip->pcm = NULL;
912 snd_pcm_lib_preallocate_free_for_all(pcm);
915 int snd_ad1848_pcm(ad1848_t *chip, int device, snd_pcm_t **rpcm)
917 snd_pcm_t *pcm;
918 int err;
920 if ((err = snd_pcm_new(chip->card, "AD1848", device, 1, 1, &pcm)) < 0)
921 return err;
923 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ad1848_playback_ops);
924 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ad1848_capture_ops);
926 pcm->private_free = snd_ad1848_pcm_free;
927 pcm->private_data = chip;
928 pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
929 strcpy(pcm->name, snd_ad1848_chip_id(chip));
931 snd_pcm_lib_preallocate_isa_pages_for_all(pcm, 64*1024, chip->dma > 3 ? 128*1024 : 64*1024);
933 chip->pcm = pcm;
934 if (rpcm)
935 *rpcm = pcm;
936 return 0;
940 * MIXER part
943 static int snd_ad1848_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
945 static char *texts[4] = {
946 "Line", "Aux", "Mic", "Mix"
949 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
950 uinfo->count = 2;
951 uinfo->value.enumerated.items = 4;
952 if (uinfo->value.enumerated.item > 3)
953 uinfo->value.enumerated.item = 3;
954 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
955 return 0;
958 static int snd_ad1848_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
960 ad1848_t *chip = snd_kcontrol_chip(kcontrol);
961 unsigned long flags;
963 spin_lock_irqsave(&chip->reg_lock, flags);
964 ucontrol->value.enumerated.item[0] = (chip->image[AD1848_LEFT_INPUT] & AD1848_MIXS_ALL) >> 6;
965 ucontrol->value.enumerated.item[1] = (chip->image[AD1848_RIGHT_INPUT] & AD1848_MIXS_ALL) >> 6;
966 spin_unlock_irqrestore(&chip->reg_lock, flags);
967 return 0;
970 static int snd_ad1848_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
972 ad1848_t *chip = snd_kcontrol_chip(kcontrol);
973 unsigned long flags;
974 unsigned short left, right;
975 int change;
977 if (ucontrol->value.enumerated.item[0] > 3 ||
978 ucontrol->value.enumerated.item[1] > 3)
979 return -EINVAL;
980 left = ucontrol->value.enumerated.item[0] << 6;
981 right = ucontrol->value.enumerated.item[1] << 6;
982 spin_lock_irqsave(&chip->reg_lock, flags);
983 left = (chip->image[AD1848_LEFT_INPUT] & ~AD1848_MIXS_ALL) | left;
984 right = (chip->image[AD1848_RIGHT_INPUT] & ~AD1848_MIXS_ALL) | right;
985 change = left != chip->image[AD1848_LEFT_INPUT] ||
986 right != chip->image[AD1848_RIGHT_INPUT];
987 snd_ad1848_out(chip, AD1848_LEFT_INPUT, left);
988 snd_ad1848_out(chip, AD1848_RIGHT_INPUT, right);
989 spin_unlock_irqrestore(&chip->reg_lock, flags);
990 return change;
993 int snd_ad1848_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
995 int mask = (kcontrol->private_value >> 16) & 0xff;
997 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
998 uinfo->count = 1;
999 uinfo->value.integer.min = 0;
1000 uinfo->value.integer.max = mask;
1001 return 0;
1004 int snd_ad1848_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1006 ad1848_t *chip = snd_kcontrol_chip(kcontrol);
1007 unsigned long flags;
1008 int reg = kcontrol->private_value & 0xff;
1009 int shift = (kcontrol->private_value >> 8) & 0xff;
1010 int mask = (kcontrol->private_value >> 16) & 0xff;
1011 int invert = (kcontrol->private_value >> 24) & 0xff;
1013 spin_lock_irqsave(&chip->reg_lock, flags);
1014 ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask;
1015 spin_unlock_irqrestore(&chip->reg_lock, flags);
1016 if (invert)
1017 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1018 return 0;
1021 int snd_ad1848_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1023 ad1848_t *chip = snd_kcontrol_chip(kcontrol);
1024 unsigned long flags;
1025 int reg = kcontrol->private_value & 0xff;
1026 int shift = (kcontrol->private_value >> 8) & 0xff;
1027 int mask = (kcontrol->private_value >> 16) & 0xff;
1028 int invert = (kcontrol->private_value >> 24) & 0xff;
1029 int change;
1030 unsigned short val;
1032 val = (ucontrol->value.integer.value[0] & mask);
1033 if (invert)
1034 val = mask - val;
1035 val <<= shift;
1036 spin_lock_irqsave(&chip->reg_lock, flags);
1037 val = (chip->image[reg] & ~(mask << shift)) | val;
1038 change = val != chip->image[reg];
1039 snd_ad1848_out(chip, reg, val);
1040 spin_unlock_irqrestore(&chip->reg_lock, flags);
1041 return change;
1044 int snd_ad1848_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1046 int mask = (kcontrol->private_value >> 24) & 0xff;
1048 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1049 uinfo->count = 2;
1050 uinfo->value.integer.min = 0;
1051 uinfo->value.integer.max = mask;
1052 return 0;
1055 int snd_ad1848_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1057 ad1848_t *chip = snd_kcontrol_chip(kcontrol);
1058 unsigned long flags;
1059 int left_reg = kcontrol->private_value & 0xff;
1060 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1061 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1062 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1063 int mask = (kcontrol->private_value >> 24) & 0xff;
1064 int invert = (kcontrol->private_value >> 22) & 1;
1066 spin_lock_irqsave(&chip->reg_lock, flags);
1067 ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
1068 ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask;
1069 spin_unlock_irqrestore(&chip->reg_lock, flags);
1070 if (invert) {
1071 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1072 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
1074 return 0;
1077 int snd_ad1848_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1079 ad1848_t *chip = snd_kcontrol_chip(kcontrol);
1080 unsigned long flags;
1081 int left_reg = kcontrol->private_value & 0xff;
1082 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1083 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1084 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1085 int mask = (kcontrol->private_value >> 24) & 0xff;
1086 int invert = (kcontrol->private_value >> 22) & 1;
1087 int change;
1088 unsigned short val1, val2;
1090 val1 = ucontrol->value.integer.value[0] & mask;
1091 val2 = ucontrol->value.integer.value[1] & mask;
1092 if (invert) {
1093 val1 = mask - val1;
1094 val2 = mask - val2;
1096 val1 <<= shift_left;
1097 val2 <<= shift_right;
1098 spin_lock_irqsave(&chip->reg_lock, flags);
1099 if (left_reg != right_reg) {
1100 val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
1101 val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2;
1102 change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg];
1103 snd_ad1848_out(chip, left_reg, val1);
1104 snd_ad1848_out(chip, right_reg, val2);
1105 } else {
1106 val1 = (chip->image[left_reg] & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
1107 change = val1 != chip->image[left_reg];
1108 snd_ad1848_out(chip, left_reg, val1);
1110 spin_unlock_irqrestore(&chip->reg_lock, flags);
1111 return change;
1114 #define AD1848_CONTROLS (sizeof(snd_ad1848_controls)/sizeof(snd_kcontrol_new_t))
1116 static snd_kcontrol_new_t snd_ad1848_controls[] = {
1117 AD1848_DOUBLE("PCM Playback Switch", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 7, 7, 1, 1),
1118 AD1848_DOUBLE("PCM Playback Volume", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 0, 0, 63, 1),
1119 AD1848_DOUBLE("Aux Playback Switch", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
1120 AD1848_DOUBLE("Aux Playback Volume", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
1121 AD1848_DOUBLE("Aux Playback Switch", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
1122 AD1848_DOUBLE("Aux Playback Volume", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
1123 AD1848_DOUBLE("Capture Volume", 0, AD1848_LEFT_INPUT, AD1848_RIGHT_INPUT, 0, 0, 15, 0),
1125 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1126 .name = "Capture Source",
1127 .info = snd_ad1848_info_mux,
1128 .get = snd_ad1848_get_mux,
1129 .put = snd_ad1848_put_mux,
1131 AD1848_SINGLE("Loopback Capture Switch", 0, AD1848_LOOPBACK, 0, 1, 0),
1132 AD1848_SINGLE("Loopback Capture Volume", 0, AD1848_LOOPBACK, 1, 63, 0)
1135 int snd_ad1848_mixer(ad1848_t *chip)
1137 snd_card_t *card;
1138 snd_pcm_t *pcm;
1139 int err, idx;
1141 snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL);
1143 pcm = chip->pcm;
1144 card = chip->card;
1146 strcpy(card->mixername, pcm->name);
1148 for (idx = 0; idx < AD1848_CONTROLS; idx++) {
1149 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ad1848_controls[idx], chip))) < 0)
1150 return err;
1152 return 0;
1155 EXPORT_SYMBOL(snd_ad1848_in);
1156 EXPORT_SYMBOL(snd_ad1848_out);
1157 EXPORT_SYMBOL(snd_ad1848_dout);
1158 EXPORT_SYMBOL(snd_ad1848_mce_up);
1159 EXPORT_SYMBOL(snd_ad1848_mce_down);
1160 EXPORT_SYMBOL(snd_ad1848_interrupt);
1161 EXPORT_SYMBOL(snd_ad1848_create);
1162 EXPORT_SYMBOL(snd_ad1848_pcm);
1163 EXPORT_SYMBOL(snd_ad1848_mixer);
1164 EXPORT_SYMBOL(snd_ad1848_info_single);
1165 EXPORT_SYMBOL(snd_ad1848_get_single);
1166 EXPORT_SYMBOL(snd_ad1848_put_single);
1167 EXPORT_SYMBOL(snd_ad1848_info_double);
1168 EXPORT_SYMBOL(snd_ad1848_get_double);
1169 EXPORT_SYMBOL(snd_ad1848_put_double);
1172 * INIT part
1175 static int __init alsa_ad1848_init(void)
1177 return 0;
1180 static void __exit alsa_ad1848_exit(void)
1184 module_init(alsa_ad1848_init)
1185 module_exit(alsa_ad1848_exit)