ALSA: es18xx: remove snd_card pointer from snd_es18xx structure
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / isa / es18xx.c
blob160752bc2e8e26cf5ec620441d1b6bdb32c17cd0
1 /*
2 * Driver for generic ESS AudioDrive ES18xx soundcards
3 * Copyright (c) by Christian Fischbach <fishbach@pool.informatik.rwth-aachen.de>
4 * Copyright (c) by Abramo Bagnara <abramo@alsa-project.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /* GENERAL NOTES:
24 * BUGS:
25 * - There are pops (we can't delay in trigger function, cause midlevel
26 * often need to trigger down and then up very quickly).
27 * Any ideas?
28 * - Support for 16 bit DMA seems to be broken. I've no hardware to tune it.
32 * ES1868 NOTES:
33 * - The chip has one half duplex pcm (with very limited full duplex support).
35 * - Duplex stereophonic sound is impossible.
36 * - Record and playback must share the same frequency rate.
38 * - The driver use dma2 for playback and dma1 for capture.
42 * ES1869 NOTES:
44 * - there are a first full duplex pcm and a second playback only pcm
45 * (incompatible with first pcm capture)
47 * - there is support for the capture volume and ESS Spatializer 3D effect.
49 * - contrarily to some pages in DS_1869.PDF the rates can be set
50 * independently.
52 * - Zoom Video is implemented by sharing the FM DAC, thus the user can
53 * have either FM playback or Video playback but not both simultaneously.
54 * The Video Playback Switch mixer control toggles this choice.
56 * BUGS:
58 * - There is a major trouble I noted:
60 * using both channel for playback stereo 16 bit samples at 44100 Hz
61 * the second pcm (Audio1) DMA slows down irregularly and sound is garbled.
63 * The same happens using Audio1 for captureing.
65 * The Windows driver does not suffer of this (although it use Audio1
66 * only for captureing). I'm unable to discover why.
71 * ES1879 NOTES:
72 * - When Zoom Video is enabled (reg 0x71 bit 6 toggled on) the PCM playback
73 * seems to be effected (speaker_test plays a lower frequency). Can't find
74 * anything in the datasheet to account for this, so a Video Playback Switch
75 * control has been included to allow ZV to be enabled only when necessary.
76 * Then again on at least one test system the 0x71 bit 6 enable bit is not
77 * needed for ZV, so maybe the datasheet is entirely wrong here.
80 #include <linux/init.h>
81 #include <linux/err.h>
82 #include <linux/isa.h>
83 #include <linux/slab.h>
84 #include <linux/pnp.h>
85 #include <linux/isapnp.h>
86 #include <linux/moduleparam.h>
87 #include <linux/delay.h>
89 #include <asm/io.h>
90 #include <asm/dma.h>
91 #include <sound/core.h>
92 #include <sound/control.h>
93 #include <sound/pcm.h>
94 #include <sound/pcm_params.h>
95 #include <sound/mpu401.h>
96 #include <sound/opl3.h>
97 #define SNDRV_LEGACY_FIND_FREE_IRQ
98 #define SNDRV_LEGACY_FIND_FREE_DMA
99 #include <sound/initval.h>
101 #define PFX "es18xx: "
103 struct snd_es18xx {
104 unsigned long port; /* port of ESS chip */
105 unsigned long mpu_port; /* MPU-401 port of ESS chip */
106 unsigned long fm_port; /* FM port */
107 unsigned long ctrl_port; /* Control port of ESS chip */
108 struct resource *res_port;
109 struct resource *res_mpu_port;
110 struct resource *res_ctrl_port;
111 int irq; /* IRQ number of ESS chip */
112 int dma1; /* DMA1 */
113 int dma2; /* DMA2 */
114 unsigned short version; /* version of ESS chip */
115 int caps; /* Chip capabilities */
116 unsigned short audio2_vol; /* volume level of audio2 */
118 unsigned short active; /* active channel mask */
119 unsigned int dma1_size;
120 unsigned int dma2_size;
121 unsigned int dma1_shift;
122 unsigned int dma2_shift;
124 struct snd_pcm *pcm;
125 struct snd_pcm_substream *playback_a_substream;
126 struct snd_pcm_substream *capture_a_substream;
127 struct snd_pcm_substream *playback_b_substream;
129 struct snd_rawmidi *rmidi;
131 struct snd_kcontrol *hw_volume;
132 struct snd_kcontrol *hw_switch;
133 struct snd_kcontrol *master_volume;
134 struct snd_kcontrol *master_switch;
136 spinlock_t reg_lock;
137 spinlock_t mixer_lock;
138 spinlock_t ctrl_lock;
139 #ifdef CONFIG_PM
140 unsigned char pm_reg;
141 #endif
144 struct snd_audiodrive {
145 struct snd_es18xx *chip;
146 #ifdef CONFIG_PNP
147 struct pnp_dev *dev;
148 struct pnp_dev *devc;
149 #endif
152 #define AUDIO1_IRQ 0x01
153 #define AUDIO2_IRQ 0x02
154 #define HWV_IRQ 0x04
155 #define MPU_IRQ 0x08
157 #define ES18XX_PCM2 0x0001 /* Has two useable PCM */
158 #define ES18XX_SPATIALIZER 0x0002 /* Has 3D Spatializer */
159 #define ES18XX_RECMIX 0x0004 /* Has record mixer */
160 #define ES18XX_DUPLEX_MONO 0x0008 /* Has mono duplex only */
161 #define ES18XX_DUPLEX_SAME 0x0010 /* Playback and record must share the same rate */
162 #define ES18XX_NEW_RATE 0x0020 /* More precise rate setting */
163 #define ES18XX_AUXB 0x0040 /* AuxB mixer control */
164 #define ES18XX_HWV 0x0080 /* Has separate hardware volume mixer controls*/
165 #define ES18XX_MONO 0x0100 /* Mono_in mixer control */
166 #define ES18XX_I2S 0x0200 /* I2S mixer control */
167 #define ES18XX_MUTEREC 0x0400 /* Record source can be muted */
168 #define ES18XX_CONTROL 0x0800 /* Has control ports */
170 /* Power Management */
171 #define ES18XX_PM 0x07
172 #define ES18XX_PM_GPO0 0x01
173 #define ES18XX_PM_GPO1 0x02
174 #define ES18XX_PM_PDR 0x04
175 #define ES18XX_PM_ANA 0x08
176 #define ES18XX_PM_FM 0x020
177 #define ES18XX_PM_SUS 0x080
179 /* Lowlevel */
181 #define DAC1 0x01
182 #define ADC1 0x02
183 #define DAC2 0x04
184 #define MILLISECOND 10000
186 static int snd_es18xx_dsp_command(struct snd_es18xx *chip, unsigned char val)
188 int i;
190 for(i = MILLISECOND; i; i--)
191 if ((inb(chip->port + 0x0C) & 0x80) == 0) {
192 outb(val, chip->port + 0x0C);
193 return 0;
195 snd_printk(KERN_ERR "dsp_command: timeout (0x%x)\n", val);
196 return -EINVAL;
199 static int snd_es18xx_dsp_get_byte(struct snd_es18xx *chip)
201 int i;
203 for(i = MILLISECOND/10; i; i--)
204 if (inb(chip->port + 0x0C) & 0x40)
205 return inb(chip->port + 0x0A);
206 snd_printk(KERN_ERR "dsp_get_byte failed: 0x%lx = 0x%x!!!\n",
207 chip->port + 0x0A, inb(chip->port + 0x0A));
208 return -ENODEV;
211 #undef REG_DEBUG
213 static int snd_es18xx_write(struct snd_es18xx *chip,
214 unsigned char reg, unsigned char data)
216 unsigned long flags;
217 int ret;
219 spin_lock_irqsave(&chip->reg_lock, flags);
220 ret = snd_es18xx_dsp_command(chip, reg);
221 if (ret < 0)
222 goto end;
223 ret = snd_es18xx_dsp_command(chip, data);
224 end:
225 spin_unlock_irqrestore(&chip->reg_lock, flags);
226 #ifdef REG_DEBUG
227 snd_printk(KERN_DEBUG "Reg %02x set to %02x\n", reg, data);
228 #endif
229 return ret;
232 static int snd_es18xx_read(struct snd_es18xx *chip, unsigned char reg)
234 unsigned long flags;
235 int ret, data;
236 spin_lock_irqsave(&chip->reg_lock, flags);
237 ret = snd_es18xx_dsp_command(chip, 0xC0);
238 if (ret < 0)
239 goto end;
240 ret = snd_es18xx_dsp_command(chip, reg);
241 if (ret < 0)
242 goto end;
243 data = snd_es18xx_dsp_get_byte(chip);
244 ret = data;
245 #ifdef REG_DEBUG
246 snd_printk(KERN_DEBUG "Reg %02x now is %02x (%d)\n", reg, data, ret);
247 #endif
248 end:
249 spin_unlock_irqrestore(&chip->reg_lock, flags);
250 return ret;
253 /* Return old value */
254 static int snd_es18xx_bits(struct snd_es18xx *chip, unsigned char reg,
255 unsigned char mask, unsigned char val)
257 int ret;
258 unsigned char old, new, oval;
259 unsigned long flags;
260 spin_lock_irqsave(&chip->reg_lock, flags);
261 ret = snd_es18xx_dsp_command(chip, 0xC0);
262 if (ret < 0)
263 goto end;
264 ret = snd_es18xx_dsp_command(chip, reg);
265 if (ret < 0)
266 goto end;
267 ret = snd_es18xx_dsp_get_byte(chip);
268 if (ret < 0) {
269 goto end;
271 old = ret;
272 oval = old & mask;
273 if (val != oval) {
274 ret = snd_es18xx_dsp_command(chip, reg);
275 if (ret < 0)
276 goto end;
277 new = (old & ~mask) | (val & mask);
278 ret = snd_es18xx_dsp_command(chip, new);
279 if (ret < 0)
280 goto end;
281 #ifdef REG_DEBUG
282 snd_printk(KERN_DEBUG "Reg %02x was %02x, set to %02x (%d)\n",
283 reg, old, new, ret);
284 #endif
286 ret = oval;
287 end:
288 spin_unlock_irqrestore(&chip->reg_lock, flags);
289 return ret;
292 static inline void snd_es18xx_mixer_write(struct snd_es18xx *chip,
293 unsigned char reg, unsigned char data)
295 unsigned long flags;
296 spin_lock_irqsave(&chip->mixer_lock, flags);
297 outb(reg, chip->port + 0x04);
298 outb(data, chip->port + 0x05);
299 spin_unlock_irqrestore(&chip->mixer_lock, flags);
300 #ifdef REG_DEBUG
301 snd_printk(KERN_DEBUG "Mixer reg %02x set to %02x\n", reg, data);
302 #endif
305 static inline int snd_es18xx_mixer_read(struct snd_es18xx *chip, unsigned char reg)
307 unsigned long flags;
308 int data;
309 spin_lock_irqsave(&chip->mixer_lock, flags);
310 outb(reg, chip->port + 0x04);
311 data = inb(chip->port + 0x05);
312 spin_unlock_irqrestore(&chip->mixer_lock, flags);
313 #ifdef REG_DEBUG
314 snd_printk(KERN_DEBUG "Mixer reg %02x now is %02x\n", reg, data);
315 #endif
316 return data;
319 /* Return old value */
320 static inline int snd_es18xx_mixer_bits(struct snd_es18xx *chip, unsigned char reg,
321 unsigned char mask, unsigned char val)
323 unsigned char old, new, oval;
324 unsigned long flags;
325 spin_lock_irqsave(&chip->mixer_lock, flags);
326 outb(reg, chip->port + 0x04);
327 old = inb(chip->port + 0x05);
328 oval = old & mask;
329 if (val != oval) {
330 new = (old & ~mask) | (val & mask);
331 outb(new, chip->port + 0x05);
332 #ifdef REG_DEBUG
333 snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x\n",
334 reg, old, new);
335 #endif
337 spin_unlock_irqrestore(&chip->mixer_lock, flags);
338 return oval;
341 static inline int snd_es18xx_mixer_writable(struct snd_es18xx *chip, unsigned char reg,
342 unsigned char mask)
344 int old, expected, new;
345 unsigned long flags;
346 spin_lock_irqsave(&chip->mixer_lock, flags);
347 outb(reg, chip->port + 0x04);
348 old = inb(chip->port + 0x05);
349 expected = old ^ mask;
350 outb(expected, chip->port + 0x05);
351 new = inb(chip->port + 0x05);
352 spin_unlock_irqrestore(&chip->mixer_lock, flags);
353 #ifdef REG_DEBUG
354 snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x, now is %02x\n",
355 reg, old, expected, new);
356 #endif
357 return expected == new;
361 static int snd_es18xx_reset(struct snd_es18xx *chip)
363 int i;
364 outb(0x03, chip->port + 0x06);
365 inb(chip->port + 0x06);
366 outb(0x00, chip->port + 0x06);
367 for(i = 0; i < MILLISECOND && !(inb(chip->port + 0x0E) & 0x80); i++);
368 if (inb(chip->port + 0x0A) != 0xAA)
369 return -1;
370 return 0;
373 static int snd_es18xx_reset_fifo(struct snd_es18xx *chip)
375 outb(0x02, chip->port + 0x06);
376 inb(chip->port + 0x06);
377 outb(0x00, chip->port + 0x06);
378 return 0;
381 static struct snd_ratnum new_clocks[2] = {
383 .num = 793800,
384 .den_min = 1,
385 .den_max = 128,
386 .den_step = 1,
389 .num = 768000,
390 .den_min = 1,
391 .den_max = 128,
392 .den_step = 1,
396 static struct snd_pcm_hw_constraint_ratnums new_hw_constraints_clocks = {
397 .nrats = 2,
398 .rats = new_clocks,
401 static struct snd_ratnum old_clocks[2] = {
403 .num = 795444,
404 .den_min = 1,
405 .den_max = 128,
406 .den_step = 1,
409 .num = 397722,
410 .den_min = 1,
411 .den_max = 128,
412 .den_step = 1,
416 static struct snd_pcm_hw_constraint_ratnums old_hw_constraints_clocks = {
417 .nrats = 2,
418 .rats = old_clocks,
422 static void snd_es18xx_rate_set(struct snd_es18xx *chip,
423 struct snd_pcm_substream *substream,
424 int mode)
426 unsigned int bits, div0;
427 struct snd_pcm_runtime *runtime = substream->runtime;
428 if (chip->caps & ES18XX_NEW_RATE) {
429 if (runtime->rate_num == new_clocks[0].num)
430 bits = 128 - runtime->rate_den;
431 else
432 bits = 256 - runtime->rate_den;
433 } else {
434 if (runtime->rate_num == old_clocks[0].num)
435 bits = 256 - runtime->rate_den;
436 else
437 bits = 128 - runtime->rate_den;
440 /* set filter register */
441 div0 = 256 - 7160000*20/(8*82*runtime->rate);
443 if ((chip->caps & ES18XX_PCM2) && mode == DAC2) {
444 snd_es18xx_mixer_write(chip, 0x70, bits);
446 * Comment from kernel oss driver:
447 * FKS: fascinating: 0x72 doesn't seem to work.
449 snd_es18xx_write(chip, 0xA2, div0);
450 snd_es18xx_mixer_write(chip, 0x72, div0);
451 } else {
452 snd_es18xx_write(chip, 0xA1, bits);
453 snd_es18xx_write(chip, 0xA2, div0);
457 static int snd_es18xx_playback_hw_params(struct snd_pcm_substream *substream,
458 struct snd_pcm_hw_params *hw_params)
460 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
461 int shift, err;
463 shift = 0;
464 if (params_channels(hw_params) == 2)
465 shift++;
466 if (snd_pcm_format_width(params_format(hw_params)) == 16)
467 shift++;
469 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
470 if ((chip->caps & ES18XX_DUPLEX_MONO) &&
471 (chip->capture_a_substream) &&
472 params_channels(hw_params) != 1) {
473 _snd_pcm_hw_param_setempty(hw_params, SNDRV_PCM_HW_PARAM_CHANNELS);
474 return -EBUSY;
476 chip->dma2_shift = shift;
477 } else {
478 chip->dma1_shift = shift;
480 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
481 return err;
482 return 0;
485 static int snd_es18xx_pcm_hw_free(struct snd_pcm_substream *substream)
487 return snd_pcm_lib_free_pages(substream);
490 static int snd_es18xx_playback1_prepare(struct snd_es18xx *chip,
491 struct snd_pcm_substream *substream)
493 struct snd_pcm_runtime *runtime = substream->runtime;
494 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
495 unsigned int count = snd_pcm_lib_period_bytes(substream);
497 chip->dma2_size = size;
499 snd_es18xx_rate_set(chip, substream, DAC2);
501 /* Transfer Count Reload */
502 count = 0x10000 - count;
503 snd_es18xx_mixer_write(chip, 0x74, count & 0xff);
504 snd_es18xx_mixer_write(chip, 0x76, count >> 8);
506 /* Set format */
507 snd_es18xx_mixer_bits(chip, 0x7A, 0x07,
508 ((runtime->channels == 1) ? 0x00 : 0x02) |
509 (snd_pcm_format_width(runtime->format) == 16 ? 0x01 : 0x00) |
510 (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x04));
512 /* Set DMA controller */
513 snd_dma_program(chip->dma2, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
515 return 0;
518 static int snd_es18xx_playback1_trigger(struct snd_es18xx *chip,
519 struct snd_pcm_substream *substream,
520 int cmd)
522 switch (cmd) {
523 case SNDRV_PCM_TRIGGER_START:
524 case SNDRV_PCM_TRIGGER_RESUME:
525 if (chip->active & DAC2)
526 return 0;
527 chip->active |= DAC2;
528 /* Start DMA */
529 if (chip->dma2 >= 4)
530 snd_es18xx_mixer_write(chip, 0x78, 0xb3);
531 else
532 snd_es18xx_mixer_write(chip, 0x78, 0x93);
533 #ifdef AVOID_POPS
534 /* Avoid pops */
535 udelay(100000);
536 if (chip->caps & ES18XX_PCM2)
537 /* Restore Audio 2 volume */
538 snd_es18xx_mixer_write(chip, 0x7C, chip->audio2_vol);
539 else
540 /* Enable PCM output */
541 snd_es18xx_dsp_command(chip, 0xD1);
542 #endif
543 break;
544 case SNDRV_PCM_TRIGGER_STOP:
545 case SNDRV_PCM_TRIGGER_SUSPEND:
546 if (!(chip->active & DAC2))
547 return 0;
548 chip->active &= ~DAC2;
549 /* Stop DMA */
550 snd_es18xx_mixer_write(chip, 0x78, 0x00);
551 #ifdef AVOID_POPS
552 udelay(25000);
553 if (chip->caps & ES18XX_PCM2)
554 /* Set Audio 2 volume to 0 */
555 snd_es18xx_mixer_write(chip, 0x7C, 0);
556 else
557 /* Disable PCM output */
558 snd_es18xx_dsp_command(chip, 0xD3);
559 #endif
560 break;
561 default:
562 return -EINVAL;
565 return 0;
568 static int snd_es18xx_capture_hw_params(struct snd_pcm_substream *substream,
569 struct snd_pcm_hw_params *hw_params)
571 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
572 int shift, err;
574 shift = 0;
575 if ((chip->caps & ES18XX_DUPLEX_MONO) &&
576 chip->playback_a_substream &&
577 params_channels(hw_params) != 1) {
578 _snd_pcm_hw_param_setempty(hw_params, SNDRV_PCM_HW_PARAM_CHANNELS);
579 return -EBUSY;
581 if (params_channels(hw_params) == 2)
582 shift++;
583 if (snd_pcm_format_width(params_format(hw_params)) == 16)
584 shift++;
585 chip->dma1_shift = shift;
586 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
587 return err;
588 return 0;
591 static int snd_es18xx_capture_prepare(struct snd_pcm_substream *substream)
593 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
594 struct snd_pcm_runtime *runtime = substream->runtime;
595 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
596 unsigned int count = snd_pcm_lib_period_bytes(substream);
598 chip->dma1_size = size;
600 snd_es18xx_reset_fifo(chip);
602 /* Set stereo/mono */
603 snd_es18xx_bits(chip, 0xA8, 0x03, runtime->channels == 1 ? 0x02 : 0x01);
605 snd_es18xx_rate_set(chip, substream, ADC1);
607 /* Transfer Count Reload */
608 count = 0x10000 - count;
609 snd_es18xx_write(chip, 0xA4, count & 0xff);
610 snd_es18xx_write(chip, 0xA5, count >> 8);
612 #ifdef AVOID_POPS
613 udelay(100000);
614 #endif
616 /* Set format */
617 snd_es18xx_write(chip, 0xB7,
618 snd_pcm_format_unsigned(runtime->format) ? 0x51 : 0x71);
619 snd_es18xx_write(chip, 0xB7, 0x90 |
620 ((runtime->channels == 1) ? 0x40 : 0x08) |
621 (snd_pcm_format_width(runtime->format) == 16 ? 0x04 : 0x00) |
622 (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x20));
624 /* Set DMA controller */
625 snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
627 return 0;
630 static int snd_es18xx_capture_trigger(struct snd_pcm_substream *substream,
631 int cmd)
633 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
635 switch (cmd) {
636 case SNDRV_PCM_TRIGGER_START:
637 case SNDRV_PCM_TRIGGER_RESUME:
638 if (chip->active & ADC1)
639 return 0;
640 chip->active |= ADC1;
641 /* Start DMA */
642 snd_es18xx_write(chip, 0xB8, 0x0f);
643 break;
644 case SNDRV_PCM_TRIGGER_STOP:
645 case SNDRV_PCM_TRIGGER_SUSPEND:
646 if (!(chip->active & ADC1))
647 return 0;
648 chip->active &= ~ADC1;
649 /* Stop DMA */
650 snd_es18xx_write(chip, 0xB8, 0x00);
651 break;
652 default:
653 return -EINVAL;
656 return 0;
659 static int snd_es18xx_playback2_prepare(struct snd_es18xx *chip,
660 struct snd_pcm_substream *substream)
662 struct snd_pcm_runtime *runtime = substream->runtime;
663 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
664 unsigned int count = snd_pcm_lib_period_bytes(substream);
666 chip->dma1_size = size;
668 snd_es18xx_reset_fifo(chip);
670 /* Set stereo/mono */
671 snd_es18xx_bits(chip, 0xA8, 0x03, runtime->channels == 1 ? 0x02 : 0x01);
673 snd_es18xx_rate_set(chip, substream, DAC1);
675 /* Transfer Count Reload */
676 count = 0x10000 - count;
677 snd_es18xx_write(chip, 0xA4, count & 0xff);
678 snd_es18xx_write(chip, 0xA5, count >> 8);
680 /* Set format */
681 snd_es18xx_write(chip, 0xB6,
682 snd_pcm_format_unsigned(runtime->format) ? 0x80 : 0x00);
683 snd_es18xx_write(chip, 0xB7,
684 snd_pcm_format_unsigned(runtime->format) ? 0x51 : 0x71);
685 snd_es18xx_write(chip, 0xB7, 0x90 |
686 (runtime->channels == 1 ? 0x40 : 0x08) |
687 (snd_pcm_format_width(runtime->format) == 16 ? 0x04 : 0x00) |
688 (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x20));
690 /* Set DMA controller */
691 snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
693 return 0;
696 static int snd_es18xx_playback2_trigger(struct snd_es18xx *chip,
697 struct snd_pcm_substream *substream,
698 int cmd)
700 switch (cmd) {
701 case SNDRV_PCM_TRIGGER_START:
702 case SNDRV_PCM_TRIGGER_RESUME:
703 if (chip->active & DAC1)
704 return 0;
705 chip->active |= DAC1;
706 /* Start DMA */
707 snd_es18xx_write(chip, 0xB8, 0x05);
708 #ifdef AVOID_POPS
709 /* Avoid pops */
710 udelay(100000);
711 /* Enable Audio 1 */
712 snd_es18xx_dsp_command(chip, 0xD1);
713 #endif
714 break;
715 case SNDRV_PCM_TRIGGER_STOP:
716 case SNDRV_PCM_TRIGGER_SUSPEND:
717 if (!(chip->active & DAC1))
718 return 0;
719 chip->active &= ~DAC1;
720 /* Stop DMA */
721 snd_es18xx_write(chip, 0xB8, 0x00);
722 #ifdef AVOID_POPS
723 /* Avoid pops */
724 udelay(25000);
725 /* Disable Audio 1 */
726 snd_es18xx_dsp_command(chip, 0xD3);
727 #endif
728 break;
729 default:
730 return -EINVAL;
733 return 0;
736 static int snd_es18xx_playback_prepare(struct snd_pcm_substream *substream)
738 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
739 if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
740 return snd_es18xx_playback1_prepare(chip, substream);
741 else
742 return snd_es18xx_playback2_prepare(chip, substream);
745 static int snd_es18xx_playback_trigger(struct snd_pcm_substream *substream,
746 int cmd)
748 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
749 if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
750 return snd_es18xx_playback1_trigger(chip, substream, cmd);
751 else
752 return snd_es18xx_playback2_trigger(chip, substream, cmd);
755 static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id)
757 struct snd_card *card = dev_id;
758 struct snd_audiodrive *acard = card->private_data;
759 struct snd_es18xx *chip = acard->chip;
760 unsigned char status;
762 if (chip->caps & ES18XX_CONTROL) {
763 /* Read Interrupt status */
764 status = inb(chip->ctrl_port + 6);
765 } else {
766 /* Read Interrupt status */
767 status = snd_es18xx_mixer_read(chip, 0x7f) >> 4;
769 #if 0
770 else {
771 status = 0;
772 if (inb(chip->port + 0x0C) & 0x01)
773 status |= AUDIO1_IRQ;
774 if (snd_es18xx_mixer_read(chip, 0x7A) & 0x80)
775 status |= AUDIO2_IRQ;
776 if ((chip->caps & ES18XX_HWV) &&
777 snd_es18xx_mixer_read(chip, 0x64) & 0x10)
778 status |= HWV_IRQ;
780 #endif
782 /* Audio 1 & Audio 2 */
783 if (status & AUDIO2_IRQ) {
784 if (chip->active & DAC2)
785 snd_pcm_period_elapsed(chip->playback_a_substream);
786 /* ack interrupt */
787 snd_es18xx_mixer_bits(chip, 0x7A, 0x80, 0x00);
789 if (status & AUDIO1_IRQ) {
790 /* ok.. capture is active */
791 if (chip->active & ADC1)
792 snd_pcm_period_elapsed(chip->capture_a_substream);
793 /* ok.. playback2 is active */
794 else if (chip->active & DAC1)
795 snd_pcm_period_elapsed(chip->playback_b_substream);
796 /* ack interrupt */
797 inb(chip->port + 0x0E);
800 /* MPU */
801 if ((status & MPU_IRQ) && chip->rmidi)
802 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
804 /* Hardware volume */
805 if (status & HWV_IRQ) {
806 int split = 0;
807 if (chip->caps & ES18XX_HWV) {
808 split = snd_es18xx_mixer_read(chip, 0x64) & 0x80;
809 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
810 &chip->hw_switch->id);
811 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
812 &chip->hw_volume->id);
814 if (!split) {
815 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
816 &chip->master_switch->id);
817 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
818 &chip->master_volume->id);
820 /* ack interrupt */
821 snd_es18xx_mixer_write(chip, 0x66, 0x00);
823 return IRQ_HANDLED;
826 static snd_pcm_uframes_t snd_es18xx_playback_pointer(struct snd_pcm_substream *substream)
828 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
829 int pos;
831 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
832 if (!(chip->active & DAC2))
833 return 0;
834 pos = snd_dma_pointer(chip->dma2, chip->dma2_size);
835 return pos >> chip->dma2_shift;
836 } else {
837 if (!(chip->active & DAC1))
838 return 0;
839 pos = snd_dma_pointer(chip->dma1, chip->dma1_size);
840 return pos >> chip->dma1_shift;
844 static snd_pcm_uframes_t snd_es18xx_capture_pointer(struct snd_pcm_substream *substream)
846 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
847 int pos;
849 if (!(chip->active & ADC1))
850 return 0;
851 pos = snd_dma_pointer(chip->dma1, chip->dma1_size);
852 return pos >> chip->dma1_shift;
855 static struct snd_pcm_hardware snd_es18xx_playback =
857 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
858 SNDRV_PCM_INFO_RESUME |
859 SNDRV_PCM_INFO_MMAP_VALID),
860 .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
861 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE),
862 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
863 .rate_min = 4000,
864 .rate_max = 48000,
865 .channels_min = 1,
866 .channels_max = 2,
867 .buffer_bytes_max = 65536,
868 .period_bytes_min = 64,
869 .period_bytes_max = 65536,
870 .periods_min = 1,
871 .periods_max = 1024,
872 .fifo_size = 0,
875 static struct snd_pcm_hardware snd_es18xx_capture =
877 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
878 SNDRV_PCM_INFO_RESUME |
879 SNDRV_PCM_INFO_MMAP_VALID),
880 .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
881 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE),
882 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
883 .rate_min = 4000,
884 .rate_max = 48000,
885 .channels_min = 1,
886 .channels_max = 2,
887 .buffer_bytes_max = 65536,
888 .period_bytes_min = 64,
889 .period_bytes_max = 65536,
890 .periods_min = 1,
891 .periods_max = 1024,
892 .fifo_size = 0,
895 static int snd_es18xx_playback_open(struct snd_pcm_substream *substream)
897 struct snd_pcm_runtime *runtime = substream->runtime;
898 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
900 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
901 if ((chip->caps & ES18XX_DUPLEX_MONO) &&
902 chip->capture_a_substream &&
903 chip->capture_a_substream->runtime->channels != 1)
904 return -EAGAIN;
905 chip->playback_a_substream = substream;
906 } else if (substream->number <= 1) {
907 if (chip->capture_a_substream)
908 return -EAGAIN;
909 chip->playback_b_substream = substream;
910 } else {
911 snd_BUG();
912 return -EINVAL;
914 substream->runtime->hw = snd_es18xx_playback;
915 snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
916 (chip->caps & ES18XX_NEW_RATE) ? &new_hw_constraints_clocks : &old_hw_constraints_clocks);
917 return 0;
920 static int snd_es18xx_capture_open(struct snd_pcm_substream *substream)
922 struct snd_pcm_runtime *runtime = substream->runtime;
923 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
925 if (chip->playback_b_substream)
926 return -EAGAIN;
927 if ((chip->caps & ES18XX_DUPLEX_MONO) &&
928 chip->playback_a_substream &&
929 chip->playback_a_substream->runtime->channels != 1)
930 return -EAGAIN;
931 chip->capture_a_substream = substream;
932 substream->runtime->hw = snd_es18xx_capture;
933 snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
934 (chip->caps & ES18XX_NEW_RATE) ? &new_hw_constraints_clocks : &old_hw_constraints_clocks);
935 return 0;
938 static int snd_es18xx_playback_close(struct snd_pcm_substream *substream)
940 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
942 if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
943 chip->playback_a_substream = NULL;
944 else
945 chip->playback_b_substream = NULL;
947 snd_pcm_lib_free_pages(substream);
948 return 0;
951 static int snd_es18xx_capture_close(struct snd_pcm_substream *substream)
953 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
955 chip->capture_a_substream = NULL;
956 snd_pcm_lib_free_pages(substream);
957 return 0;
961 * MIXER part
964 /* Record source mux routines:
965 * Depending on the chipset this mux switches between 4, 5, or 8 possible inputs.
966 * bit table for the 4/5 source mux:
967 * reg 1C:
968 * b2 b1 b0 muxSource
969 * x 0 x microphone
970 * 0 1 x CD
971 * 1 1 0 line
972 * 1 1 1 mixer
973 * if it's "mixer" and it's a 5 source mux chipset then reg 7A bit 3 determines
974 * either the play mixer or the capture mixer.
976 * "map4Source" translates from source number to reg bit pattern
977 * "invMap4Source" translates from reg bit pattern to source number
980 static int snd_es18xx_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
982 static char *texts4Source[4] = {
983 "Mic", "CD", "Line", "Master"
985 static char *texts5Source[5] = {
986 "Mic", "CD", "Line", "Master", "Mix"
988 static char *texts8Source[8] = {
989 "Mic", "Mic Master", "CD", "AOUT",
990 "Mic1", "Mix", "Line", "Master"
992 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
994 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
995 uinfo->count = 1;
996 switch (chip->version) {
997 case 0x1868:
998 case 0x1878:
999 uinfo->value.enumerated.items = 4;
1000 if (uinfo->value.enumerated.item > 3)
1001 uinfo->value.enumerated.item = 3;
1002 strcpy(uinfo->value.enumerated.name, texts4Source[uinfo->value.enumerated.item]);
1003 break;
1004 case 0x1887:
1005 case 0x1888:
1006 uinfo->value.enumerated.items = 5;
1007 if (uinfo->value.enumerated.item > 4)
1008 uinfo->value.enumerated.item = 4;
1009 strcpy(uinfo->value.enumerated.name, texts5Source[uinfo->value.enumerated.item]);
1010 break;
1011 case 0x1869: /* DS somewhat contradictory for 1869: could be be 5 or 8 */
1012 case 0x1879:
1013 uinfo->value.enumerated.items = 8;
1014 if (uinfo->value.enumerated.item > 7)
1015 uinfo->value.enumerated.item = 7;
1016 strcpy(uinfo->value.enumerated.name, texts8Source[uinfo->value.enumerated.item]);
1017 break;
1018 default:
1019 return -EINVAL;
1021 return 0;
1024 static int snd_es18xx_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1026 static unsigned char invMap4Source[8] = {0, 0, 1, 1, 0, 0, 2, 3};
1027 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1028 int muxSource = snd_es18xx_mixer_read(chip, 0x1c) & 0x07;
1029 if (!(chip->version == 0x1869 || chip->version == 0x1879)) {
1030 muxSource = invMap4Source[muxSource];
1031 if (muxSource==3 &&
1032 (chip->version == 0x1887 || chip->version == 0x1888) &&
1033 (snd_es18xx_mixer_read(chip, 0x7a) & 0x08)
1035 muxSource = 4;
1037 ucontrol->value.enumerated.item[0] = muxSource;
1038 return 0;
1041 static int snd_es18xx_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1043 static unsigned char map4Source[4] = {0, 2, 6, 7};
1044 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1045 unsigned char val = ucontrol->value.enumerated.item[0];
1046 unsigned char retVal = 0;
1048 switch (chip->version) {
1049 /* 5 source chips */
1050 case 0x1887:
1051 case 0x1888:
1052 if (val > 4)
1053 return -EINVAL;
1054 if (val == 4) {
1055 retVal = snd_es18xx_mixer_bits(chip, 0x7a, 0x08, 0x08) != 0x08;
1056 val = 3;
1057 } else
1058 retVal = snd_es18xx_mixer_bits(chip, 0x7a, 0x08, 0x00) != 0x00;
1059 /* 4 source chips */
1060 case 0x1868:
1061 case 0x1878:
1062 if (val > 3)
1063 return -EINVAL;
1064 val = map4Source[val];
1065 break;
1066 /* 8 source chips */
1067 case 0x1869:
1068 case 0x1879:
1069 if (val > 7)
1070 return -EINVAL;
1071 break;
1072 default:
1073 return -EINVAL;
1075 return (snd_es18xx_mixer_bits(chip, 0x1c, 0x07, val) != val) || retVal;
1078 #define snd_es18xx_info_spatializer_enable snd_ctl_boolean_mono_info
1080 static int snd_es18xx_get_spatializer_enable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1082 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1083 unsigned char val = snd_es18xx_mixer_read(chip, 0x50);
1084 ucontrol->value.integer.value[0] = !!(val & 8);
1085 return 0;
1088 static int snd_es18xx_put_spatializer_enable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1090 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1091 unsigned char oval, nval;
1092 int change;
1093 nval = ucontrol->value.integer.value[0] ? 0x0c : 0x04;
1094 oval = snd_es18xx_mixer_read(chip, 0x50) & 0x0c;
1095 change = nval != oval;
1096 if (change) {
1097 snd_es18xx_mixer_write(chip, 0x50, nval & ~0x04);
1098 snd_es18xx_mixer_write(chip, 0x50, nval);
1100 return change;
1103 static int snd_es18xx_info_hw_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1105 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1106 uinfo->count = 2;
1107 uinfo->value.integer.min = 0;
1108 uinfo->value.integer.max = 63;
1109 return 0;
1112 static int snd_es18xx_get_hw_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1114 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1115 ucontrol->value.integer.value[0] = snd_es18xx_mixer_read(chip, 0x61) & 0x3f;
1116 ucontrol->value.integer.value[1] = snd_es18xx_mixer_read(chip, 0x63) & 0x3f;
1117 return 0;
1120 #define snd_es18xx_info_hw_switch snd_ctl_boolean_stereo_info
1122 static int snd_es18xx_get_hw_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1124 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1125 ucontrol->value.integer.value[0] = !(snd_es18xx_mixer_read(chip, 0x61) & 0x40);
1126 ucontrol->value.integer.value[1] = !(snd_es18xx_mixer_read(chip, 0x63) & 0x40);
1127 return 0;
1130 static void snd_es18xx_hwv_free(struct snd_kcontrol *kcontrol)
1132 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1133 chip->master_volume = NULL;
1134 chip->master_switch = NULL;
1135 chip->hw_volume = NULL;
1136 chip->hw_switch = NULL;
1139 static int snd_es18xx_reg_bits(struct snd_es18xx *chip, unsigned char reg,
1140 unsigned char mask, unsigned char val)
1142 if (reg < 0xa0)
1143 return snd_es18xx_mixer_bits(chip, reg, mask, val);
1144 else
1145 return snd_es18xx_bits(chip, reg, mask, val);
1148 static int snd_es18xx_reg_read(struct snd_es18xx *chip, unsigned char reg)
1150 if (reg < 0xa0)
1151 return snd_es18xx_mixer_read(chip, reg);
1152 else
1153 return snd_es18xx_read(chip, reg);
1156 #define ES18XX_SINGLE(xname, xindex, reg, shift, mask, invert) \
1157 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1158 .info = snd_es18xx_info_single, \
1159 .get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \
1160 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
1162 static int snd_es18xx_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1164 int mask = (kcontrol->private_value >> 16) & 0xff;
1166 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1167 uinfo->count = 1;
1168 uinfo->value.integer.min = 0;
1169 uinfo->value.integer.max = mask;
1170 return 0;
1173 static int snd_es18xx_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1175 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1176 int reg = kcontrol->private_value & 0xff;
1177 int shift = (kcontrol->private_value >> 8) & 0xff;
1178 int mask = (kcontrol->private_value >> 16) & 0xff;
1179 int invert = (kcontrol->private_value >> 24) & 0xff;
1180 int val;
1182 val = snd_es18xx_reg_read(chip, reg);
1183 ucontrol->value.integer.value[0] = (val >> shift) & mask;
1184 if (invert)
1185 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1186 return 0;
1189 static int snd_es18xx_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1191 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1192 int reg = kcontrol->private_value & 0xff;
1193 int shift = (kcontrol->private_value >> 8) & 0xff;
1194 int mask = (kcontrol->private_value >> 16) & 0xff;
1195 int invert = (kcontrol->private_value >> 24) & 0xff;
1196 unsigned char val;
1198 val = (ucontrol->value.integer.value[0] & mask);
1199 if (invert)
1200 val = mask - val;
1201 mask <<= shift;
1202 val <<= shift;
1203 return snd_es18xx_reg_bits(chip, reg, mask, val) != val;
1206 #define ES18XX_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
1207 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1208 .info = snd_es18xx_info_double, \
1209 .get = snd_es18xx_get_double, .put = snd_es18xx_put_double, \
1210 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
1212 static int snd_es18xx_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1214 int mask = (kcontrol->private_value >> 24) & 0xff;
1216 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1217 uinfo->count = 2;
1218 uinfo->value.integer.min = 0;
1219 uinfo->value.integer.max = mask;
1220 return 0;
1223 static int snd_es18xx_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1225 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1226 int left_reg = kcontrol->private_value & 0xff;
1227 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1228 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1229 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1230 int mask = (kcontrol->private_value >> 24) & 0xff;
1231 int invert = (kcontrol->private_value >> 22) & 1;
1232 unsigned char left, right;
1234 left = snd_es18xx_reg_read(chip, left_reg);
1235 if (left_reg != right_reg)
1236 right = snd_es18xx_reg_read(chip, right_reg);
1237 else
1238 right = left;
1239 ucontrol->value.integer.value[0] = (left >> shift_left) & mask;
1240 ucontrol->value.integer.value[1] = (right >> shift_right) & mask;
1241 if (invert) {
1242 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1243 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
1245 return 0;
1248 static int snd_es18xx_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1250 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1251 int left_reg = kcontrol->private_value & 0xff;
1252 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1253 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1254 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1255 int mask = (kcontrol->private_value >> 24) & 0xff;
1256 int invert = (kcontrol->private_value >> 22) & 1;
1257 int change;
1258 unsigned char val1, val2, mask1, mask2;
1260 val1 = ucontrol->value.integer.value[0] & mask;
1261 val2 = ucontrol->value.integer.value[1] & mask;
1262 if (invert) {
1263 val1 = mask - val1;
1264 val2 = mask - val2;
1266 val1 <<= shift_left;
1267 val2 <<= shift_right;
1268 mask1 = mask << shift_left;
1269 mask2 = mask << shift_right;
1270 if (left_reg != right_reg) {
1271 change = 0;
1272 if (snd_es18xx_reg_bits(chip, left_reg, mask1, val1) != val1)
1273 change = 1;
1274 if (snd_es18xx_reg_bits(chip, right_reg, mask2, val2) != val2)
1275 change = 1;
1276 } else {
1277 change = (snd_es18xx_reg_bits(chip, left_reg, mask1 | mask2,
1278 val1 | val2) != (val1 | val2));
1280 return change;
1283 /* Mixer controls
1284 * These arrays contain setup data for mixer controls.
1286 * The controls that are universal to all chipsets are fully initialized
1287 * here.
1289 static struct snd_kcontrol_new snd_es18xx_base_controls[] = {
1290 ES18XX_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0),
1291 ES18XX_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1),
1292 ES18XX_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0),
1293 ES18XX_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0),
1294 ES18XX_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0),
1295 ES18XX_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0),
1296 ES18XX_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0),
1297 ES18XX_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
1298 ES18XX_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0),
1300 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1301 .name = "Capture Source",
1302 .info = snd_es18xx_info_mux,
1303 .get = snd_es18xx_get_mux,
1304 .put = snd_es18xx_put_mux,
1308 static struct snd_kcontrol_new snd_es18xx_recmix_controls[] = {
1309 ES18XX_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0),
1310 ES18XX_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0),
1311 ES18XX_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0),
1312 ES18XX_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0),
1313 ES18XX_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0),
1314 ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0)
1318 * The chipset specific mixer controls
1320 static struct snd_kcontrol_new snd_es18xx_opt_speaker =
1321 ES18XX_SINGLE("PC Speaker Playback Volume", 0, 0x3c, 0, 7, 0);
1323 static struct snd_kcontrol_new snd_es18xx_opt_1869[] = {
1324 ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
1325 ES18XX_SINGLE("Video Playback Switch", 0, 0x7f, 0, 1, 0),
1326 ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1327 ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0)
1330 static struct snd_kcontrol_new snd_es18xx_opt_1878 =
1331 ES18XX_DOUBLE("Video Playback Volume", 0, 0x68, 0x68, 4, 0, 15, 0);
1333 static struct snd_kcontrol_new snd_es18xx_opt_1879[] = {
1334 ES18XX_SINGLE("Video Playback Switch", 0, 0x71, 6, 1, 0),
1335 ES18XX_DOUBLE("Video Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1336 ES18XX_DOUBLE("Video Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0)
1339 static struct snd_kcontrol_new snd_es18xx_pcm1_controls[] = {
1340 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x14, 0x14, 4, 0, 15, 0),
1343 static struct snd_kcontrol_new snd_es18xx_pcm2_controls[] = {
1344 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0),
1345 ES18XX_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0)
1348 static struct snd_kcontrol_new snd_es18xx_spatializer_controls[] = {
1349 ES18XX_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
1351 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1352 .name = "3D Control - Switch",
1353 .info = snd_es18xx_info_spatializer_enable,
1354 .get = snd_es18xx_get_spatializer_enable,
1355 .put = snd_es18xx_put_spatializer_enable,
1359 static struct snd_kcontrol_new snd_es18xx_micpre1_control =
1360 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0xa9, 2, 1, 0);
1362 static struct snd_kcontrol_new snd_es18xx_micpre2_control =
1363 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0);
1365 static struct snd_kcontrol_new snd_es18xx_hw_volume_controls[] = {
1367 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1368 .name = "Hardware Master Playback Volume",
1369 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1370 .info = snd_es18xx_info_hw_volume,
1371 .get = snd_es18xx_get_hw_volume,
1374 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1375 .name = "Hardware Master Playback Switch",
1376 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1377 .info = snd_es18xx_info_hw_switch,
1378 .get = snd_es18xx_get_hw_switch,
1380 ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0),
1383 static int __devinit snd_es18xx_config_read(struct snd_es18xx *chip, unsigned char reg)
1385 int data;
1386 unsigned long flags;
1387 spin_lock_irqsave(&chip->ctrl_lock, flags);
1388 outb(reg, chip->ctrl_port);
1389 data = inb(chip->ctrl_port + 1);
1390 spin_unlock_irqrestore(&chip->ctrl_lock, flags);
1391 return data;
1394 static void __devinit snd_es18xx_config_write(struct snd_es18xx *chip,
1395 unsigned char reg, unsigned char data)
1397 /* No need for spinlocks, this function is used only in
1398 otherwise protected init code */
1399 outb(reg, chip->ctrl_port);
1400 outb(data, chip->ctrl_port + 1);
1401 #ifdef REG_DEBUG
1402 snd_printk(KERN_DEBUG "Config reg %02x set to %02x\n", reg, data);
1403 #endif
1406 static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip)
1408 int mask = 0;
1410 /* enable extended mode */
1411 snd_es18xx_dsp_command(chip, 0xC6);
1412 /* Reset mixer registers */
1413 snd_es18xx_mixer_write(chip, 0x00, 0x00);
1415 /* Audio 1 DMA demand mode (4 bytes/request) */
1416 snd_es18xx_write(chip, 0xB9, 2);
1417 if (chip->caps & ES18XX_CONTROL) {
1418 /* Hardware volume IRQ */
1419 snd_es18xx_config_write(chip, 0x27, chip->irq);
1420 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) {
1421 /* FM I/O */
1422 snd_es18xx_config_write(chip, 0x62, chip->fm_port >> 8);
1423 snd_es18xx_config_write(chip, 0x63, chip->fm_port & 0xff);
1425 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) {
1426 /* MPU-401 I/O */
1427 snd_es18xx_config_write(chip, 0x64, chip->mpu_port >> 8);
1428 snd_es18xx_config_write(chip, 0x65, chip->mpu_port & 0xff);
1429 /* MPU-401 IRQ */
1430 snd_es18xx_config_write(chip, 0x28, chip->irq);
1432 /* Audio1 IRQ */
1433 snd_es18xx_config_write(chip, 0x70, chip->irq);
1434 /* Audio2 IRQ */
1435 snd_es18xx_config_write(chip, 0x72, chip->irq);
1436 /* Audio1 DMA */
1437 snd_es18xx_config_write(chip, 0x74, chip->dma1);
1438 /* Audio2 DMA */
1439 snd_es18xx_config_write(chip, 0x75, chip->dma2);
1441 /* Enable Audio 1 IRQ */
1442 snd_es18xx_write(chip, 0xB1, 0x50);
1443 /* Enable Audio 2 IRQ */
1444 snd_es18xx_mixer_write(chip, 0x7A, 0x40);
1445 /* Enable Audio 1 DMA */
1446 snd_es18xx_write(chip, 0xB2, 0x50);
1447 /* Enable MPU and hardware volume interrupt */
1448 snd_es18xx_mixer_write(chip, 0x64, 0x42);
1449 /* Enable ESS wavetable input */
1450 snd_es18xx_mixer_bits(chip, 0x48, 0x10, 0x10);
1452 else {
1453 int irqmask, dma1mask, dma2mask;
1454 switch (chip->irq) {
1455 case 2:
1456 case 9:
1457 irqmask = 0;
1458 break;
1459 case 5:
1460 irqmask = 1;
1461 break;
1462 case 7:
1463 irqmask = 2;
1464 break;
1465 case 10:
1466 irqmask = 3;
1467 break;
1468 default:
1469 snd_printk(KERN_ERR "invalid irq %d\n", chip->irq);
1470 return -ENODEV;
1472 switch (chip->dma1) {
1473 case 0:
1474 dma1mask = 1;
1475 break;
1476 case 1:
1477 dma1mask = 2;
1478 break;
1479 case 3:
1480 dma1mask = 3;
1481 break;
1482 default:
1483 snd_printk(KERN_ERR "invalid dma1 %d\n", chip->dma1);
1484 return -ENODEV;
1486 switch (chip->dma2) {
1487 case 0:
1488 dma2mask = 0;
1489 break;
1490 case 1:
1491 dma2mask = 1;
1492 break;
1493 case 3:
1494 dma2mask = 2;
1495 break;
1496 case 5:
1497 dma2mask = 3;
1498 break;
1499 default:
1500 snd_printk(KERN_ERR "invalid dma2 %d\n", chip->dma2);
1501 return -ENODEV;
1504 /* Enable and set Audio 1 IRQ */
1505 snd_es18xx_write(chip, 0xB1, 0x50 | (irqmask << 2));
1506 /* Enable and set Audio 1 DMA */
1507 snd_es18xx_write(chip, 0xB2, 0x50 | (dma1mask << 2));
1508 /* Set Audio 2 DMA */
1509 snd_es18xx_mixer_bits(chip, 0x7d, 0x07, 0x04 | dma2mask);
1510 /* Enable Audio 2 IRQ and DMA
1511 Set capture mixer input */
1512 snd_es18xx_mixer_write(chip, 0x7A, 0x68);
1513 /* Enable and set hardware volume interrupt */
1514 snd_es18xx_mixer_write(chip, 0x64, 0x06);
1515 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) {
1516 /* MPU401 share irq with audio
1517 Joystick enabled
1518 FM enabled */
1519 snd_es18xx_mixer_write(chip, 0x40, 0x43 | (chip->mpu_port & 0xf0) >> 1);
1521 snd_es18xx_mixer_write(chip, 0x7f, ((irqmask + 1) << 1) | 0x01);
1523 if (chip->caps & ES18XX_NEW_RATE) {
1524 /* Change behaviour of register A1
1525 4x oversampling
1526 2nd channel DAC asynchronous */
1527 snd_es18xx_mixer_write(chip, 0x71, 0x32);
1529 if (!(chip->caps & ES18XX_PCM2)) {
1530 /* Enable DMA FIFO */
1531 snd_es18xx_write(chip, 0xB7, 0x80);
1533 if (chip->caps & ES18XX_SPATIALIZER) {
1534 /* Set spatializer parameters to recommended values */
1535 snd_es18xx_mixer_write(chip, 0x54, 0x8f);
1536 snd_es18xx_mixer_write(chip, 0x56, 0x95);
1537 snd_es18xx_mixer_write(chip, 0x58, 0x94);
1538 snd_es18xx_mixer_write(chip, 0x5a, 0x80);
1540 /* Flip the "enable I2S" bits for those chipsets that need it */
1541 switch (chip->version) {
1542 case 0x1879:
1543 //Leaving I2S enabled on the 1879 screws up the PCM playback (rate effected somehow)
1544 //so a Switch control has been added to toggle this 0x71 bit on/off:
1545 //snd_es18xx_mixer_bits(chip, 0x71, 0x40, 0x40);
1546 /* Note: we fall through on purpose here. */
1547 case 0x1878:
1548 snd_es18xx_config_write(chip, 0x29, snd_es18xx_config_read(chip, 0x29) | 0x40);
1549 break;
1551 /* Mute input source */
1552 if (chip->caps & ES18XX_MUTEREC)
1553 mask = 0x10;
1554 if (chip->caps & ES18XX_RECMIX)
1555 snd_es18xx_mixer_write(chip, 0x1c, 0x05 | mask);
1556 else {
1557 snd_es18xx_mixer_write(chip, 0x1c, 0x00 | mask);
1558 snd_es18xx_write(chip, 0xb4, 0x00);
1560 #ifndef AVOID_POPS
1561 /* Enable PCM output */
1562 snd_es18xx_dsp_command(chip, 0xD1);
1563 #endif
1565 return 0;
1568 static int __devinit snd_es18xx_identify(struct snd_es18xx *chip)
1570 int hi,lo;
1572 /* reset */
1573 if (snd_es18xx_reset(chip) < 0) {
1574 snd_printk(KERN_ERR "reset at 0x%lx failed!!!\n", chip->port);
1575 return -ENODEV;
1578 snd_es18xx_dsp_command(chip, 0xe7);
1579 hi = snd_es18xx_dsp_get_byte(chip);
1580 if (hi < 0) {
1581 return hi;
1583 lo = snd_es18xx_dsp_get_byte(chip);
1584 if ((lo & 0xf0) != 0x80) {
1585 return -ENODEV;
1587 if (hi == 0x48) {
1588 chip->version = 0x488;
1589 return 0;
1591 if (hi != 0x68) {
1592 return -ENODEV;
1594 if ((lo & 0x0f) < 8) {
1595 chip->version = 0x688;
1596 return 0;
1599 outb(0x40, chip->port + 0x04);
1600 udelay(10);
1601 hi = inb(chip->port + 0x05);
1602 udelay(10);
1603 lo = inb(chip->port + 0x05);
1604 if (hi != lo) {
1605 chip->version = hi << 8 | lo;
1606 chip->ctrl_port = inb(chip->port + 0x05) << 8;
1607 udelay(10);
1608 chip->ctrl_port += inb(chip->port + 0x05);
1610 if ((chip->res_ctrl_port = request_region(chip->ctrl_port, 8, "ES18xx - CTRL")) == NULL) {
1611 snd_printk(KERN_ERR PFX "unable go grab port 0x%lx\n", chip->ctrl_port);
1612 return -EBUSY;
1615 return 0;
1618 /* If has Hardware volume */
1619 if (snd_es18xx_mixer_writable(chip, 0x64, 0x04)) {
1620 /* If has Audio2 */
1621 if (snd_es18xx_mixer_writable(chip, 0x70, 0x7f)) {
1622 /* If has volume count */
1623 if (snd_es18xx_mixer_writable(chip, 0x64, 0x20)) {
1624 chip->version = 0x1887;
1625 } else {
1626 chip->version = 0x1888;
1628 } else {
1629 chip->version = 0x1788;
1632 else
1633 chip->version = 0x1688;
1634 return 0;
1637 static int __devinit snd_es18xx_probe(struct snd_es18xx *chip)
1639 if (snd_es18xx_identify(chip) < 0) {
1640 snd_printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port);
1641 return -ENODEV;
1644 switch (chip->version) {
1645 case 0x1868:
1646 chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_CONTROL;
1647 break;
1648 case 0x1869:
1649 chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_MONO | ES18XX_MUTEREC | ES18XX_CONTROL | ES18XX_HWV;
1650 break;
1651 case 0x1878:
1652 chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_I2S | ES18XX_CONTROL;
1653 break;
1654 case 0x1879:
1655 chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV;
1656 break;
1657 case 0x1887:
1658 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME;
1659 break;
1660 case 0x1888:
1661 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME;
1662 break;
1663 default:
1664 snd_printk(KERN_ERR "[0x%lx] unsupported chip ES%x\n",
1665 chip->port, chip->version);
1666 return -ENODEV;
1669 snd_printd("[0x%lx] ESS%x chip found\n", chip->port, chip->version);
1671 if (chip->dma1 == chip->dma2)
1672 chip->caps &= ~(ES18XX_PCM2 | ES18XX_DUPLEX_SAME);
1674 return snd_es18xx_initialize(chip);
1677 static struct snd_pcm_ops snd_es18xx_playback_ops = {
1678 .open = snd_es18xx_playback_open,
1679 .close = snd_es18xx_playback_close,
1680 .ioctl = snd_pcm_lib_ioctl,
1681 .hw_params = snd_es18xx_playback_hw_params,
1682 .hw_free = snd_es18xx_pcm_hw_free,
1683 .prepare = snd_es18xx_playback_prepare,
1684 .trigger = snd_es18xx_playback_trigger,
1685 .pointer = snd_es18xx_playback_pointer,
1688 static struct snd_pcm_ops snd_es18xx_capture_ops = {
1689 .open = snd_es18xx_capture_open,
1690 .close = snd_es18xx_capture_close,
1691 .ioctl = snd_pcm_lib_ioctl,
1692 .hw_params = snd_es18xx_capture_hw_params,
1693 .hw_free = snd_es18xx_pcm_hw_free,
1694 .prepare = snd_es18xx_capture_prepare,
1695 .trigger = snd_es18xx_capture_trigger,
1696 .pointer = snd_es18xx_capture_pointer,
1699 static int __devinit snd_es18xx_pcm(struct snd_card *card, int device,
1700 struct snd_pcm **rpcm)
1702 struct snd_audiodrive *acard = card->private_data;
1703 struct snd_es18xx *chip = acard->chip;
1704 struct snd_pcm *pcm;
1705 char str[16];
1706 int err;
1708 if (rpcm)
1709 *rpcm = NULL;
1710 sprintf(str, "ES%x", chip->version);
1711 if (chip->caps & ES18XX_PCM2)
1712 err = snd_pcm_new(card, str, device, 2, 1, &pcm);
1713 else
1714 err = snd_pcm_new(card, str, device, 1, 1, &pcm);
1715 if (err < 0)
1716 return err;
1718 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es18xx_playback_ops);
1719 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es18xx_capture_ops);
1721 /* global setup */
1722 pcm->private_data = chip;
1723 pcm->info_flags = 0;
1724 if (chip->caps & ES18XX_DUPLEX_SAME)
1725 pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX;
1726 if (! (chip->caps & ES18XX_PCM2))
1727 pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX;
1728 sprintf(pcm->name, "ESS AudioDrive ES%x", chip->version);
1729 chip->pcm = pcm;
1731 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1732 snd_dma_isa_data(),
1733 64*1024,
1734 chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024);
1736 if (rpcm)
1737 *rpcm = pcm;
1738 return 0;
1741 /* Power Management support functions */
1742 #ifdef CONFIG_PM
1743 static int snd_es18xx_suspend(struct snd_card *card, pm_message_t state)
1745 struct snd_audiodrive *acard = card->private_data;
1746 struct snd_es18xx *chip = acard->chip;
1748 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1750 snd_pcm_suspend_all(chip->pcm);
1752 /* power down */
1753 chip->pm_reg = (unsigned char)snd_es18xx_read(chip, ES18XX_PM);
1754 chip->pm_reg |= (ES18XX_PM_FM | ES18XX_PM_SUS);
1755 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg);
1756 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_SUS);
1758 return 0;
1761 static int snd_es18xx_resume(struct snd_card *card)
1763 struct snd_audiodrive *acard = card->private_data;
1764 struct snd_es18xx *chip = acard->chip;
1766 /* restore PM register, we won't wake till (not 0x07) i/o activity though */
1767 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM);
1769 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1770 return 0;
1772 #endif /* CONFIG_PM */
1774 static int snd_es18xx_free(struct snd_card *card)
1776 struct snd_audiodrive *acard = card->private_data;
1777 struct snd_es18xx *chip = acard->chip;
1779 release_and_free_resource(chip->res_port);
1780 release_and_free_resource(chip->res_ctrl_port);
1781 release_and_free_resource(chip->res_mpu_port);
1782 if (chip->irq >= 0)
1783 free_irq(chip->irq, (void *) card);
1784 if (chip->dma1 >= 0) {
1785 disable_dma(chip->dma1);
1786 free_dma(chip->dma1);
1788 if (chip->dma2 >= 0 && chip->dma1 != chip->dma2) {
1789 disable_dma(chip->dma2);
1790 free_dma(chip->dma2);
1792 kfree(chip);
1793 return 0;
1796 static int snd_es18xx_dev_free(struct snd_device *device)
1798 return snd_es18xx_free(device->card);
1801 static int __devinit snd_es18xx_new_device(struct snd_card *card,
1802 unsigned long port,
1803 unsigned long mpu_port,
1804 unsigned long fm_port,
1805 int irq, int dma1, int dma2,
1806 struct snd_es18xx ** rchip)
1808 struct snd_es18xx *chip;
1809 static struct snd_device_ops ops = {
1810 .dev_free = snd_es18xx_dev_free,
1812 int err;
1814 *rchip = NULL;
1815 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1816 if (chip == NULL)
1817 return -ENOMEM;
1818 spin_lock_init(&chip->reg_lock);
1819 spin_lock_init(&chip->mixer_lock);
1820 spin_lock_init(&chip->ctrl_lock);
1821 chip->port = port;
1822 chip->mpu_port = mpu_port;
1823 chip->fm_port = fm_port;
1824 chip->irq = -1;
1825 chip->dma1 = -1;
1826 chip->dma2 = -1;
1827 chip->audio2_vol = 0x00;
1828 chip->active = 0;
1830 chip->res_port = request_region(port, 16, "ES18xx");
1831 if (chip->res_port == NULL) {
1832 snd_es18xx_free(card);
1833 snd_printk(KERN_ERR PFX "unable to grap ports 0x%lx-0x%lx\n", port, port + 16 - 1);
1834 return -EBUSY;
1837 if (request_irq(irq, snd_es18xx_interrupt, IRQF_DISABLED, "ES18xx",
1838 (void *) card)) {
1839 snd_es18xx_free(card);
1840 snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq);
1841 return -EBUSY;
1843 chip->irq = irq;
1845 if (request_dma(dma1, "ES18xx DMA 1")) {
1846 snd_es18xx_free(card);
1847 snd_printk(KERN_ERR PFX "unable to grap DMA1 %d\n", dma1);
1848 return -EBUSY;
1850 chip->dma1 = dma1;
1852 if (dma2 != dma1 && request_dma(dma2, "ES18xx DMA 2")) {
1853 snd_es18xx_free(card);
1854 snd_printk(KERN_ERR PFX "unable to grap DMA2 %d\n", dma2);
1855 return -EBUSY;
1857 chip->dma2 = dma2;
1859 if (snd_es18xx_probe(chip) < 0) {
1860 snd_es18xx_free(card);
1861 return -ENODEV;
1863 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, NULL, &ops);
1864 if (err < 0) {
1865 snd_es18xx_free(card);
1866 return err;
1868 *rchip = chip;
1869 return 0;
1872 static int __devinit snd_es18xx_mixer(struct snd_card *card)
1874 struct snd_audiodrive *acard = card->private_data;
1875 struct snd_es18xx *chip = acard->chip;
1876 int err;
1877 unsigned int idx;
1879 strcpy(card->mixername, chip->pcm->name);
1881 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_base_controls); idx++) {
1882 struct snd_kcontrol *kctl;
1883 kctl = snd_ctl_new1(&snd_es18xx_base_controls[idx], chip);
1884 if (chip->caps & ES18XX_HWV) {
1885 switch (idx) {
1886 case 0:
1887 chip->master_volume = kctl;
1888 kctl->private_free = snd_es18xx_hwv_free;
1889 break;
1890 case 1:
1891 chip->master_switch = kctl;
1892 kctl->private_free = snd_es18xx_hwv_free;
1893 break;
1896 if ((err = snd_ctl_add(card, kctl)) < 0)
1897 return err;
1899 if (chip->caps & ES18XX_PCM2) {
1900 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_pcm2_controls); idx++) {
1901 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_pcm2_controls[idx], chip))) < 0)
1902 return err;
1904 } else {
1905 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_pcm1_controls); idx++) {
1906 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_pcm1_controls[idx], chip))) < 0)
1907 return err;
1911 if (chip->caps & ES18XX_RECMIX) {
1912 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_recmix_controls); idx++) {
1913 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_recmix_controls[idx], chip))) < 0)
1914 return err;
1917 switch (chip->version) {
1918 default:
1919 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_micpre1_control, chip))) < 0)
1920 return err;
1921 break;
1922 case 0x1869:
1923 case 0x1879:
1924 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_micpre2_control, chip))) < 0)
1925 return err;
1926 break;
1928 if (chip->caps & ES18XX_SPATIALIZER) {
1929 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_spatializer_controls); idx++) {
1930 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_spatializer_controls[idx], chip))) < 0)
1931 return err;
1934 if (chip->caps & ES18XX_HWV) {
1935 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_hw_volume_controls); idx++) {
1936 struct snd_kcontrol *kctl;
1937 kctl = snd_ctl_new1(&snd_es18xx_hw_volume_controls[idx], chip);
1938 if (idx == 0)
1939 chip->hw_volume = kctl;
1940 else
1941 chip->hw_switch = kctl;
1942 kctl->private_free = snd_es18xx_hwv_free;
1943 if ((err = snd_ctl_add(card, kctl)) < 0)
1944 return err;
1948 /* finish initializing other chipset specific controls
1950 if (chip->version != 0x1868) {
1951 err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_opt_speaker,
1952 chip));
1953 if (err < 0)
1954 return err;
1956 if (chip->version == 0x1869) {
1957 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_opt_1869); idx++) {
1958 err = snd_ctl_add(card,
1959 snd_ctl_new1(&snd_es18xx_opt_1869[idx],
1960 chip));
1961 if (err < 0)
1962 return err;
1964 } else if (chip->version == 0x1878) {
1965 err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_opt_1878,
1966 chip));
1967 if (err < 0)
1968 return err;
1969 } else if (chip->version == 0x1879) {
1970 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_opt_1879); idx++) {
1971 err = snd_ctl_add(card,
1972 snd_ctl_new1(&snd_es18xx_opt_1879[idx],
1973 chip));
1974 if (err < 0)
1975 return err;
1978 return 0;
1982 /* Card level */
1984 MODULE_AUTHOR("Christian Fischbach <fishbach@pool.informatik.rwth-aachen.de>, Abramo Bagnara <abramo@alsa-project.org>");
1985 MODULE_DESCRIPTION("ESS ES18xx AudioDrive");
1986 MODULE_LICENSE("GPL");
1987 MODULE_SUPPORTED_DEVICE("{{ESS,ES1868 PnP AudioDrive},"
1988 "{ESS,ES1869 PnP AudioDrive},"
1989 "{ESS,ES1878 PnP AudioDrive},"
1990 "{ESS,ES1879 PnP AudioDrive},"
1991 "{ESS,ES1887 PnP AudioDrive},"
1992 "{ESS,ES1888 PnP AudioDrive},"
1993 "{ESS,ES1887 AudioDrive},"
1994 "{ESS,ES1888 AudioDrive}}");
1996 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
1997 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
1998 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
1999 #ifdef CONFIG_PNP
2000 static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
2001 #endif
2002 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260,0x280 */
2003 #ifndef CONFIG_PNP
2004 static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
2005 #else
2006 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
2007 #endif
2008 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
2009 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
2010 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
2011 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
2013 module_param_array(index, int, NULL, 0444);
2014 MODULE_PARM_DESC(index, "Index value for ES18xx soundcard.");
2015 module_param_array(id, charp, NULL, 0444);
2016 MODULE_PARM_DESC(id, "ID string for ES18xx soundcard.");
2017 module_param_array(enable, bool, NULL, 0444);
2018 MODULE_PARM_DESC(enable, "Enable ES18xx soundcard.");
2019 #ifdef CONFIG_PNP
2020 module_param_array(isapnp, bool, NULL, 0444);
2021 MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
2022 #endif
2023 module_param_array(port, long, NULL, 0444);
2024 MODULE_PARM_DESC(port, "Port # for ES18xx driver.");
2025 module_param_array(mpu_port, long, NULL, 0444);
2026 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ES18xx driver.");
2027 module_param_array(fm_port, long, NULL, 0444);
2028 MODULE_PARM_DESC(fm_port, "FM port # for ES18xx driver.");
2029 module_param_array(irq, int, NULL, 0444);
2030 MODULE_PARM_DESC(irq, "IRQ # for ES18xx driver.");
2031 module_param_array(dma1, int, NULL, 0444);
2032 MODULE_PARM_DESC(dma1, "DMA 1 # for ES18xx driver.");
2033 module_param_array(dma2, int, NULL, 0444);
2034 MODULE_PARM_DESC(dma2, "DMA 2 # for ES18xx driver.");
2036 #ifdef CONFIG_PNP
2037 static int isa_registered;
2038 static int pnp_registered;
2039 static int pnpc_registered;
2041 static struct pnp_device_id snd_audiodrive_pnpbiosids[] = {
2042 { .id = "ESS1869" },
2043 { .id = "ESS1879" },
2044 { .id = "" } /* end */
2047 MODULE_DEVICE_TABLE(pnp, snd_audiodrive_pnpbiosids);
2049 /* PnP main device initialization */
2050 static int __devinit snd_audiodrive_pnp_init_main(int dev, struct pnp_dev *pdev)
2052 if (pnp_activate_dev(pdev) < 0) {
2053 snd_printk(KERN_ERR PFX "PnP configure failure (out of resources?)\n");
2054 return -EBUSY;
2056 /* ok. hack using Vendor-Defined Card-Level registers */
2057 /* skip csn and logdev initialization - already done in isapnp_configure */
2058 if (pnp_device_is_isapnp(pdev)) {
2059 isapnp_cfg_begin(isapnp_card_number(pdev), isapnp_csn_number(pdev));
2060 isapnp_write_byte(0x27, pnp_irq(pdev, 0)); /* Hardware Volume IRQ Number */
2061 if (mpu_port[dev] != SNDRV_AUTO_PORT)
2062 isapnp_write_byte(0x28, pnp_irq(pdev, 0)); /* MPU-401 IRQ Number */
2063 isapnp_write_byte(0x72, pnp_irq(pdev, 0)); /* second IRQ */
2064 isapnp_cfg_end();
2066 port[dev] = pnp_port_start(pdev, 0);
2067 fm_port[dev] = pnp_port_start(pdev, 1);
2068 mpu_port[dev] = pnp_port_start(pdev, 2);
2069 dma1[dev] = pnp_dma(pdev, 0);
2070 dma2[dev] = pnp_dma(pdev, 1);
2071 irq[dev] = pnp_irq(pdev, 0);
2072 snd_printdd("PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port[dev], fm_port[dev], mpu_port[dev]);
2073 snd_printdd("PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
2074 return 0;
2077 static int __devinit snd_audiodrive_pnp(int dev, struct snd_audiodrive *acard,
2078 struct pnp_dev *pdev)
2080 acard->dev = pdev;
2081 if (snd_audiodrive_pnp_init_main(dev, acard->dev) < 0)
2082 return -EBUSY;
2083 return 0;
2086 static struct pnp_card_device_id snd_audiodrive_pnpids[] = {
2087 /* ESS 1868 (integrated on Compaq dual P-Pro motherboard and Genius 18PnP 3D) */
2088 { .id = "ESS1868", .devs = { { "ESS1868" }, { "ESS0000" } } },
2089 /* ESS 1868 (integrated on Maxisound Cards) */
2090 { .id = "ESS1868", .devs = { { "ESS8601" }, { "ESS8600" } } },
2091 /* ESS 1868 (integrated on Maxisound Cards) */
2092 { .id = "ESS1868", .devs = { { "ESS8611" }, { "ESS8610" } } },
2093 /* ESS ES1869 Plug and Play AudioDrive */
2094 { .id = "ESS0003", .devs = { { "ESS1869" }, { "ESS0006" } } },
2095 /* ESS 1869 */
2096 { .id = "ESS1869", .devs = { { "ESS1869" }, { "ESS0006" } } },
2097 /* ESS 1878 */
2098 { .id = "ESS1878", .devs = { { "ESS1878" }, { "ESS0004" } } },
2099 /* ESS 1879 */
2100 { .id = "ESS1879", .devs = { { "ESS1879" }, { "ESS0009" } } },
2101 /* --- */
2102 { .id = "" } /* end */
2105 MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids);
2107 static int __devinit snd_audiodrive_pnpc(int dev, struct snd_audiodrive *acard,
2108 struct pnp_card_link *card,
2109 const struct pnp_card_device_id *id)
2111 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
2112 if (acard->dev == NULL)
2113 return -EBUSY;
2115 acard->devc = pnp_request_card_device(card, id->devs[1].id, NULL);
2116 if (acard->devc == NULL)
2117 return -EBUSY;
2119 /* Control port initialization */
2120 if (pnp_activate_dev(acard->devc) < 0) {
2121 snd_printk(KERN_ERR PFX "PnP control configure failure (out of resources?)\n");
2122 return -EAGAIN;
2124 snd_printdd("pnp: port=0x%llx\n",
2125 (unsigned long long)pnp_port_start(acard->devc, 0));
2126 if (snd_audiodrive_pnp_init_main(dev, acard->dev) < 0)
2127 return -EBUSY;
2129 return 0;
2131 #endif /* CONFIG_PNP */
2133 #ifdef CONFIG_PNP
2134 #define is_isapnp_selected(dev) isapnp[dev]
2135 #else
2136 #define is_isapnp_selected(dev) 0
2137 #endif
2139 static int snd_es18xx_card_new(int dev, struct snd_card **cardp)
2141 return snd_card_create(index[dev], id[dev], THIS_MODULE,
2142 sizeof(struct snd_audiodrive), cardp);
2145 static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev)
2147 struct snd_audiodrive *acard = card->private_data;
2148 struct snd_es18xx *chip;
2149 struct snd_opl3 *opl3;
2150 int err;
2152 if ((err = snd_es18xx_new_device(card,
2153 port[dev],
2154 mpu_port[dev],
2155 fm_port[dev],
2156 irq[dev], dma1[dev], dma2[dev],
2157 &chip)) < 0)
2158 return err;
2159 acard->chip = chip;
2161 sprintf(card->driver, "ES%x", chip->version);
2163 sprintf(card->shortname, "ESS AudioDrive ES%x", chip->version);
2164 if (dma1[dev] != dma2[dev])
2165 sprintf(card->longname, "%s at 0x%lx, irq %d, dma1 %d, dma2 %d",
2166 card->shortname,
2167 chip->port,
2168 irq[dev], dma1[dev], dma2[dev]);
2169 else
2170 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
2171 card->shortname,
2172 chip->port,
2173 irq[dev], dma1[dev]);
2175 err = snd_es18xx_pcm(card, 0, NULL);
2176 if (err < 0)
2177 return err;
2179 err = snd_es18xx_mixer(card);
2180 if (err < 0)
2181 return err;
2183 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
2184 if (snd_opl3_create(card, chip->fm_port, chip->fm_port + 2, OPL3_HW_OPL3, 0, &opl3) < 0) {
2185 snd_printk(KERN_WARNING PFX "opl3 not detected at 0x%lx\n", chip->fm_port);
2186 } else {
2187 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
2188 return err;
2192 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
2193 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX,
2194 chip->mpu_port, 0,
2195 irq[dev], 0,
2196 &chip->rmidi)) < 0)
2197 return err;
2200 return snd_card_register(card);
2203 static int __devinit snd_es18xx_isa_match(struct device *pdev, unsigned int dev)
2205 return enable[dev] && !is_isapnp_selected(dev);
2208 static int __devinit snd_es18xx_isa_probe1(int dev, struct device *devptr)
2210 struct snd_card *card;
2211 int err;
2213 err = snd_es18xx_card_new(dev, &card);
2214 if (err < 0)
2215 return err;
2216 snd_card_set_dev(card, devptr);
2217 if ((err = snd_audiodrive_probe(card, dev)) < 0) {
2218 snd_card_free(card);
2219 return err;
2221 dev_set_drvdata(devptr, card);
2222 return 0;
2225 static int __devinit snd_es18xx_isa_probe(struct device *pdev, unsigned int dev)
2227 int err;
2228 static int possible_irqs[] = {5, 9, 10, 7, 11, 12, -1};
2229 static int possible_dmas[] = {1, 0, 3, 5, -1};
2231 if (irq[dev] == SNDRV_AUTO_IRQ) {
2232 if ((irq[dev] = snd_legacy_find_free_irq(possible_irqs)) < 0) {
2233 snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
2234 return -EBUSY;
2237 if (dma1[dev] == SNDRV_AUTO_DMA) {
2238 if ((dma1[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) {
2239 snd_printk(KERN_ERR PFX "unable to find a free DMA1\n");
2240 return -EBUSY;
2243 if (dma2[dev] == SNDRV_AUTO_DMA) {
2244 if ((dma2[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) {
2245 snd_printk(KERN_ERR PFX "unable to find a free DMA2\n");
2246 return -EBUSY;
2250 if (port[dev] != SNDRV_AUTO_PORT) {
2251 return snd_es18xx_isa_probe1(dev, pdev);
2252 } else {
2253 static unsigned long possible_ports[] = {0x220, 0x240, 0x260, 0x280};
2254 int i;
2255 for (i = 0; i < ARRAY_SIZE(possible_ports); i++) {
2256 port[dev] = possible_ports[i];
2257 err = snd_es18xx_isa_probe1(dev, pdev);
2258 if (! err)
2259 return 0;
2261 return err;
2265 static int __devexit snd_es18xx_isa_remove(struct device *devptr,
2266 unsigned int dev)
2268 snd_card_free(dev_get_drvdata(devptr));
2269 dev_set_drvdata(devptr, NULL);
2270 return 0;
2273 #ifdef CONFIG_PM
2274 static int snd_es18xx_isa_suspend(struct device *dev, unsigned int n,
2275 pm_message_t state)
2277 return snd_es18xx_suspend(dev_get_drvdata(dev), state);
2280 static int snd_es18xx_isa_resume(struct device *dev, unsigned int n)
2282 return snd_es18xx_resume(dev_get_drvdata(dev));
2284 #endif
2286 #define DEV_NAME "es18xx"
2288 static struct isa_driver snd_es18xx_isa_driver = {
2289 .match = snd_es18xx_isa_match,
2290 .probe = snd_es18xx_isa_probe,
2291 .remove = __devexit_p(snd_es18xx_isa_remove),
2292 #ifdef CONFIG_PM
2293 .suspend = snd_es18xx_isa_suspend,
2294 .resume = snd_es18xx_isa_resume,
2295 #endif
2296 .driver = {
2297 .name = DEV_NAME
2302 #ifdef CONFIG_PNP
2303 static int __devinit snd_audiodrive_pnp_detect(struct pnp_dev *pdev,
2304 const struct pnp_device_id *id)
2306 static int dev;
2307 int err;
2308 struct snd_card *card;
2310 if (pnp_device_is_isapnp(pdev))
2311 return -ENOENT; /* we have another procedure - card */
2312 for (; dev < SNDRV_CARDS; dev++) {
2313 if (enable[dev] && isapnp[dev])
2314 break;
2316 if (dev >= SNDRV_CARDS)
2317 return -ENODEV;
2319 err = snd_es18xx_card_new(dev, &card);
2320 if (err < 0)
2321 return err;
2322 if ((err = snd_audiodrive_pnp(dev, card->private_data, pdev)) < 0) {
2323 snd_card_free(card);
2324 return err;
2326 snd_card_set_dev(card, &pdev->dev);
2327 if ((err = snd_audiodrive_probe(card, dev)) < 0) {
2328 snd_card_free(card);
2329 return err;
2331 pnp_set_drvdata(pdev, card);
2332 dev++;
2333 return 0;
2336 static void __devexit snd_audiodrive_pnp_remove(struct pnp_dev * pdev)
2338 snd_card_free(pnp_get_drvdata(pdev));
2339 pnp_set_drvdata(pdev, NULL);
2342 #ifdef CONFIG_PM
2343 static int snd_audiodrive_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
2345 return snd_es18xx_suspend(pnp_get_drvdata(pdev), state);
2347 static int snd_audiodrive_pnp_resume(struct pnp_dev *pdev)
2349 return snd_es18xx_resume(pnp_get_drvdata(pdev));
2351 #endif
2353 static struct pnp_driver es18xx_pnp_driver = {
2354 .name = "es18xx-pnpbios",
2355 .id_table = snd_audiodrive_pnpbiosids,
2356 .probe = snd_audiodrive_pnp_detect,
2357 .remove = __devexit_p(snd_audiodrive_pnp_remove),
2358 #ifdef CONFIG_PM
2359 .suspend = snd_audiodrive_pnp_suspend,
2360 .resume = snd_audiodrive_pnp_resume,
2361 #endif
2364 static int __devinit snd_audiodrive_pnpc_detect(struct pnp_card_link *pcard,
2365 const struct pnp_card_device_id *pid)
2367 static int dev;
2368 struct snd_card *card;
2369 int res;
2371 for ( ; dev < SNDRV_CARDS; dev++) {
2372 if (enable[dev] && isapnp[dev])
2373 break;
2375 if (dev >= SNDRV_CARDS)
2376 return -ENODEV;
2378 res = snd_es18xx_card_new(dev, &card);
2379 if (res < 0)
2380 return res;
2382 if ((res = snd_audiodrive_pnpc(dev, card->private_data, pcard, pid)) < 0) {
2383 snd_card_free(card);
2384 return res;
2386 snd_card_set_dev(card, &pcard->card->dev);
2387 if ((res = snd_audiodrive_probe(card, dev)) < 0) {
2388 snd_card_free(card);
2389 return res;
2392 pnp_set_card_drvdata(pcard, card);
2393 dev++;
2394 return 0;
2397 static void __devexit snd_audiodrive_pnpc_remove(struct pnp_card_link * pcard)
2399 snd_card_free(pnp_get_card_drvdata(pcard));
2400 pnp_set_card_drvdata(pcard, NULL);
2403 #ifdef CONFIG_PM
2404 static int snd_audiodrive_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
2406 return snd_es18xx_suspend(pnp_get_card_drvdata(pcard), state);
2409 static int snd_audiodrive_pnpc_resume(struct pnp_card_link *pcard)
2411 return snd_es18xx_resume(pnp_get_card_drvdata(pcard));
2414 #endif
2416 static struct pnp_card_driver es18xx_pnpc_driver = {
2417 .flags = PNP_DRIVER_RES_DISABLE,
2418 .name = "es18xx",
2419 .id_table = snd_audiodrive_pnpids,
2420 .probe = snd_audiodrive_pnpc_detect,
2421 .remove = __devexit_p(snd_audiodrive_pnpc_remove),
2422 #ifdef CONFIG_PM
2423 .suspend = snd_audiodrive_pnpc_suspend,
2424 .resume = snd_audiodrive_pnpc_resume,
2425 #endif
2427 #endif /* CONFIG_PNP */
2429 static int __init alsa_card_es18xx_init(void)
2431 int err;
2433 err = isa_register_driver(&snd_es18xx_isa_driver, SNDRV_CARDS);
2434 #ifdef CONFIG_PNP
2435 if (!err)
2436 isa_registered = 1;
2438 err = pnp_register_driver(&es18xx_pnp_driver);
2439 if (!err)
2440 pnp_registered = 1;
2442 err = pnp_register_card_driver(&es18xx_pnpc_driver);
2443 if (!err)
2444 pnpc_registered = 1;
2446 if (isa_registered || pnp_registered)
2447 err = 0;
2448 #endif
2449 return err;
2452 static void __exit alsa_card_es18xx_exit(void)
2454 #ifdef CONFIG_PNP
2455 if (pnpc_registered)
2456 pnp_unregister_card_driver(&es18xx_pnpc_driver);
2457 if (pnp_registered)
2458 pnp_unregister_driver(&es18xx_pnp_driver);
2459 if (isa_registered)
2460 #endif
2461 isa_unregister_driver(&snd_es18xx_isa_driver);
2464 module_init(alsa_card_es18xx_init)
2465 module_exit(alsa_card_es18xx_exit)