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;
112 snd_pcm_substream_t *playback_a_substream;
113 snd_pcm_substream_t *capture_a_substream;
114 snd_pcm_substream_t *playback_b_substream;
116 snd_rawmidi_t *rmidi;
118 snd_kcontrol_t *hw_volume;
119 snd_kcontrol_t *hw_switch;
120 snd_kcontrol_t *master_volume;
121 snd_kcontrol_t *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
158 typedef struct _snd_es18xx es18xx_t;
165 #define MILLISECOND 10000
167 static int snd_es18xx_dsp_command(es18xx_t *chip, unsigned char val)
171 for(i = MILLISECOND; i; i--)
172 if ((inb(chip->port + 0x0C) & 0x80) == 0) {
173 outb(val, chip->port + 0x0C);
176 snd_printk(KERN_ERR "dsp_command: timeout (0x%x)\n", val);
180 static int snd_es18xx_dsp_get_byte(es18xx_t *chip)
184 for(i = MILLISECOND/10; i; i--)
185 if (inb(chip->port + 0x0C) & 0x40)
186 return inb(chip->port + 0x0A);
187 snd_printk(KERN_ERR "dsp_get_byte failed: 0x%lx = 0x%x!!!\n",
188 chip->port + 0x0A, inb(chip->port + 0x0A));
194 static int snd_es18xx_write(es18xx_t *chip,
195 unsigned char reg, unsigned char data)
200 spin_lock_irqsave(&chip->reg_lock, flags);
201 ret = snd_es18xx_dsp_command(chip, reg);
204 ret = snd_es18xx_dsp_command(chip, data);
206 spin_unlock_irqrestore(&chip->reg_lock, flags);
208 snd_printk(KERN_DEBUG "Reg %02x set to %02x\n", reg, data);
213 static int snd_es18xx_read(es18xx_t *chip, unsigned char reg)
217 spin_lock_irqsave(&chip->reg_lock, flags);
218 ret = snd_es18xx_dsp_command(chip, 0xC0);
221 ret = snd_es18xx_dsp_command(chip, reg);
224 data = snd_es18xx_dsp_get_byte(chip);
227 snd_printk(KERN_DEBUG "Reg %02x now is %02x (%d)\n", reg, data, ret);
230 spin_unlock_irqrestore(&chip->reg_lock, flags);
234 /* Return old value */
235 static int snd_es18xx_bits(es18xx_t *chip, unsigned char reg,
236 unsigned char mask, unsigned char val)
239 unsigned char old, new, oval;
241 spin_lock_irqsave(&chip->reg_lock, flags);
242 ret = snd_es18xx_dsp_command(chip, 0xC0);
245 ret = snd_es18xx_dsp_command(chip, reg);
248 ret = snd_es18xx_dsp_get_byte(chip);
255 ret = snd_es18xx_dsp_command(chip, reg);
258 new = (old & ~mask) | (val & mask);
259 ret = snd_es18xx_dsp_command(chip, new);
263 snd_printk(KERN_DEBUG "Reg %02x was %02x, set to %02x (%d)\n",
269 spin_unlock_irqrestore(&chip->reg_lock, flags);
273 static inline void snd_es18xx_mixer_write(es18xx_t *chip,
274 unsigned char reg, unsigned char data)
277 spin_lock_irqsave(&chip->mixer_lock, flags);
278 outb(reg, chip->port + 0x04);
279 outb(data, chip->port + 0x05);
280 spin_unlock_irqrestore(&chip->mixer_lock, flags);
282 snd_printk(KERN_DEBUG "Mixer reg %02x set to %02x\n", reg, data);
286 static inline int snd_es18xx_mixer_read(es18xx_t *chip, unsigned char reg)
290 spin_lock_irqsave(&chip->mixer_lock, flags);
291 outb(reg, chip->port + 0x04);
292 data = inb(chip->port + 0x05);
293 spin_unlock_irqrestore(&chip->mixer_lock, flags);
295 snd_printk(KERN_DEBUG "Mixer reg %02x now is %02x\n", reg, data);
300 /* Return old value */
301 static inline int snd_es18xx_mixer_bits(es18xx_t *chip, unsigned char reg,
302 unsigned char mask, unsigned char val)
304 unsigned char old, new, oval;
306 spin_lock_irqsave(&chip->mixer_lock, flags);
307 outb(reg, chip->port + 0x04);
308 old = inb(chip->port + 0x05);
311 new = (old & ~mask) | (val & mask);
312 outb(new, chip->port + 0x05);
314 snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x\n",
318 spin_unlock_irqrestore(&chip->mixer_lock, flags);
322 static inline int snd_es18xx_mixer_writable(es18xx_t *chip, unsigned char reg,
325 int old, expected, new;
327 spin_lock_irqsave(&chip->mixer_lock, flags);
328 outb(reg, chip->port + 0x04);
329 old = inb(chip->port + 0x05);
330 expected = old ^ mask;
331 outb(expected, chip->port + 0x05);
332 new = inb(chip->port + 0x05);
333 spin_unlock_irqrestore(&chip->mixer_lock, flags);
335 snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x, now is %02x\n",
336 reg, old, expected, new);
338 return expected == new;
342 static int snd_es18xx_reset(es18xx_t *chip)
345 outb(0x03, chip->port + 0x06);
346 inb(chip->port + 0x06);
347 outb(0x00, chip->port + 0x06);
348 for(i = 0; i < MILLISECOND && !(inb(chip->port + 0x0E) & 0x80); i++);
349 if (inb(chip->port + 0x0A) != 0xAA)
354 static int snd_es18xx_reset_fifo(es18xx_t *chip)
356 outb(0x02, chip->port + 0x06);
357 inb(chip->port + 0x06);
358 outb(0x00, chip->port + 0x06);
362 static ratnum_t new_clocks[2] = {
377 static snd_pcm_hw_constraint_ratnums_t new_hw_constraints_clocks = {
382 static ratnum_t old_clocks[2] = {
397 static snd_pcm_hw_constraint_ratnums_t old_hw_constraints_clocks = {
403 static void snd_es18xx_rate_set(es18xx_t *chip,
404 snd_pcm_substream_t *substream,
407 unsigned int bits, div0;
408 snd_pcm_runtime_t *runtime = substream->runtime;
409 if (chip->caps & ES18XX_NEW_RATE) {
410 if (runtime->rate_num == new_clocks[0].num)
411 bits = 128 - runtime->rate_den;
413 bits = 256 - runtime->rate_den;
415 if (runtime->rate_num == old_clocks[0].num)
416 bits = 256 - runtime->rate_den;
418 bits = 128 - runtime->rate_den;
421 /* set filter register */
422 div0 = 256 - 7160000*20/(8*82*runtime->rate);
424 if ((chip->caps & ES18XX_PCM2) && mode == DAC2) {
425 snd_es18xx_mixer_write(chip, 0x70, bits);
427 * Comment from kernel oss driver:
428 * FKS: fascinating: 0x72 doesn't seem to work.
430 snd_es18xx_write(chip, 0xA2, div0);
431 snd_es18xx_mixer_write(chip, 0x72, div0);
433 snd_es18xx_write(chip, 0xA1, bits);
434 snd_es18xx_write(chip, 0xA2, div0);
438 static int snd_es18xx_playback_hw_params(snd_pcm_substream_t * substream,
439 snd_pcm_hw_params_t * hw_params)
441 es18xx_t *chip = snd_pcm_substream_chip(substream);
445 if (params_channels(hw_params) == 2)
447 if (snd_pcm_format_width(params_format(hw_params)) == 16)
450 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
451 if ((chip->caps & ES18XX_DUPLEX_MONO) &&
452 (chip->capture_a_substream) &&
453 params_channels(hw_params) != 1) {
454 _snd_pcm_hw_param_setempty(hw_params, SNDRV_PCM_HW_PARAM_CHANNELS);
457 chip->dma2_shift = shift;
459 chip->dma1_shift = shift;
461 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
466 static int snd_es18xx_pcm_hw_free(snd_pcm_substream_t * substream)
468 return snd_pcm_lib_free_pages(substream);
471 static int snd_es18xx_playback1_prepare(es18xx_t *chip,
472 snd_pcm_substream_t *substream)
474 snd_pcm_runtime_t *runtime = substream->runtime;
475 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
476 unsigned int count = snd_pcm_lib_period_bytes(substream);
478 chip->dma2_size = size;
480 snd_es18xx_rate_set(chip, substream, DAC2);
482 /* Transfer Count Reload */
483 count = 0x10000 - count;
484 snd_es18xx_mixer_write(chip, 0x74, count & 0xff);
485 snd_es18xx_mixer_write(chip, 0x76, count >> 8);
488 snd_es18xx_mixer_bits(chip, 0x7A, 0x07,
489 ((runtime->channels == 1) ? 0x00 : 0x02) |
490 (snd_pcm_format_width(runtime->format) == 16 ? 0x01 : 0x00) |
491 (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x04));
493 /* Set DMA controller */
494 snd_dma_program(chip->dma2, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
499 static int snd_es18xx_playback1_trigger(es18xx_t *chip,
500 snd_pcm_substream_t * substream,
504 case SNDRV_PCM_TRIGGER_START:
505 case SNDRV_PCM_TRIGGER_RESUME:
506 if (chip->active & DAC2)
508 chip->active |= DAC2;
511 snd_es18xx_mixer_write(chip, 0x78, 0xb3);
513 snd_es18xx_mixer_write(chip, 0x78, 0x93);
517 if (chip->caps & ES18XX_PCM2)
518 /* Restore Audio 2 volume */
519 snd_es18xx_mixer_write(chip, 0x7C, chip->audio2_vol);
521 /* Enable PCM output */
522 snd_es18xx_dsp_command(chip, 0xD1);
525 case SNDRV_PCM_TRIGGER_STOP:
526 case SNDRV_PCM_TRIGGER_SUSPEND:
527 if (!(chip->active & DAC2))
529 chip->active &= ~DAC2;
531 snd_es18xx_mixer_write(chip, 0x78, 0x00);
534 if (chip->caps & ES18XX_PCM2)
535 /* Set Audio 2 volume to 0 */
536 snd_es18xx_mixer_write(chip, 0x7C, 0);
538 /* Disable PCM output */
539 snd_es18xx_dsp_command(chip, 0xD3);
549 static int snd_es18xx_capture_hw_params(snd_pcm_substream_t * substream,
550 snd_pcm_hw_params_t * hw_params)
552 es18xx_t *chip = snd_pcm_substream_chip(substream);
556 if ((chip->caps & ES18XX_DUPLEX_MONO) &&
557 chip->playback_a_substream &&
558 params_channels(hw_params) != 1) {
559 _snd_pcm_hw_param_setempty(hw_params, SNDRV_PCM_HW_PARAM_CHANNELS);
562 if (params_channels(hw_params) == 2)
564 if (snd_pcm_format_width(params_format(hw_params)) == 16)
566 chip->dma1_shift = shift;
567 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
572 static int snd_es18xx_capture_prepare(snd_pcm_substream_t *substream)
574 es18xx_t *chip = snd_pcm_substream_chip(substream);
575 snd_pcm_runtime_t *runtime = substream->runtime;
576 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
577 unsigned int count = snd_pcm_lib_period_bytes(substream);
579 chip->dma1_size = size;
581 snd_es18xx_reset_fifo(chip);
583 /* Set stereo/mono */
584 snd_es18xx_bits(chip, 0xA8, 0x03, runtime->channels == 1 ? 0x02 : 0x01);
586 snd_es18xx_rate_set(chip, substream, ADC1);
588 /* Transfer Count Reload */
589 count = 0x10000 - count;
590 snd_es18xx_write(chip, 0xA4, count & 0xff);
591 snd_es18xx_write(chip, 0xA5, count >> 8);
598 snd_es18xx_write(chip, 0xB7,
599 snd_pcm_format_unsigned(runtime->format) ? 0x51 : 0x71);
600 snd_es18xx_write(chip, 0xB7, 0x90 |
601 ((runtime->channels == 1) ? 0x40 : 0x08) |
602 (snd_pcm_format_width(runtime->format) == 16 ? 0x04 : 0x00) |
603 (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x20));
605 /* Set DMA controler */
606 snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
611 static int snd_es18xx_capture_trigger(snd_pcm_substream_t *substream,
614 es18xx_t *chip = snd_pcm_substream_chip(substream);
617 case SNDRV_PCM_TRIGGER_START:
618 case SNDRV_PCM_TRIGGER_RESUME:
619 if (chip->active & ADC1)
621 chip->active |= ADC1;
623 snd_es18xx_write(chip, 0xB8, 0x0f);
625 case SNDRV_PCM_TRIGGER_STOP:
626 case SNDRV_PCM_TRIGGER_SUSPEND:
627 if (!(chip->active & ADC1))
629 chip->active &= ~ADC1;
631 snd_es18xx_write(chip, 0xB8, 0x00);
640 static int snd_es18xx_playback2_prepare(es18xx_t *chip,
641 snd_pcm_substream_t *substream)
643 snd_pcm_runtime_t *runtime = substream->runtime;
644 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
645 unsigned int count = snd_pcm_lib_period_bytes(substream);
647 chip->dma1_size = size;
649 snd_es18xx_reset_fifo(chip);
651 /* Set stereo/mono */
652 snd_es18xx_bits(chip, 0xA8, 0x03, runtime->channels == 1 ? 0x02 : 0x01);
654 snd_es18xx_rate_set(chip, substream, DAC1);
656 /* Transfer Count Reload */
657 count = 0x10000 - count;
658 snd_es18xx_write(chip, 0xA4, count & 0xff);
659 snd_es18xx_write(chip, 0xA5, count >> 8);
662 snd_es18xx_write(chip, 0xB6,
663 snd_pcm_format_unsigned(runtime->format) ? 0x80 : 0x00);
664 snd_es18xx_write(chip, 0xB7,
665 snd_pcm_format_unsigned(runtime->format) ? 0x51 : 0x71);
666 snd_es18xx_write(chip, 0xB7, 0x90 |
667 (runtime->channels == 1 ? 0x40 : 0x08) |
668 (snd_pcm_format_width(runtime->format) == 16 ? 0x04 : 0x00) |
669 (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x20));
671 /* Set DMA controler */
672 snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
677 static int snd_es18xx_playback2_trigger(es18xx_t *chip,
678 snd_pcm_substream_t *substream,
682 case SNDRV_PCM_TRIGGER_START:
683 case SNDRV_PCM_TRIGGER_RESUME:
684 if (chip->active & DAC1)
686 chip->active |= DAC1;
688 snd_es18xx_write(chip, 0xB8, 0x05);
693 snd_es18xx_dsp_command(chip, 0xD1);
696 case SNDRV_PCM_TRIGGER_STOP:
697 case SNDRV_PCM_TRIGGER_SUSPEND:
698 if (!(chip->active & DAC1))
700 chip->active &= ~DAC1;
702 snd_es18xx_write(chip, 0xB8, 0x00);
706 /* Disable Audio 1 */
707 snd_es18xx_dsp_command(chip, 0xD3);
717 static int snd_es18xx_playback_prepare(snd_pcm_substream_t *substream)
719 es18xx_t *chip = snd_pcm_substream_chip(substream);
720 if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
721 return snd_es18xx_playback1_prepare(chip, substream);
723 return snd_es18xx_playback2_prepare(chip, substream);
726 static int snd_es18xx_playback_trigger(snd_pcm_substream_t *substream,
729 es18xx_t *chip = snd_pcm_substream_chip(substream);
730 if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
731 return snd_es18xx_playback1_trigger(chip, substream, cmd);
733 return snd_es18xx_playback2_trigger(chip, substream, cmd);
736 static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
738 es18xx_t *chip = dev_id;
739 unsigned char status;
741 if (chip->caps & ES18XX_CONTROL) {
742 /* Read Interrupt status */
743 status = inb(chip->ctrl_port + 6);
745 /* Read Interrupt status */
746 status = snd_es18xx_mixer_read(chip, 0x7f) >> 4;
751 if (inb(chip->port + 0x0C) & 0x01)
752 status |= AUDIO1_IRQ;
753 if (snd_es18xx_mixer_read(chip, 0x7A) & 0x80)
754 status |= AUDIO2_IRQ;
755 if ((chip->caps & ES18XX_HWV) &&
756 snd_es18xx_mixer_read(chip, 0x64) & 0x10)
761 /* Audio 1 & Audio 2 */
762 if (status & AUDIO2_IRQ) {
763 if (chip->active & DAC2)
764 snd_pcm_period_elapsed(chip->playback_a_substream);
766 snd_es18xx_mixer_bits(chip, 0x7A, 0x80, 0x00);
768 if (status & AUDIO1_IRQ) {
769 /* ok.. capture is active */
770 if (chip->active & ADC1)
771 snd_pcm_period_elapsed(chip->capture_a_substream);
772 /* ok.. playback2 is active */
773 else if (chip->active & DAC1)
774 snd_pcm_period_elapsed(chip->playback_b_substream);
776 inb(chip->port + 0x0E);
780 if ((status & MPU_IRQ) && chip->rmidi)
781 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
783 /* Hardware volume */
784 if (status & HWV_IRQ) {
785 int split = snd_es18xx_mixer_read(chip, 0x64) & 0x80;
786 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_switch->id);
787 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_volume->id);
789 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_switch->id);
790 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_volume->id);
793 snd_es18xx_mixer_write(chip, 0x66, 0x00);
798 static snd_pcm_uframes_t snd_es18xx_playback_pointer(snd_pcm_substream_t * substream)
800 es18xx_t *chip = snd_pcm_substream_chip(substream);
803 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
804 if (!(chip->active & DAC2))
806 pos = snd_dma_pointer(chip->dma2, chip->dma2_size);
807 return pos >> chip->dma2_shift;
809 if (!(chip->active & DAC1))
811 pos = snd_dma_pointer(chip->dma1, chip->dma1_size);
812 return pos >> chip->dma1_shift;
816 static snd_pcm_uframes_t snd_es18xx_capture_pointer(snd_pcm_substream_t * substream)
818 es18xx_t *chip = snd_pcm_substream_chip(substream);
821 if (!(chip->active & ADC1))
823 pos = snd_dma_pointer(chip->dma1, chip->dma1_size);
824 return pos >> chip->dma1_shift;
827 static snd_pcm_hardware_t snd_es18xx_playback =
829 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
830 SNDRV_PCM_INFO_RESUME |
831 SNDRV_PCM_INFO_MMAP_VALID),
832 .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
833 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE),
834 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
839 .buffer_bytes_max = 65536,
840 .period_bytes_min = 64,
841 .period_bytes_max = 65536,
847 static snd_pcm_hardware_t snd_es18xx_capture =
849 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
850 SNDRV_PCM_INFO_RESUME |
851 SNDRV_PCM_INFO_MMAP_VALID),
852 .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
853 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE),
854 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
859 .buffer_bytes_max = 65536,
860 .period_bytes_min = 64,
861 .period_bytes_max = 65536,
867 static int snd_es18xx_playback_open(snd_pcm_substream_t * substream)
869 snd_pcm_runtime_t *runtime = substream->runtime;
870 es18xx_t *chip = snd_pcm_substream_chip(substream);
872 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
873 if ((chip->caps & ES18XX_DUPLEX_MONO) &&
874 chip->capture_a_substream &&
875 chip->capture_a_substream->runtime->channels != 1)
877 chip->playback_a_substream = substream;
878 } else if (substream->number <= 1) {
879 if (chip->capture_a_substream)
881 chip->playback_b_substream = substream;
886 substream->runtime->hw = snd_es18xx_playback;
887 snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
888 (chip->caps & ES18XX_NEW_RATE) ? &new_hw_constraints_clocks : &old_hw_constraints_clocks);
892 static int snd_es18xx_capture_open(snd_pcm_substream_t * substream)
894 snd_pcm_runtime_t *runtime = substream->runtime;
895 es18xx_t *chip = snd_pcm_substream_chip(substream);
897 if (chip->playback_b_substream)
899 if ((chip->caps & ES18XX_DUPLEX_MONO) &&
900 chip->playback_a_substream &&
901 chip->playback_a_substream->runtime->channels != 1)
903 chip->capture_a_substream = substream;
904 substream->runtime->hw = snd_es18xx_capture;
905 snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
906 (chip->caps & ES18XX_NEW_RATE) ? &new_hw_constraints_clocks : &old_hw_constraints_clocks);
910 static int snd_es18xx_playback_close(snd_pcm_substream_t * substream)
912 es18xx_t *chip = snd_pcm_substream_chip(substream);
914 if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
915 chip->playback_a_substream = NULL;
917 chip->playback_b_substream = NULL;
919 snd_pcm_lib_free_pages(substream);
923 static int snd_es18xx_capture_close(snd_pcm_substream_t * substream)
925 es18xx_t *chip = snd_pcm_substream_chip(substream);
927 chip->capture_a_substream = NULL;
928 snd_pcm_lib_free_pages(substream);
936 static int snd_es18xx_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
938 static char *texts[8] = {
939 "Mic", "Mic Master", "CD", "AOUT",
940 "Mic1", "Mix", "Line", "Master"
943 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
945 uinfo->value.enumerated.items = 8;
946 if (uinfo->value.enumerated.item > 7)
947 uinfo->value.enumerated.item = 7;
948 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
952 static int snd_es18xx_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
954 es18xx_t *chip = snd_kcontrol_chip(kcontrol);
955 ucontrol->value.enumerated.item[0] = snd_es18xx_mixer_read(chip, 0x1c) & 0x07;
959 static int snd_es18xx_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
961 es18xx_t *chip = snd_kcontrol_chip(kcontrol);
962 unsigned char val = ucontrol->value.enumerated.item[0];
966 return snd_es18xx_mixer_bits(chip, 0x1c, 0x07, val) != val;
969 static int snd_es18xx_info_spatializer_enable(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
971 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
973 uinfo->value.integer.min = 0;
974 uinfo->value.integer.max = 1;
978 static int snd_es18xx_get_spatializer_enable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
980 es18xx_t *chip = snd_kcontrol_chip(kcontrol);
981 unsigned char val = snd_es18xx_mixer_read(chip, 0x50);
982 ucontrol->value.integer.value[0] = !!(val & 8);
986 static int snd_es18xx_put_spatializer_enable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
988 es18xx_t *chip = snd_kcontrol_chip(kcontrol);
989 unsigned char oval, nval;
991 nval = ucontrol->value.integer.value[0] ? 0x0c : 0x04;
992 oval = snd_es18xx_mixer_read(chip, 0x50) & 0x0c;
993 change = nval != oval;
995 snd_es18xx_mixer_write(chip, 0x50, nval & ~0x04);
996 snd_es18xx_mixer_write(chip, 0x50, nval);
1001 static int snd_es18xx_info_hw_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1003 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1005 uinfo->value.integer.min = 0;
1006 uinfo->value.integer.max = 63;
1010 static int snd_es18xx_get_hw_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1012 es18xx_t *chip = snd_kcontrol_chip(kcontrol);
1013 ucontrol->value.integer.value[0] = snd_es18xx_mixer_read(chip, 0x61) & 0x3f;
1014 ucontrol->value.integer.value[1] = snd_es18xx_mixer_read(chip, 0x63) & 0x3f;
1018 static int snd_es18xx_info_hw_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1020 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1022 uinfo->value.integer.min = 0;
1023 uinfo->value.integer.max = 1;
1027 static int snd_es18xx_get_hw_switch(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1029 es18xx_t *chip = snd_kcontrol_chip(kcontrol);
1030 ucontrol->value.integer.value[0] = !(snd_es18xx_mixer_read(chip, 0x61) & 0x40);
1031 ucontrol->value.integer.value[1] = !(snd_es18xx_mixer_read(chip, 0x63) & 0x40);
1035 static void snd_es18xx_hwv_free(snd_kcontrol_t *kcontrol)
1037 es18xx_t *chip = snd_kcontrol_chip(kcontrol);
1038 chip->master_volume = NULL;
1039 chip->master_switch = NULL;
1040 chip->hw_volume = NULL;
1041 chip->hw_switch = NULL;
1044 static int snd_es18xx_reg_bits(es18xx_t *chip, unsigned char reg,
1045 unsigned char mask, unsigned char val)
1048 return snd_es18xx_mixer_bits(chip, reg, mask, val);
1050 return snd_es18xx_bits(chip, reg, mask, val);
1053 static int snd_es18xx_reg_read(es18xx_t *chip, unsigned char reg)
1056 return snd_es18xx_mixer_read(chip, reg);
1058 return snd_es18xx_read(chip, reg);
1061 #define ES18XX_SINGLE(xname, xindex, reg, shift, mask, invert) \
1062 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1063 .info = snd_es18xx_info_single, \
1064 .get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \
1065 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
1067 static int snd_es18xx_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1069 int mask = (kcontrol->private_value >> 16) & 0xff;
1071 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1073 uinfo->value.integer.min = 0;
1074 uinfo->value.integer.max = mask;
1078 static int snd_es18xx_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1080 es18xx_t *chip = snd_kcontrol_chip(kcontrol);
1081 int reg = kcontrol->private_value & 0xff;
1082 int shift = (kcontrol->private_value >> 8) & 0xff;
1083 int mask = (kcontrol->private_value >> 16) & 0xff;
1084 int invert = (kcontrol->private_value >> 24) & 0xff;
1087 val = snd_es18xx_reg_read(chip, reg);
1088 ucontrol->value.integer.value[0] = (val >> shift) & mask;
1090 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1094 static int snd_es18xx_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1096 es18xx_t *chip = snd_kcontrol_chip(kcontrol);
1097 int reg = kcontrol->private_value & 0xff;
1098 int shift = (kcontrol->private_value >> 8) & 0xff;
1099 int mask = (kcontrol->private_value >> 16) & 0xff;
1100 int invert = (kcontrol->private_value >> 24) & 0xff;
1103 val = (ucontrol->value.integer.value[0] & mask);
1108 return snd_es18xx_reg_bits(chip, reg, mask, val) != val;
1111 #define ES18XX_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
1112 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1113 .info = snd_es18xx_info_double, \
1114 .get = snd_es18xx_get_double, .put = snd_es18xx_put_double, \
1115 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
1117 static int snd_es18xx_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1119 int mask = (kcontrol->private_value >> 24) & 0xff;
1121 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1123 uinfo->value.integer.min = 0;
1124 uinfo->value.integer.max = mask;
1128 static int snd_es18xx_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1130 es18xx_t *chip = snd_kcontrol_chip(kcontrol);
1131 int left_reg = kcontrol->private_value & 0xff;
1132 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1133 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1134 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1135 int mask = (kcontrol->private_value >> 24) & 0xff;
1136 int invert = (kcontrol->private_value >> 22) & 1;
1137 unsigned char left, right;
1139 left = snd_es18xx_reg_read(chip, left_reg);
1140 if (left_reg != right_reg)
1141 right = snd_es18xx_reg_read(chip, right_reg);
1144 ucontrol->value.integer.value[0] = (left >> shift_left) & mask;
1145 ucontrol->value.integer.value[1] = (right >> shift_right) & mask;
1147 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1148 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
1153 static int snd_es18xx_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1155 es18xx_t *chip = snd_kcontrol_chip(kcontrol);
1156 int left_reg = kcontrol->private_value & 0xff;
1157 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1158 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1159 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1160 int mask = (kcontrol->private_value >> 24) & 0xff;
1161 int invert = (kcontrol->private_value >> 22) & 1;
1163 unsigned char val1, val2, mask1, mask2;
1165 val1 = ucontrol->value.integer.value[0] & mask;
1166 val2 = ucontrol->value.integer.value[1] & mask;
1171 val1 <<= shift_left;
1172 val2 <<= shift_right;
1173 mask1 = mask << shift_left;
1174 mask2 = mask << shift_right;
1175 if (left_reg != right_reg) {
1177 if (snd_es18xx_reg_bits(chip, left_reg, mask1, val1) != val1)
1179 if (snd_es18xx_reg_bits(chip, right_reg, mask2, val2) != val2)
1182 change = (snd_es18xx_reg_bits(chip, left_reg, mask1 | mask2,
1183 val1 | val2) != (val1 | val2));
1188 static snd_kcontrol_new_t snd_es18xx_base_controls[] = {
1189 ES18XX_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0),
1190 ES18XX_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1),
1191 ES18XX_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0),
1192 ES18XX_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0),
1193 ES18XX_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0),
1194 ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1195 ES18XX_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0),
1196 ES18XX_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0),
1197 ES18XX_SINGLE("PC Speaker Playback Volume", 0, 0x3c, 0, 7, 0),
1198 ES18XX_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
1199 ES18XX_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0),
1200 ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
1202 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1203 .name = "Capture Source",
1204 .info = snd_es18xx_info_mux,
1205 .get = snd_es18xx_get_mux,
1206 .put = snd_es18xx_put_mux,
1210 static snd_kcontrol_new_t snd_es18xx_mono_in_control =
1211 ES18XX_DOUBLE("Mono Input Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0);
1213 static snd_kcontrol_new_t snd_es18xx_recmix_controls[] = {
1214 ES18XX_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0),
1215 ES18XX_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0),
1216 ES18XX_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0),
1217 ES18XX_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0),
1218 ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0),
1219 ES18XX_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0),
1220 ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0)
1223 static snd_kcontrol_new_t snd_es18xx_pcm1_controls[] = {
1224 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x14, 0x14, 4, 0, 15, 0),
1227 static snd_kcontrol_new_t snd_es18xx_pcm2_controls[] = {
1228 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0),
1229 ES18XX_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0)
1232 static snd_kcontrol_new_t snd_es18xx_spatializer_controls[] = {
1233 ES18XX_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
1235 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1236 .name = "3D Control - Switch",
1237 .info = snd_es18xx_info_spatializer_enable,
1238 .get = snd_es18xx_get_spatializer_enable,
1239 .put = snd_es18xx_put_spatializer_enable,
1243 static snd_kcontrol_new_t snd_es18xx_micpre1_control =
1244 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0xa9, 2, 1, 0);
1246 static snd_kcontrol_new_t snd_es18xx_micpre2_control =
1247 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0);
1249 static snd_kcontrol_new_t snd_es18xx_hw_volume_controls[] = {
1251 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1252 .name = "Hardware Master Playback Volume",
1253 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1254 .info = snd_es18xx_info_hw_volume,
1255 .get = snd_es18xx_get_hw_volume,
1258 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1259 .name = "Hardware Master Playback Switch",
1260 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1261 .info = snd_es18xx_info_hw_switch,
1262 .get = snd_es18xx_get_hw_switch,
1264 ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0),
1268 static int __devinit snd_es18xx_config_read(es18xx_t *chip, unsigned char reg)
1271 unsigned long flags;
1272 spin_lock_irqsave(&chip->ctrl_lock, flags);
1273 outb(reg, chip->ctrl_port);
1274 data = inb(chip->ctrl_port + 1);
1275 spin_unlock_irqrestore(&chip->ctrl_lock, flags);
1280 static void __devinit snd_es18xx_config_write(es18xx_t *chip,
1281 unsigned char reg, unsigned char data)
1283 /* No need for spinlocks, this function is used only in
1284 otherwise protected init code */
1285 outb(reg, chip->ctrl_port);
1286 outb(data, chip->ctrl_port + 1);
1288 snd_printk(KERN_DEBUG "Config reg %02x set to %02x\n", reg, data);
1292 static int __devinit snd_es18xx_initialize(es18xx_t *chip)
1296 /* enable extended mode */
1297 snd_es18xx_dsp_command(chip, 0xC6);
1298 /* Reset mixer registers */
1299 snd_es18xx_mixer_write(chip, 0x00, 0x00);
1301 /* Audio 1 DMA demand mode (4 bytes/request) */
1302 snd_es18xx_write(chip, 0xB9, 2);
1303 if (chip->caps & ES18XX_CONTROL) {
1304 /* Hardware volume IRQ */
1305 snd_es18xx_config_write(chip, 0x27, chip->irq);
1306 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) {
1308 snd_es18xx_config_write(chip, 0x62, chip->fm_port >> 8);
1309 snd_es18xx_config_write(chip, 0x63, chip->fm_port & 0xff);
1311 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) {
1313 snd_es18xx_config_write(chip, 0x64, chip->mpu_port >> 8);
1314 snd_es18xx_config_write(chip, 0x65, chip->mpu_port & 0xff);
1316 snd_es18xx_config_write(chip, 0x28, chip->irq);
1319 snd_es18xx_config_write(chip, 0x70, chip->irq);
1321 snd_es18xx_config_write(chip, 0x72, chip->irq);
1323 snd_es18xx_config_write(chip, 0x74, chip->dma1);
1325 snd_es18xx_config_write(chip, 0x75, chip->dma2);
1327 /* Enable Audio 1 IRQ */
1328 snd_es18xx_write(chip, 0xB1, 0x50);
1329 /* Enable Audio 2 IRQ */
1330 snd_es18xx_mixer_write(chip, 0x7A, 0x40);
1331 /* Enable Audio 1 DMA */
1332 snd_es18xx_write(chip, 0xB2, 0x50);
1333 /* Enable MPU and hardware volume interrupt */
1334 snd_es18xx_mixer_write(chip, 0x64, 0x42);
1337 int irqmask, dma1mask, dma2mask;
1338 switch (chip->irq) {
1353 snd_printk(KERN_ERR "invalid irq %d\n", chip->irq);
1356 switch (chip->dma1) {
1367 snd_printk(KERN_ERR "invalid dma1 %d\n", chip->dma1);
1370 switch (chip->dma2) {
1384 snd_printk(KERN_ERR "invalid dma2 %d\n", chip->dma2);
1388 /* Enable and set Audio 1 IRQ */
1389 snd_es18xx_write(chip, 0xB1, 0x50 | (irqmask << 2));
1390 /* Enable and set Audio 1 DMA */
1391 snd_es18xx_write(chip, 0xB2, 0x50 | (dma1mask << 2));
1392 /* Set Audio 2 DMA */
1393 snd_es18xx_mixer_bits(chip, 0x7d, 0x07, 0x04 | dma2mask);
1394 /* Enable Audio 2 IRQ and DMA
1395 Set capture mixer input */
1396 snd_es18xx_mixer_write(chip, 0x7A, 0x68);
1397 /* Enable and set hardware volume interrupt */
1398 snd_es18xx_mixer_write(chip, 0x64, 0x06);
1399 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) {
1400 /* MPU401 share irq with audio
1403 snd_es18xx_mixer_write(chip, 0x40, 0x43 | (chip->mpu_port & 0xf0) >> 1);
1405 snd_es18xx_mixer_write(chip, 0x7f, ((irqmask + 1) << 1) | 0x01);
1407 if (chip->caps & ES18XX_NEW_RATE) {
1408 /* Change behaviour of register A1
1410 2nd channel DAC asynchronous */
1411 snd_es18xx_mixer_write(chip, 0x71, 0x32);
1413 if (!(chip->caps & ES18XX_PCM2)) {
1414 /* Enable DMA FIFO */
1415 snd_es18xx_write(chip, 0xB7, 0x80);
1417 if (chip->caps & ES18XX_SPATIALIZER) {
1418 /* Set spatializer parameters to recommended values */
1419 snd_es18xx_mixer_write(chip, 0x54, 0x8f);
1420 snd_es18xx_mixer_write(chip, 0x56, 0x95);
1421 snd_es18xx_mixer_write(chip, 0x58, 0x94);
1422 snd_es18xx_mixer_write(chip, 0x5a, 0x80);
1424 /* Mute input source */
1425 if (chip->caps & ES18XX_MUTEREC)
1427 if (chip->caps & ES18XX_RECMIX)
1428 snd_es18xx_mixer_write(chip, 0x1c, 0x05 | mask);
1430 snd_es18xx_mixer_write(chip, 0x1c, 0x00 | mask);
1431 snd_es18xx_write(chip, 0xb4, 0x00);
1434 /* Enable PCM output */
1435 snd_es18xx_dsp_command(chip, 0xD1);
1441 static int __devinit snd_es18xx_identify(es18xx_t *chip)
1446 if (snd_es18xx_reset(chip) < 0) {
1447 snd_printk(KERN_ERR "reset at 0x%lx failed!!!\n", chip->port);
1451 snd_es18xx_dsp_command(chip, 0xe7);
1452 hi = snd_es18xx_dsp_get_byte(chip);
1456 lo = snd_es18xx_dsp_get_byte(chip);
1457 if ((lo & 0xf0) != 0x80) {
1461 chip->version = 0x488;
1467 if ((lo & 0x0f) < 8) {
1468 chip->version = 0x688;
1472 outb(0x40, chip->port + 0x04);
1473 hi = inb(chip->port + 0x05);
1474 lo = inb(chip->port + 0x05);
1476 chip->version = hi << 8 | lo;
1477 chip->ctrl_port = inb(chip->port + 0x05) << 8;
1478 chip->ctrl_port += inb(chip->port + 0x05);
1480 if ((chip->res_ctrl_port = request_region(chip->ctrl_port, 8, "ES18xx - CTRL")) == NULL) {
1481 snd_printk(KERN_ERR PFX "unable go grab port 0x%lx\n", chip->ctrl_port);
1488 /* If has Hardware volume */
1489 if (snd_es18xx_mixer_writable(chip, 0x64, 0x04)) {
1491 if (snd_es18xx_mixer_writable(chip, 0x70, 0x7f)) {
1492 /* If has volume count */
1493 if (snd_es18xx_mixer_writable(chip, 0x64, 0x20)) {
1494 chip->version = 0x1887;
1496 chip->version = 0x1888;
1499 chip->version = 0x1788;
1503 chip->version = 0x1688;
1507 static int __devinit snd_es18xx_probe(es18xx_t *chip)
1509 if (snd_es18xx_identify(chip) < 0) {
1510 snd_printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port);
1514 switch (chip->version) {
1516 chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_CONTROL | ES18XX_HWV;
1519 chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_MONO | ES18XX_MUTEREC | ES18XX_CONTROL | ES18XX_HWV;
1522 chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV;
1525 chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV;
1528 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME | ES18XX_HWV;
1531 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME | ES18XX_HWV;
1534 snd_printk(KERN_ERR "[0x%lx] unsupported chip ES%x\n",
1535 chip->port, chip->version);
1539 snd_printd("[0x%lx] ESS%x chip found\n", chip->port, chip->version);
1541 if (chip->dma1 == chip->dma2)
1542 chip->caps &= ~(ES18XX_PCM2 | ES18XX_DUPLEX_SAME);
1544 return snd_es18xx_initialize(chip);
1547 static snd_pcm_ops_t snd_es18xx_playback_ops = {
1548 .open = snd_es18xx_playback_open,
1549 .close = snd_es18xx_playback_close,
1550 .ioctl = snd_pcm_lib_ioctl,
1551 .hw_params = snd_es18xx_playback_hw_params,
1552 .hw_free = snd_es18xx_pcm_hw_free,
1553 .prepare = snd_es18xx_playback_prepare,
1554 .trigger = snd_es18xx_playback_trigger,
1555 .pointer = snd_es18xx_playback_pointer,
1558 static snd_pcm_ops_t snd_es18xx_capture_ops = {
1559 .open = snd_es18xx_capture_open,
1560 .close = snd_es18xx_capture_close,
1561 .ioctl = snd_pcm_lib_ioctl,
1562 .hw_params = snd_es18xx_capture_hw_params,
1563 .hw_free = snd_es18xx_pcm_hw_free,
1564 .prepare = snd_es18xx_capture_prepare,
1565 .trigger = snd_es18xx_capture_trigger,
1566 .pointer = snd_es18xx_capture_pointer,
1569 static void snd_es18xx_pcm_free(snd_pcm_t *pcm)
1571 es18xx_t *codec = pcm->private_data;
1573 snd_pcm_lib_preallocate_free_for_all(pcm);
1576 static int __devinit snd_es18xx_pcm(es18xx_t *chip, int device, snd_pcm_t ** rpcm)
1584 sprintf(str, "ES%x", chip->version);
1585 if (chip->caps & ES18XX_PCM2) {
1586 err = snd_pcm_new(chip->card, str, device, 2, 1, &pcm);
1588 err = snd_pcm_new(chip->card, str, device, 1, 1, &pcm);
1593 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es18xx_playback_ops);
1594 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es18xx_capture_ops);
1597 pcm->private_data = chip;
1598 pcm->private_free = snd_es18xx_pcm_free;
1599 pcm->info_flags = 0;
1600 if (chip->caps & ES18XX_DUPLEX_SAME)
1601 pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX;
1602 if (! (chip->caps & ES18XX_PCM2))
1603 pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX;
1604 sprintf(pcm->name, "ESS AudioDrive ES%x", chip->version);
1607 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1610 chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024);
1617 /* Power Management support functions */
1619 static int snd_es18xx_suspend(snd_card_t *card, pm_message_t state)
1621 es18xx_t *chip = card->pm_private_data;
1623 snd_pcm_suspend_all(chip->pcm);
1626 chip->pm_reg = (unsigned char)snd_es18xx_read(chip, ES18XX_PM);
1627 chip->pm_reg |= (ES18XX_PM_FM | ES18XX_PM_SUS);
1628 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg);
1629 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_SUS);
1634 static int snd_es18xx_resume(snd_card_t *card)
1636 es18xx_t *chip = card->pm_private_data;
1638 /* restore PM register, we won't wake till (not 0x07) i/o activity though */
1639 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM);
1643 #endif /* CONFIG_PM */
1645 static int snd_es18xx_free(es18xx_t *chip)
1647 release_and_free_resource(chip->res_port);
1648 release_and_free_resource(chip->res_ctrl_port);
1649 release_and_free_resource(chip->res_mpu_port);
1651 free_irq(chip->irq, (void *) chip);
1652 if (chip->dma1 >= 0) {
1653 disable_dma(chip->dma1);
1654 free_dma(chip->dma1);
1656 if (chip->dma2 >= 0 && chip->dma1 != chip->dma2) {
1657 disable_dma(chip->dma2);
1658 free_dma(chip->dma2);
1664 static int snd_es18xx_dev_free(snd_device_t *device)
1666 es18xx_t *chip = device->device_data;
1667 return snd_es18xx_free(chip);
1670 static int __devinit snd_es18xx_new_device(snd_card_t * card,
1672 unsigned long mpu_port,
1673 unsigned long fm_port,
1674 int irq, int dma1, int dma2,
1678 static snd_device_ops_t ops = {
1679 .dev_free = snd_es18xx_dev_free,
1684 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1687 spin_lock_init(&chip->reg_lock);
1688 spin_lock_init(&chip->mixer_lock);
1689 spin_lock_init(&chip->ctrl_lock);
1692 chip->mpu_port = mpu_port;
1693 chip->fm_port = fm_port;
1697 chip->audio2_vol = 0x00;
1700 if ((chip->res_port = request_region(port, 16, "ES18xx")) == NULL) {
1701 snd_es18xx_free(chip);
1702 snd_printk(KERN_ERR PFX "unable to grap ports 0x%lx-0x%lx\n", port, port + 16 - 1);
1706 if (request_irq(irq, snd_es18xx_interrupt, SA_INTERRUPT, "ES18xx", (void *) chip)) {
1707 snd_es18xx_free(chip);
1708 snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq);
1713 if (request_dma(dma1, "ES18xx DMA 1")) {
1714 snd_es18xx_free(chip);
1715 snd_printk(KERN_ERR PFX "unable to grap DMA1 %d\n", dma1);
1720 if (dma2 != dma1 && request_dma(dma2, "ES18xx DMA 2")) {
1721 snd_es18xx_free(chip);
1722 snd_printk(KERN_ERR PFX "unable to grap DMA2 %d\n", dma2);
1727 if (snd_es18xx_probe(chip) < 0) {
1728 snd_es18xx_free(chip);
1731 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1732 snd_es18xx_free(chip);
1739 static int __devinit snd_es18xx_mixer(es18xx_t *chip)
1747 strcpy(card->mixername, chip->pcm->name);
1749 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_base_controls); idx++) {
1750 snd_kcontrol_t *kctl;
1751 kctl = snd_ctl_new1(&snd_es18xx_base_controls[idx], chip);
1752 if (chip->caps & ES18XX_HWV) {
1755 chip->master_volume = kctl;
1756 kctl->private_free = snd_es18xx_hwv_free;
1759 chip->master_switch = kctl;
1760 kctl->private_free = snd_es18xx_hwv_free;
1764 if ((err = snd_ctl_add(card, kctl)) < 0)
1767 if (chip->caps & ES18XX_PCM2) {
1768 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_pcm2_controls); idx++) {
1769 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_pcm2_controls[idx], chip))) < 0)
1773 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_pcm1_controls); idx++) {
1774 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_pcm1_controls[idx], chip))) < 0)
1779 if (chip->caps & ES18XX_MONO) {
1780 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_mono_in_control, chip))) < 0)
1783 if (chip->caps & ES18XX_RECMIX) {
1784 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_recmix_controls); idx++) {
1785 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_recmix_controls[idx], chip))) < 0)
1789 switch (chip->version) {
1791 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_micpre1_control, chip))) < 0)
1796 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_micpre2_control, chip))) < 0)
1800 if (chip->caps & ES18XX_SPATIALIZER) {
1801 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_spatializer_controls); idx++) {
1802 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_spatializer_controls[idx], chip))) < 0)
1806 if (chip->caps & ES18XX_HWV) {
1807 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_hw_volume_controls); idx++) {
1808 snd_kcontrol_t *kctl;
1809 kctl = snd_ctl_new1(&snd_es18xx_hw_volume_controls[idx], chip);
1811 chip->hw_volume = kctl;
1813 chip->hw_switch = kctl;
1814 kctl->private_free = snd_es18xx_hwv_free;
1815 if ((err = snd_ctl_add(card, kctl)) < 0)
1826 MODULE_AUTHOR("Christian Fischbach <fishbach@pool.informatik.rwth-aachen.de>, Abramo Bagnara <abramo@alsa-project.org>");
1827 MODULE_DESCRIPTION("ESS ES18xx AudioDrive");
1828 MODULE_LICENSE("GPL");
1829 MODULE_SUPPORTED_DEVICE("{{ESS,ES1868 PnP AudioDrive},"
1830 "{ESS,ES1869 PnP AudioDrive},"
1831 "{ESS,ES1878 PnP AudioDrive},"
1832 "{ESS,ES1879 PnP AudioDrive},"
1833 "{ESS,ES1887 PnP AudioDrive},"
1834 "{ESS,ES1888 PnP AudioDrive},"
1835 "{ESS,ES1887 AudioDrive},"
1836 "{ESS,ES1888 AudioDrive}}");
1838 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
1839 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
1840 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
1842 static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
1844 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260,0x280 */
1846 static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
1848 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
1850 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
1851 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
1852 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
1853 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
1855 module_param_array(index, int, NULL, 0444);
1856 MODULE_PARM_DESC(index, "Index value for ES18xx soundcard.");
1857 module_param_array(id, charp, NULL, 0444);
1858 MODULE_PARM_DESC(id, "ID string for ES18xx soundcard.");
1859 module_param_array(enable, bool, NULL, 0444);
1860 MODULE_PARM_DESC(enable, "Enable ES18xx soundcard.");
1862 module_param_array(isapnp, bool, NULL, 0444);
1863 MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
1865 module_param_array(port, long, NULL, 0444);
1866 MODULE_PARM_DESC(port, "Port # for ES18xx driver.");
1867 module_param_array(mpu_port, long, NULL, 0444);
1868 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ES18xx driver.");
1869 module_param_array(fm_port, long, NULL, 0444);
1870 MODULE_PARM_DESC(fm_port, "FM port # for ES18xx driver.");
1871 module_param_array(irq, int, NULL, 0444);
1872 MODULE_PARM_DESC(irq, "IRQ # for ES18xx driver.");
1873 module_param_array(dma1, int, NULL, 0444);
1874 MODULE_PARM_DESC(dma1, "DMA 1 # for ES18xx driver.");
1875 module_param_array(dma2, int, NULL, 0444);
1876 MODULE_PARM_DESC(dma2, "DMA 2 # for ES18xx driver.");
1878 struct snd_audiodrive {
1880 struct pnp_dev *dev;
1881 struct pnp_dev *devc;
1885 static snd_card_t *snd_audiodrive_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
1889 static struct pnp_card_device_id snd_audiodrive_pnpids[] = {
1890 /* ESS 1868 (integrated on Compaq dual P-Pro motherboard and Genius 18PnP 3D) */
1891 { .id = "ESS1868", .devs = { { "ESS1868" }, { "ESS0000" } } },
1892 /* ESS 1868 (integrated on Maxisound Cards) */
1893 { .id = "ESS1868", .devs = { { "ESS8601" }, { "ESS8600" } } },
1894 /* ESS 1868 (integrated on Maxisound Cards) */
1895 { .id = "ESS1868", .devs = { { "ESS8611" }, { "ESS8610" } } },
1896 /* ESS ES1869 Plug and Play AudioDrive */
1897 { .id = "ESS0003", .devs = { { "ESS1869" }, { "ESS0006" } } },
1899 { .id = "ESS1869", .devs = { { "ESS1869" }, { "ESS0006" } } },
1901 { .id = "ESS1878", .devs = { { "ESS1878" }, { "ESS0004" } } },
1903 { .id = "ESS1879", .devs = { { "ESS1879" }, { "ESS0009" } } },
1905 { .id = "" } /* end */
1908 MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids);
1910 static int __devinit snd_audiodrive_pnp(int dev, struct snd_audiodrive *acard,
1911 struct pnp_card_link *card,
1912 const struct pnp_card_device_id *id)
1914 struct pnp_dev *pdev;
1915 struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
1920 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
1921 if (acard->dev == NULL) {
1925 acard->devc = pnp_request_card_device(card, id->devs[1].id, NULL);
1926 if (acard->devc == NULL) {
1930 /* Control port initialization */
1931 err = pnp_activate_dev(acard->devc);
1933 snd_printk(KERN_ERR PFX "PnP control configure failure (out of resources?)\n");
1936 snd_printdd("pnp: port=0x%lx\n", pnp_port_start(acard->devc, 0));
1937 /* PnP initialization */
1939 pnp_init_resource_table(cfg);
1940 if (port[dev] != SNDRV_AUTO_PORT)
1941 pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
1942 if (fm_port[dev] != SNDRV_AUTO_PORT)
1943 pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
1944 if (mpu_port[dev] != SNDRV_AUTO_PORT)
1945 pnp_resource_change(&cfg->port_resource[2], mpu_port[dev], 2);
1946 if (dma1[dev] != SNDRV_AUTO_DMA)
1947 pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
1948 if (dma2[dev] != SNDRV_AUTO_DMA)
1949 pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
1950 if (irq[dev] != SNDRV_AUTO_IRQ)
1951 pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
1952 err = pnp_manual_config_dev(pdev, cfg, 0);
1954 snd_printk(KERN_ERR PFX "PnP manual resources are invalid, using auto config\n");
1955 err = pnp_activate_dev(pdev);
1957 snd_printk(KERN_ERR PFX "PnP configure failure (out of resources?)\n");
1961 /* ok. hack using Vendor-Defined Card-Level registers */
1962 /* skip csn and logdev initialization - already done in isapnp_configure */
1963 if (pnp_device_is_isapnp(pdev)) {
1964 isapnp_cfg_begin(isapnp_card_number(pdev), isapnp_csn_number(pdev));
1965 isapnp_write_byte(0x27, pnp_irq(pdev, 0)); /* Hardware Volume IRQ Number */
1966 if (mpu_port[dev] != SNDRV_AUTO_PORT)
1967 isapnp_write_byte(0x28, pnp_irq(pdev, 0)); /* MPU-401 IRQ Number */
1968 isapnp_write_byte(0x72, pnp_irq(pdev, 0)); /* second IRQ */
1971 snd_printk(KERN_ERR PFX "unable to install ISA PnP hack, expect malfunction\n");
1973 port[dev] = pnp_port_start(pdev, 0);
1974 fm_port[dev] = pnp_port_start(pdev, 1);
1975 mpu_port[dev] = pnp_port_start(pdev, 2);
1976 dma1[dev] = pnp_dma(pdev, 0);
1977 dma2[dev] = pnp_dma(pdev, 1);
1978 irq[dev] = pnp_irq(pdev, 0);
1979 snd_printdd("PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port[dev], fm_port[dev], mpu_port[dev]);
1980 snd_printdd("PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
1984 #endif /* CONFIG_PNP */
1987 #define is_isapnp_selected(dev) isapnp[dev]
1989 #define is_isapnp_selected(dev) 0
1992 static int __devinit snd_audiodrive_probe(int dev, struct pnp_card_link *pcard,
1993 const struct pnp_card_device_id *pid)
1995 static int possible_irqs[] = {5, 9, 10, 7, 11, 12, -1};
1996 static int possible_dmas[] = {1, 0, 3, 5, -1};
1997 int xirq, xdma1, xdma2;
1999 struct snd_audiodrive *acard;
2004 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
2005 sizeof(struct snd_audiodrive));
2008 acard = (struct snd_audiodrive *)card->private_data;
2011 if ((err = snd_audiodrive_pnp(dev, acard, pcard, pid)) < 0) {
2012 snd_card_free(card);
2015 snd_card_set_dev(card, &pcard->card->dev);
2020 if (xirq == SNDRV_AUTO_IRQ) {
2021 if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
2022 snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
2028 if (xdma1 == SNDRV_AUTO_DMA) {
2029 if ((xdma1 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
2030 snd_printk(KERN_ERR PFX "unable to find a free DMA1\n");
2036 if (xdma2 == SNDRV_AUTO_DMA) {
2037 if ((xdma2 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
2038 snd_printk(KERN_ERR PFX "unable to find a free DMA2\n");
2044 if ((err = snd_es18xx_new_device(card,
2052 sprintf(card->driver, "ES%x", chip->version);
2053 sprintf(card->shortname, "ESS AudioDrive ES%x", chip->version);
2055 sprintf(card->longname, "%s at 0x%lx, irq %d, dma1 %d, dma2 %d",
2058 xirq, xdma1, xdma2);
2060 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
2065 if ((err = snd_es18xx_pcm(chip, 0, NULL)) < 0)
2068 if ((err = snd_es18xx_mixer(chip)) < 0)
2071 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
2072 if (snd_opl3_create(card, chip->fm_port, chip->fm_port + 2, OPL3_HW_OPL3, 0, &opl3) < 0) {
2073 snd_printk(KERN_WARNING PFX "opl3 not detected at 0x%lx\n", chip->fm_port);
2075 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
2080 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
2081 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX,
2088 if ((err = snd_card_set_generic_dev(card)) < 0)
2091 /* Power Management */
2092 snd_card_set_isa_pm_callback(card, snd_es18xx_suspend, snd_es18xx_resume, chip);
2094 if ((err = snd_card_register(card)) < 0)
2098 pnp_set_card_drvdata(pcard, card);
2100 snd_audiodrive_legacy[dev] = card;
2104 snd_card_free(card);
2108 static int __devinit snd_audiodrive_probe_legacy_port(unsigned long xport)
2113 for ( ; dev < SNDRV_CARDS; dev++) {
2114 if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
2116 if (is_isapnp_selected(dev))
2119 res = snd_audiodrive_probe(dev, NULL, NULL);
2121 port[dev] = SNDRV_AUTO_PORT;
2129 static int __devinit snd_audiodrive_pnp_detect(struct pnp_card_link *card,
2130 const struct pnp_card_device_id *id)
2135 for ( ; dev < SNDRV_CARDS; dev++) {
2136 if (!enable[dev] || !isapnp[dev])
2138 res = snd_audiodrive_probe(dev, card, id);
2148 static void __devexit snd_audiodrive_pnp_remove(struct pnp_card_link * pcard)
2150 snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
2152 snd_card_disconnect(card);
2153 snd_card_free_in_thread(card);
2156 static struct pnp_card_driver es18xx_pnpc_driver = {
2157 .flags = PNP_DRIVER_RES_DISABLE,
2159 .id_table = snd_audiodrive_pnpids,
2160 .probe = snd_audiodrive_pnp_detect,
2161 .remove = __devexit_p(snd_audiodrive_pnp_remove),
2163 #endif /* CONFIG_PNP */
2165 static int __init alsa_card_es18xx_init(void)
2167 static unsigned long possible_ports[] = {0x220, 0x240, 0x260, 0x280, -1};
2168 int dev, cards = 0, i;
2170 /* legacy non-auto cards at first */
2171 for (dev = 0; dev < SNDRV_CARDS; dev++) {
2172 if (!enable[dev] || port[dev] == SNDRV_AUTO_PORT)
2174 if (is_isapnp_selected(dev))
2176 if (snd_audiodrive_probe(dev, NULL, NULL) >= 0)
2179 /* legacy auto configured cards */
2180 i = snd_legacy_auto_probe(possible_ports, snd_audiodrive_probe_legacy_port);
2185 /* ISA PnP cards at last */
2186 i = pnp_register_card_driver(&es18xx_pnpc_driver);
2193 pnp_unregister_card_driver(&es18xx_pnpc_driver);
2196 snd_printk(KERN_ERR "ESS AudioDrive ES18xx soundcard not found or device busy\n");
2203 static void __exit alsa_card_es18xx_exit(void)
2208 /* PnP cards first */
2209 pnp_unregister_card_driver(&es18xx_pnpc_driver);
2211 for(idx = 0; idx < SNDRV_CARDS; idx++)
2212 snd_card_free(snd_audiodrive_legacy[idx]);
2215 module_init(alsa_card_es18xx_init)
2216 module_exit(alsa_card_es18xx_exit)