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
52 * - Zoom Video is implemented by sharing the FM DAC, thus the user can
53 * have either FM playback or Video playback but not both simultaneously.
54 * The Video Playback Switch mixer control toggles this choice.
58 * - There is a major trouble I noted:
60 * using both channel for playback stereo 16 bit samples at 44100 Hz
61 * the second pcm (Audio1) DMA slows down irregularly and sound is garbled.
63 * The same happens using Audio1 for captureing.
65 * The Windows driver does not suffer of this (although it use Audio1
66 * only for captureing). I'm unable to discover why.
72 * - When Zoom Video is enabled (reg 0x71 bit 6 toggled on) the PCM playback
73 * seems to be effected (speaker_test plays a lower frequency). Can't find
74 * anything in the datasheet to account for this, so a Video Playback Switch
75 * control has been included to allow ZV to be enabled only when necessary.
76 * Then again on at least one test system the 0x71 bit 6 enable bit is not
77 * needed for ZV, so maybe the datasheet is entirely wrong here.
80 #include <linux/init.h>
81 #include <linux/err.h>
82 #include <linux/isa.h>
83 #include <linux/pnp.h>
84 #include <linux/isapnp.h>
85 #include <linux/module.h>
86 #include <linux/delay.h>
90 #include <sound/core.h>
91 #include <sound/control.h>
92 #include <sound/pcm.h>
93 #include <sound/pcm_params.h>
94 #include <sound/mpu401.h>
95 #include <sound/opl3.h>
96 #define SNDRV_LEGACY_FIND_FREE_IRQ
97 #define SNDRV_LEGACY_FIND_FREE_DMA
98 #include <sound/initval.h>
100 #define PFX "es18xx: "
103 unsigned long port
; /* port of ESS chip */
104 unsigned long ctrl_port
; /* Control port of ESS chip */
105 struct resource
*res_port
;
106 struct resource
*res_mpu_port
;
107 struct resource
*res_ctrl_port
;
108 int irq
; /* IRQ number of ESS chip */
111 unsigned short version
; /* version of ESS chip */
112 int caps
; /* Chip capabilities */
113 unsigned short audio2_vol
; /* volume level of audio2 */
115 unsigned short active
; /* active channel mask */
116 unsigned int dma1_shift
;
117 unsigned int dma2_shift
;
120 struct snd_pcm_substream
*playback_a_substream
;
121 struct snd_pcm_substream
*capture_a_substream
;
122 struct snd_pcm_substream
*playback_b_substream
;
124 struct snd_rawmidi
*rmidi
;
126 struct snd_kcontrol
*hw_volume
;
127 struct snd_kcontrol
*hw_switch
;
128 struct snd_kcontrol
*master_volume
;
129 struct snd_kcontrol
*master_switch
;
132 spinlock_t mixer_lock
;
134 unsigned char pm_reg
;
138 struct pnp_dev
*devc
;
142 #define AUDIO1_IRQ 0x01
143 #define AUDIO2_IRQ 0x02
147 #define ES18XX_PCM2 0x0001 /* Has two useable PCM */
148 #define ES18XX_SPATIALIZER 0x0002 /* Has 3D Spatializer */
149 #define ES18XX_RECMIX 0x0004 /* Has record mixer */
150 #define ES18XX_DUPLEX_MONO 0x0008 /* Has mono duplex only */
151 #define ES18XX_DUPLEX_SAME 0x0010 /* Playback and record must share the same rate */
152 #define ES18XX_NEW_RATE 0x0020 /* More precise rate setting */
153 #define ES18XX_AUXB 0x0040 /* AuxB mixer control */
154 #define ES18XX_HWV 0x0080 /* Has separate hardware volume mixer controls*/
155 #define ES18XX_MONO 0x0100 /* Mono_in mixer control */
156 #define ES18XX_I2S 0x0200 /* I2S mixer control */
157 #define ES18XX_MUTEREC 0x0400 /* Record source can be muted */
158 #define ES18XX_CONTROL 0x0800 /* Has control ports */
160 /* Power Management */
161 #define ES18XX_PM 0x07
162 #define ES18XX_PM_GPO0 0x01
163 #define ES18XX_PM_GPO1 0x02
164 #define ES18XX_PM_PDR 0x04
165 #define ES18XX_PM_ANA 0x08
166 #define ES18XX_PM_FM 0x020
167 #define ES18XX_PM_SUS 0x080
174 #define MILLISECOND 10000
176 static int snd_es18xx_dsp_command(struct snd_es18xx
*chip
, unsigned char val
)
180 for(i
= MILLISECOND
; i
; i
--)
181 if ((inb(chip
->port
+ 0x0C) & 0x80) == 0) {
182 outb(val
, chip
->port
+ 0x0C);
185 snd_printk(KERN_ERR
"dsp_command: timeout (0x%x)\n", val
);
189 static int snd_es18xx_dsp_get_byte(struct snd_es18xx
*chip
)
193 for(i
= MILLISECOND
/10; i
; i
--)
194 if (inb(chip
->port
+ 0x0C) & 0x40)
195 return inb(chip
->port
+ 0x0A);
196 snd_printk(KERN_ERR
"dsp_get_byte failed: 0x%lx = 0x%x!!!\n",
197 chip
->port
+ 0x0A, inb(chip
->port
+ 0x0A));
203 static int snd_es18xx_write(struct snd_es18xx
*chip
,
204 unsigned char reg
, unsigned char data
)
209 spin_lock_irqsave(&chip
->reg_lock
, flags
);
210 ret
= snd_es18xx_dsp_command(chip
, reg
);
213 ret
= snd_es18xx_dsp_command(chip
, data
);
215 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
217 snd_printk(KERN_DEBUG
"Reg %02x set to %02x\n", reg
, data
);
222 static int snd_es18xx_read(struct snd_es18xx
*chip
, unsigned char reg
)
226 spin_lock_irqsave(&chip
->reg_lock
, flags
);
227 ret
= snd_es18xx_dsp_command(chip
, 0xC0);
230 ret
= snd_es18xx_dsp_command(chip
, reg
);
233 data
= snd_es18xx_dsp_get_byte(chip
);
236 snd_printk(KERN_DEBUG
"Reg %02x now is %02x (%d)\n", reg
, data
, ret
);
239 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
243 /* Return old value */
244 static int snd_es18xx_bits(struct snd_es18xx
*chip
, unsigned char reg
,
245 unsigned char mask
, unsigned char val
)
248 unsigned char old
, new, oval
;
250 spin_lock_irqsave(&chip
->reg_lock
, flags
);
251 ret
= snd_es18xx_dsp_command(chip
, 0xC0);
254 ret
= snd_es18xx_dsp_command(chip
, reg
);
257 ret
= snd_es18xx_dsp_get_byte(chip
);
264 ret
= snd_es18xx_dsp_command(chip
, reg
);
267 new = (old
& ~mask
) | (val
& mask
);
268 ret
= snd_es18xx_dsp_command(chip
, new);
272 snd_printk(KERN_DEBUG
"Reg %02x was %02x, set to %02x (%d)\n",
278 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
282 static inline void snd_es18xx_mixer_write(struct snd_es18xx
*chip
,
283 unsigned char reg
, unsigned char data
)
286 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
287 outb(reg
, chip
->port
+ 0x04);
288 outb(data
, chip
->port
+ 0x05);
289 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
291 snd_printk(KERN_DEBUG
"Mixer reg %02x set to %02x\n", reg
, data
);
295 static inline int snd_es18xx_mixer_read(struct snd_es18xx
*chip
, unsigned char reg
)
299 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
300 outb(reg
, chip
->port
+ 0x04);
301 data
= inb(chip
->port
+ 0x05);
302 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
304 snd_printk(KERN_DEBUG
"Mixer reg %02x now is %02x\n", reg
, data
);
309 /* Return old value */
310 static inline int snd_es18xx_mixer_bits(struct snd_es18xx
*chip
, unsigned char reg
,
311 unsigned char mask
, unsigned char val
)
313 unsigned char old
, new, oval
;
315 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
316 outb(reg
, chip
->port
+ 0x04);
317 old
= inb(chip
->port
+ 0x05);
320 new = (old
& ~mask
) | (val
& mask
);
321 outb(new, chip
->port
+ 0x05);
323 snd_printk(KERN_DEBUG
"Mixer reg %02x was %02x, set to %02x\n",
327 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
331 static inline int snd_es18xx_mixer_writable(struct snd_es18xx
*chip
, unsigned char reg
,
334 int old
, expected
, new;
336 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
337 outb(reg
, chip
->port
+ 0x04);
338 old
= inb(chip
->port
+ 0x05);
339 expected
= old
^ mask
;
340 outb(expected
, chip
->port
+ 0x05);
341 new = inb(chip
->port
+ 0x05);
342 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
344 snd_printk(KERN_DEBUG
"Mixer reg %02x was %02x, set to %02x, now is %02x\n",
345 reg
, old
, expected
, new);
347 return expected
== new;
351 static int snd_es18xx_reset(struct snd_es18xx
*chip
)
354 outb(0x03, chip
->port
+ 0x06);
355 inb(chip
->port
+ 0x06);
356 outb(0x00, chip
->port
+ 0x06);
357 for(i
= 0; i
< MILLISECOND
&& !(inb(chip
->port
+ 0x0E) & 0x80); i
++);
358 if (inb(chip
->port
+ 0x0A) != 0xAA)
363 static int snd_es18xx_reset_fifo(struct snd_es18xx
*chip
)
365 outb(0x02, chip
->port
+ 0x06);
366 inb(chip
->port
+ 0x06);
367 outb(0x00, chip
->port
+ 0x06);
371 static struct snd_ratnum new_clocks
[2] = {
386 static struct snd_pcm_hw_constraint_ratnums new_hw_constraints_clocks
= {
391 static struct snd_ratnum old_clocks
[2] = {
406 static struct snd_pcm_hw_constraint_ratnums old_hw_constraints_clocks
= {
412 static void snd_es18xx_rate_set(struct snd_es18xx
*chip
,
413 struct snd_pcm_substream
*substream
,
416 unsigned int bits
, div0
;
417 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
418 if (chip
->caps
& ES18XX_NEW_RATE
) {
419 if (runtime
->rate_num
== new_clocks
[0].num
)
420 bits
= 128 - runtime
->rate_den
;
422 bits
= 256 - runtime
->rate_den
;
424 if (runtime
->rate_num
== old_clocks
[0].num
)
425 bits
= 256 - runtime
->rate_den
;
427 bits
= 128 - runtime
->rate_den
;
430 /* set filter register */
431 div0
= 256 - 7160000*20/(8*82*runtime
->rate
);
433 if ((chip
->caps
& ES18XX_PCM2
) && mode
== DAC2
) {
434 snd_es18xx_mixer_write(chip
, 0x70, bits
);
436 * Comment from kernel oss driver:
437 * FKS: fascinating: 0x72 doesn't seem to work.
439 snd_es18xx_write(chip
, 0xA2, div0
);
440 snd_es18xx_mixer_write(chip
, 0x72, div0
);
442 snd_es18xx_write(chip
, 0xA1, bits
);
443 snd_es18xx_write(chip
, 0xA2, div0
);
447 static int snd_es18xx_playback_hw_params(struct snd_pcm_substream
*substream
,
448 struct snd_pcm_hw_params
*hw_params
)
450 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
454 if (params_channels(hw_params
) == 2)
456 if (snd_pcm_format_width(params_format(hw_params
)) == 16)
459 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
460 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
461 (chip
->capture_a_substream
) &&
462 params_channels(hw_params
) != 1) {
463 _snd_pcm_hw_param_setempty(hw_params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
466 chip
->dma2_shift
= shift
;
468 chip
->dma1_shift
= shift
;
470 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
475 static int snd_es18xx_pcm_hw_free(struct snd_pcm_substream
*substream
)
477 return snd_pcm_lib_free_pages(substream
);
480 static int snd_es18xx_playback1_prepare(struct snd_es18xx
*chip
,
481 struct snd_pcm_substream
*substream
)
483 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
484 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
485 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
487 snd_es18xx_rate_set(chip
, substream
, DAC2
);
489 /* Transfer Count Reload */
490 count
= 0x10000 - count
;
491 snd_es18xx_mixer_write(chip
, 0x74, count
& 0xff);
492 snd_es18xx_mixer_write(chip
, 0x76, count
>> 8);
495 snd_es18xx_mixer_bits(chip
, 0x7A, 0x07,
496 ((runtime
->channels
== 1) ? 0x00 : 0x02) |
497 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x01 : 0x00) |
498 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x04));
500 /* Set DMA controller */
501 snd_dma_program(chip
->dma2
, runtime
->dma_addr
, size
, DMA_MODE_WRITE
| DMA_AUTOINIT
);
506 static int snd_es18xx_playback1_trigger(struct snd_es18xx
*chip
,
507 struct snd_pcm_substream
*substream
,
511 case SNDRV_PCM_TRIGGER_START
:
512 case SNDRV_PCM_TRIGGER_RESUME
:
513 if (chip
->active
& DAC2
)
515 chip
->active
|= DAC2
;
518 snd_es18xx_mixer_write(chip
, 0x78, 0xb3);
520 snd_es18xx_mixer_write(chip
, 0x78, 0x93);
524 if (chip
->caps
& ES18XX_PCM2
)
525 /* Restore Audio 2 volume */
526 snd_es18xx_mixer_write(chip
, 0x7C, chip
->audio2_vol
);
528 /* Enable PCM output */
529 snd_es18xx_dsp_command(chip
, 0xD1);
532 case SNDRV_PCM_TRIGGER_STOP
:
533 case SNDRV_PCM_TRIGGER_SUSPEND
:
534 if (!(chip
->active
& DAC2
))
536 chip
->active
&= ~DAC2
;
538 snd_es18xx_mixer_write(chip
, 0x78, 0x00);
541 if (chip
->caps
& ES18XX_PCM2
)
542 /* Set Audio 2 volume to 0 */
543 snd_es18xx_mixer_write(chip
, 0x7C, 0);
545 /* Disable PCM output */
546 snd_es18xx_dsp_command(chip
, 0xD3);
556 static int snd_es18xx_capture_hw_params(struct snd_pcm_substream
*substream
,
557 struct snd_pcm_hw_params
*hw_params
)
559 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
563 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
564 chip
->playback_a_substream
&&
565 params_channels(hw_params
) != 1) {
566 _snd_pcm_hw_param_setempty(hw_params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
569 if (params_channels(hw_params
) == 2)
571 if (snd_pcm_format_width(params_format(hw_params
)) == 16)
573 chip
->dma1_shift
= shift
;
574 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
579 static int snd_es18xx_capture_prepare(struct snd_pcm_substream
*substream
)
581 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
582 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
583 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
584 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
586 snd_es18xx_reset_fifo(chip
);
588 /* Set stereo/mono */
589 snd_es18xx_bits(chip
, 0xA8, 0x03, runtime
->channels
== 1 ? 0x02 : 0x01);
591 snd_es18xx_rate_set(chip
, substream
, ADC1
);
593 /* Transfer Count Reload */
594 count
= 0x10000 - count
;
595 snd_es18xx_write(chip
, 0xA4, count
& 0xff);
596 snd_es18xx_write(chip
, 0xA5, count
>> 8);
603 snd_es18xx_write(chip
, 0xB7,
604 snd_pcm_format_unsigned(runtime
->format
) ? 0x51 : 0x71);
605 snd_es18xx_write(chip
, 0xB7, 0x90 |
606 ((runtime
->channels
== 1) ? 0x40 : 0x08) |
607 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x04 : 0x00) |
608 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x20));
610 /* Set DMA controller */
611 snd_dma_program(chip
->dma1
, runtime
->dma_addr
, size
, DMA_MODE_READ
| DMA_AUTOINIT
);
616 static int snd_es18xx_capture_trigger(struct snd_pcm_substream
*substream
,
619 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
622 case SNDRV_PCM_TRIGGER_START
:
623 case SNDRV_PCM_TRIGGER_RESUME
:
624 if (chip
->active
& ADC1
)
626 chip
->active
|= ADC1
;
628 snd_es18xx_write(chip
, 0xB8, 0x0f);
630 case SNDRV_PCM_TRIGGER_STOP
:
631 case SNDRV_PCM_TRIGGER_SUSPEND
:
632 if (!(chip
->active
& ADC1
))
634 chip
->active
&= ~ADC1
;
636 snd_es18xx_write(chip
, 0xB8, 0x00);
645 static int snd_es18xx_playback2_prepare(struct snd_es18xx
*chip
,
646 struct snd_pcm_substream
*substream
)
648 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
649 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
650 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
652 snd_es18xx_reset_fifo(chip
);
654 /* Set stereo/mono */
655 snd_es18xx_bits(chip
, 0xA8, 0x03, runtime
->channels
== 1 ? 0x02 : 0x01);
657 snd_es18xx_rate_set(chip
, substream
, DAC1
);
659 /* Transfer Count Reload */
660 count
= 0x10000 - count
;
661 snd_es18xx_write(chip
, 0xA4, count
& 0xff);
662 snd_es18xx_write(chip
, 0xA5, count
>> 8);
665 snd_es18xx_write(chip
, 0xB6,
666 snd_pcm_format_unsigned(runtime
->format
) ? 0x80 : 0x00);
667 snd_es18xx_write(chip
, 0xB7,
668 snd_pcm_format_unsigned(runtime
->format
) ? 0x51 : 0x71);
669 snd_es18xx_write(chip
, 0xB7, 0x90 |
670 (runtime
->channels
== 1 ? 0x40 : 0x08) |
671 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x04 : 0x00) |
672 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x20));
674 /* Set DMA controller */
675 snd_dma_program(chip
->dma1
, runtime
->dma_addr
, size
, DMA_MODE_WRITE
| DMA_AUTOINIT
);
680 static int snd_es18xx_playback2_trigger(struct snd_es18xx
*chip
,
681 struct snd_pcm_substream
*substream
,
685 case SNDRV_PCM_TRIGGER_START
:
686 case SNDRV_PCM_TRIGGER_RESUME
:
687 if (chip
->active
& DAC1
)
689 chip
->active
|= DAC1
;
691 snd_es18xx_write(chip
, 0xB8, 0x05);
696 snd_es18xx_dsp_command(chip
, 0xD1);
699 case SNDRV_PCM_TRIGGER_STOP
:
700 case SNDRV_PCM_TRIGGER_SUSPEND
:
701 if (!(chip
->active
& DAC1
))
703 chip
->active
&= ~DAC1
;
705 snd_es18xx_write(chip
, 0xB8, 0x00);
709 /* Disable Audio 1 */
710 snd_es18xx_dsp_command(chip
, 0xD3);
720 static int snd_es18xx_playback_prepare(struct snd_pcm_substream
*substream
)
722 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
723 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
724 return snd_es18xx_playback1_prepare(chip
, substream
);
726 return snd_es18xx_playback2_prepare(chip
, substream
);
729 static int snd_es18xx_playback_trigger(struct snd_pcm_substream
*substream
,
732 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
733 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
734 return snd_es18xx_playback1_trigger(chip
, substream
, cmd
);
736 return snd_es18xx_playback2_trigger(chip
, substream
, cmd
);
739 static irqreturn_t
snd_es18xx_interrupt(int irq
, void *dev_id
)
741 struct snd_card
*card
= dev_id
;
742 struct snd_es18xx
*chip
= card
->private_data
;
743 unsigned char status
;
745 if (chip
->caps
& ES18XX_CONTROL
) {
746 /* Read Interrupt status */
747 status
= inb(chip
->ctrl_port
+ 6);
749 /* Read Interrupt status */
750 status
= snd_es18xx_mixer_read(chip
, 0x7f) >> 4;
755 if (inb(chip
->port
+ 0x0C) & 0x01)
756 status
|= AUDIO1_IRQ
;
757 if (snd_es18xx_mixer_read(chip
, 0x7A) & 0x80)
758 status
|= AUDIO2_IRQ
;
759 if ((chip
->caps
& ES18XX_HWV
) &&
760 snd_es18xx_mixer_read(chip
, 0x64) & 0x10)
765 /* Audio 1 & Audio 2 */
766 if (status
& AUDIO2_IRQ
) {
767 if (chip
->active
& DAC2
)
768 snd_pcm_period_elapsed(chip
->playback_a_substream
);
770 snd_es18xx_mixer_bits(chip
, 0x7A, 0x80, 0x00);
772 if (status
& AUDIO1_IRQ
) {
773 /* ok.. capture is active */
774 if (chip
->active
& ADC1
)
775 snd_pcm_period_elapsed(chip
->capture_a_substream
);
776 /* ok.. playback2 is active */
777 else if (chip
->active
& DAC1
)
778 snd_pcm_period_elapsed(chip
->playback_b_substream
);
780 inb(chip
->port
+ 0x0E);
784 if ((status
& MPU_IRQ
) && chip
->rmidi
)
785 snd_mpu401_uart_interrupt(irq
, chip
->rmidi
->private_data
);
787 /* Hardware volume */
788 if (status
& HWV_IRQ
) {
790 if (chip
->caps
& ES18XX_HWV
) {
791 split
= snd_es18xx_mixer_read(chip
, 0x64) & 0x80;
792 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
,
793 &chip
->hw_switch
->id
);
794 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
,
795 &chip
->hw_volume
->id
);
798 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
,
799 &chip
->master_switch
->id
);
800 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
,
801 &chip
->master_volume
->id
);
804 snd_es18xx_mixer_write(chip
, 0x66, 0x00);
809 static snd_pcm_uframes_t
snd_es18xx_playback_pointer(struct snd_pcm_substream
*substream
)
811 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
812 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
815 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
816 if (!(chip
->active
& DAC2
))
818 pos
= snd_dma_pointer(chip
->dma2
, size
);
819 return pos
>> chip
->dma2_shift
;
821 if (!(chip
->active
& DAC1
))
823 pos
= snd_dma_pointer(chip
->dma1
, size
);
824 return pos
>> chip
->dma1_shift
;
828 static snd_pcm_uframes_t
snd_es18xx_capture_pointer(struct snd_pcm_substream
*substream
)
830 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
831 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
834 if (!(chip
->active
& ADC1
))
836 pos
= snd_dma_pointer(chip
->dma1
, size
);
837 return pos
>> chip
->dma1_shift
;
840 static struct snd_pcm_hardware snd_es18xx_playback
=
842 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
843 SNDRV_PCM_INFO_RESUME
|
844 SNDRV_PCM_INFO_MMAP_VALID
),
845 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S8
|
846 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_U16_LE
),
847 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
852 .buffer_bytes_max
= 65536,
853 .period_bytes_min
= 64,
854 .period_bytes_max
= 65536,
860 static struct snd_pcm_hardware snd_es18xx_capture
=
862 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
863 SNDRV_PCM_INFO_RESUME
|
864 SNDRV_PCM_INFO_MMAP_VALID
),
865 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S8
|
866 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_U16_LE
),
867 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
872 .buffer_bytes_max
= 65536,
873 .period_bytes_min
= 64,
874 .period_bytes_max
= 65536,
880 static int snd_es18xx_playback_open(struct snd_pcm_substream
*substream
)
882 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
883 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
885 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
886 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
887 chip
->capture_a_substream
&&
888 chip
->capture_a_substream
->runtime
->channels
!= 1)
890 chip
->playback_a_substream
= substream
;
891 } else if (substream
->number
<= 1) {
892 if (chip
->capture_a_substream
)
894 chip
->playback_b_substream
= substream
;
899 substream
->runtime
->hw
= snd_es18xx_playback
;
900 snd_pcm_hw_constraint_ratnums(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
901 (chip
->caps
& ES18XX_NEW_RATE
) ? &new_hw_constraints_clocks
: &old_hw_constraints_clocks
);
905 static int snd_es18xx_capture_open(struct snd_pcm_substream
*substream
)
907 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
908 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
910 if (chip
->playback_b_substream
)
912 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
913 chip
->playback_a_substream
&&
914 chip
->playback_a_substream
->runtime
->channels
!= 1)
916 chip
->capture_a_substream
= substream
;
917 substream
->runtime
->hw
= snd_es18xx_capture
;
918 snd_pcm_hw_constraint_ratnums(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
919 (chip
->caps
& ES18XX_NEW_RATE
) ? &new_hw_constraints_clocks
: &old_hw_constraints_clocks
);
923 static int snd_es18xx_playback_close(struct snd_pcm_substream
*substream
)
925 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
927 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
928 chip
->playback_a_substream
= NULL
;
930 chip
->playback_b_substream
= NULL
;
932 snd_pcm_lib_free_pages(substream
);
936 static int snd_es18xx_capture_close(struct snd_pcm_substream
*substream
)
938 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
940 chip
->capture_a_substream
= NULL
;
941 snd_pcm_lib_free_pages(substream
);
949 /* Record source mux routines:
950 * Depending on the chipset this mux switches between 4, 5, or 8 possible inputs.
951 * bit table for the 4/5 source mux:
958 * if it's "mixer" and it's a 5 source mux chipset then reg 7A bit 3 determines
959 * either the play mixer or the capture mixer.
961 * "map4Source" translates from source number to reg bit pattern
962 * "invMap4Source" translates from reg bit pattern to source number
965 static int snd_es18xx_info_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
967 static char *texts5Source
[5] = {
968 "Mic", "CD", "Line", "Master", "Mix"
970 static char *texts8Source
[8] = {
971 "Mic", "Mic Master", "CD", "AOUT",
972 "Mic1", "Mix", "Line", "Master"
974 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
976 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
978 switch (chip
->version
) {
981 uinfo
->value
.enumerated
.items
= 4;
982 if (uinfo
->value
.enumerated
.item
> 3)
983 uinfo
->value
.enumerated
.item
= 3;
984 strcpy(uinfo
->value
.enumerated
.name
,
985 texts5Source
[uinfo
->value
.enumerated
.item
]);
989 uinfo
->value
.enumerated
.items
= 5;
990 if (uinfo
->value
.enumerated
.item
> 4)
991 uinfo
->value
.enumerated
.item
= 4;
992 strcpy(uinfo
->value
.enumerated
.name
, texts5Source
[uinfo
->value
.enumerated
.item
]);
994 case 0x1869: /* DS somewhat contradictory for 1869: could be be 5 or 8 */
996 uinfo
->value
.enumerated
.items
= 8;
997 if (uinfo
->value
.enumerated
.item
> 7)
998 uinfo
->value
.enumerated
.item
= 7;
999 strcpy(uinfo
->value
.enumerated
.name
, texts8Source
[uinfo
->value
.enumerated
.item
]);
1007 static int snd_es18xx_get_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1009 static unsigned char invMap4Source
[8] = {0, 0, 1, 1, 0, 0, 2, 3};
1010 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1011 int muxSource
= snd_es18xx_mixer_read(chip
, 0x1c) & 0x07;
1012 if (!(chip
->version
== 0x1869 || chip
->version
== 0x1879)) {
1013 muxSource
= invMap4Source
[muxSource
];
1015 (chip
->version
== 0x1887 || chip
->version
== 0x1888) &&
1016 (snd_es18xx_mixer_read(chip
, 0x7a) & 0x08)
1020 ucontrol
->value
.enumerated
.item
[0] = muxSource
;
1024 static int snd_es18xx_put_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1026 static unsigned char map4Source
[4] = {0, 2, 6, 7};
1027 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1028 unsigned char val
= ucontrol
->value
.enumerated
.item
[0];
1029 unsigned char retVal
= 0;
1031 switch (chip
->version
) {
1032 /* 5 source chips */
1038 retVal
= snd_es18xx_mixer_bits(chip
, 0x7a, 0x08, 0x08) != 0x08;
1041 retVal
= snd_es18xx_mixer_bits(chip
, 0x7a, 0x08, 0x00) != 0x00;
1042 /* 4 source chips */
1047 val
= map4Source
[val
];
1049 /* 8 source chips */
1058 return (snd_es18xx_mixer_bits(chip
, 0x1c, 0x07, val
) != val
) || retVal
;
1061 #define snd_es18xx_info_spatializer_enable snd_ctl_boolean_mono_info
1063 static int snd_es18xx_get_spatializer_enable(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1065 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1066 unsigned char val
= snd_es18xx_mixer_read(chip
, 0x50);
1067 ucontrol
->value
.integer
.value
[0] = !!(val
& 8);
1071 static int snd_es18xx_put_spatializer_enable(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1073 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1074 unsigned char oval
, nval
;
1076 nval
= ucontrol
->value
.integer
.value
[0] ? 0x0c : 0x04;
1077 oval
= snd_es18xx_mixer_read(chip
, 0x50) & 0x0c;
1078 change
= nval
!= oval
;
1080 snd_es18xx_mixer_write(chip
, 0x50, nval
& ~0x04);
1081 snd_es18xx_mixer_write(chip
, 0x50, nval
);
1086 static int snd_es18xx_info_hw_volume(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1088 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1090 uinfo
->value
.integer
.min
= 0;
1091 uinfo
->value
.integer
.max
= 63;
1095 static int snd_es18xx_get_hw_volume(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1097 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1098 ucontrol
->value
.integer
.value
[0] = snd_es18xx_mixer_read(chip
, 0x61) & 0x3f;
1099 ucontrol
->value
.integer
.value
[1] = snd_es18xx_mixer_read(chip
, 0x63) & 0x3f;
1103 #define snd_es18xx_info_hw_switch snd_ctl_boolean_stereo_info
1105 static int snd_es18xx_get_hw_switch(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1107 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1108 ucontrol
->value
.integer
.value
[0] = !(snd_es18xx_mixer_read(chip
, 0x61) & 0x40);
1109 ucontrol
->value
.integer
.value
[1] = !(snd_es18xx_mixer_read(chip
, 0x63) & 0x40);
1113 static void snd_es18xx_hwv_free(struct snd_kcontrol
*kcontrol
)
1115 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1116 chip
->master_volume
= NULL
;
1117 chip
->master_switch
= NULL
;
1118 chip
->hw_volume
= NULL
;
1119 chip
->hw_switch
= NULL
;
1122 static int snd_es18xx_reg_bits(struct snd_es18xx
*chip
, unsigned char reg
,
1123 unsigned char mask
, unsigned char val
)
1126 return snd_es18xx_mixer_bits(chip
, reg
, mask
, val
);
1128 return snd_es18xx_bits(chip
, reg
, mask
, val
);
1131 static int snd_es18xx_reg_read(struct snd_es18xx
*chip
, unsigned char reg
)
1134 return snd_es18xx_mixer_read(chip
, reg
);
1136 return snd_es18xx_read(chip
, reg
);
1139 #define ES18XX_SINGLE(xname, xindex, reg, shift, mask, invert) \
1140 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1141 .info = snd_es18xx_info_single, \
1142 .get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \
1143 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
1145 static int snd_es18xx_info_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1147 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1149 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1151 uinfo
->value
.integer
.min
= 0;
1152 uinfo
->value
.integer
.max
= mask
;
1156 static int snd_es18xx_get_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1158 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1159 int reg
= kcontrol
->private_value
& 0xff;
1160 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1161 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1162 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1165 val
= snd_es18xx_reg_read(chip
, reg
);
1166 ucontrol
->value
.integer
.value
[0] = (val
>> shift
) & mask
;
1168 ucontrol
->value
.integer
.value
[0] = mask
- ucontrol
->value
.integer
.value
[0];
1172 static int snd_es18xx_put_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1174 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1175 int reg
= kcontrol
->private_value
& 0xff;
1176 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1177 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1178 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1181 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1186 return snd_es18xx_reg_bits(chip
, reg
, mask
, val
) != val
;
1189 #define ES18XX_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
1190 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1191 .info = snd_es18xx_info_double, \
1192 .get = snd_es18xx_get_double, .put = snd_es18xx_put_double, \
1193 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
1195 static int snd_es18xx_info_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1197 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1199 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1201 uinfo
->value
.integer
.min
= 0;
1202 uinfo
->value
.integer
.max
= mask
;
1206 static int snd_es18xx_get_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1208 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1209 int left_reg
= kcontrol
->private_value
& 0xff;
1210 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
1211 int shift_left
= (kcontrol
->private_value
>> 16) & 0x07;
1212 int shift_right
= (kcontrol
->private_value
>> 19) & 0x07;
1213 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1214 int invert
= (kcontrol
->private_value
>> 22) & 1;
1215 unsigned char left
, right
;
1217 left
= snd_es18xx_reg_read(chip
, left_reg
);
1218 if (left_reg
!= right_reg
)
1219 right
= snd_es18xx_reg_read(chip
, right_reg
);
1222 ucontrol
->value
.integer
.value
[0] = (left
>> shift_left
) & mask
;
1223 ucontrol
->value
.integer
.value
[1] = (right
>> shift_right
) & mask
;
1225 ucontrol
->value
.integer
.value
[0] = mask
- ucontrol
->value
.integer
.value
[0];
1226 ucontrol
->value
.integer
.value
[1] = mask
- ucontrol
->value
.integer
.value
[1];
1231 static int snd_es18xx_put_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1233 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1234 int left_reg
= kcontrol
->private_value
& 0xff;
1235 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
1236 int shift_left
= (kcontrol
->private_value
>> 16) & 0x07;
1237 int shift_right
= (kcontrol
->private_value
>> 19) & 0x07;
1238 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1239 int invert
= (kcontrol
->private_value
>> 22) & 1;
1241 unsigned char val1
, val2
, mask1
, mask2
;
1243 val1
= ucontrol
->value
.integer
.value
[0] & mask
;
1244 val2
= ucontrol
->value
.integer
.value
[1] & mask
;
1249 val1
<<= shift_left
;
1250 val2
<<= shift_right
;
1251 mask1
= mask
<< shift_left
;
1252 mask2
= mask
<< shift_right
;
1253 if (left_reg
!= right_reg
) {
1255 if (snd_es18xx_reg_bits(chip
, left_reg
, mask1
, val1
) != val1
)
1257 if (snd_es18xx_reg_bits(chip
, right_reg
, mask2
, val2
) != val2
)
1260 change
= (snd_es18xx_reg_bits(chip
, left_reg
, mask1
| mask2
,
1261 val1
| val2
) != (val1
| val2
));
1267 * These arrays contain setup data for mixer controls.
1269 * The controls that are universal to all chipsets are fully initialized
1272 static struct snd_kcontrol_new snd_es18xx_base_controls
[] = {
1273 ES18XX_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0),
1274 ES18XX_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1),
1275 ES18XX_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0),
1276 ES18XX_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0),
1277 ES18XX_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0),
1278 ES18XX_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0),
1279 ES18XX_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0),
1280 ES18XX_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
1281 ES18XX_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0),
1283 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1284 .name
= "Capture Source",
1285 .info
= snd_es18xx_info_mux
,
1286 .get
= snd_es18xx_get_mux
,
1287 .put
= snd_es18xx_put_mux
,
1291 static struct snd_kcontrol_new snd_es18xx_recmix_controls
[] = {
1292 ES18XX_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0),
1293 ES18XX_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0),
1294 ES18XX_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0),
1295 ES18XX_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0),
1296 ES18XX_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0),
1297 ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0)
1301 * The chipset specific mixer controls
1303 static struct snd_kcontrol_new snd_es18xx_opt_speaker
=
1304 ES18XX_SINGLE("Beep Playback Volume", 0, 0x3c, 0, 7, 0);
1306 static struct snd_kcontrol_new snd_es18xx_opt_1869
[] = {
1307 ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
1308 ES18XX_SINGLE("Video Playback Switch", 0, 0x7f, 0, 1, 0),
1309 ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1310 ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0)
1313 static struct snd_kcontrol_new snd_es18xx_opt_1878
=
1314 ES18XX_DOUBLE("Video Playback Volume", 0, 0x68, 0x68, 4, 0, 15, 0);
1316 static struct snd_kcontrol_new snd_es18xx_opt_1879
[] = {
1317 ES18XX_SINGLE("Video Playback Switch", 0, 0x71, 6, 1, 0),
1318 ES18XX_DOUBLE("Video Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1319 ES18XX_DOUBLE("Video Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0)
1322 static struct snd_kcontrol_new snd_es18xx_pcm1_controls
[] = {
1323 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x14, 0x14, 4, 0, 15, 0),
1326 static struct snd_kcontrol_new snd_es18xx_pcm2_controls
[] = {
1327 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0),
1328 ES18XX_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0)
1331 static struct snd_kcontrol_new snd_es18xx_spatializer_controls
[] = {
1332 ES18XX_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
1334 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1335 .name
= "3D Control - Switch",
1336 .info
= snd_es18xx_info_spatializer_enable
,
1337 .get
= snd_es18xx_get_spatializer_enable
,
1338 .put
= snd_es18xx_put_spatializer_enable
,
1342 static struct snd_kcontrol_new snd_es18xx_micpre1_control
=
1343 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0xa9, 2, 1, 0);
1345 static struct snd_kcontrol_new snd_es18xx_micpre2_control
=
1346 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0);
1348 static struct snd_kcontrol_new snd_es18xx_hw_volume_controls
[] = {
1350 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1351 .name
= "Hardware Master Playback Volume",
1352 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1353 .info
= snd_es18xx_info_hw_volume
,
1354 .get
= snd_es18xx_get_hw_volume
,
1357 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1358 .name
= "Hardware Master Playback Switch",
1359 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1360 .info
= snd_es18xx_info_hw_switch
,
1361 .get
= snd_es18xx_get_hw_switch
,
1363 ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0),
1366 static int snd_es18xx_config_read(struct snd_es18xx
*chip
, unsigned char reg
)
1370 outb(reg
, chip
->ctrl_port
);
1371 data
= inb(chip
->ctrl_port
+ 1);
1375 static void snd_es18xx_config_write(struct snd_es18xx
*chip
,
1376 unsigned char reg
, unsigned char data
)
1378 /* No need for spinlocks, this function is used only in
1379 otherwise protected init code */
1380 outb(reg
, chip
->ctrl_port
);
1381 outb(data
, chip
->ctrl_port
+ 1);
1383 snd_printk(KERN_DEBUG
"Config reg %02x set to %02x\n", reg
, data
);
1387 static int snd_es18xx_initialize(struct snd_es18xx
*chip
,
1388 unsigned long mpu_port
,
1389 unsigned long fm_port
)
1393 /* enable extended mode */
1394 snd_es18xx_dsp_command(chip
, 0xC6);
1395 /* Reset mixer registers */
1396 snd_es18xx_mixer_write(chip
, 0x00, 0x00);
1398 /* Audio 1 DMA demand mode (4 bytes/request) */
1399 snd_es18xx_write(chip
, 0xB9, 2);
1400 if (chip
->caps
& ES18XX_CONTROL
) {
1401 /* Hardware volume IRQ */
1402 snd_es18xx_config_write(chip
, 0x27, chip
->irq
);
1403 if (fm_port
> 0 && fm_port
!= SNDRV_AUTO_PORT
) {
1405 snd_es18xx_config_write(chip
, 0x62, fm_port
>> 8);
1406 snd_es18xx_config_write(chip
, 0x63, fm_port
& 0xff);
1408 if (mpu_port
> 0 && mpu_port
!= SNDRV_AUTO_PORT
) {
1410 snd_es18xx_config_write(chip
, 0x64, mpu_port
>> 8);
1411 snd_es18xx_config_write(chip
, 0x65, mpu_port
& 0xff);
1413 snd_es18xx_config_write(chip
, 0x28, chip
->irq
);
1416 snd_es18xx_config_write(chip
, 0x70, chip
->irq
);
1418 snd_es18xx_config_write(chip
, 0x72, chip
->irq
);
1420 snd_es18xx_config_write(chip
, 0x74, chip
->dma1
);
1422 snd_es18xx_config_write(chip
, 0x75, chip
->dma2
);
1424 /* Enable Audio 1 IRQ */
1425 snd_es18xx_write(chip
, 0xB1, 0x50);
1426 /* Enable Audio 2 IRQ */
1427 snd_es18xx_mixer_write(chip
, 0x7A, 0x40);
1428 /* Enable Audio 1 DMA */
1429 snd_es18xx_write(chip
, 0xB2, 0x50);
1430 /* Enable MPU and hardware volume interrupt */
1431 snd_es18xx_mixer_write(chip
, 0x64, 0x42);
1432 /* Enable ESS wavetable input */
1433 snd_es18xx_mixer_bits(chip
, 0x48, 0x10, 0x10);
1436 int irqmask
, dma1mask
, dma2mask
;
1437 switch (chip
->irq
) {
1452 snd_printk(KERN_ERR
"invalid irq %d\n", chip
->irq
);
1455 switch (chip
->dma1
) {
1466 snd_printk(KERN_ERR
"invalid dma1 %d\n", chip
->dma1
);
1469 switch (chip
->dma2
) {
1483 snd_printk(KERN_ERR
"invalid dma2 %d\n", chip
->dma2
);
1487 /* Enable and set Audio 1 IRQ */
1488 snd_es18xx_write(chip
, 0xB1, 0x50 | (irqmask
<< 2));
1489 /* Enable and set Audio 1 DMA */
1490 snd_es18xx_write(chip
, 0xB2, 0x50 | (dma1mask
<< 2));
1491 /* Set Audio 2 DMA */
1492 snd_es18xx_mixer_bits(chip
, 0x7d, 0x07, 0x04 | dma2mask
);
1493 /* Enable Audio 2 IRQ and DMA
1494 Set capture mixer input */
1495 snd_es18xx_mixer_write(chip
, 0x7A, 0x68);
1496 /* Enable and set hardware volume interrupt */
1497 snd_es18xx_mixer_write(chip
, 0x64, 0x06);
1498 if (mpu_port
> 0 && mpu_port
!= SNDRV_AUTO_PORT
) {
1499 /* MPU401 share irq with audio
1502 snd_es18xx_mixer_write(chip
, 0x40,
1503 0x43 | (mpu_port
& 0xf0) >> 1);
1505 snd_es18xx_mixer_write(chip
, 0x7f, ((irqmask
+ 1) << 1) | 0x01);
1507 if (chip
->caps
& ES18XX_NEW_RATE
) {
1508 /* Change behaviour of register A1
1510 2nd channel DAC asynchronous */
1511 snd_es18xx_mixer_write(chip
, 0x71, 0x32);
1513 if (!(chip
->caps
& ES18XX_PCM2
)) {
1514 /* Enable DMA FIFO */
1515 snd_es18xx_write(chip
, 0xB7, 0x80);
1517 if (chip
->caps
& ES18XX_SPATIALIZER
) {
1518 /* Set spatializer parameters to recommended values */
1519 snd_es18xx_mixer_write(chip
, 0x54, 0x8f);
1520 snd_es18xx_mixer_write(chip
, 0x56, 0x95);
1521 snd_es18xx_mixer_write(chip
, 0x58, 0x94);
1522 snd_es18xx_mixer_write(chip
, 0x5a, 0x80);
1524 /* Flip the "enable I2S" bits for those chipsets that need it */
1525 switch (chip
->version
) {
1527 //Leaving I2S enabled on the 1879 screws up the PCM playback (rate effected somehow)
1528 //so a Switch control has been added to toggle this 0x71 bit on/off:
1529 //snd_es18xx_mixer_bits(chip, 0x71, 0x40, 0x40);
1530 /* Note: we fall through on purpose here. */
1532 snd_es18xx_config_write(chip
, 0x29, snd_es18xx_config_read(chip
, 0x29) | 0x40);
1535 /* Mute input source */
1536 if (chip
->caps
& ES18XX_MUTEREC
)
1538 if (chip
->caps
& ES18XX_RECMIX
)
1539 snd_es18xx_mixer_write(chip
, 0x1c, 0x05 | mask
);
1541 snd_es18xx_mixer_write(chip
, 0x1c, 0x00 | mask
);
1542 snd_es18xx_write(chip
, 0xb4, 0x00);
1545 /* Enable PCM output */
1546 snd_es18xx_dsp_command(chip
, 0xD1);
1552 static int snd_es18xx_identify(struct snd_es18xx
*chip
)
1557 if (snd_es18xx_reset(chip
) < 0) {
1558 snd_printk(KERN_ERR
"reset at 0x%lx failed!!!\n", chip
->port
);
1562 snd_es18xx_dsp_command(chip
, 0xe7);
1563 hi
= snd_es18xx_dsp_get_byte(chip
);
1567 lo
= snd_es18xx_dsp_get_byte(chip
);
1568 if ((lo
& 0xf0) != 0x80) {
1572 chip
->version
= 0x488;
1578 if ((lo
& 0x0f) < 8) {
1579 chip
->version
= 0x688;
1583 outb(0x40, chip
->port
+ 0x04);
1585 hi
= inb(chip
->port
+ 0x05);
1587 lo
= inb(chip
->port
+ 0x05);
1589 chip
->version
= hi
<< 8 | lo
;
1590 chip
->ctrl_port
= inb(chip
->port
+ 0x05) << 8;
1592 chip
->ctrl_port
+= inb(chip
->port
+ 0x05);
1594 if ((chip
->res_ctrl_port
= request_region(chip
->ctrl_port
, 8, "ES18xx - CTRL")) == NULL
) {
1595 snd_printk(KERN_ERR PFX
"unable go grab port 0x%lx\n", chip
->ctrl_port
);
1602 /* If has Hardware volume */
1603 if (snd_es18xx_mixer_writable(chip
, 0x64, 0x04)) {
1605 if (snd_es18xx_mixer_writable(chip
, 0x70, 0x7f)) {
1606 /* If has volume count */
1607 if (snd_es18xx_mixer_writable(chip
, 0x64, 0x20)) {
1608 chip
->version
= 0x1887;
1610 chip
->version
= 0x1888;
1613 chip
->version
= 0x1788;
1617 chip
->version
= 0x1688;
1621 static int snd_es18xx_probe(struct snd_es18xx
*chip
,
1622 unsigned long mpu_port
,
1623 unsigned long fm_port
)
1625 if (snd_es18xx_identify(chip
) < 0) {
1626 snd_printk(KERN_ERR PFX
"[0x%lx] ESS chip not found\n", chip
->port
);
1630 switch (chip
->version
) {
1632 chip
->caps
= ES18XX_DUPLEX_MONO
| ES18XX_DUPLEX_SAME
| ES18XX_CONTROL
;
1635 chip
->caps
= ES18XX_PCM2
| ES18XX_SPATIALIZER
| ES18XX_RECMIX
| ES18XX_NEW_RATE
| ES18XX_AUXB
| ES18XX_MONO
| ES18XX_MUTEREC
| ES18XX_CONTROL
| ES18XX_HWV
;
1638 chip
->caps
= ES18XX_DUPLEX_MONO
| ES18XX_DUPLEX_SAME
| ES18XX_I2S
| ES18XX_CONTROL
;
1641 chip
->caps
= ES18XX_PCM2
| ES18XX_SPATIALIZER
| ES18XX_RECMIX
| ES18XX_NEW_RATE
| ES18XX_AUXB
| ES18XX_I2S
| ES18XX_CONTROL
| ES18XX_HWV
;
1645 chip
->caps
= ES18XX_PCM2
| ES18XX_RECMIX
| ES18XX_AUXB
| ES18XX_DUPLEX_SAME
;
1648 snd_printk(KERN_ERR
"[0x%lx] unsupported chip ES%x\n",
1649 chip
->port
, chip
->version
);
1653 snd_printd("[0x%lx] ESS%x chip found\n", chip
->port
, chip
->version
);
1655 if (chip
->dma1
== chip
->dma2
)
1656 chip
->caps
&= ~(ES18XX_PCM2
| ES18XX_DUPLEX_SAME
);
1658 return snd_es18xx_initialize(chip
, mpu_port
, fm_port
);
1661 static struct snd_pcm_ops snd_es18xx_playback_ops
= {
1662 .open
= snd_es18xx_playback_open
,
1663 .close
= snd_es18xx_playback_close
,
1664 .ioctl
= snd_pcm_lib_ioctl
,
1665 .hw_params
= snd_es18xx_playback_hw_params
,
1666 .hw_free
= snd_es18xx_pcm_hw_free
,
1667 .prepare
= snd_es18xx_playback_prepare
,
1668 .trigger
= snd_es18xx_playback_trigger
,
1669 .pointer
= snd_es18xx_playback_pointer
,
1672 static struct snd_pcm_ops snd_es18xx_capture_ops
= {
1673 .open
= snd_es18xx_capture_open
,
1674 .close
= snd_es18xx_capture_close
,
1675 .ioctl
= snd_pcm_lib_ioctl
,
1676 .hw_params
= snd_es18xx_capture_hw_params
,
1677 .hw_free
= snd_es18xx_pcm_hw_free
,
1678 .prepare
= snd_es18xx_capture_prepare
,
1679 .trigger
= snd_es18xx_capture_trigger
,
1680 .pointer
= snd_es18xx_capture_pointer
,
1683 static int snd_es18xx_pcm(struct snd_card
*card
, int device
,
1684 struct snd_pcm
**rpcm
)
1686 struct snd_es18xx
*chip
= card
->private_data
;
1687 struct snd_pcm
*pcm
;
1693 sprintf(str
, "ES%x", chip
->version
);
1694 if (chip
->caps
& ES18XX_PCM2
)
1695 err
= snd_pcm_new(card
, str
, device
, 2, 1, &pcm
);
1697 err
= snd_pcm_new(card
, str
, device
, 1, 1, &pcm
);
1701 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_es18xx_playback_ops
);
1702 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_es18xx_capture_ops
);
1705 pcm
->private_data
= chip
;
1706 pcm
->info_flags
= 0;
1707 if (chip
->caps
& ES18XX_DUPLEX_SAME
)
1708 pcm
->info_flags
|= SNDRV_PCM_INFO_JOINT_DUPLEX
;
1709 if (! (chip
->caps
& ES18XX_PCM2
))
1710 pcm
->info_flags
|= SNDRV_PCM_INFO_HALF_DUPLEX
;
1711 sprintf(pcm
->name
, "ESS AudioDrive ES%x", chip
->version
);
1714 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1717 chip
->dma1
> 3 || chip
->dma2
> 3 ? 128*1024 : 64*1024);
1724 /* Power Management support functions */
1726 static int snd_es18xx_suspend(struct snd_card
*card
, pm_message_t state
)
1728 struct snd_es18xx
*chip
= card
->private_data
;
1730 snd_power_change_state(card
, SNDRV_CTL_POWER_D3hot
);
1732 snd_pcm_suspend_all(chip
->pcm
);
1735 chip
->pm_reg
= (unsigned char)snd_es18xx_read(chip
, ES18XX_PM
);
1736 chip
->pm_reg
|= (ES18XX_PM_FM
| ES18XX_PM_SUS
);
1737 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
);
1738 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
^= ES18XX_PM_SUS
);
1743 static int snd_es18xx_resume(struct snd_card
*card
)
1745 struct snd_es18xx
*chip
= card
->private_data
;
1747 /* restore PM register, we won't wake till (not 0x07) i/o activity though */
1748 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
^= ES18XX_PM_FM
);
1750 snd_power_change_state(card
, SNDRV_CTL_POWER_D0
);
1753 #endif /* CONFIG_PM */
1755 static int snd_es18xx_free(struct snd_card
*card
)
1757 struct snd_es18xx
*chip
= card
->private_data
;
1759 release_and_free_resource(chip
->res_port
);
1760 release_and_free_resource(chip
->res_ctrl_port
);
1761 release_and_free_resource(chip
->res_mpu_port
);
1763 free_irq(chip
->irq
, (void *) card
);
1764 if (chip
->dma1
>= 0) {
1765 disable_dma(chip
->dma1
);
1766 free_dma(chip
->dma1
);
1768 if (chip
->dma2
>= 0 && chip
->dma1
!= chip
->dma2
) {
1769 disable_dma(chip
->dma2
);
1770 free_dma(chip
->dma2
);
1775 static int snd_es18xx_dev_free(struct snd_device
*device
)
1777 return snd_es18xx_free(device
->card
);
1780 static int snd_es18xx_new_device(struct snd_card
*card
,
1782 unsigned long mpu_port
,
1783 unsigned long fm_port
,
1784 int irq
, int dma1
, int dma2
)
1786 struct snd_es18xx
*chip
= card
->private_data
;
1787 static struct snd_device_ops ops
= {
1788 .dev_free
= snd_es18xx_dev_free
,
1792 spin_lock_init(&chip
->reg_lock
);
1793 spin_lock_init(&chip
->mixer_lock
);
1798 chip
->audio2_vol
= 0x00;
1801 chip
->res_port
= request_region(port
, 16, "ES18xx");
1802 if (chip
->res_port
== NULL
) {
1803 snd_es18xx_free(card
);
1804 snd_printk(KERN_ERR PFX
"unable to grap ports 0x%lx-0x%lx\n", port
, port
+ 16 - 1);
1808 if (request_irq(irq
, snd_es18xx_interrupt
, 0, "ES18xx",
1810 snd_es18xx_free(card
);
1811 snd_printk(KERN_ERR PFX
"unable to grap IRQ %d\n", irq
);
1816 if (request_dma(dma1
, "ES18xx DMA 1")) {
1817 snd_es18xx_free(card
);
1818 snd_printk(KERN_ERR PFX
"unable to grap DMA1 %d\n", dma1
);
1823 if (dma2
!= dma1
&& request_dma(dma2
, "ES18xx DMA 2")) {
1824 snd_es18xx_free(card
);
1825 snd_printk(KERN_ERR PFX
"unable to grap DMA2 %d\n", dma2
);
1830 if (snd_es18xx_probe(chip
, mpu_port
, fm_port
) < 0) {
1831 snd_es18xx_free(card
);
1834 err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
);
1836 snd_es18xx_free(card
);
1842 static int snd_es18xx_mixer(struct snd_card
*card
)
1844 struct snd_es18xx
*chip
= card
->private_data
;
1848 strcpy(card
->mixername
, chip
->pcm
->name
);
1850 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_base_controls
); idx
++) {
1851 struct snd_kcontrol
*kctl
;
1852 kctl
= snd_ctl_new1(&snd_es18xx_base_controls
[idx
], chip
);
1853 if (chip
->caps
& ES18XX_HWV
) {
1856 chip
->master_volume
= kctl
;
1857 kctl
->private_free
= snd_es18xx_hwv_free
;
1860 chip
->master_switch
= kctl
;
1861 kctl
->private_free
= snd_es18xx_hwv_free
;
1865 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
1868 if (chip
->caps
& ES18XX_PCM2
) {
1869 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_pcm2_controls
); idx
++) {
1870 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_pcm2_controls
[idx
], chip
))) < 0)
1874 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_pcm1_controls
); idx
++) {
1875 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_pcm1_controls
[idx
], chip
))) < 0)
1880 if (chip
->caps
& ES18XX_RECMIX
) {
1881 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_recmix_controls
); idx
++) {
1882 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_recmix_controls
[idx
], chip
))) < 0)
1886 switch (chip
->version
) {
1888 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_micpre1_control
, chip
))) < 0)
1893 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_micpre2_control
, chip
))) < 0)
1897 if (chip
->caps
& ES18XX_SPATIALIZER
) {
1898 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_spatializer_controls
); idx
++) {
1899 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_spatializer_controls
[idx
], chip
))) < 0)
1903 if (chip
->caps
& ES18XX_HWV
) {
1904 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_hw_volume_controls
); idx
++) {
1905 struct snd_kcontrol
*kctl
;
1906 kctl
= snd_ctl_new1(&snd_es18xx_hw_volume_controls
[idx
], chip
);
1908 chip
->hw_volume
= kctl
;
1910 chip
->hw_switch
= kctl
;
1911 kctl
->private_free
= snd_es18xx_hwv_free
;
1912 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
1917 /* finish initializing other chipset specific controls
1919 if (chip
->version
!= 0x1868) {
1920 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_opt_speaker
,
1925 if (chip
->version
== 0x1869) {
1926 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_opt_1869
); idx
++) {
1927 err
= snd_ctl_add(card
,
1928 snd_ctl_new1(&snd_es18xx_opt_1869
[idx
],
1933 } else if (chip
->version
== 0x1878) {
1934 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_opt_1878
,
1938 } else if (chip
->version
== 0x1879) {
1939 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_opt_1879
); idx
++) {
1940 err
= snd_ctl_add(card
,
1941 snd_ctl_new1(&snd_es18xx_opt_1879
[idx
],
1953 MODULE_AUTHOR("Christian Fischbach <fishbach@pool.informatik.rwth-aachen.de>, Abramo Bagnara <abramo@alsa-project.org>");
1954 MODULE_DESCRIPTION("ESS ES18xx AudioDrive");
1955 MODULE_LICENSE("GPL");
1956 MODULE_SUPPORTED_DEVICE("{{ESS,ES1868 PnP AudioDrive},"
1957 "{ESS,ES1869 PnP AudioDrive},"
1958 "{ESS,ES1878 PnP AudioDrive},"
1959 "{ESS,ES1879 PnP AudioDrive},"
1960 "{ESS,ES1887 PnP AudioDrive},"
1961 "{ESS,ES1888 PnP AudioDrive},"
1962 "{ESS,ES1887 AudioDrive},"
1963 "{ESS,ES1888 AudioDrive}}");
1965 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
1966 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
1967 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_ISAPNP
; /* Enable this card */
1969 static bool isapnp
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_ISAPNP
;
1971 static long port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
; /* 0x220,0x240,0x260,0x280 */
1973 static long mpu_port
[SNDRV_CARDS
] = {[0 ... (SNDRV_CARDS
- 1)] = -1};
1975 static long mpu_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
1977 static long fm_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
1978 static int irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
; /* 5,7,9,10 */
1979 static int dma1
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* 0,1,3 */
1980 static int dma2
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* 0,1,3 */
1982 module_param_array(index
, int, NULL
, 0444);
1983 MODULE_PARM_DESC(index
, "Index value for ES18xx soundcard.");
1984 module_param_array(id
, charp
, NULL
, 0444);
1985 MODULE_PARM_DESC(id
, "ID string for ES18xx soundcard.");
1986 module_param_array(enable
, bool, NULL
, 0444);
1987 MODULE_PARM_DESC(enable
, "Enable ES18xx soundcard.");
1989 module_param_array(isapnp
, bool, NULL
, 0444);
1990 MODULE_PARM_DESC(isapnp
, "PnP detection for specified soundcard.");
1992 module_param_array(port
, long, NULL
, 0444);
1993 MODULE_PARM_DESC(port
, "Port # for ES18xx driver.");
1994 module_param_array(mpu_port
, long, NULL
, 0444);
1995 MODULE_PARM_DESC(mpu_port
, "MPU-401 port # for ES18xx driver.");
1996 module_param_array(fm_port
, long, NULL
, 0444);
1997 MODULE_PARM_DESC(fm_port
, "FM port # for ES18xx driver.");
1998 module_param_array(irq
, int, NULL
, 0444);
1999 MODULE_PARM_DESC(irq
, "IRQ # for ES18xx driver.");
2000 module_param_array(dma1
, int, NULL
, 0444);
2001 MODULE_PARM_DESC(dma1
, "DMA 1 # for ES18xx driver.");
2002 module_param_array(dma2
, int, NULL
, 0444);
2003 MODULE_PARM_DESC(dma2
, "DMA 2 # for ES18xx driver.");
2006 static int isa_registered
;
2007 static int pnp_registered
;
2008 static int pnpc_registered
;
2010 static struct pnp_device_id snd_audiodrive_pnpbiosids
[] = {
2011 { .id
= "ESS1869" },
2012 { .id
= "ESS1879" },
2013 { .id
= "" } /* end */
2016 MODULE_DEVICE_TABLE(pnp
, snd_audiodrive_pnpbiosids
);
2018 /* PnP main device initialization */
2019 static int snd_audiodrive_pnp_init_main(int dev
, struct pnp_dev
*pdev
)
2021 if (pnp_activate_dev(pdev
) < 0) {
2022 snd_printk(KERN_ERR PFX
"PnP configure failure (out of resources?)\n");
2025 /* ok. hack using Vendor-Defined Card-Level registers */
2026 /* skip csn and logdev initialization - already done in isapnp_configure */
2027 if (pnp_device_is_isapnp(pdev
)) {
2028 isapnp_cfg_begin(isapnp_card_number(pdev
), isapnp_csn_number(pdev
));
2029 isapnp_write_byte(0x27, pnp_irq(pdev
, 0)); /* Hardware Volume IRQ Number */
2030 if (mpu_port
[dev
] != SNDRV_AUTO_PORT
)
2031 isapnp_write_byte(0x28, pnp_irq(pdev
, 0)); /* MPU-401 IRQ Number */
2032 isapnp_write_byte(0x72, pnp_irq(pdev
, 0)); /* second IRQ */
2035 port
[dev
] = pnp_port_start(pdev
, 0);
2036 fm_port
[dev
] = pnp_port_start(pdev
, 1);
2037 mpu_port
[dev
] = pnp_port_start(pdev
, 2);
2038 dma1
[dev
] = pnp_dma(pdev
, 0);
2039 dma2
[dev
] = pnp_dma(pdev
, 1);
2040 irq
[dev
] = pnp_irq(pdev
, 0);
2041 snd_printdd("PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port
[dev
], fm_port
[dev
], mpu_port
[dev
]);
2042 snd_printdd("PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1
[dev
], dma2
[dev
], irq
[dev
]);
2046 static int snd_audiodrive_pnp(int dev
, struct snd_es18xx
*chip
,
2047 struct pnp_dev
*pdev
)
2050 if (snd_audiodrive_pnp_init_main(dev
, chip
->dev
) < 0)
2055 static struct pnp_card_device_id snd_audiodrive_pnpids
[] = {
2056 /* ESS 1868 (integrated on Compaq dual P-Pro motherboard and Genius 18PnP 3D) */
2057 { .id
= "ESS1868", .devs
= { { "ESS1868" }, { "ESS0000" } } },
2058 /* ESS 1868 (integrated on Maxisound Cards) */
2059 { .id
= "ESS1868", .devs
= { { "ESS8601" }, { "ESS8600" } } },
2060 /* ESS 1868 (integrated on Maxisound Cards) */
2061 { .id
= "ESS1868", .devs
= { { "ESS8611" }, { "ESS8610" } } },
2062 /* ESS ES1869 Plug and Play AudioDrive */
2063 { .id
= "ESS0003", .devs
= { { "ESS1869" }, { "ESS0006" } } },
2065 { .id
= "ESS1869", .devs
= { { "ESS1869" }, { "ESS0006" } } },
2067 { .id
= "ESS1878", .devs
= { { "ESS1878" }, { "ESS0004" } } },
2069 { .id
= "ESS1879", .devs
= { { "ESS1879" }, { "ESS0009" } } },
2071 { .id
= "" } /* end */
2074 MODULE_DEVICE_TABLE(pnp_card
, snd_audiodrive_pnpids
);
2076 static int snd_audiodrive_pnpc(int dev
, struct snd_es18xx
*chip
,
2077 struct pnp_card_link
*card
,
2078 const struct pnp_card_device_id
*id
)
2080 chip
->dev
= pnp_request_card_device(card
, id
->devs
[0].id
, NULL
);
2081 if (chip
->dev
== NULL
)
2084 chip
->devc
= pnp_request_card_device(card
, id
->devs
[1].id
, NULL
);
2085 if (chip
->devc
== NULL
)
2088 /* Control port initialization */
2089 if (pnp_activate_dev(chip
->devc
) < 0) {
2090 snd_printk(KERN_ERR PFX
"PnP control configure failure (out of resources?)\n");
2093 snd_printdd("pnp: port=0x%llx\n",
2094 (unsigned long long)pnp_port_start(chip
->devc
, 0));
2095 if (snd_audiodrive_pnp_init_main(dev
, chip
->dev
) < 0)
2100 #endif /* CONFIG_PNP */
2103 #define is_isapnp_selected(dev) isapnp[dev]
2105 #define is_isapnp_selected(dev) 0
2108 static int snd_es18xx_card_new(struct device
*pdev
, int dev
,
2109 struct snd_card
**cardp
)
2111 return snd_card_new(pdev
, index
[dev
], id
[dev
], THIS_MODULE
,
2112 sizeof(struct snd_es18xx
), cardp
);
2115 static int snd_audiodrive_probe(struct snd_card
*card
, int dev
)
2117 struct snd_es18xx
*chip
= card
->private_data
;
2118 struct snd_opl3
*opl3
;
2121 err
= snd_es18xx_new_device(card
,
2122 port
[dev
], mpu_port
[dev
], fm_port
[dev
],
2123 irq
[dev
], dma1
[dev
], dma2
[dev
]);
2127 sprintf(card
->driver
, "ES%x", chip
->version
);
2129 sprintf(card
->shortname
, "ESS AudioDrive ES%x", chip
->version
);
2130 if (dma1
[dev
] != dma2
[dev
])
2131 sprintf(card
->longname
, "%s at 0x%lx, irq %d, dma1 %d, dma2 %d",
2134 irq
[dev
], dma1
[dev
], dma2
[dev
]);
2136 sprintf(card
->longname
, "%s at 0x%lx, irq %d, dma %d",
2139 irq
[dev
], dma1
[dev
]);
2141 err
= snd_es18xx_pcm(card
, 0, NULL
);
2145 err
= snd_es18xx_mixer(card
);
2149 if (fm_port
[dev
] > 0 && fm_port
[dev
] != SNDRV_AUTO_PORT
) {
2150 if (snd_opl3_create(card
, fm_port
[dev
], fm_port
[dev
] + 2,
2151 OPL3_HW_OPL3
, 0, &opl3
) < 0) {
2152 snd_printk(KERN_WARNING PFX
2153 "opl3 not detected at 0x%lx\n",
2156 err
= snd_opl3_hwdep_new(opl3
, 0, 1, NULL
);
2162 if (mpu_port
[dev
] > 0 && mpu_port
[dev
] != SNDRV_AUTO_PORT
) {
2163 err
= snd_mpu401_uart_new(card
, 0, MPU401_HW_ES18XX
,
2164 mpu_port
[dev
], MPU401_INFO_IRQ_HOOK
,
2170 return snd_card_register(card
);
2173 static int snd_es18xx_isa_match(struct device
*pdev
, unsigned int dev
)
2175 return enable
[dev
] && !is_isapnp_selected(dev
);
2178 static int snd_es18xx_isa_probe1(int dev
, struct device
*devptr
)
2180 struct snd_card
*card
;
2183 err
= snd_es18xx_card_new(devptr
, dev
, &card
);
2186 if ((err
= snd_audiodrive_probe(card
, dev
)) < 0) {
2187 snd_card_free(card
);
2190 dev_set_drvdata(devptr
, card
);
2194 static int snd_es18xx_isa_probe(struct device
*pdev
, unsigned int dev
)
2197 static int possible_irqs
[] = {5, 9, 10, 7, 11, 12, -1};
2198 static int possible_dmas
[] = {1, 0, 3, 5, -1};
2200 if (irq
[dev
] == SNDRV_AUTO_IRQ
) {
2201 if ((irq
[dev
] = snd_legacy_find_free_irq(possible_irqs
)) < 0) {
2202 snd_printk(KERN_ERR PFX
"unable to find a free IRQ\n");
2206 if (dma1
[dev
] == SNDRV_AUTO_DMA
) {
2207 if ((dma1
[dev
] = snd_legacy_find_free_dma(possible_dmas
)) < 0) {
2208 snd_printk(KERN_ERR PFX
"unable to find a free DMA1\n");
2212 if (dma2
[dev
] == SNDRV_AUTO_DMA
) {
2213 if ((dma2
[dev
] = snd_legacy_find_free_dma(possible_dmas
)) < 0) {
2214 snd_printk(KERN_ERR PFX
"unable to find a free DMA2\n");
2219 if (port
[dev
] != SNDRV_AUTO_PORT
) {
2220 return snd_es18xx_isa_probe1(dev
, pdev
);
2222 static unsigned long possible_ports
[] = {0x220, 0x240, 0x260, 0x280};
2224 for (i
= 0; i
< ARRAY_SIZE(possible_ports
); i
++) {
2225 port
[dev
] = possible_ports
[i
];
2226 err
= snd_es18xx_isa_probe1(dev
, pdev
);
2234 static int snd_es18xx_isa_remove(struct device
*devptr
,
2237 snd_card_free(dev_get_drvdata(devptr
));
2242 static int snd_es18xx_isa_suspend(struct device
*dev
, unsigned int n
,
2245 return snd_es18xx_suspend(dev_get_drvdata(dev
), state
);
2248 static int snd_es18xx_isa_resume(struct device
*dev
, unsigned int n
)
2250 return snd_es18xx_resume(dev_get_drvdata(dev
));
2254 #define DEV_NAME "es18xx"
2256 static struct isa_driver snd_es18xx_isa_driver
= {
2257 .match
= snd_es18xx_isa_match
,
2258 .probe
= snd_es18xx_isa_probe
,
2259 .remove
= snd_es18xx_isa_remove
,
2261 .suspend
= snd_es18xx_isa_suspend
,
2262 .resume
= snd_es18xx_isa_resume
,
2271 static int snd_audiodrive_pnp_detect(struct pnp_dev
*pdev
,
2272 const struct pnp_device_id
*id
)
2276 struct snd_card
*card
;
2278 if (pnp_device_is_isapnp(pdev
))
2279 return -ENOENT
; /* we have another procedure - card */
2280 for (; dev
< SNDRV_CARDS
; dev
++) {
2281 if (enable
[dev
] && isapnp
[dev
])
2284 if (dev
>= SNDRV_CARDS
)
2287 err
= snd_es18xx_card_new(&pdev
->dev
, dev
, &card
);
2290 if ((err
= snd_audiodrive_pnp(dev
, card
->private_data
, pdev
)) < 0) {
2291 snd_card_free(card
);
2294 if ((err
= snd_audiodrive_probe(card
, dev
)) < 0) {
2295 snd_card_free(card
);
2298 pnp_set_drvdata(pdev
, card
);
2303 static void snd_audiodrive_pnp_remove(struct pnp_dev
*pdev
)
2305 snd_card_free(pnp_get_drvdata(pdev
));
2309 static int snd_audiodrive_pnp_suspend(struct pnp_dev
*pdev
, pm_message_t state
)
2311 return snd_es18xx_suspend(pnp_get_drvdata(pdev
), state
);
2313 static int snd_audiodrive_pnp_resume(struct pnp_dev
*pdev
)
2315 return snd_es18xx_resume(pnp_get_drvdata(pdev
));
2319 static struct pnp_driver es18xx_pnp_driver
= {
2320 .name
= "es18xx-pnpbios",
2321 .id_table
= snd_audiodrive_pnpbiosids
,
2322 .probe
= snd_audiodrive_pnp_detect
,
2323 .remove
= snd_audiodrive_pnp_remove
,
2325 .suspend
= snd_audiodrive_pnp_suspend
,
2326 .resume
= snd_audiodrive_pnp_resume
,
2330 static int snd_audiodrive_pnpc_detect(struct pnp_card_link
*pcard
,
2331 const struct pnp_card_device_id
*pid
)
2334 struct snd_card
*card
;
2337 for ( ; dev
< SNDRV_CARDS
; dev
++) {
2338 if (enable
[dev
] && isapnp
[dev
])
2341 if (dev
>= SNDRV_CARDS
)
2344 res
= snd_es18xx_card_new(&pcard
->card
->dev
, dev
, &card
);
2348 if ((res
= snd_audiodrive_pnpc(dev
, card
->private_data
, pcard
, pid
)) < 0) {
2349 snd_card_free(card
);
2352 if ((res
= snd_audiodrive_probe(card
, dev
)) < 0) {
2353 snd_card_free(card
);
2357 pnp_set_card_drvdata(pcard
, card
);
2362 static void snd_audiodrive_pnpc_remove(struct pnp_card_link
*pcard
)
2364 snd_card_free(pnp_get_card_drvdata(pcard
));
2365 pnp_set_card_drvdata(pcard
, NULL
);
2369 static int snd_audiodrive_pnpc_suspend(struct pnp_card_link
*pcard
, pm_message_t state
)
2371 return snd_es18xx_suspend(pnp_get_card_drvdata(pcard
), state
);
2374 static int snd_audiodrive_pnpc_resume(struct pnp_card_link
*pcard
)
2376 return snd_es18xx_resume(pnp_get_card_drvdata(pcard
));
2381 static struct pnp_card_driver es18xx_pnpc_driver
= {
2382 .flags
= PNP_DRIVER_RES_DISABLE
,
2384 .id_table
= snd_audiodrive_pnpids
,
2385 .probe
= snd_audiodrive_pnpc_detect
,
2386 .remove
= snd_audiodrive_pnpc_remove
,
2388 .suspend
= snd_audiodrive_pnpc_suspend
,
2389 .resume
= snd_audiodrive_pnpc_resume
,
2392 #endif /* CONFIG_PNP */
2394 static int __init
alsa_card_es18xx_init(void)
2398 err
= isa_register_driver(&snd_es18xx_isa_driver
, SNDRV_CARDS
);
2403 err
= pnp_register_driver(&es18xx_pnp_driver
);
2407 err
= pnp_register_card_driver(&es18xx_pnpc_driver
);
2409 pnpc_registered
= 1;
2411 if (isa_registered
|| pnp_registered
)
2417 static void __exit
alsa_card_es18xx_exit(void)
2420 if (pnpc_registered
)
2421 pnp_unregister_card_driver(&es18xx_pnpc_driver
);
2423 pnp_unregister_driver(&es18xx_pnp_driver
);
2426 isa_unregister_driver(&snd_es18xx_isa_driver
);
2429 module_init(alsa_card_es18xx_init
)
2430 module_exit(alsa_card_es18xx_exit
)