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
25 * - There are pops (we can't delay in trigger function, cause midlevel
26 * often need to trigger down and then up very quickly).
28 * - Support for 16 bit DMA seems to be broken. I've no hardware to tune it.
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.
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
54 * - There is a major trouble I noted:
56 * using both channel for playback stereo 16 bit samples at 44100 Hz
57 * the second pcm (Audio1) DMA slows down irregularly and sound is garbled.
59 * The same happens using Audio1 for captureing.
61 * The Windows driver does not suffer of this (although it use Audio1
62 * only for captureing). I'm unable to discover why.
67 #include <sound/driver.h>
70 #include <linux/init.h>
72 #include <linux/slab.h>
73 #include <linux/pnp.h>
74 #include <linux/isapnp.h>
75 #include <linux/moduleparam.h>
76 #include <sound/core.h>
77 #include <sound/control.h>
78 #include <sound/pcm.h>
79 #include <sound/pcm_params.h>
80 #include <sound/mpu401.h>
81 #include <sound/opl3.h>
82 #define SNDRV_LEGACY_AUTO_PROBE
83 #define SNDRV_LEGACY_FIND_FREE_IRQ
84 #define SNDRV_LEGACY_FIND_FREE_DMA
85 #include <sound/initval.h>
87 #define PFX "es18xx: "
90 unsigned long port; /* port of ESS chip */
91 unsigned long mpu_port; /* MPU-401 port of ESS chip */
92 unsigned long fm_port; /* FM port */
93 unsigned long ctrl_port; /* Control port of ESS chip */
94 struct resource *res_port;
95 struct resource *res_mpu_port;
96 struct resource *res_ctrl_port;
97 int irq; /* IRQ number of ESS chip */
100 unsigned short version; /* version of ESS chip */
101 int caps; /* Chip capabilities */
102 unsigned short audio2_vol; /* volume level of audio2 */
104 unsigned short active; /* active channel mask */
105 unsigned int dma1_size;
106 unsigned int dma2_size;
107 unsigned int dma1_shift;
108 unsigned int dma2_shift;
110 struct snd_card *card;
112 struct snd_pcm_substream *playback_a_substream;
113 struct snd_pcm_substream *capture_a_substream;
114 struct snd_pcm_substream *playback_b_substream;
116 struct snd_rawmidi *rmidi;
118 struct snd_kcontrol *hw_volume;
119 struct snd_kcontrol *hw_switch;
120 struct snd_kcontrol *master_volume;
121 struct snd_kcontrol *master_switch;
124 spinlock_t mixer_lock;
125 spinlock_t ctrl_lock;
127 unsigned char pm_reg;
131 #define AUDIO1_IRQ 0x01
132 #define AUDIO2_IRQ 0x02
136 #define ES18XX_PCM2 0x0001 /* Has two useable PCM */
137 #define ES18XX_SPATIALIZER 0x0002 /* Has 3D Spatializer */
138 #define ES18XX_RECMIX 0x0004 /* Has record mixer */
139 #define ES18XX_DUPLEX_MONO 0x0008 /* Has mono duplex only */
140 #define ES18XX_DUPLEX_SAME 0x0010 /* Playback and record must share the same rate */
141 #define ES18XX_NEW_RATE 0x0020 /* More precise rate setting */
142 #define ES18XX_AUXB 0x0040 /* AuxB mixer control */
143 #define ES18XX_HWV 0x0080 /* Has hardware volume */
144 #define ES18XX_MONO 0x0100 /* Mono_in mixer control */
145 #define ES18XX_I2S 0x0200 /* I2S mixer control */
146 #define ES18XX_MUTEREC 0x0400 /* Record source can be muted */
147 #define ES18XX_CONTROL 0x0800 /* Has control ports */
149 /* Power Management */
150 #define ES18XX_PM 0x07
151 #define ES18XX_PM_GPO0 0x01
152 #define ES18XX_PM_GPO1 0x02
153 #define ES18XX_PM_PDR 0x04
154 #define ES18XX_PM_ANA 0x08
155 #define ES18XX_PM_FM 0x020
156 #define ES18XX_PM_SUS 0x080
163 #define MILLISECOND 10000
165 static int snd_es18xx_dsp_command(struct snd_es18xx *chip, unsigned char val)
169 for(i = MILLISECOND; i; i--)
170 if ((inb(chip->port + 0x0C) & 0x80) == 0) {
171 outb(val, chip->port + 0x0C);
174 snd_printk(KERN_ERR "dsp_command: timeout (0x%x)\n", val);
178 static int snd_es18xx_dsp_get_byte(struct snd_es18xx *chip)
182 for(i = MILLISECOND/10; i; i--)
183 if (inb(chip->port + 0x0C) & 0x40)
184 return inb(chip->port + 0x0A);
185 snd_printk(KERN_ERR "dsp_get_byte failed: 0x%lx = 0x%x!!!\n",
186 chip->port + 0x0A, inb(chip->port + 0x0A));
192 static int snd_es18xx_write(struct snd_es18xx *chip,
193 unsigned char reg, unsigned char data)
198 spin_lock_irqsave(&chip->reg_lock, flags);
199 ret = snd_es18xx_dsp_command(chip, reg);
202 ret = snd_es18xx_dsp_command(chip, data);
204 spin_unlock_irqrestore(&chip->reg_lock, flags);
206 snd_printk(KERN_DEBUG "Reg %02x set to %02x\n", reg, data);
211 static int snd_es18xx_read(struct snd_es18xx *chip, unsigned char reg)
215 spin_lock_irqsave(&chip->reg_lock, flags);
216 ret = snd_es18xx_dsp_command(chip, 0xC0);
219 ret = snd_es18xx_dsp_command(chip, reg);
222 data = snd_es18xx_dsp_get_byte(chip);
225 snd_printk(KERN_DEBUG "Reg %02x now is %02x (%d)\n", reg, data, ret);
228 spin_unlock_irqrestore(&chip->reg_lock, flags);
232 /* Return old value */
233 static int snd_es18xx_bits(struct snd_es18xx *chip, unsigned char reg,
234 unsigned char mask, unsigned char val)
237 unsigned char old, new, oval;
239 spin_lock_irqsave(&chip->reg_lock, flags);
240 ret = snd_es18xx_dsp_command(chip, 0xC0);
243 ret = snd_es18xx_dsp_command(chip, reg);
246 ret = snd_es18xx_dsp_get_byte(chip);
253 ret = snd_es18xx_dsp_command(chip, reg);
256 new = (old & ~mask) | (val & mask);
257 ret = snd_es18xx_dsp_command(chip, new);
261 snd_printk(KERN_DEBUG "Reg %02x was %02x, set to %02x (%d)\n",
267 spin_unlock_irqrestore(&chip->reg_lock, flags);
271 static inline void snd_es18xx_mixer_write(struct snd_es18xx *chip,
272 unsigned char reg, unsigned char data)
275 spin_lock_irqsave(&chip->mixer_lock, flags);
276 outb(reg, chip->port + 0x04);
277 outb(data, chip->port + 0x05);
278 spin_unlock_irqrestore(&chip->mixer_lock, flags);
280 snd_printk(KERN_DEBUG "Mixer reg %02x set to %02x\n", reg, data);
284 static inline int snd_es18xx_mixer_read(struct snd_es18xx *chip, unsigned char reg)
288 spin_lock_irqsave(&chip->mixer_lock, flags);
289 outb(reg, chip->port + 0x04);
290 data = inb(chip->port + 0x05);
291 spin_unlock_irqrestore(&chip->mixer_lock, flags);
293 snd_printk(KERN_DEBUG "Mixer reg %02x now is %02x\n", reg, data);
298 /* Return old value */
299 static inline int snd_es18xx_mixer_bits(struct snd_es18xx *chip, unsigned char reg,
300 unsigned char mask, unsigned char val)
302 unsigned char old, new, oval;
304 spin_lock_irqsave(&chip->mixer_lock, flags);
305 outb(reg, chip->port + 0x04);
306 old = inb(chip->port + 0x05);
309 new = (old & ~mask) | (val & mask);
310 outb(new, chip->port + 0x05);
312 snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x\n",
316 spin_unlock_irqrestore(&chip->mixer_lock, flags);
320 static inline int snd_es18xx_mixer_writable(struct snd_es18xx *chip, unsigned char reg,
323 int old, expected, new;
325 spin_lock_irqsave(&chip->mixer_lock, flags);
326 outb(reg, chip->port + 0x04);
327 old = inb(chip->port + 0x05);
328 expected = old ^ mask;
329 outb(expected, chip->port + 0x05);
330 new = inb(chip->port + 0x05);
331 spin_unlock_irqrestore(&chip->mixer_lock, flags);
333 snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x, now is %02x\n",
334 reg, old, expected, new);
336 return expected == new;
340 static int snd_es18xx_reset(struct snd_es18xx *chip)
343 outb(0x03, chip->port + 0x06);
344 inb(chip->port + 0x06);
345 outb(0x00, chip->port + 0x06);
346 for(i = 0; i < MILLISECOND && !(inb(chip->port + 0x0E) & 0x80); i++);
347 if (inb(chip->port + 0x0A) != 0xAA)
352 static int snd_es18xx_reset_fifo(struct snd_es18xx *chip)
354 outb(0x02, chip->port + 0x06);
355 inb(chip->port + 0x06);
356 outb(0x00, chip->port + 0x06);
360 static struct snd_ratnum new_clocks[2] = {
375 static struct snd_pcm_hw_constraint_ratnums new_hw_constraints_clocks = {
380 static struct snd_ratnum old_clocks[2] = {
395 static struct snd_pcm_hw_constraint_ratnums old_hw_constraints_clocks = {
401 static void snd_es18xx_rate_set(struct snd_es18xx *chip,
402 struct snd_pcm_substream *substream,
405 unsigned int bits, div0;
406 struct snd_pcm_runtime *runtime = substream->runtime;
407 if (chip->caps & ES18XX_NEW_RATE) {
408 if (runtime->rate_num == new_clocks[0].num)
409 bits = 128 - runtime->rate_den;
411 bits = 256 - runtime->rate_den;
413 if (runtime->rate_num == old_clocks[0].num)
414 bits = 256 - runtime->rate_den;
416 bits = 128 - runtime->rate_den;
419 /* set filter register */
420 div0 = 256 - 7160000*20/(8*82*runtime->rate);
422 if ((chip->caps & ES18XX_PCM2) && mode == DAC2) {
423 snd_es18xx_mixer_write(chip, 0x70, bits);
425 * Comment from kernel oss driver:
426 * FKS: fascinating: 0x72 doesn't seem to work.
428 snd_es18xx_write(chip, 0xA2, div0);
429 snd_es18xx_mixer_write(chip, 0x72, div0);
431 snd_es18xx_write(chip, 0xA1, bits);
432 snd_es18xx_write(chip, 0xA2, div0);
436 static int snd_es18xx_playback_hw_params(struct snd_pcm_substream *substream,
437 struct snd_pcm_hw_params *hw_params)
439 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
443 if (params_channels(hw_params) == 2)
445 if (snd_pcm_format_width(params_format(hw_params)) == 16)
448 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
449 if ((chip->caps & ES18XX_DUPLEX_MONO) &&
450 (chip->capture_a_substream) &&
451 params_channels(hw_params) != 1) {
452 _snd_pcm_hw_param_setempty(hw_params, SNDRV_PCM_HW_PARAM_CHANNELS);
455 chip->dma2_shift = shift;
457 chip->dma1_shift = shift;
459 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
464 static int snd_es18xx_pcm_hw_free(struct snd_pcm_substream *substream)
466 return snd_pcm_lib_free_pages(substream);
469 static int snd_es18xx_playback1_prepare(struct snd_es18xx *chip,
470 struct snd_pcm_substream *substream)
472 struct snd_pcm_runtime *runtime = substream->runtime;
473 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
474 unsigned int count = snd_pcm_lib_period_bytes(substream);
476 chip->dma2_size = size;
478 snd_es18xx_rate_set(chip, substream, DAC2);
480 /* Transfer Count Reload */
481 count = 0x10000 - count;
482 snd_es18xx_mixer_write(chip, 0x74, count & 0xff);
483 snd_es18xx_mixer_write(chip, 0x76, count >> 8);
486 snd_es18xx_mixer_bits(chip, 0x7A, 0x07,
487 ((runtime->channels == 1) ? 0x00 : 0x02) |
488 (snd_pcm_format_width(runtime->format) == 16 ? 0x01 : 0x00) |
489 (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x04));
491 /* Set DMA controller */
492 snd_dma_program(chip->dma2, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
497 static int snd_es18xx_playback1_trigger(struct snd_es18xx *chip,
498 struct snd_pcm_substream *substream,
502 case SNDRV_PCM_TRIGGER_START:
503 case SNDRV_PCM_TRIGGER_RESUME:
504 if (chip->active & DAC2)
506 chip->active |= DAC2;
509 snd_es18xx_mixer_write(chip, 0x78, 0xb3);
511 snd_es18xx_mixer_write(chip, 0x78, 0x93);
515 if (chip->caps & ES18XX_PCM2)
516 /* Restore Audio 2 volume */
517 snd_es18xx_mixer_write(chip, 0x7C, chip->audio2_vol);
519 /* Enable PCM output */
520 snd_es18xx_dsp_command(chip, 0xD1);
523 case SNDRV_PCM_TRIGGER_STOP:
524 case SNDRV_PCM_TRIGGER_SUSPEND:
525 if (!(chip->active & DAC2))
527 chip->active &= ~DAC2;
529 snd_es18xx_mixer_write(chip, 0x78, 0x00);
532 if (chip->caps & ES18XX_PCM2)
533 /* Set Audio 2 volume to 0 */
534 snd_es18xx_mixer_write(chip, 0x7C, 0);
536 /* Disable PCM output */
537 snd_es18xx_dsp_command(chip, 0xD3);
547 static int snd_es18xx_capture_hw_params(struct snd_pcm_substream *substream,
548 struct snd_pcm_hw_params *hw_params)
550 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
554 if ((chip->caps & ES18XX_DUPLEX_MONO) &&
555 chip->playback_a_substream &&
556 params_channels(hw_params) != 1) {
557 _snd_pcm_hw_param_setempty(hw_params, SNDRV_PCM_HW_PARAM_CHANNELS);
560 if (params_channels(hw_params) == 2)
562 if (snd_pcm_format_width(params_format(hw_params)) == 16)
564 chip->dma1_shift = shift;
565 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
570 static int snd_es18xx_capture_prepare(struct snd_pcm_substream *substream)
572 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
573 struct snd_pcm_runtime *runtime = substream->runtime;
574 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
575 unsigned int count = snd_pcm_lib_period_bytes(substream);
577 chip->dma1_size = size;
579 snd_es18xx_reset_fifo(chip);
581 /* Set stereo/mono */
582 snd_es18xx_bits(chip, 0xA8, 0x03, runtime->channels == 1 ? 0x02 : 0x01);
584 snd_es18xx_rate_set(chip, substream, ADC1);
586 /* Transfer Count Reload */
587 count = 0x10000 - count;
588 snd_es18xx_write(chip, 0xA4, count & 0xff);
589 snd_es18xx_write(chip, 0xA5, count >> 8);
596 snd_es18xx_write(chip, 0xB7,
597 snd_pcm_format_unsigned(runtime->format) ? 0x51 : 0x71);
598 snd_es18xx_write(chip, 0xB7, 0x90 |
599 ((runtime->channels == 1) ? 0x40 : 0x08) |
600 (snd_pcm_format_width(runtime->format) == 16 ? 0x04 : 0x00) |
601 (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x20));
603 /* Set DMA controler */
604 snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
609 static int snd_es18xx_capture_trigger(struct snd_pcm_substream *substream,
612 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
615 case SNDRV_PCM_TRIGGER_START:
616 case SNDRV_PCM_TRIGGER_RESUME:
617 if (chip->active & ADC1)
619 chip->active |= ADC1;
621 snd_es18xx_write(chip, 0xB8, 0x0f);
623 case SNDRV_PCM_TRIGGER_STOP:
624 case SNDRV_PCM_TRIGGER_SUSPEND:
625 if (!(chip->active & ADC1))
627 chip->active &= ~ADC1;
629 snd_es18xx_write(chip, 0xB8, 0x00);
638 static int snd_es18xx_playback2_prepare(struct snd_es18xx *chip,
639 struct snd_pcm_substream *substream)
641 struct snd_pcm_runtime *runtime = substream->runtime;
642 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
643 unsigned int count = snd_pcm_lib_period_bytes(substream);
645 chip->dma1_size = size;
647 snd_es18xx_reset_fifo(chip);
649 /* Set stereo/mono */
650 snd_es18xx_bits(chip, 0xA8, 0x03, runtime->channels == 1 ? 0x02 : 0x01);
652 snd_es18xx_rate_set(chip, substream, DAC1);
654 /* Transfer Count Reload */
655 count = 0x10000 - count;
656 snd_es18xx_write(chip, 0xA4, count & 0xff);
657 snd_es18xx_write(chip, 0xA5, count >> 8);
660 snd_es18xx_write(chip, 0xB6,
661 snd_pcm_format_unsigned(runtime->format) ? 0x80 : 0x00);
662 snd_es18xx_write(chip, 0xB7,
663 snd_pcm_format_unsigned(runtime->format) ? 0x51 : 0x71);
664 snd_es18xx_write(chip, 0xB7, 0x90 |
665 (runtime->channels == 1 ? 0x40 : 0x08) |
666 (snd_pcm_format_width(runtime->format) == 16 ? 0x04 : 0x00) |
667 (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x20));
669 /* Set DMA controler */
670 snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
675 static int snd_es18xx_playback2_trigger(struct snd_es18xx *chip,
676 struct snd_pcm_substream *substream,
680 case SNDRV_PCM_TRIGGER_START:
681 case SNDRV_PCM_TRIGGER_RESUME:
682 if (chip->active & DAC1)
684 chip->active |= DAC1;
686 snd_es18xx_write(chip, 0xB8, 0x05);
691 snd_es18xx_dsp_command(chip, 0xD1);
694 case SNDRV_PCM_TRIGGER_STOP:
695 case SNDRV_PCM_TRIGGER_SUSPEND:
696 if (!(chip->active & DAC1))
698 chip->active &= ~DAC1;
700 snd_es18xx_write(chip, 0xB8, 0x00);
704 /* Disable Audio 1 */
705 snd_es18xx_dsp_command(chip, 0xD3);
715 static int snd_es18xx_playback_prepare(struct snd_pcm_substream *substream)
717 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
718 if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
719 return snd_es18xx_playback1_prepare(chip, substream);
721 return snd_es18xx_playback2_prepare(chip, substream);
724 static int snd_es18xx_playback_trigger(struct snd_pcm_substream *substream,
727 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
728 if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
729 return snd_es18xx_playback1_trigger(chip, substream, cmd);
731 return snd_es18xx_playback2_trigger(chip, substream, cmd);
734 static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
736 struct snd_es18xx *chip = dev_id;
737 unsigned char status;
739 if (chip->caps & ES18XX_CONTROL) {
740 /* Read Interrupt status */
741 status = inb(chip->ctrl_port + 6);
743 /* Read Interrupt status */
744 status = snd_es18xx_mixer_read(chip, 0x7f) >> 4;
749 if (inb(chip->port + 0x0C) & 0x01)
750 status |= AUDIO1_IRQ;
751 if (snd_es18xx_mixer_read(chip, 0x7A) & 0x80)
752 status |= AUDIO2_IRQ;
753 if ((chip->caps & ES18XX_HWV) &&
754 snd_es18xx_mixer_read(chip, 0x64) & 0x10)
759 /* Audio 1 & Audio 2 */
760 if (status & AUDIO2_IRQ) {
761 if (chip->active & DAC2)
762 snd_pcm_period_elapsed(chip->playback_a_substream);
764 snd_es18xx_mixer_bits(chip, 0x7A, 0x80, 0x00);
766 if (status & AUDIO1_IRQ) {
767 /* ok.. capture is active */
768 if (chip->active & ADC1)
769 snd_pcm_period_elapsed(chip->capture_a_substream);
770 /* ok.. playback2 is active */
771 else if (chip->active & DAC1)
772 snd_pcm_period_elapsed(chip->playback_b_substream);
774 inb(chip->port + 0x0E);
778 if ((status & MPU_IRQ) && chip->rmidi)
779 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
781 /* Hardware volume */
782 if (status & HWV_IRQ) {
783 int split = snd_es18xx_mixer_read(chip, 0x64) & 0x80;
784 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_switch->id);
785 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_volume->id);
787 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_switch->id);
788 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_volume->id);
791 snd_es18xx_mixer_write(chip, 0x66, 0x00);
796 static snd_pcm_uframes_t snd_es18xx_playback_pointer(struct snd_pcm_substream *substream)
798 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
801 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
802 if (!(chip->active & DAC2))
804 pos = snd_dma_pointer(chip->dma2, chip->dma2_size);
805 return pos >> chip->dma2_shift;
807 if (!(chip->active & DAC1))
809 pos = snd_dma_pointer(chip->dma1, chip->dma1_size);
810 return pos >> chip->dma1_shift;
814 static snd_pcm_uframes_t snd_es18xx_capture_pointer(struct snd_pcm_substream *substream)
816 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
819 if (!(chip->active & ADC1))
821 pos = snd_dma_pointer(chip->dma1, chip->dma1_size);
822 return pos >> chip->dma1_shift;
825 static struct snd_pcm_hardware snd_es18xx_playback =
827 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
828 SNDRV_PCM_INFO_RESUME |
829 SNDRV_PCM_INFO_MMAP_VALID),
830 .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
831 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE),
832 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
837 .buffer_bytes_max = 65536,
838 .period_bytes_min = 64,
839 .period_bytes_max = 65536,
845 static struct snd_pcm_hardware snd_es18xx_capture =
847 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
848 SNDRV_PCM_INFO_RESUME |
849 SNDRV_PCM_INFO_MMAP_VALID),
850 .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
851 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE),
852 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
857 .buffer_bytes_max = 65536,
858 .period_bytes_min = 64,
859 .period_bytes_max = 65536,
865 static int snd_es18xx_playback_open(struct snd_pcm_substream *substream)
867 struct snd_pcm_runtime *runtime = substream->runtime;
868 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
870 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
871 if ((chip->caps & ES18XX_DUPLEX_MONO) &&
872 chip->capture_a_substream &&
873 chip->capture_a_substream->runtime->channels != 1)
875 chip->playback_a_substream = substream;
876 } else if (substream->number <= 1) {
877 if (chip->capture_a_substream)
879 chip->playback_b_substream = substream;
884 substream->runtime->hw = snd_es18xx_playback;
885 snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
886 (chip->caps & ES18XX_NEW_RATE) ? &new_hw_constraints_clocks : &old_hw_constraints_clocks);
890 static int snd_es18xx_capture_open(struct snd_pcm_substream *substream)
892 struct snd_pcm_runtime *runtime = substream->runtime;
893 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
895 if (chip->playback_b_substream)
897 if ((chip->caps & ES18XX_DUPLEX_MONO) &&
898 chip->playback_a_substream &&
899 chip->playback_a_substream->runtime->channels != 1)
901 chip->capture_a_substream = substream;
902 substream->runtime->hw = snd_es18xx_capture;
903 snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
904 (chip->caps & ES18XX_NEW_RATE) ? &new_hw_constraints_clocks : &old_hw_constraints_clocks);
908 static int snd_es18xx_playback_close(struct snd_pcm_substream *substream)
910 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
912 if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
913 chip->playback_a_substream = NULL;
915 chip->playback_b_substream = NULL;
917 snd_pcm_lib_free_pages(substream);
921 static int snd_es18xx_capture_close(struct snd_pcm_substream *substream)
923 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
925 chip->capture_a_substream = NULL;
926 snd_pcm_lib_free_pages(substream);
934 static int snd_es18xx_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
936 static char *texts[8] = {
937 "Mic", "Mic Master", "CD", "AOUT",
938 "Mic1", "Mix", "Line", "Master"
941 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
943 uinfo->value.enumerated.items = 8;
944 if (uinfo->value.enumerated.item > 7)
945 uinfo->value.enumerated.item = 7;
946 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
950 static int snd_es18xx_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
952 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
953 ucontrol->value.enumerated.item[0] = snd_es18xx_mixer_read(chip, 0x1c) & 0x07;
957 static int snd_es18xx_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
959 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
960 unsigned char val = ucontrol->value.enumerated.item[0];
964 return snd_es18xx_mixer_bits(chip, 0x1c, 0x07, val) != val;
967 static int snd_es18xx_info_spatializer_enable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
969 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
971 uinfo->value.integer.min = 0;
972 uinfo->value.integer.max = 1;
976 static int snd_es18xx_get_spatializer_enable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
978 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
979 unsigned char val = snd_es18xx_mixer_read(chip, 0x50);
980 ucontrol->value.integer.value[0] = !!(val & 8);
984 static int snd_es18xx_put_spatializer_enable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
986 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
987 unsigned char oval, nval;
989 nval = ucontrol->value.integer.value[0] ? 0x0c : 0x04;
990 oval = snd_es18xx_mixer_read(chip, 0x50) & 0x0c;
991 change = nval != oval;
993 snd_es18xx_mixer_write(chip, 0x50, nval & ~0x04);
994 snd_es18xx_mixer_write(chip, 0x50, nval);
999 static int snd_es18xx_info_hw_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1001 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1003 uinfo->value.integer.min = 0;
1004 uinfo->value.integer.max = 63;
1008 static int snd_es18xx_get_hw_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1010 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1011 ucontrol->value.integer.value[0] = snd_es18xx_mixer_read(chip, 0x61) & 0x3f;
1012 ucontrol->value.integer.value[1] = snd_es18xx_mixer_read(chip, 0x63) & 0x3f;
1016 static int snd_es18xx_info_hw_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1018 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1020 uinfo->value.integer.min = 0;
1021 uinfo->value.integer.max = 1;
1025 static int snd_es18xx_get_hw_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1027 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1028 ucontrol->value.integer.value[0] = !(snd_es18xx_mixer_read(chip, 0x61) & 0x40);
1029 ucontrol->value.integer.value[1] = !(snd_es18xx_mixer_read(chip, 0x63) & 0x40);
1033 static void snd_es18xx_hwv_free(struct snd_kcontrol *kcontrol)
1035 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1036 chip->master_volume = NULL;
1037 chip->master_switch = NULL;
1038 chip->hw_volume = NULL;
1039 chip->hw_switch = NULL;
1042 static int snd_es18xx_reg_bits(struct snd_es18xx *chip, unsigned char reg,
1043 unsigned char mask, unsigned char val)
1046 return snd_es18xx_mixer_bits(chip, reg, mask, val);
1048 return snd_es18xx_bits(chip, reg, mask, val);
1051 static int snd_es18xx_reg_read(struct snd_es18xx *chip, unsigned char reg)
1054 return snd_es18xx_mixer_read(chip, reg);
1056 return snd_es18xx_read(chip, reg);
1059 #define ES18XX_SINGLE(xname, xindex, reg, shift, mask, invert) \
1060 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1061 .info = snd_es18xx_info_single, \
1062 .get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \
1063 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
1065 static int snd_es18xx_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1067 int mask = (kcontrol->private_value >> 16) & 0xff;
1069 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1071 uinfo->value.integer.min = 0;
1072 uinfo->value.integer.max = mask;
1076 static int snd_es18xx_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1078 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1079 int reg = kcontrol->private_value & 0xff;
1080 int shift = (kcontrol->private_value >> 8) & 0xff;
1081 int mask = (kcontrol->private_value >> 16) & 0xff;
1082 int invert = (kcontrol->private_value >> 24) & 0xff;
1085 val = snd_es18xx_reg_read(chip, reg);
1086 ucontrol->value.integer.value[0] = (val >> shift) & mask;
1088 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1092 static int snd_es18xx_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1094 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1095 int reg = kcontrol->private_value & 0xff;
1096 int shift = (kcontrol->private_value >> 8) & 0xff;
1097 int mask = (kcontrol->private_value >> 16) & 0xff;
1098 int invert = (kcontrol->private_value >> 24) & 0xff;
1101 val = (ucontrol->value.integer.value[0] & mask);
1106 return snd_es18xx_reg_bits(chip, reg, mask, val) != val;
1109 #define ES18XX_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
1110 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1111 .info = snd_es18xx_info_double, \
1112 .get = snd_es18xx_get_double, .put = snd_es18xx_put_double, \
1113 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
1115 static int snd_es18xx_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1117 int mask = (kcontrol->private_value >> 24) & 0xff;
1119 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1121 uinfo->value.integer.min = 0;
1122 uinfo->value.integer.max = mask;
1126 static int snd_es18xx_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1128 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1129 int left_reg = kcontrol->private_value & 0xff;
1130 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1131 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1132 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1133 int mask = (kcontrol->private_value >> 24) & 0xff;
1134 int invert = (kcontrol->private_value >> 22) & 1;
1135 unsigned char left, right;
1137 left = snd_es18xx_reg_read(chip, left_reg);
1138 if (left_reg != right_reg)
1139 right = snd_es18xx_reg_read(chip, right_reg);
1142 ucontrol->value.integer.value[0] = (left >> shift_left) & mask;
1143 ucontrol->value.integer.value[1] = (right >> shift_right) & mask;
1145 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1146 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
1151 static int snd_es18xx_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1153 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
1154 int left_reg = kcontrol->private_value & 0xff;
1155 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1156 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1157 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1158 int mask = (kcontrol->private_value >> 24) & 0xff;
1159 int invert = (kcontrol->private_value >> 22) & 1;
1161 unsigned char val1, val2, mask1, mask2;
1163 val1 = ucontrol->value.integer.value[0] & mask;
1164 val2 = ucontrol->value.integer.value[1] & mask;
1169 val1 <<= shift_left;
1170 val2 <<= shift_right;
1171 mask1 = mask << shift_left;
1172 mask2 = mask << shift_right;
1173 if (left_reg != right_reg) {
1175 if (snd_es18xx_reg_bits(chip, left_reg, mask1, val1) != val1)
1177 if (snd_es18xx_reg_bits(chip, right_reg, mask2, val2) != val2)
1180 change = (snd_es18xx_reg_bits(chip, left_reg, mask1 | mask2,
1181 val1 | val2) != (val1 | val2));
1186 static struct snd_kcontrol_new snd_es18xx_base_controls[] = {
1187 ES18XX_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0),
1188 ES18XX_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1),
1189 ES18XX_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0),
1190 ES18XX_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0),
1191 ES18XX_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0),
1192 ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1193 ES18XX_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0),
1194 ES18XX_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0),
1195 ES18XX_SINGLE("PC Speaker Playback Volume", 0, 0x3c, 0, 7, 0),
1196 ES18XX_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
1197 ES18XX_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0),
1198 ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
1200 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1201 .name = "Capture Source",
1202 .info = snd_es18xx_info_mux,
1203 .get = snd_es18xx_get_mux,
1204 .put = snd_es18xx_put_mux,
1208 static struct snd_kcontrol_new snd_es18xx_mono_in_control =
1209 ES18XX_DOUBLE("Mono Input Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0);
1211 static struct snd_kcontrol_new snd_es18xx_recmix_controls[] = {
1212 ES18XX_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0),
1213 ES18XX_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0),
1214 ES18XX_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0),
1215 ES18XX_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0),
1216 ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0),
1217 ES18XX_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0),
1218 ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0)
1221 static struct snd_kcontrol_new snd_es18xx_pcm1_controls[] = {
1222 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x14, 0x14, 4, 0, 15, 0),
1225 static struct snd_kcontrol_new snd_es18xx_pcm2_controls[] = {
1226 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0),
1227 ES18XX_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0)
1230 static struct snd_kcontrol_new snd_es18xx_spatializer_controls[] = {
1231 ES18XX_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
1233 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1234 .name = "3D Control - Switch",
1235 .info = snd_es18xx_info_spatializer_enable,
1236 .get = snd_es18xx_get_spatializer_enable,
1237 .put = snd_es18xx_put_spatializer_enable,
1241 static struct snd_kcontrol_new snd_es18xx_micpre1_control =
1242 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0xa9, 2, 1, 0);
1244 static struct snd_kcontrol_new snd_es18xx_micpre2_control =
1245 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0);
1247 static struct snd_kcontrol_new snd_es18xx_hw_volume_controls[] = {
1249 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1250 .name = "Hardware Master Playback Volume",
1251 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1252 .info = snd_es18xx_info_hw_volume,
1253 .get = snd_es18xx_get_hw_volume,
1256 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1257 .name = "Hardware Master Playback Switch",
1258 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1259 .info = snd_es18xx_info_hw_switch,
1260 .get = snd_es18xx_get_hw_switch,
1262 ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0),
1266 static int __devinit snd_es18xx_config_read(struct snd_es18xx *chip, unsigned char reg)
1269 unsigned long flags;
1270 spin_lock_irqsave(&chip->ctrl_lock, flags);
1271 outb(reg, chip->ctrl_port);
1272 data = inb(chip->ctrl_port + 1);
1273 spin_unlock_irqrestore(&chip->ctrl_lock, flags);
1278 static void __devinit snd_es18xx_config_write(struct snd_es18xx *chip,
1279 unsigned char reg, unsigned char data)
1281 /* No need for spinlocks, this function is used only in
1282 otherwise protected init code */
1283 outb(reg, chip->ctrl_port);
1284 outb(data, chip->ctrl_port + 1);
1286 snd_printk(KERN_DEBUG "Config reg %02x set to %02x\n", reg, data);
1290 static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip)
1294 /* enable extended mode */
1295 snd_es18xx_dsp_command(chip, 0xC6);
1296 /* Reset mixer registers */
1297 snd_es18xx_mixer_write(chip, 0x00, 0x00);
1299 /* Audio 1 DMA demand mode (4 bytes/request) */
1300 snd_es18xx_write(chip, 0xB9, 2);
1301 if (chip->caps & ES18XX_CONTROL) {
1302 /* Hardware volume IRQ */
1303 snd_es18xx_config_write(chip, 0x27, chip->irq);
1304 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) {
1306 snd_es18xx_config_write(chip, 0x62, chip->fm_port >> 8);
1307 snd_es18xx_config_write(chip, 0x63, chip->fm_port & 0xff);
1309 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) {
1311 snd_es18xx_config_write(chip, 0x64, chip->mpu_port >> 8);
1312 snd_es18xx_config_write(chip, 0x65, chip->mpu_port & 0xff);
1314 snd_es18xx_config_write(chip, 0x28, chip->irq);
1317 snd_es18xx_config_write(chip, 0x70, chip->irq);
1319 snd_es18xx_config_write(chip, 0x72, chip->irq);
1321 snd_es18xx_config_write(chip, 0x74, chip->dma1);
1323 snd_es18xx_config_write(chip, 0x75, chip->dma2);
1325 /* Enable Audio 1 IRQ */
1326 snd_es18xx_write(chip, 0xB1, 0x50);
1327 /* Enable Audio 2 IRQ */
1328 snd_es18xx_mixer_write(chip, 0x7A, 0x40);
1329 /* Enable Audio 1 DMA */
1330 snd_es18xx_write(chip, 0xB2, 0x50);
1331 /* Enable MPU and hardware volume interrupt */
1332 snd_es18xx_mixer_write(chip, 0x64, 0x42);
1335 int irqmask, dma1mask, dma2mask;
1336 switch (chip->irq) {
1351 snd_printk(KERN_ERR "invalid irq %d\n", chip->irq);
1354 switch (chip->dma1) {
1365 snd_printk(KERN_ERR "invalid dma1 %d\n", chip->dma1);
1368 switch (chip->dma2) {
1382 snd_printk(KERN_ERR "invalid dma2 %d\n", chip->dma2);
1386 /* Enable and set Audio 1 IRQ */
1387 snd_es18xx_write(chip, 0xB1, 0x50 | (irqmask << 2));
1388 /* Enable and set Audio 1 DMA */
1389 snd_es18xx_write(chip, 0xB2, 0x50 | (dma1mask << 2));
1390 /* Set Audio 2 DMA */
1391 snd_es18xx_mixer_bits(chip, 0x7d, 0x07, 0x04 | dma2mask);
1392 /* Enable Audio 2 IRQ and DMA
1393 Set capture mixer input */
1394 snd_es18xx_mixer_write(chip, 0x7A, 0x68);
1395 /* Enable and set hardware volume interrupt */
1396 snd_es18xx_mixer_write(chip, 0x64, 0x06);
1397 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) {
1398 /* MPU401 share irq with audio
1401 snd_es18xx_mixer_write(chip, 0x40, 0x43 | (chip->mpu_port & 0xf0) >> 1);
1403 snd_es18xx_mixer_write(chip, 0x7f, ((irqmask + 1) << 1) | 0x01);
1405 if (chip->caps & ES18XX_NEW_RATE) {
1406 /* Change behaviour of register A1
1408 2nd channel DAC asynchronous */
1409 snd_es18xx_mixer_write(chip, 0x71, 0x32);
1411 if (!(chip->caps & ES18XX_PCM2)) {
1412 /* Enable DMA FIFO */
1413 snd_es18xx_write(chip, 0xB7, 0x80);
1415 if (chip->caps & ES18XX_SPATIALIZER) {
1416 /* Set spatializer parameters to recommended values */
1417 snd_es18xx_mixer_write(chip, 0x54, 0x8f);
1418 snd_es18xx_mixer_write(chip, 0x56, 0x95);
1419 snd_es18xx_mixer_write(chip, 0x58, 0x94);
1420 snd_es18xx_mixer_write(chip, 0x5a, 0x80);
1422 /* Mute input source */
1423 if (chip->caps & ES18XX_MUTEREC)
1425 if (chip->caps & ES18XX_RECMIX)
1426 snd_es18xx_mixer_write(chip, 0x1c, 0x05 | mask);
1428 snd_es18xx_mixer_write(chip, 0x1c, 0x00 | mask);
1429 snd_es18xx_write(chip, 0xb4, 0x00);
1432 /* Enable PCM output */
1433 snd_es18xx_dsp_command(chip, 0xD1);
1439 static int __devinit snd_es18xx_identify(struct snd_es18xx *chip)
1444 if (snd_es18xx_reset(chip) < 0) {
1445 snd_printk(KERN_ERR "reset at 0x%lx failed!!!\n", chip->port);
1449 snd_es18xx_dsp_command(chip, 0xe7);
1450 hi = snd_es18xx_dsp_get_byte(chip);
1454 lo = snd_es18xx_dsp_get_byte(chip);
1455 if ((lo & 0xf0) != 0x80) {
1459 chip->version = 0x488;
1465 if ((lo & 0x0f) < 8) {
1466 chip->version = 0x688;
1470 outb(0x40, chip->port + 0x04);
1471 hi = inb(chip->port + 0x05);
1472 lo = inb(chip->port + 0x05);
1474 chip->version = hi << 8 | lo;
1475 chip->ctrl_port = inb(chip->port + 0x05) << 8;
1476 chip->ctrl_port += inb(chip->port + 0x05);
1478 if ((chip->res_ctrl_port = request_region(chip->ctrl_port, 8, "ES18xx - CTRL")) == NULL) {
1479 snd_printk(KERN_ERR PFX "unable go grab port 0x%lx\n", chip->ctrl_port);
1486 /* If has Hardware volume */
1487 if (snd_es18xx_mixer_writable(chip, 0x64, 0x04)) {
1489 if (snd_es18xx_mixer_writable(chip, 0x70, 0x7f)) {
1490 /* If has volume count */
1491 if (snd_es18xx_mixer_writable(chip, 0x64, 0x20)) {
1492 chip->version = 0x1887;
1494 chip->version = 0x1888;
1497 chip->version = 0x1788;
1501 chip->version = 0x1688;
1505 static int __devinit snd_es18xx_probe(struct snd_es18xx *chip)
1507 if (snd_es18xx_identify(chip) < 0) {
1508 snd_printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port);
1512 switch (chip->version) {
1514 chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_CONTROL | ES18XX_HWV;
1517 chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_MONO | ES18XX_MUTEREC | ES18XX_CONTROL | ES18XX_HWV;
1520 chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV;
1523 chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV;
1526 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME | ES18XX_HWV;
1529 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME | ES18XX_HWV;
1532 snd_printk(KERN_ERR "[0x%lx] unsupported chip ES%x\n",
1533 chip->port, chip->version);
1537 snd_printd("[0x%lx] ESS%x chip found\n", chip->port, chip->version);
1539 if (chip->dma1 == chip->dma2)
1540 chip->caps &= ~(ES18XX_PCM2 | ES18XX_DUPLEX_SAME);
1542 return snd_es18xx_initialize(chip);
1545 static struct snd_pcm_ops snd_es18xx_playback_ops = {
1546 .open = snd_es18xx_playback_open,
1547 .close = snd_es18xx_playback_close,
1548 .ioctl = snd_pcm_lib_ioctl,
1549 .hw_params = snd_es18xx_playback_hw_params,
1550 .hw_free = snd_es18xx_pcm_hw_free,
1551 .prepare = snd_es18xx_playback_prepare,
1552 .trigger = snd_es18xx_playback_trigger,
1553 .pointer = snd_es18xx_playback_pointer,
1556 static struct snd_pcm_ops snd_es18xx_capture_ops = {
1557 .open = snd_es18xx_capture_open,
1558 .close = snd_es18xx_capture_close,
1559 .ioctl = snd_pcm_lib_ioctl,
1560 .hw_params = snd_es18xx_capture_hw_params,
1561 .hw_free = snd_es18xx_pcm_hw_free,
1562 .prepare = snd_es18xx_capture_prepare,
1563 .trigger = snd_es18xx_capture_trigger,
1564 .pointer = snd_es18xx_capture_pointer,
1567 static int __devinit snd_es18xx_pcm(struct snd_es18xx *chip, int device, struct snd_pcm ** rpcm)
1569 struct snd_pcm *pcm;
1575 sprintf(str, "ES%x", chip->version);
1576 if (chip->caps & ES18XX_PCM2) {
1577 err = snd_pcm_new(chip->card, str, device, 2, 1, &pcm);
1579 err = snd_pcm_new(chip->card, str, device, 1, 1, &pcm);
1584 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es18xx_playback_ops);
1585 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es18xx_capture_ops);
1588 pcm->private_data = chip;
1589 pcm->info_flags = 0;
1590 if (chip->caps & ES18XX_DUPLEX_SAME)
1591 pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX;
1592 if (! (chip->caps & ES18XX_PCM2))
1593 pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX;
1594 sprintf(pcm->name, "ESS AudioDrive ES%x", chip->version);
1597 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1600 chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024);
1607 /* Power Management support functions */
1609 static int snd_es18xx_suspend(struct snd_card *card, pm_message_t state)
1611 struct snd_es18xx *chip = card->pm_private_data;
1613 snd_pcm_suspend_all(chip->pcm);
1616 chip->pm_reg = (unsigned char)snd_es18xx_read(chip, ES18XX_PM);
1617 chip->pm_reg |= (ES18XX_PM_FM | ES18XX_PM_SUS);
1618 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg);
1619 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_SUS);
1624 static int snd_es18xx_resume(struct snd_card *card)
1626 struct snd_es18xx *chip = card->pm_private_data;
1628 /* restore PM register, we won't wake till (not 0x07) i/o activity though */
1629 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM);
1633 #endif /* CONFIG_PM */
1635 static int snd_es18xx_free(struct snd_es18xx *chip)
1637 release_and_free_resource(chip->res_port);
1638 release_and_free_resource(chip->res_ctrl_port);
1639 release_and_free_resource(chip->res_mpu_port);
1641 free_irq(chip->irq, (void *) chip);
1642 if (chip->dma1 >= 0) {
1643 disable_dma(chip->dma1);
1644 free_dma(chip->dma1);
1646 if (chip->dma2 >= 0 && chip->dma1 != chip->dma2) {
1647 disable_dma(chip->dma2);
1648 free_dma(chip->dma2);
1654 static int snd_es18xx_dev_free(struct snd_device *device)
1656 struct snd_es18xx *chip = device->device_data;
1657 return snd_es18xx_free(chip);
1660 static int __devinit snd_es18xx_new_device(struct snd_card *card,
1662 unsigned long mpu_port,
1663 unsigned long fm_port,
1664 int irq, int dma1, int dma2,
1665 struct snd_es18xx ** rchip)
1667 struct snd_es18xx *chip;
1668 static struct snd_device_ops ops = {
1669 .dev_free = snd_es18xx_dev_free,
1674 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1677 spin_lock_init(&chip->reg_lock);
1678 spin_lock_init(&chip->mixer_lock);
1679 spin_lock_init(&chip->ctrl_lock);
1682 chip->mpu_port = mpu_port;
1683 chip->fm_port = fm_port;
1687 chip->audio2_vol = 0x00;
1690 if ((chip->res_port = request_region(port, 16, "ES18xx")) == NULL) {
1691 snd_es18xx_free(chip);
1692 snd_printk(KERN_ERR PFX "unable to grap ports 0x%lx-0x%lx\n", port, port + 16 - 1);
1696 if (request_irq(irq, snd_es18xx_interrupt, SA_INTERRUPT, "ES18xx", (void *) chip)) {
1697 snd_es18xx_free(chip);
1698 snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq);
1703 if (request_dma(dma1, "ES18xx DMA 1")) {
1704 snd_es18xx_free(chip);
1705 snd_printk(KERN_ERR PFX "unable to grap DMA1 %d\n", dma1);
1710 if (dma2 != dma1 && request_dma(dma2, "ES18xx DMA 2")) {
1711 snd_es18xx_free(chip);
1712 snd_printk(KERN_ERR PFX "unable to grap DMA2 %d\n", dma2);
1717 if (snd_es18xx_probe(chip) < 0) {
1718 snd_es18xx_free(chip);
1721 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1722 snd_es18xx_free(chip);
1729 static int __devinit snd_es18xx_mixer(struct snd_es18xx *chip)
1731 struct snd_card *card;
1737 strcpy(card->mixername, chip->pcm->name);
1739 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_base_controls); idx++) {
1740 struct snd_kcontrol *kctl;
1741 kctl = snd_ctl_new1(&snd_es18xx_base_controls[idx], chip);
1742 if (chip->caps & ES18XX_HWV) {
1745 chip->master_volume = kctl;
1746 kctl->private_free = snd_es18xx_hwv_free;
1749 chip->master_switch = kctl;
1750 kctl->private_free = snd_es18xx_hwv_free;
1754 if ((err = snd_ctl_add(card, kctl)) < 0)
1757 if (chip->caps & ES18XX_PCM2) {
1758 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_pcm2_controls); idx++) {
1759 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_pcm2_controls[idx], chip))) < 0)
1763 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_pcm1_controls); idx++) {
1764 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_pcm1_controls[idx], chip))) < 0)
1769 if (chip->caps & ES18XX_MONO) {
1770 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_mono_in_control, chip))) < 0)
1773 if (chip->caps & ES18XX_RECMIX) {
1774 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_recmix_controls); idx++) {
1775 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_recmix_controls[idx], chip))) < 0)
1779 switch (chip->version) {
1781 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_micpre1_control, chip))) < 0)
1786 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_micpre2_control, chip))) < 0)
1790 if (chip->caps & ES18XX_SPATIALIZER) {
1791 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_spatializer_controls); idx++) {
1792 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_spatializer_controls[idx], chip))) < 0)
1796 if (chip->caps & ES18XX_HWV) {
1797 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_hw_volume_controls); idx++) {
1798 struct snd_kcontrol *kctl;
1799 kctl = snd_ctl_new1(&snd_es18xx_hw_volume_controls[idx], chip);
1801 chip->hw_volume = kctl;
1803 chip->hw_switch = kctl;
1804 kctl->private_free = snd_es18xx_hwv_free;
1805 if ((err = snd_ctl_add(card, kctl)) < 0)
1816 MODULE_AUTHOR("Christian Fischbach <fishbach@pool.informatik.rwth-aachen.de>, Abramo Bagnara <abramo@alsa-project.org>");
1817 MODULE_DESCRIPTION("ESS ES18xx AudioDrive");
1818 MODULE_LICENSE("GPL");
1819 MODULE_SUPPORTED_DEVICE("{{ESS,ES1868 PnP AudioDrive},"
1820 "{ESS,ES1869 PnP AudioDrive},"
1821 "{ESS,ES1878 PnP AudioDrive},"
1822 "{ESS,ES1879 PnP AudioDrive},"
1823 "{ESS,ES1887 PnP AudioDrive},"
1824 "{ESS,ES1888 PnP AudioDrive},"
1825 "{ESS,ES1887 AudioDrive},"
1826 "{ESS,ES1888 AudioDrive}}");
1828 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
1829 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
1830 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
1832 static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
1834 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260,0x280 */
1836 static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
1838 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
1840 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
1841 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
1842 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
1843 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
1845 module_param_array(index, int, NULL, 0444);
1846 MODULE_PARM_DESC(index, "Index value for ES18xx soundcard.");
1847 module_param_array(id, charp, NULL, 0444);
1848 MODULE_PARM_DESC(id, "ID string for ES18xx soundcard.");
1849 module_param_array(enable, bool, NULL, 0444);
1850 MODULE_PARM_DESC(enable, "Enable ES18xx soundcard.");
1852 module_param_array(isapnp, bool, NULL, 0444);
1853 MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
1855 module_param_array(port, long, NULL, 0444);
1856 MODULE_PARM_DESC(port, "Port # for ES18xx driver.");
1857 module_param_array(mpu_port, long, NULL, 0444);
1858 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ES18xx driver.");
1859 module_param_array(fm_port, long, NULL, 0444);
1860 MODULE_PARM_DESC(fm_port, "FM port # for ES18xx driver.");
1861 module_param_array(irq, int, NULL, 0444);
1862 MODULE_PARM_DESC(irq, "IRQ # for ES18xx driver.");
1863 module_param_array(dma1, int, NULL, 0444);
1864 MODULE_PARM_DESC(dma1, "DMA 1 # for ES18xx driver.");
1865 module_param_array(dma2, int, NULL, 0444);
1866 MODULE_PARM_DESC(dma2, "DMA 2 # for ES18xx driver.");
1868 struct snd_audiodrive {
1870 struct pnp_dev *dev;
1871 struct pnp_dev *devc;
1875 static struct snd_card *snd_audiodrive_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
1879 static struct pnp_card_device_id snd_audiodrive_pnpids[] = {
1880 /* ESS 1868 (integrated on Compaq dual P-Pro motherboard and Genius 18PnP 3D) */
1881 { .id = "ESS1868", .devs = { { "ESS1868" }, { "ESS0000" } } },
1882 /* ESS 1868 (integrated on Maxisound Cards) */
1883 { .id = "ESS1868", .devs = { { "ESS8601" }, { "ESS8600" } } },
1884 /* ESS 1868 (integrated on Maxisound Cards) */
1885 { .id = "ESS1868", .devs = { { "ESS8611" }, { "ESS8610" } } },
1886 /* ESS ES1869 Plug and Play AudioDrive */
1887 { .id = "ESS0003", .devs = { { "ESS1869" }, { "ESS0006" } } },
1889 { .id = "ESS1869", .devs = { { "ESS1869" }, { "ESS0006" } } },
1891 { .id = "ESS1878", .devs = { { "ESS1878" }, { "ESS0004" } } },
1893 { .id = "ESS1879", .devs = { { "ESS1879" }, { "ESS0009" } } },
1895 { .id = "" } /* end */
1898 MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids);
1900 static int __devinit snd_audiodrive_pnp(int dev, struct snd_audiodrive *acard,
1901 struct pnp_card_link *card,
1902 const struct pnp_card_device_id *id)
1904 struct pnp_dev *pdev;
1905 struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
1910 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
1911 if (acard->dev == NULL) {
1915 acard->devc = pnp_request_card_device(card, id->devs[1].id, NULL);
1916 if (acard->devc == NULL) {
1920 /* Control port initialization */
1921 err = pnp_activate_dev(acard->devc);
1923 snd_printk(KERN_ERR PFX "PnP control configure failure (out of resources?)\n");
1926 snd_printdd("pnp: port=0x%lx\n", pnp_port_start(acard->devc, 0));
1927 /* PnP initialization */
1929 pnp_init_resource_table(cfg);
1930 if (port[dev] != SNDRV_AUTO_PORT)
1931 pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
1932 if (fm_port[dev] != SNDRV_AUTO_PORT)
1933 pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
1934 if (mpu_port[dev] != SNDRV_AUTO_PORT)
1935 pnp_resource_change(&cfg->port_resource[2], mpu_port[dev], 2);
1936 if (dma1[dev] != SNDRV_AUTO_DMA)
1937 pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
1938 if (dma2[dev] != SNDRV_AUTO_DMA)
1939 pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
1940 if (irq[dev] != SNDRV_AUTO_IRQ)
1941 pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
1942 err = pnp_manual_config_dev(pdev, cfg, 0);
1944 snd_printk(KERN_ERR PFX "PnP manual resources are invalid, using auto config\n");
1945 err = pnp_activate_dev(pdev);
1947 snd_printk(KERN_ERR PFX "PnP configure failure (out of resources?)\n");
1951 /* ok. hack using Vendor-Defined Card-Level registers */
1952 /* skip csn and logdev initialization - already done in isapnp_configure */
1953 if (pnp_device_is_isapnp(pdev)) {
1954 isapnp_cfg_begin(isapnp_card_number(pdev), isapnp_csn_number(pdev));
1955 isapnp_write_byte(0x27, pnp_irq(pdev, 0)); /* Hardware Volume IRQ Number */
1956 if (mpu_port[dev] != SNDRV_AUTO_PORT)
1957 isapnp_write_byte(0x28, pnp_irq(pdev, 0)); /* MPU-401 IRQ Number */
1958 isapnp_write_byte(0x72, pnp_irq(pdev, 0)); /* second IRQ */
1961 snd_printk(KERN_ERR PFX "unable to install ISA PnP hack, expect malfunction\n");
1963 port[dev] = pnp_port_start(pdev, 0);
1964 fm_port[dev] = pnp_port_start(pdev, 1);
1965 mpu_port[dev] = pnp_port_start(pdev, 2);
1966 dma1[dev] = pnp_dma(pdev, 0);
1967 dma2[dev] = pnp_dma(pdev, 1);
1968 irq[dev] = pnp_irq(pdev, 0);
1969 snd_printdd("PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port[dev], fm_port[dev], mpu_port[dev]);
1970 snd_printdd("PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
1974 #endif /* CONFIG_PNP */
1977 #define is_isapnp_selected(dev) isapnp[dev]
1979 #define is_isapnp_selected(dev) 0
1982 static int __devinit snd_audiodrive_probe(int dev, struct pnp_card_link *pcard,
1983 const struct pnp_card_device_id *pid)
1985 static int possible_irqs[] = {5, 9, 10, 7, 11, 12, -1};
1986 static int possible_dmas[] = {1, 0, 3, 5, -1};
1987 int xirq, xdma1, xdma2;
1988 struct snd_card *card;
1989 struct snd_audiodrive *acard;
1990 struct snd_es18xx *chip;
1991 struct snd_opl3 *opl3;
1994 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
1995 sizeof(struct snd_audiodrive));
1998 acard = (struct snd_audiodrive *)card->private_data;
2001 if ((err = snd_audiodrive_pnp(dev, acard, pcard, pid)) < 0) {
2002 snd_card_free(card);
2005 snd_card_set_dev(card, &pcard->card->dev);
2010 if (xirq == SNDRV_AUTO_IRQ) {
2011 if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
2012 snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
2018 if (xdma1 == SNDRV_AUTO_DMA) {
2019 if ((xdma1 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
2020 snd_printk(KERN_ERR PFX "unable to find a free DMA1\n");
2026 if (xdma2 == SNDRV_AUTO_DMA) {
2027 if ((xdma2 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
2028 snd_printk(KERN_ERR PFX "unable to find a free DMA2\n");
2034 if ((err = snd_es18xx_new_device(card,
2042 sprintf(card->driver, "ES%x", chip->version);
2043 sprintf(card->shortname, "ESS AudioDrive ES%x", chip->version);
2045 sprintf(card->longname, "%s at 0x%lx, irq %d, dma1 %d, dma2 %d",
2048 xirq, xdma1, xdma2);
2050 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
2055 if ((err = snd_es18xx_pcm(chip, 0, NULL)) < 0)
2058 if ((err = snd_es18xx_mixer(chip)) < 0)
2061 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
2062 if (snd_opl3_create(card, chip->fm_port, chip->fm_port + 2, OPL3_HW_OPL3, 0, &opl3) < 0) {
2063 snd_printk(KERN_WARNING PFX "opl3 not detected at 0x%lx\n", chip->fm_port);
2065 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
2070 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
2071 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX,
2078 if ((err = snd_card_set_generic_dev(card)) < 0)
2081 /* Power Management */
2082 snd_card_set_isa_pm_callback(card, snd_es18xx_suspend, snd_es18xx_resume, chip);
2084 if ((err = snd_card_register(card)) < 0)
2088 pnp_set_card_drvdata(pcard, card);
2090 snd_audiodrive_legacy[dev] = card;
2094 snd_card_free(card);
2098 static int __devinit snd_audiodrive_probe_legacy_port(unsigned long xport)
2103 for ( ; dev < SNDRV_CARDS; dev++) {
2104 if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
2106 if (is_isapnp_selected(dev))
2109 res = snd_audiodrive_probe(dev, NULL, NULL);
2111 port[dev] = SNDRV_AUTO_PORT;
2119 static int __devinit snd_audiodrive_pnp_detect(struct pnp_card_link *card,
2120 const struct pnp_card_device_id *id)
2125 for ( ; dev < SNDRV_CARDS; dev++) {
2126 if (!enable[dev] || !isapnp[dev])
2128 res = snd_audiodrive_probe(dev, card, id);
2138 static void __devexit snd_audiodrive_pnp_remove(struct pnp_card_link * pcard)
2140 struct snd_card *card = (struct snd_card *) pnp_get_card_drvdata(pcard);
2142 snd_card_disconnect(card);
2143 snd_card_free_in_thread(card);
2146 static struct pnp_card_driver es18xx_pnpc_driver = {
2147 .flags = PNP_DRIVER_RES_DISABLE,
2149 .id_table = snd_audiodrive_pnpids,
2150 .probe = snd_audiodrive_pnp_detect,
2151 .remove = __devexit_p(snd_audiodrive_pnp_remove),
2153 #endif /* CONFIG_PNP */
2155 static int __init alsa_card_es18xx_init(void)
2157 static unsigned long possible_ports[] = {0x220, 0x240, 0x260, 0x280, -1};
2158 int dev, cards = 0, i;
2160 /* legacy non-auto cards at first */
2161 for (dev = 0; dev < SNDRV_CARDS; dev++) {
2162 if (!enable[dev] || port[dev] == SNDRV_AUTO_PORT)
2164 if (is_isapnp_selected(dev))
2166 if (snd_audiodrive_probe(dev, NULL, NULL) >= 0)
2169 /* legacy auto configured cards */
2170 i = snd_legacy_auto_probe(possible_ports, snd_audiodrive_probe_legacy_port);
2175 /* ISA PnP cards at last */
2176 i = pnp_register_card_driver(&es18xx_pnpc_driver);
2183 pnp_unregister_card_driver(&es18xx_pnpc_driver);
2186 snd_printk(KERN_ERR "ESS AudioDrive ES18xx soundcard not found or device busy\n");
2193 static void __exit alsa_card_es18xx_exit(void)
2198 /* PnP cards first */
2199 pnp_unregister_card_driver(&es18xx_pnpc_driver);
2201 for(idx = 0; idx < SNDRV_CARDS; idx++)
2202 snd_card_free(snd_audiodrive_legacy[idx]);
2205 module_init(alsa_card_es18xx_init)
2206 module_exit(alsa_card_es18xx_exit)