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/slab.h>
84 #include <linux/pnp.h>
85 #include <linux/isapnp.h>
86 #include <linux/moduleparam.h>
87 #include <linux/delay.h>
91 #include <sound/core.h>
92 #include <sound/control.h>
93 #include <sound/pcm.h>
94 #include <sound/pcm_params.h>
95 #include <sound/mpu401.h>
96 #include <sound/opl3.h>
97 #define SNDRV_LEGACY_FIND_FREE_IRQ
98 #define SNDRV_LEGACY_FIND_FREE_DMA
99 #include <sound/initval.h>
101 #define PFX "es18xx: "
104 unsigned long port
; /* port of ESS chip */
105 unsigned long ctrl_port
; /* Control port of ESS chip */
106 struct resource
*res_port
;
107 struct resource
*res_mpu_port
;
108 struct resource
*res_ctrl_port
;
109 int irq
; /* IRQ number of ESS chip */
112 unsigned short version
; /* version of ESS chip */
113 int caps
; /* Chip capabilities */
114 unsigned short audio2_vol
; /* volume level of audio2 */
116 unsigned short active
; /* active channel mask */
117 unsigned int dma1_shift
;
118 unsigned int dma2_shift
;
121 struct snd_pcm_substream
*playback_a_substream
;
122 struct snd_pcm_substream
*capture_a_substream
;
123 struct snd_pcm_substream
*playback_b_substream
;
125 struct snd_rawmidi
*rmidi
;
127 struct snd_kcontrol
*hw_volume
;
128 struct snd_kcontrol
*hw_switch
;
129 struct snd_kcontrol
*master_volume
;
130 struct snd_kcontrol
*master_switch
;
133 spinlock_t mixer_lock
;
135 unsigned char pm_reg
;
139 struct pnp_dev
*devc
;
143 #define AUDIO1_IRQ 0x01
144 #define AUDIO2_IRQ 0x02
148 #define ES18XX_PCM2 0x0001 /* Has two useable PCM */
149 #define ES18XX_SPATIALIZER 0x0002 /* Has 3D Spatializer */
150 #define ES18XX_RECMIX 0x0004 /* Has record mixer */
151 #define ES18XX_DUPLEX_MONO 0x0008 /* Has mono duplex only */
152 #define ES18XX_DUPLEX_SAME 0x0010 /* Playback and record must share the same rate */
153 #define ES18XX_NEW_RATE 0x0020 /* More precise rate setting */
154 #define ES18XX_AUXB 0x0040 /* AuxB mixer control */
155 #define ES18XX_HWV 0x0080 /* Has separate hardware volume mixer controls*/
156 #define ES18XX_MONO 0x0100 /* Mono_in mixer control */
157 #define ES18XX_I2S 0x0200 /* I2S mixer control */
158 #define ES18XX_MUTEREC 0x0400 /* Record source can be muted */
159 #define ES18XX_CONTROL 0x0800 /* Has control ports */
161 /* Power Management */
162 #define ES18XX_PM 0x07
163 #define ES18XX_PM_GPO0 0x01
164 #define ES18XX_PM_GPO1 0x02
165 #define ES18XX_PM_PDR 0x04
166 #define ES18XX_PM_ANA 0x08
167 #define ES18XX_PM_FM 0x020
168 #define ES18XX_PM_SUS 0x080
175 #define MILLISECOND 10000
177 static int snd_es18xx_dsp_command(struct snd_es18xx
*chip
, unsigned char val
)
181 for(i
= MILLISECOND
; i
; i
--)
182 if ((inb(chip
->port
+ 0x0C) & 0x80) == 0) {
183 outb(val
, chip
->port
+ 0x0C);
186 snd_printk(KERN_ERR
"dsp_command: timeout (0x%x)\n", val
);
190 static int snd_es18xx_dsp_get_byte(struct snd_es18xx
*chip
)
194 for(i
= MILLISECOND
/10; i
; i
--)
195 if (inb(chip
->port
+ 0x0C) & 0x40)
196 return inb(chip
->port
+ 0x0A);
197 snd_printk(KERN_ERR
"dsp_get_byte failed: 0x%lx = 0x%x!!!\n",
198 chip
->port
+ 0x0A, inb(chip
->port
+ 0x0A));
204 static int snd_es18xx_write(struct snd_es18xx
*chip
,
205 unsigned char reg
, unsigned char data
)
210 spin_lock_irqsave(&chip
->reg_lock
, flags
);
211 ret
= snd_es18xx_dsp_command(chip
, reg
);
214 ret
= snd_es18xx_dsp_command(chip
, data
);
216 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
218 snd_printk(KERN_DEBUG
"Reg %02x set to %02x\n", reg
, data
);
223 static int snd_es18xx_read(struct snd_es18xx
*chip
, unsigned char reg
)
227 spin_lock_irqsave(&chip
->reg_lock
, flags
);
228 ret
= snd_es18xx_dsp_command(chip
, 0xC0);
231 ret
= snd_es18xx_dsp_command(chip
, reg
);
234 data
= snd_es18xx_dsp_get_byte(chip
);
237 snd_printk(KERN_DEBUG
"Reg %02x now is %02x (%d)\n", reg
, data
, ret
);
240 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
244 /* Return old value */
245 static int snd_es18xx_bits(struct snd_es18xx
*chip
, unsigned char reg
,
246 unsigned char mask
, unsigned char val
)
249 unsigned char old
, new, oval
;
251 spin_lock_irqsave(&chip
->reg_lock
, flags
);
252 ret
= snd_es18xx_dsp_command(chip
, 0xC0);
255 ret
= snd_es18xx_dsp_command(chip
, reg
);
258 ret
= snd_es18xx_dsp_get_byte(chip
);
265 ret
= snd_es18xx_dsp_command(chip
, reg
);
268 new = (old
& ~mask
) | (val
& mask
);
269 ret
= snd_es18xx_dsp_command(chip
, new);
273 snd_printk(KERN_DEBUG
"Reg %02x was %02x, set to %02x (%d)\n",
279 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
283 static inline void snd_es18xx_mixer_write(struct snd_es18xx
*chip
,
284 unsigned char reg
, unsigned char data
)
287 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
288 outb(reg
, chip
->port
+ 0x04);
289 outb(data
, chip
->port
+ 0x05);
290 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
292 snd_printk(KERN_DEBUG
"Mixer reg %02x set to %02x\n", reg
, data
);
296 static inline int snd_es18xx_mixer_read(struct snd_es18xx
*chip
, unsigned char reg
)
300 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
301 outb(reg
, chip
->port
+ 0x04);
302 data
= inb(chip
->port
+ 0x05);
303 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
305 snd_printk(KERN_DEBUG
"Mixer reg %02x now is %02x\n", reg
, data
);
310 /* Return old value */
311 static inline int snd_es18xx_mixer_bits(struct snd_es18xx
*chip
, unsigned char reg
,
312 unsigned char mask
, unsigned char val
)
314 unsigned char old
, new, oval
;
316 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
317 outb(reg
, chip
->port
+ 0x04);
318 old
= inb(chip
->port
+ 0x05);
321 new = (old
& ~mask
) | (val
& mask
);
322 outb(new, chip
->port
+ 0x05);
324 snd_printk(KERN_DEBUG
"Mixer reg %02x was %02x, set to %02x\n",
328 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
332 static inline int snd_es18xx_mixer_writable(struct snd_es18xx
*chip
, unsigned char reg
,
335 int old
, expected
, new;
337 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
338 outb(reg
, chip
->port
+ 0x04);
339 old
= inb(chip
->port
+ 0x05);
340 expected
= old
^ mask
;
341 outb(expected
, chip
->port
+ 0x05);
342 new = inb(chip
->port
+ 0x05);
343 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
345 snd_printk(KERN_DEBUG
"Mixer reg %02x was %02x, set to %02x, now is %02x\n",
346 reg
, old
, expected
, new);
348 return expected
== new;
352 static int __devinit
snd_es18xx_reset(struct snd_es18xx
*chip
)
355 outb(0x03, chip
->port
+ 0x06);
356 inb(chip
->port
+ 0x06);
357 outb(0x00, chip
->port
+ 0x06);
358 for(i
= 0; i
< MILLISECOND
&& !(inb(chip
->port
+ 0x0E) & 0x80); i
++);
359 if (inb(chip
->port
+ 0x0A) != 0xAA)
364 static int snd_es18xx_reset_fifo(struct snd_es18xx
*chip
)
366 outb(0x02, chip
->port
+ 0x06);
367 inb(chip
->port
+ 0x06);
368 outb(0x00, chip
->port
+ 0x06);
372 static struct snd_ratnum new_clocks
[2] = {
387 static struct snd_pcm_hw_constraint_ratnums new_hw_constraints_clocks
= {
392 static struct snd_ratnum old_clocks
[2] = {
407 static struct snd_pcm_hw_constraint_ratnums old_hw_constraints_clocks
= {
413 static void snd_es18xx_rate_set(struct snd_es18xx
*chip
,
414 struct snd_pcm_substream
*substream
,
417 unsigned int bits
, div0
;
418 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
419 if (chip
->caps
& ES18XX_NEW_RATE
) {
420 if (runtime
->rate_num
== new_clocks
[0].num
)
421 bits
= 128 - runtime
->rate_den
;
423 bits
= 256 - runtime
->rate_den
;
425 if (runtime
->rate_num
== old_clocks
[0].num
)
426 bits
= 256 - runtime
->rate_den
;
428 bits
= 128 - runtime
->rate_den
;
431 /* set filter register */
432 div0
= 256 - 7160000*20/(8*82*runtime
->rate
);
434 if ((chip
->caps
& ES18XX_PCM2
) && mode
== DAC2
) {
435 snd_es18xx_mixer_write(chip
, 0x70, bits
);
437 * Comment from kernel oss driver:
438 * FKS: fascinating: 0x72 doesn't seem to work.
440 snd_es18xx_write(chip
, 0xA2, div0
);
441 snd_es18xx_mixer_write(chip
, 0x72, div0
);
443 snd_es18xx_write(chip
, 0xA1, bits
);
444 snd_es18xx_write(chip
, 0xA2, div0
);
448 static int snd_es18xx_playback_hw_params(struct snd_pcm_substream
*substream
,
449 struct snd_pcm_hw_params
*hw_params
)
451 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
455 if (params_channels(hw_params
) == 2)
457 if (snd_pcm_format_width(params_format(hw_params
)) == 16)
460 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
461 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
462 (chip
->capture_a_substream
) &&
463 params_channels(hw_params
) != 1) {
464 _snd_pcm_hw_param_setempty(hw_params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
467 chip
->dma2_shift
= shift
;
469 chip
->dma1_shift
= shift
;
471 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
476 static int snd_es18xx_pcm_hw_free(struct snd_pcm_substream
*substream
)
478 return snd_pcm_lib_free_pages(substream
);
481 static int snd_es18xx_playback1_prepare(struct snd_es18xx
*chip
,
482 struct snd_pcm_substream
*substream
)
484 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
485 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
486 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
488 snd_es18xx_rate_set(chip
, substream
, DAC2
);
490 /* Transfer Count Reload */
491 count
= 0x10000 - count
;
492 snd_es18xx_mixer_write(chip
, 0x74, count
& 0xff);
493 snd_es18xx_mixer_write(chip
, 0x76, count
>> 8);
496 snd_es18xx_mixer_bits(chip
, 0x7A, 0x07,
497 ((runtime
->channels
== 1) ? 0x00 : 0x02) |
498 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x01 : 0x00) |
499 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x04));
501 /* Set DMA controller */
502 snd_dma_program(chip
->dma2
, runtime
->dma_addr
, size
, DMA_MODE_WRITE
| DMA_AUTOINIT
);
507 static int snd_es18xx_playback1_trigger(struct snd_es18xx
*chip
,
508 struct snd_pcm_substream
*substream
,
512 case SNDRV_PCM_TRIGGER_START
:
513 case SNDRV_PCM_TRIGGER_RESUME
:
514 if (chip
->active
& DAC2
)
516 chip
->active
|= DAC2
;
519 snd_es18xx_mixer_write(chip
, 0x78, 0xb3);
521 snd_es18xx_mixer_write(chip
, 0x78, 0x93);
525 if (chip
->caps
& ES18XX_PCM2
)
526 /* Restore Audio 2 volume */
527 snd_es18xx_mixer_write(chip
, 0x7C, chip
->audio2_vol
);
529 /* Enable PCM output */
530 snd_es18xx_dsp_command(chip
, 0xD1);
533 case SNDRV_PCM_TRIGGER_STOP
:
534 case SNDRV_PCM_TRIGGER_SUSPEND
:
535 if (!(chip
->active
& DAC2
))
537 chip
->active
&= ~DAC2
;
539 snd_es18xx_mixer_write(chip
, 0x78, 0x00);
542 if (chip
->caps
& ES18XX_PCM2
)
543 /* Set Audio 2 volume to 0 */
544 snd_es18xx_mixer_write(chip
, 0x7C, 0);
546 /* Disable PCM output */
547 snd_es18xx_dsp_command(chip
, 0xD3);
557 static int snd_es18xx_capture_hw_params(struct snd_pcm_substream
*substream
,
558 struct snd_pcm_hw_params
*hw_params
)
560 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
564 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
565 chip
->playback_a_substream
&&
566 params_channels(hw_params
) != 1) {
567 _snd_pcm_hw_param_setempty(hw_params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
570 if (params_channels(hw_params
) == 2)
572 if (snd_pcm_format_width(params_format(hw_params
)) == 16)
574 chip
->dma1_shift
= shift
;
575 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
580 static int snd_es18xx_capture_prepare(struct snd_pcm_substream
*substream
)
582 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
583 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
584 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
585 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
587 snd_es18xx_reset_fifo(chip
);
589 /* Set stereo/mono */
590 snd_es18xx_bits(chip
, 0xA8, 0x03, runtime
->channels
== 1 ? 0x02 : 0x01);
592 snd_es18xx_rate_set(chip
, substream
, ADC1
);
594 /* Transfer Count Reload */
595 count
= 0x10000 - count
;
596 snd_es18xx_write(chip
, 0xA4, count
& 0xff);
597 snd_es18xx_write(chip
, 0xA5, count
>> 8);
604 snd_es18xx_write(chip
, 0xB7,
605 snd_pcm_format_unsigned(runtime
->format
) ? 0x51 : 0x71);
606 snd_es18xx_write(chip
, 0xB7, 0x90 |
607 ((runtime
->channels
== 1) ? 0x40 : 0x08) |
608 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x04 : 0x00) |
609 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x20));
611 /* Set DMA controller */
612 snd_dma_program(chip
->dma1
, runtime
->dma_addr
, size
, DMA_MODE_READ
| DMA_AUTOINIT
);
617 static int snd_es18xx_capture_trigger(struct snd_pcm_substream
*substream
,
620 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
623 case SNDRV_PCM_TRIGGER_START
:
624 case SNDRV_PCM_TRIGGER_RESUME
:
625 if (chip
->active
& ADC1
)
627 chip
->active
|= ADC1
;
629 snd_es18xx_write(chip
, 0xB8, 0x0f);
631 case SNDRV_PCM_TRIGGER_STOP
:
632 case SNDRV_PCM_TRIGGER_SUSPEND
:
633 if (!(chip
->active
& ADC1
))
635 chip
->active
&= ~ADC1
;
637 snd_es18xx_write(chip
, 0xB8, 0x00);
646 static int snd_es18xx_playback2_prepare(struct snd_es18xx
*chip
,
647 struct snd_pcm_substream
*substream
)
649 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
650 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
651 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
653 snd_es18xx_reset_fifo(chip
);
655 /* Set stereo/mono */
656 snd_es18xx_bits(chip
, 0xA8, 0x03, runtime
->channels
== 1 ? 0x02 : 0x01);
658 snd_es18xx_rate_set(chip
, substream
, DAC1
);
660 /* Transfer Count Reload */
661 count
= 0x10000 - count
;
662 snd_es18xx_write(chip
, 0xA4, count
& 0xff);
663 snd_es18xx_write(chip
, 0xA5, count
>> 8);
666 snd_es18xx_write(chip
, 0xB6,
667 snd_pcm_format_unsigned(runtime
->format
) ? 0x80 : 0x00);
668 snd_es18xx_write(chip
, 0xB7,
669 snd_pcm_format_unsigned(runtime
->format
) ? 0x51 : 0x71);
670 snd_es18xx_write(chip
, 0xB7, 0x90 |
671 (runtime
->channels
== 1 ? 0x40 : 0x08) |
672 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x04 : 0x00) |
673 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x20));
675 /* Set DMA controller */
676 snd_dma_program(chip
->dma1
, runtime
->dma_addr
, size
, DMA_MODE_WRITE
| DMA_AUTOINIT
);
681 static int snd_es18xx_playback2_trigger(struct snd_es18xx
*chip
,
682 struct snd_pcm_substream
*substream
,
686 case SNDRV_PCM_TRIGGER_START
:
687 case SNDRV_PCM_TRIGGER_RESUME
:
688 if (chip
->active
& DAC1
)
690 chip
->active
|= DAC1
;
692 snd_es18xx_write(chip
, 0xB8, 0x05);
697 snd_es18xx_dsp_command(chip
, 0xD1);
700 case SNDRV_PCM_TRIGGER_STOP
:
701 case SNDRV_PCM_TRIGGER_SUSPEND
:
702 if (!(chip
->active
& DAC1
))
704 chip
->active
&= ~DAC1
;
706 snd_es18xx_write(chip
, 0xB8, 0x00);
710 /* Disable Audio 1 */
711 snd_es18xx_dsp_command(chip
, 0xD3);
721 static int snd_es18xx_playback_prepare(struct snd_pcm_substream
*substream
)
723 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
724 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
725 return snd_es18xx_playback1_prepare(chip
, substream
);
727 return snd_es18xx_playback2_prepare(chip
, substream
);
730 static int snd_es18xx_playback_trigger(struct snd_pcm_substream
*substream
,
733 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
734 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
735 return snd_es18xx_playback1_trigger(chip
, substream
, cmd
);
737 return snd_es18xx_playback2_trigger(chip
, substream
, cmd
);
740 static irqreturn_t
snd_es18xx_interrupt(int irq
, void *dev_id
)
742 struct snd_card
*card
= dev_id
;
743 struct snd_es18xx
*chip
= card
->private_data
;
744 unsigned char status
;
746 if (chip
->caps
& ES18XX_CONTROL
) {
747 /* Read Interrupt status */
748 status
= inb(chip
->ctrl_port
+ 6);
750 /* Read Interrupt status */
751 status
= snd_es18xx_mixer_read(chip
, 0x7f) >> 4;
756 if (inb(chip
->port
+ 0x0C) & 0x01)
757 status
|= AUDIO1_IRQ
;
758 if (snd_es18xx_mixer_read(chip
, 0x7A) & 0x80)
759 status
|= AUDIO2_IRQ
;
760 if ((chip
->caps
& ES18XX_HWV
) &&
761 snd_es18xx_mixer_read(chip
, 0x64) & 0x10)
766 /* Audio 1 & Audio 2 */
767 if (status
& AUDIO2_IRQ
) {
768 if (chip
->active
& DAC2
)
769 snd_pcm_period_elapsed(chip
->playback_a_substream
);
771 snd_es18xx_mixer_bits(chip
, 0x7A, 0x80, 0x00);
773 if (status
& AUDIO1_IRQ
) {
774 /* ok.. capture is active */
775 if (chip
->active
& ADC1
)
776 snd_pcm_period_elapsed(chip
->capture_a_substream
);
777 /* ok.. playback2 is active */
778 else if (chip
->active
& DAC1
)
779 snd_pcm_period_elapsed(chip
->playback_b_substream
);
781 inb(chip
->port
+ 0x0E);
785 if ((status
& MPU_IRQ
) && chip
->rmidi
)
786 snd_mpu401_uart_interrupt(irq
, chip
->rmidi
->private_data
);
788 /* Hardware volume */
789 if (status
& HWV_IRQ
) {
791 if (chip
->caps
& ES18XX_HWV
) {
792 split
= snd_es18xx_mixer_read(chip
, 0x64) & 0x80;
793 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
,
794 &chip
->hw_switch
->id
);
795 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
,
796 &chip
->hw_volume
->id
);
799 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
,
800 &chip
->master_switch
->id
);
801 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
,
802 &chip
->master_volume
->id
);
805 snd_es18xx_mixer_write(chip
, 0x66, 0x00);
810 static snd_pcm_uframes_t
snd_es18xx_playback_pointer(struct snd_pcm_substream
*substream
)
812 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
813 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
816 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
817 if (!(chip
->active
& DAC2
))
819 pos
= snd_dma_pointer(chip
->dma2
, size
);
820 return pos
>> chip
->dma2_shift
;
822 if (!(chip
->active
& DAC1
))
824 pos
= snd_dma_pointer(chip
->dma1
, size
);
825 return pos
>> chip
->dma1_shift
;
829 static snd_pcm_uframes_t
snd_es18xx_capture_pointer(struct snd_pcm_substream
*substream
)
831 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
832 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
835 if (!(chip
->active
& ADC1
))
837 pos
= snd_dma_pointer(chip
->dma1
, size
);
838 return pos
>> chip
->dma1_shift
;
841 static struct snd_pcm_hardware snd_es18xx_playback
=
843 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
844 SNDRV_PCM_INFO_RESUME
|
845 SNDRV_PCM_INFO_MMAP_VALID
),
846 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S8
|
847 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_U16_LE
),
848 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
853 .buffer_bytes_max
= 65536,
854 .period_bytes_min
= 64,
855 .period_bytes_max
= 65536,
861 static struct snd_pcm_hardware snd_es18xx_capture
=
863 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
864 SNDRV_PCM_INFO_RESUME
|
865 SNDRV_PCM_INFO_MMAP_VALID
),
866 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S8
|
867 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_U16_LE
),
868 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
873 .buffer_bytes_max
= 65536,
874 .period_bytes_min
= 64,
875 .period_bytes_max
= 65536,
881 static int snd_es18xx_playback_open(struct snd_pcm_substream
*substream
)
883 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
884 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
886 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
887 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
888 chip
->capture_a_substream
&&
889 chip
->capture_a_substream
->runtime
->channels
!= 1)
891 chip
->playback_a_substream
= substream
;
892 } else if (substream
->number
<= 1) {
893 if (chip
->capture_a_substream
)
895 chip
->playback_b_substream
= substream
;
900 substream
->runtime
->hw
= snd_es18xx_playback
;
901 snd_pcm_hw_constraint_ratnums(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
902 (chip
->caps
& ES18XX_NEW_RATE
) ? &new_hw_constraints_clocks
: &old_hw_constraints_clocks
);
906 static int snd_es18xx_capture_open(struct snd_pcm_substream
*substream
)
908 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
909 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
911 if (chip
->playback_b_substream
)
913 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
914 chip
->playback_a_substream
&&
915 chip
->playback_a_substream
->runtime
->channels
!= 1)
917 chip
->capture_a_substream
= substream
;
918 substream
->runtime
->hw
= snd_es18xx_capture
;
919 snd_pcm_hw_constraint_ratnums(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
920 (chip
->caps
& ES18XX_NEW_RATE
) ? &new_hw_constraints_clocks
: &old_hw_constraints_clocks
);
924 static int snd_es18xx_playback_close(struct snd_pcm_substream
*substream
)
926 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
928 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
929 chip
->playback_a_substream
= NULL
;
931 chip
->playback_b_substream
= NULL
;
933 snd_pcm_lib_free_pages(substream
);
937 static int snd_es18xx_capture_close(struct snd_pcm_substream
*substream
)
939 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
941 chip
->capture_a_substream
= NULL
;
942 snd_pcm_lib_free_pages(substream
);
950 /* Record source mux routines:
951 * Depending on the chipset this mux switches between 4, 5, or 8 possible inputs.
952 * bit table for the 4/5 source mux:
959 * if it's "mixer" and it's a 5 source mux chipset then reg 7A bit 3 determines
960 * either the play mixer or the capture mixer.
962 * "map4Source" translates from source number to reg bit pattern
963 * "invMap4Source" translates from reg bit pattern to source number
966 static int snd_es18xx_info_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
968 static char *texts5Source
[5] = {
969 "Mic", "CD", "Line", "Master", "Mix"
971 static char *texts8Source
[8] = {
972 "Mic", "Mic Master", "CD", "AOUT",
973 "Mic1", "Mix", "Line", "Master"
975 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
977 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
979 switch (chip
->version
) {
982 uinfo
->value
.enumerated
.items
= 4;
983 if (uinfo
->value
.enumerated
.item
> 3)
984 uinfo
->value
.enumerated
.item
= 3;
985 strcpy(uinfo
->value
.enumerated
.name
,
986 texts5Source
[uinfo
->value
.enumerated
.item
]);
990 uinfo
->value
.enumerated
.items
= 5;
991 if (uinfo
->value
.enumerated
.item
> 4)
992 uinfo
->value
.enumerated
.item
= 4;
993 strcpy(uinfo
->value
.enumerated
.name
, texts5Source
[uinfo
->value
.enumerated
.item
]);
995 case 0x1869: /* DS somewhat contradictory for 1869: could be be 5 or 8 */
997 uinfo
->value
.enumerated
.items
= 8;
998 if (uinfo
->value
.enumerated
.item
> 7)
999 uinfo
->value
.enumerated
.item
= 7;
1000 strcpy(uinfo
->value
.enumerated
.name
, texts8Source
[uinfo
->value
.enumerated
.item
]);
1008 static int snd_es18xx_get_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1010 static unsigned char invMap4Source
[8] = {0, 0, 1, 1, 0, 0, 2, 3};
1011 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1012 int muxSource
= snd_es18xx_mixer_read(chip
, 0x1c) & 0x07;
1013 if (!(chip
->version
== 0x1869 || chip
->version
== 0x1879)) {
1014 muxSource
= invMap4Source
[muxSource
];
1016 (chip
->version
== 0x1887 || chip
->version
== 0x1888) &&
1017 (snd_es18xx_mixer_read(chip
, 0x7a) & 0x08)
1021 ucontrol
->value
.enumerated
.item
[0] = muxSource
;
1025 static int snd_es18xx_put_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1027 static unsigned char map4Source
[4] = {0, 2, 6, 7};
1028 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1029 unsigned char val
= ucontrol
->value
.enumerated
.item
[0];
1030 unsigned char retVal
= 0;
1032 switch (chip
->version
) {
1033 /* 5 source chips */
1039 retVal
= snd_es18xx_mixer_bits(chip
, 0x7a, 0x08, 0x08) != 0x08;
1042 retVal
= snd_es18xx_mixer_bits(chip
, 0x7a, 0x08, 0x00) != 0x00;
1043 /* 4 source chips */
1048 val
= map4Source
[val
];
1050 /* 8 source chips */
1059 return (snd_es18xx_mixer_bits(chip
, 0x1c, 0x07, val
) != val
) || retVal
;
1062 #define snd_es18xx_info_spatializer_enable snd_ctl_boolean_mono_info
1064 static int snd_es18xx_get_spatializer_enable(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1066 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1067 unsigned char val
= snd_es18xx_mixer_read(chip
, 0x50);
1068 ucontrol
->value
.integer
.value
[0] = !!(val
& 8);
1072 static int snd_es18xx_put_spatializer_enable(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1074 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1075 unsigned char oval
, nval
;
1077 nval
= ucontrol
->value
.integer
.value
[0] ? 0x0c : 0x04;
1078 oval
= snd_es18xx_mixer_read(chip
, 0x50) & 0x0c;
1079 change
= nval
!= oval
;
1081 snd_es18xx_mixer_write(chip
, 0x50, nval
& ~0x04);
1082 snd_es18xx_mixer_write(chip
, 0x50, nval
);
1087 static int snd_es18xx_info_hw_volume(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1089 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1091 uinfo
->value
.integer
.min
= 0;
1092 uinfo
->value
.integer
.max
= 63;
1096 static int snd_es18xx_get_hw_volume(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1098 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1099 ucontrol
->value
.integer
.value
[0] = snd_es18xx_mixer_read(chip
, 0x61) & 0x3f;
1100 ucontrol
->value
.integer
.value
[1] = snd_es18xx_mixer_read(chip
, 0x63) & 0x3f;
1104 #define snd_es18xx_info_hw_switch snd_ctl_boolean_stereo_info
1106 static int snd_es18xx_get_hw_switch(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1108 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1109 ucontrol
->value
.integer
.value
[0] = !(snd_es18xx_mixer_read(chip
, 0x61) & 0x40);
1110 ucontrol
->value
.integer
.value
[1] = !(snd_es18xx_mixer_read(chip
, 0x63) & 0x40);
1114 static void snd_es18xx_hwv_free(struct snd_kcontrol
*kcontrol
)
1116 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1117 chip
->master_volume
= NULL
;
1118 chip
->master_switch
= NULL
;
1119 chip
->hw_volume
= NULL
;
1120 chip
->hw_switch
= NULL
;
1123 static int snd_es18xx_reg_bits(struct snd_es18xx
*chip
, unsigned char reg
,
1124 unsigned char mask
, unsigned char val
)
1127 return snd_es18xx_mixer_bits(chip
, reg
, mask
, val
);
1129 return snd_es18xx_bits(chip
, reg
, mask
, val
);
1132 static int snd_es18xx_reg_read(struct snd_es18xx
*chip
, unsigned char reg
)
1135 return snd_es18xx_mixer_read(chip
, reg
);
1137 return snd_es18xx_read(chip
, reg
);
1140 #define ES18XX_SINGLE(xname, xindex, reg, shift, mask, invert) \
1141 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1142 .info = snd_es18xx_info_single, \
1143 .get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \
1144 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
1146 static int snd_es18xx_info_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1148 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1150 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1152 uinfo
->value
.integer
.min
= 0;
1153 uinfo
->value
.integer
.max
= mask
;
1157 static int snd_es18xx_get_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1159 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1160 int reg
= kcontrol
->private_value
& 0xff;
1161 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1162 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1163 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1166 val
= snd_es18xx_reg_read(chip
, reg
);
1167 ucontrol
->value
.integer
.value
[0] = (val
>> shift
) & mask
;
1169 ucontrol
->value
.integer
.value
[0] = mask
- ucontrol
->value
.integer
.value
[0];
1173 static int snd_es18xx_put_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1175 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1176 int reg
= kcontrol
->private_value
& 0xff;
1177 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1178 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1179 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1182 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1187 return snd_es18xx_reg_bits(chip
, reg
, mask
, val
) != val
;
1190 #define ES18XX_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
1191 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1192 .info = snd_es18xx_info_double, \
1193 .get = snd_es18xx_get_double, .put = snd_es18xx_put_double, \
1194 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
1196 static int snd_es18xx_info_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1198 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1200 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1202 uinfo
->value
.integer
.min
= 0;
1203 uinfo
->value
.integer
.max
= mask
;
1207 static int snd_es18xx_get_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1209 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1210 int left_reg
= kcontrol
->private_value
& 0xff;
1211 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
1212 int shift_left
= (kcontrol
->private_value
>> 16) & 0x07;
1213 int shift_right
= (kcontrol
->private_value
>> 19) & 0x07;
1214 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1215 int invert
= (kcontrol
->private_value
>> 22) & 1;
1216 unsigned char left
, right
;
1218 left
= snd_es18xx_reg_read(chip
, left_reg
);
1219 if (left_reg
!= right_reg
)
1220 right
= snd_es18xx_reg_read(chip
, right_reg
);
1223 ucontrol
->value
.integer
.value
[0] = (left
>> shift_left
) & mask
;
1224 ucontrol
->value
.integer
.value
[1] = (right
>> shift_right
) & mask
;
1226 ucontrol
->value
.integer
.value
[0] = mask
- ucontrol
->value
.integer
.value
[0];
1227 ucontrol
->value
.integer
.value
[1] = mask
- ucontrol
->value
.integer
.value
[1];
1232 static int snd_es18xx_put_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1234 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1235 int left_reg
= kcontrol
->private_value
& 0xff;
1236 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
1237 int shift_left
= (kcontrol
->private_value
>> 16) & 0x07;
1238 int shift_right
= (kcontrol
->private_value
>> 19) & 0x07;
1239 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1240 int invert
= (kcontrol
->private_value
>> 22) & 1;
1242 unsigned char val1
, val2
, mask1
, mask2
;
1244 val1
= ucontrol
->value
.integer
.value
[0] & mask
;
1245 val2
= ucontrol
->value
.integer
.value
[1] & mask
;
1250 val1
<<= shift_left
;
1251 val2
<<= shift_right
;
1252 mask1
= mask
<< shift_left
;
1253 mask2
= mask
<< shift_right
;
1254 if (left_reg
!= right_reg
) {
1256 if (snd_es18xx_reg_bits(chip
, left_reg
, mask1
, val1
) != val1
)
1258 if (snd_es18xx_reg_bits(chip
, right_reg
, mask2
, val2
) != val2
)
1261 change
= (snd_es18xx_reg_bits(chip
, left_reg
, mask1
| mask2
,
1262 val1
| val2
) != (val1
| val2
));
1268 * These arrays contain setup data for mixer controls.
1270 * The controls that are universal to all chipsets are fully initialized
1273 static struct snd_kcontrol_new snd_es18xx_base_controls
[] = {
1274 ES18XX_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0),
1275 ES18XX_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1),
1276 ES18XX_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0),
1277 ES18XX_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0),
1278 ES18XX_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0),
1279 ES18XX_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0),
1280 ES18XX_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0),
1281 ES18XX_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
1282 ES18XX_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0),
1284 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1285 .name
= "Capture Source",
1286 .info
= snd_es18xx_info_mux
,
1287 .get
= snd_es18xx_get_mux
,
1288 .put
= snd_es18xx_put_mux
,
1292 static struct snd_kcontrol_new snd_es18xx_recmix_controls
[] = {
1293 ES18XX_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0),
1294 ES18XX_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0),
1295 ES18XX_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0),
1296 ES18XX_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0),
1297 ES18XX_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0),
1298 ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0)
1302 * The chipset specific mixer controls
1304 static struct snd_kcontrol_new snd_es18xx_opt_speaker
=
1305 ES18XX_SINGLE("Beep Playback Volume", 0, 0x3c, 0, 7, 0);
1307 static struct snd_kcontrol_new snd_es18xx_opt_1869
[] = {
1308 ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
1309 ES18XX_SINGLE("Video Playback Switch", 0, 0x7f, 0, 1, 0),
1310 ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1311 ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0)
1314 static struct snd_kcontrol_new snd_es18xx_opt_1878
=
1315 ES18XX_DOUBLE("Video Playback Volume", 0, 0x68, 0x68, 4, 0, 15, 0);
1317 static struct snd_kcontrol_new snd_es18xx_opt_1879
[] = {
1318 ES18XX_SINGLE("Video Playback Switch", 0, 0x71, 6, 1, 0),
1319 ES18XX_DOUBLE("Video Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1320 ES18XX_DOUBLE("Video Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0)
1323 static struct snd_kcontrol_new snd_es18xx_pcm1_controls
[] = {
1324 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x14, 0x14, 4, 0, 15, 0),
1327 static struct snd_kcontrol_new snd_es18xx_pcm2_controls
[] = {
1328 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0),
1329 ES18XX_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0)
1332 static struct snd_kcontrol_new snd_es18xx_spatializer_controls
[] = {
1333 ES18XX_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
1335 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1336 .name
= "3D Control - Switch",
1337 .info
= snd_es18xx_info_spatializer_enable
,
1338 .get
= snd_es18xx_get_spatializer_enable
,
1339 .put
= snd_es18xx_put_spatializer_enable
,
1343 static struct snd_kcontrol_new snd_es18xx_micpre1_control
=
1344 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0xa9, 2, 1, 0);
1346 static struct snd_kcontrol_new snd_es18xx_micpre2_control
=
1347 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0);
1349 static struct snd_kcontrol_new snd_es18xx_hw_volume_controls
[] = {
1351 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1352 .name
= "Hardware Master Playback Volume",
1353 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1354 .info
= snd_es18xx_info_hw_volume
,
1355 .get
= snd_es18xx_get_hw_volume
,
1358 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1359 .name
= "Hardware Master Playback Switch",
1360 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1361 .info
= snd_es18xx_info_hw_switch
,
1362 .get
= snd_es18xx_get_hw_switch
,
1364 ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0),
1367 static int __devinit
snd_es18xx_config_read(struct snd_es18xx
*chip
, unsigned char reg
)
1371 outb(reg
, chip
->ctrl_port
);
1372 data
= inb(chip
->ctrl_port
+ 1);
1376 static void __devinit
snd_es18xx_config_write(struct snd_es18xx
*chip
,
1377 unsigned char reg
, unsigned char data
)
1379 /* No need for spinlocks, this function is used only in
1380 otherwise protected init code */
1381 outb(reg
, chip
->ctrl_port
);
1382 outb(data
, chip
->ctrl_port
+ 1);
1384 snd_printk(KERN_DEBUG
"Config reg %02x set to %02x\n", reg
, data
);
1388 static int __devinit
snd_es18xx_initialize(struct snd_es18xx
*chip
,
1389 unsigned long mpu_port
,
1390 unsigned long fm_port
)
1394 /* enable extended mode */
1395 snd_es18xx_dsp_command(chip
, 0xC6);
1396 /* Reset mixer registers */
1397 snd_es18xx_mixer_write(chip
, 0x00, 0x00);
1399 /* Audio 1 DMA demand mode (4 bytes/request) */
1400 snd_es18xx_write(chip
, 0xB9, 2);
1401 if (chip
->caps
& ES18XX_CONTROL
) {
1402 /* Hardware volume IRQ */
1403 snd_es18xx_config_write(chip
, 0x27, chip
->irq
);
1404 if (fm_port
> 0 && fm_port
!= SNDRV_AUTO_PORT
) {
1406 snd_es18xx_config_write(chip
, 0x62, fm_port
>> 8);
1407 snd_es18xx_config_write(chip
, 0x63, fm_port
& 0xff);
1409 if (mpu_port
> 0 && mpu_port
!= SNDRV_AUTO_PORT
) {
1411 snd_es18xx_config_write(chip
, 0x64, mpu_port
>> 8);
1412 snd_es18xx_config_write(chip
, 0x65, mpu_port
& 0xff);
1414 snd_es18xx_config_write(chip
, 0x28, chip
->irq
);
1417 snd_es18xx_config_write(chip
, 0x70, chip
->irq
);
1419 snd_es18xx_config_write(chip
, 0x72, chip
->irq
);
1421 snd_es18xx_config_write(chip
, 0x74, chip
->dma1
);
1423 snd_es18xx_config_write(chip
, 0x75, chip
->dma2
);
1425 /* Enable Audio 1 IRQ */
1426 snd_es18xx_write(chip
, 0xB1, 0x50);
1427 /* Enable Audio 2 IRQ */
1428 snd_es18xx_mixer_write(chip
, 0x7A, 0x40);
1429 /* Enable Audio 1 DMA */
1430 snd_es18xx_write(chip
, 0xB2, 0x50);
1431 /* Enable MPU and hardware volume interrupt */
1432 snd_es18xx_mixer_write(chip
, 0x64, 0x42);
1433 /* Enable ESS wavetable input */
1434 snd_es18xx_mixer_bits(chip
, 0x48, 0x10, 0x10);
1437 int irqmask
, dma1mask
, dma2mask
;
1438 switch (chip
->irq
) {
1453 snd_printk(KERN_ERR
"invalid irq %d\n", chip
->irq
);
1456 switch (chip
->dma1
) {
1467 snd_printk(KERN_ERR
"invalid dma1 %d\n", chip
->dma1
);
1470 switch (chip
->dma2
) {
1484 snd_printk(KERN_ERR
"invalid dma2 %d\n", chip
->dma2
);
1488 /* Enable and set Audio 1 IRQ */
1489 snd_es18xx_write(chip
, 0xB1, 0x50 | (irqmask
<< 2));
1490 /* Enable and set Audio 1 DMA */
1491 snd_es18xx_write(chip
, 0xB2, 0x50 | (dma1mask
<< 2));
1492 /* Set Audio 2 DMA */
1493 snd_es18xx_mixer_bits(chip
, 0x7d, 0x07, 0x04 | dma2mask
);
1494 /* Enable Audio 2 IRQ and DMA
1495 Set capture mixer input */
1496 snd_es18xx_mixer_write(chip
, 0x7A, 0x68);
1497 /* Enable and set hardware volume interrupt */
1498 snd_es18xx_mixer_write(chip
, 0x64, 0x06);
1499 if (mpu_port
> 0 && mpu_port
!= SNDRV_AUTO_PORT
) {
1500 /* MPU401 share irq with audio
1503 snd_es18xx_mixer_write(chip
, 0x40,
1504 0x43 | (mpu_port
& 0xf0) >> 1);
1506 snd_es18xx_mixer_write(chip
, 0x7f, ((irqmask
+ 1) << 1) | 0x01);
1508 if (chip
->caps
& ES18XX_NEW_RATE
) {
1509 /* Change behaviour of register A1
1511 2nd channel DAC asynchronous */
1512 snd_es18xx_mixer_write(chip
, 0x71, 0x32);
1514 if (!(chip
->caps
& ES18XX_PCM2
)) {
1515 /* Enable DMA FIFO */
1516 snd_es18xx_write(chip
, 0xB7, 0x80);
1518 if (chip
->caps
& ES18XX_SPATIALIZER
) {
1519 /* Set spatializer parameters to recommended values */
1520 snd_es18xx_mixer_write(chip
, 0x54, 0x8f);
1521 snd_es18xx_mixer_write(chip
, 0x56, 0x95);
1522 snd_es18xx_mixer_write(chip
, 0x58, 0x94);
1523 snd_es18xx_mixer_write(chip
, 0x5a, 0x80);
1525 /* Flip the "enable I2S" bits for those chipsets that need it */
1526 switch (chip
->version
) {
1528 //Leaving I2S enabled on the 1879 screws up the PCM playback (rate effected somehow)
1529 //so a Switch control has been added to toggle this 0x71 bit on/off:
1530 //snd_es18xx_mixer_bits(chip, 0x71, 0x40, 0x40);
1531 /* Note: we fall through on purpose here. */
1533 snd_es18xx_config_write(chip
, 0x29, snd_es18xx_config_read(chip
, 0x29) | 0x40);
1536 /* Mute input source */
1537 if (chip
->caps
& ES18XX_MUTEREC
)
1539 if (chip
->caps
& ES18XX_RECMIX
)
1540 snd_es18xx_mixer_write(chip
, 0x1c, 0x05 | mask
);
1542 snd_es18xx_mixer_write(chip
, 0x1c, 0x00 | mask
);
1543 snd_es18xx_write(chip
, 0xb4, 0x00);
1546 /* Enable PCM output */
1547 snd_es18xx_dsp_command(chip
, 0xD1);
1553 static int __devinit
snd_es18xx_identify(struct snd_es18xx
*chip
)
1558 if (snd_es18xx_reset(chip
) < 0) {
1559 snd_printk(KERN_ERR
"reset at 0x%lx failed!!!\n", chip
->port
);
1563 snd_es18xx_dsp_command(chip
, 0xe7);
1564 hi
= snd_es18xx_dsp_get_byte(chip
);
1568 lo
= snd_es18xx_dsp_get_byte(chip
);
1569 if ((lo
& 0xf0) != 0x80) {
1573 chip
->version
= 0x488;
1579 if ((lo
& 0x0f) < 8) {
1580 chip
->version
= 0x688;
1584 outb(0x40, chip
->port
+ 0x04);
1586 hi
= inb(chip
->port
+ 0x05);
1588 lo
= inb(chip
->port
+ 0x05);
1590 chip
->version
= hi
<< 8 | lo
;
1591 chip
->ctrl_port
= inb(chip
->port
+ 0x05) << 8;
1593 chip
->ctrl_port
+= inb(chip
->port
+ 0x05);
1595 if ((chip
->res_ctrl_port
= request_region(chip
->ctrl_port
, 8, "ES18xx - CTRL")) == NULL
) {
1596 snd_printk(KERN_ERR PFX
"unable go grab port 0x%lx\n", chip
->ctrl_port
);
1603 /* If has Hardware volume */
1604 if (snd_es18xx_mixer_writable(chip
, 0x64, 0x04)) {
1606 if (snd_es18xx_mixer_writable(chip
, 0x70, 0x7f)) {
1607 /* If has volume count */
1608 if (snd_es18xx_mixer_writable(chip
, 0x64, 0x20)) {
1609 chip
->version
= 0x1887;
1611 chip
->version
= 0x1888;
1614 chip
->version
= 0x1788;
1618 chip
->version
= 0x1688;
1622 static int __devinit
snd_es18xx_probe(struct snd_es18xx
*chip
,
1623 unsigned long mpu_port
,
1624 unsigned long fm_port
)
1626 if (snd_es18xx_identify(chip
) < 0) {
1627 snd_printk(KERN_ERR PFX
"[0x%lx] ESS chip not found\n", chip
->port
);
1631 switch (chip
->version
) {
1633 chip
->caps
= ES18XX_DUPLEX_MONO
| ES18XX_DUPLEX_SAME
| ES18XX_CONTROL
;
1636 chip
->caps
= ES18XX_PCM2
| ES18XX_SPATIALIZER
| ES18XX_RECMIX
| ES18XX_NEW_RATE
| ES18XX_AUXB
| ES18XX_MONO
| ES18XX_MUTEREC
| ES18XX_CONTROL
| ES18XX_HWV
;
1639 chip
->caps
= ES18XX_DUPLEX_MONO
| ES18XX_DUPLEX_SAME
| ES18XX_I2S
| ES18XX_CONTROL
;
1642 chip
->caps
= ES18XX_PCM2
| ES18XX_SPATIALIZER
| ES18XX_RECMIX
| ES18XX_NEW_RATE
| ES18XX_AUXB
| ES18XX_I2S
| ES18XX_CONTROL
| ES18XX_HWV
;
1646 chip
->caps
= ES18XX_PCM2
| ES18XX_RECMIX
| ES18XX_AUXB
| ES18XX_DUPLEX_SAME
;
1649 snd_printk(KERN_ERR
"[0x%lx] unsupported chip ES%x\n",
1650 chip
->port
, chip
->version
);
1654 snd_printd("[0x%lx] ESS%x chip found\n", chip
->port
, chip
->version
);
1656 if (chip
->dma1
== chip
->dma2
)
1657 chip
->caps
&= ~(ES18XX_PCM2
| ES18XX_DUPLEX_SAME
);
1659 return snd_es18xx_initialize(chip
, mpu_port
, fm_port
);
1662 static struct snd_pcm_ops snd_es18xx_playback_ops
= {
1663 .open
= snd_es18xx_playback_open
,
1664 .close
= snd_es18xx_playback_close
,
1665 .ioctl
= snd_pcm_lib_ioctl
,
1666 .hw_params
= snd_es18xx_playback_hw_params
,
1667 .hw_free
= snd_es18xx_pcm_hw_free
,
1668 .prepare
= snd_es18xx_playback_prepare
,
1669 .trigger
= snd_es18xx_playback_trigger
,
1670 .pointer
= snd_es18xx_playback_pointer
,
1673 static struct snd_pcm_ops snd_es18xx_capture_ops
= {
1674 .open
= snd_es18xx_capture_open
,
1675 .close
= snd_es18xx_capture_close
,
1676 .ioctl
= snd_pcm_lib_ioctl
,
1677 .hw_params
= snd_es18xx_capture_hw_params
,
1678 .hw_free
= snd_es18xx_pcm_hw_free
,
1679 .prepare
= snd_es18xx_capture_prepare
,
1680 .trigger
= snd_es18xx_capture_trigger
,
1681 .pointer
= snd_es18xx_capture_pointer
,
1684 static int __devinit
snd_es18xx_pcm(struct snd_card
*card
, int device
,
1685 struct snd_pcm
**rpcm
)
1687 struct snd_es18xx
*chip
= card
->private_data
;
1688 struct snd_pcm
*pcm
;
1694 sprintf(str
, "ES%x", chip
->version
);
1695 if (chip
->caps
& ES18XX_PCM2
)
1696 err
= snd_pcm_new(card
, str
, device
, 2, 1, &pcm
);
1698 err
= snd_pcm_new(card
, str
, device
, 1, 1, &pcm
);
1702 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_es18xx_playback_ops
);
1703 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_es18xx_capture_ops
);
1706 pcm
->private_data
= chip
;
1707 pcm
->info_flags
= 0;
1708 if (chip
->caps
& ES18XX_DUPLEX_SAME
)
1709 pcm
->info_flags
|= SNDRV_PCM_INFO_JOINT_DUPLEX
;
1710 if (! (chip
->caps
& ES18XX_PCM2
))
1711 pcm
->info_flags
|= SNDRV_PCM_INFO_HALF_DUPLEX
;
1712 sprintf(pcm
->name
, "ESS AudioDrive ES%x", chip
->version
);
1715 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1718 chip
->dma1
> 3 || chip
->dma2
> 3 ? 128*1024 : 64*1024);
1725 /* Power Management support functions */
1727 static int snd_es18xx_suspend(struct snd_card
*card
, pm_message_t state
)
1729 struct snd_es18xx
*chip
= card
->private_data
;
1731 snd_power_change_state(card
, SNDRV_CTL_POWER_D3hot
);
1733 snd_pcm_suspend_all(chip
->pcm
);
1736 chip
->pm_reg
= (unsigned char)snd_es18xx_read(chip
, ES18XX_PM
);
1737 chip
->pm_reg
|= (ES18XX_PM_FM
| ES18XX_PM_SUS
);
1738 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
);
1739 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
^= ES18XX_PM_SUS
);
1744 static int snd_es18xx_resume(struct snd_card
*card
)
1746 struct snd_es18xx
*chip
= card
->private_data
;
1748 /* restore PM register, we won't wake till (not 0x07) i/o activity though */
1749 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
^= ES18XX_PM_FM
);
1751 snd_power_change_state(card
, SNDRV_CTL_POWER_D0
);
1754 #endif /* CONFIG_PM */
1756 static int snd_es18xx_free(struct snd_card
*card
)
1758 struct snd_es18xx
*chip
= card
->private_data
;
1760 release_and_free_resource(chip
->res_port
);
1761 release_and_free_resource(chip
->res_ctrl_port
);
1762 release_and_free_resource(chip
->res_mpu_port
);
1764 free_irq(chip
->irq
, (void *) card
);
1765 if (chip
->dma1
>= 0) {
1766 disable_dma(chip
->dma1
);
1767 free_dma(chip
->dma1
);
1769 if (chip
->dma2
>= 0 && chip
->dma1
!= chip
->dma2
) {
1770 disable_dma(chip
->dma2
);
1771 free_dma(chip
->dma2
);
1776 static int snd_es18xx_dev_free(struct snd_device
*device
)
1778 return snd_es18xx_free(device
->card
);
1781 static int __devinit
snd_es18xx_new_device(struct snd_card
*card
,
1783 unsigned long mpu_port
,
1784 unsigned long fm_port
,
1785 int irq
, int dma1
, int dma2
)
1787 struct snd_es18xx
*chip
= card
->private_data
;
1788 static struct snd_device_ops ops
= {
1789 .dev_free
= snd_es18xx_dev_free
,
1793 spin_lock_init(&chip
->reg_lock
);
1794 spin_lock_init(&chip
->mixer_lock
);
1799 chip
->audio2_vol
= 0x00;
1802 chip
->res_port
= request_region(port
, 16, "ES18xx");
1803 if (chip
->res_port
== NULL
) {
1804 snd_es18xx_free(card
);
1805 snd_printk(KERN_ERR PFX
"unable to grap ports 0x%lx-0x%lx\n", port
, port
+ 16 - 1);
1809 if (request_irq(irq
, snd_es18xx_interrupt
, IRQF_DISABLED
, "ES18xx",
1811 snd_es18xx_free(card
);
1812 snd_printk(KERN_ERR PFX
"unable to grap IRQ %d\n", irq
);
1817 if (request_dma(dma1
, "ES18xx DMA 1")) {
1818 snd_es18xx_free(card
);
1819 snd_printk(KERN_ERR PFX
"unable to grap DMA1 %d\n", dma1
);
1824 if (dma2
!= dma1
&& request_dma(dma2
, "ES18xx DMA 2")) {
1825 snd_es18xx_free(card
);
1826 snd_printk(KERN_ERR PFX
"unable to grap DMA2 %d\n", dma2
);
1831 if (snd_es18xx_probe(chip
, mpu_port
, fm_port
) < 0) {
1832 snd_es18xx_free(card
);
1835 err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
);
1837 snd_es18xx_free(card
);
1843 static int __devinit
snd_es18xx_mixer(struct snd_card
*card
)
1845 struct snd_es18xx
*chip
= card
->private_data
;
1849 strcpy(card
->mixername
, chip
->pcm
->name
);
1851 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_base_controls
); idx
++) {
1852 struct snd_kcontrol
*kctl
;
1853 kctl
= snd_ctl_new1(&snd_es18xx_base_controls
[idx
], chip
);
1854 if (chip
->caps
& ES18XX_HWV
) {
1857 chip
->master_volume
= kctl
;
1858 kctl
->private_free
= snd_es18xx_hwv_free
;
1861 chip
->master_switch
= kctl
;
1862 kctl
->private_free
= snd_es18xx_hwv_free
;
1866 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
1869 if (chip
->caps
& ES18XX_PCM2
) {
1870 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_pcm2_controls
); idx
++) {
1871 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_pcm2_controls
[idx
], chip
))) < 0)
1875 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_pcm1_controls
); idx
++) {
1876 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_pcm1_controls
[idx
], chip
))) < 0)
1881 if (chip
->caps
& ES18XX_RECMIX
) {
1882 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_recmix_controls
); idx
++) {
1883 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_recmix_controls
[idx
], chip
))) < 0)
1887 switch (chip
->version
) {
1889 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_micpre1_control
, chip
))) < 0)
1894 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_micpre2_control
, chip
))) < 0)
1898 if (chip
->caps
& ES18XX_SPATIALIZER
) {
1899 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_spatializer_controls
); idx
++) {
1900 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_spatializer_controls
[idx
], chip
))) < 0)
1904 if (chip
->caps
& ES18XX_HWV
) {
1905 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_hw_volume_controls
); idx
++) {
1906 struct snd_kcontrol
*kctl
;
1907 kctl
= snd_ctl_new1(&snd_es18xx_hw_volume_controls
[idx
], chip
);
1909 chip
->hw_volume
= kctl
;
1911 chip
->hw_switch
= kctl
;
1912 kctl
->private_free
= snd_es18xx_hwv_free
;
1913 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
1918 /* finish initializing other chipset specific controls
1920 if (chip
->version
!= 0x1868) {
1921 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_opt_speaker
,
1926 if (chip
->version
== 0x1869) {
1927 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_opt_1869
); idx
++) {
1928 err
= snd_ctl_add(card
,
1929 snd_ctl_new1(&snd_es18xx_opt_1869
[idx
],
1934 } else if (chip
->version
== 0x1878) {
1935 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_opt_1878
,
1939 } else if (chip
->version
== 0x1879) {
1940 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_opt_1879
); idx
++) {
1941 err
= snd_ctl_add(card
,
1942 snd_ctl_new1(&snd_es18xx_opt_1879
[idx
],
1954 MODULE_AUTHOR("Christian Fischbach <fishbach@pool.informatik.rwth-aachen.de>, Abramo Bagnara <abramo@alsa-project.org>");
1955 MODULE_DESCRIPTION("ESS ES18xx AudioDrive");
1956 MODULE_LICENSE("GPL");
1957 MODULE_SUPPORTED_DEVICE("{{ESS,ES1868 PnP AudioDrive},"
1958 "{ESS,ES1869 PnP AudioDrive},"
1959 "{ESS,ES1878 PnP AudioDrive},"
1960 "{ESS,ES1879 PnP AudioDrive},"
1961 "{ESS,ES1887 PnP AudioDrive},"
1962 "{ESS,ES1888 PnP AudioDrive},"
1963 "{ESS,ES1887 AudioDrive},"
1964 "{ESS,ES1888 AudioDrive}}");
1966 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
1967 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
1968 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_ISAPNP
; /* Enable this card */
1970 static int isapnp
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_ISAPNP
;
1972 static long port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
; /* 0x220,0x240,0x260,0x280 */
1974 static long mpu_port
[SNDRV_CARDS
] = {[0 ... (SNDRV_CARDS
- 1)] = -1};
1976 static long mpu_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
1978 static long fm_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
1979 static int irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
; /* 5,7,9,10 */
1980 static int dma1
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* 0,1,3 */
1981 static int dma2
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* 0,1,3 */
1983 module_param_array(index
, int, NULL
, 0444);
1984 MODULE_PARM_DESC(index
, "Index value for ES18xx soundcard.");
1985 module_param_array(id
, charp
, NULL
, 0444);
1986 MODULE_PARM_DESC(id
, "ID string for ES18xx soundcard.");
1987 module_param_array(enable
, bool, NULL
, 0444);
1988 MODULE_PARM_DESC(enable
, "Enable ES18xx soundcard.");
1990 module_param_array(isapnp
, bool, NULL
, 0444);
1991 MODULE_PARM_DESC(isapnp
, "PnP detection for specified soundcard.");
1993 module_param_array(port
, long, NULL
, 0444);
1994 MODULE_PARM_DESC(port
, "Port # for ES18xx driver.");
1995 module_param_array(mpu_port
, long, NULL
, 0444);
1996 MODULE_PARM_DESC(mpu_port
, "MPU-401 port # for ES18xx driver.");
1997 module_param_array(fm_port
, long, NULL
, 0444);
1998 MODULE_PARM_DESC(fm_port
, "FM port # for ES18xx driver.");
1999 module_param_array(irq
, int, NULL
, 0444);
2000 MODULE_PARM_DESC(irq
, "IRQ # for ES18xx driver.");
2001 module_param_array(dma1
, int, NULL
, 0444);
2002 MODULE_PARM_DESC(dma1
, "DMA 1 # for ES18xx driver.");
2003 module_param_array(dma2
, int, NULL
, 0444);
2004 MODULE_PARM_DESC(dma2
, "DMA 2 # for ES18xx driver.");
2007 static int isa_registered
;
2008 static int pnp_registered
;
2009 static int pnpc_registered
;
2011 static struct pnp_device_id snd_audiodrive_pnpbiosids
[] = {
2012 { .id
= "ESS1869" },
2013 { .id
= "ESS1879" },
2014 { .id
= "" } /* end */
2017 MODULE_DEVICE_TABLE(pnp
, snd_audiodrive_pnpbiosids
);
2019 /* PnP main device initialization */
2020 static int __devinit
snd_audiodrive_pnp_init_main(int dev
, struct pnp_dev
*pdev
)
2022 if (pnp_activate_dev(pdev
) < 0) {
2023 snd_printk(KERN_ERR PFX
"PnP configure failure (out of resources?)\n");
2026 /* ok. hack using Vendor-Defined Card-Level registers */
2027 /* skip csn and logdev initialization - already done in isapnp_configure */
2028 if (pnp_device_is_isapnp(pdev
)) {
2029 isapnp_cfg_begin(isapnp_card_number(pdev
), isapnp_csn_number(pdev
));
2030 isapnp_write_byte(0x27, pnp_irq(pdev
, 0)); /* Hardware Volume IRQ Number */
2031 if (mpu_port
[dev
] != SNDRV_AUTO_PORT
)
2032 isapnp_write_byte(0x28, pnp_irq(pdev
, 0)); /* MPU-401 IRQ Number */
2033 isapnp_write_byte(0x72, pnp_irq(pdev
, 0)); /* second IRQ */
2036 port
[dev
] = pnp_port_start(pdev
, 0);
2037 fm_port
[dev
] = pnp_port_start(pdev
, 1);
2038 mpu_port
[dev
] = pnp_port_start(pdev
, 2);
2039 dma1
[dev
] = pnp_dma(pdev
, 0);
2040 dma2
[dev
] = pnp_dma(pdev
, 1);
2041 irq
[dev
] = pnp_irq(pdev
, 0);
2042 snd_printdd("PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port
[dev
], fm_port
[dev
], mpu_port
[dev
]);
2043 snd_printdd("PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1
[dev
], dma2
[dev
], irq
[dev
]);
2047 static int __devinit
snd_audiodrive_pnp(int dev
, struct snd_es18xx
*chip
,
2048 struct pnp_dev
*pdev
)
2051 if (snd_audiodrive_pnp_init_main(dev
, chip
->dev
) < 0)
2056 static struct pnp_card_device_id snd_audiodrive_pnpids
[] = {
2057 /* ESS 1868 (integrated on Compaq dual P-Pro motherboard and Genius 18PnP 3D) */
2058 { .id
= "ESS1868", .devs
= { { "ESS1868" }, { "ESS0000" } } },
2059 /* ESS 1868 (integrated on Maxisound Cards) */
2060 { .id
= "ESS1868", .devs
= { { "ESS8601" }, { "ESS8600" } } },
2061 /* ESS 1868 (integrated on Maxisound Cards) */
2062 { .id
= "ESS1868", .devs
= { { "ESS8611" }, { "ESS8610" } } },
2063 /* ESS ES1869 Plug and Play AudioDrive */
2064 { .id
= "ESS0003", .devs
= { { "ESS1869" }, { "ESS0006" } } },
2066 { .id
= "ESS1869", .devs
= { { "ESS1869" }, { "ESS0006" } } },
2068 { .id
= "ESS1878", .devs
= { { "ESS1878" }, { "ESS0004" } } },
2070 { .id
= "ESS1879", .devs
= { { "ESS1879" }, { "ESS0009" } } },
2072 { .id
= "" } /* end */
2075 MODULE_DEVICE_TABLE(pnp_card
, snd_audiodrive_pnpids
);
2077 static int __devinit
snd_audiodrive_pnpc(int dev
, struct snd_es18xx
*chip
,
2078 struct pnp_card_link
*card
,
2079 const struct pnp_card_device_id
*id
)
2081 chip
->dev
= pnp_request_card_device(card
, id
->devs
[0].id
, NULL
);
2082 if (chip
->dev
== NULL
)
2085 chip
->devc
= pnp_request_card_device(card
, id
->devs
[1].id
, NULL
);
2086 if (chip
->devc
== NULL
)
2089 /* Control port initialization */
2090 if (pnp_activate_dev(chip
->devc
) < 0) {
2091 snd_printk(KERN_ERR PFX
"PnP control configure failure (out of resources?)\n");
2094 snd_printdd("pnp: port=0x%llx\n",
2095 (unsigned long long)pnp_port_start(chip
->devc
, 0));
2096 if (snd_audiodrive_pnp_init_main(dev
, chip
->dev
) < 0)
2101 #endif /* CONFIG_PNP */
2104 #define is_isapnp_selected(dev) isapnp[dev]
2106 #define is_isapnp_selected(dev) 0
2109 static int snd_es18xx_card_new(int dev
, struct snd_card
**cardp
)
2111 return snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
,
2112 sizeof(struct snd_es18xx
), cardp
);
2115 static int __devinit
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
,
2165 irq
[dev
], 0, &chip
->rmidi
);
2170 return snd_card_register(card
);
2173 static int __devinit
snd_es18xx_isa_match(struct device
*pdev
, unsigned int dev
)
2175 return enable
[dev
] && !is_isapnp_selected(dev
);
2178 static int __devinit
snd_es18xx_isa_probe1(int dev
, struct device
*devptr
)
2180 struct snd_card
*card
;
2183 err
= snd_es18xx_card_new(dev
, &card
);
2186 snd_card_set_dev(card
, devptr
);
2187 if ((err
= snd_audiodrive_probe(card
, dev
)) < 0) {
2188 snd_card_free(card
);
2191 dev_set_drvdata(devptr
, card
);
2195 static int __devinit
snd_es18xx_isa_probe(struct device
*pdev
, unsigned int dev
)
2198 static int possible_irqs
[] = {5, 9, 10, 7, 11, 12, -1};
2199 static int possible_dmas
[] = {1, 0, 3, 5, -1};
2201 if (irq
[dev
] == SNDRV_AUTO_IRQ
) {
2202 if ((irq
[dev
] = snd_legacy_find_free_irq(possible_irqs
)) < 0) {
2203 snd_printk(KERN_ERR PFX
"unable to find a free IRQ\n");
2207 if (dma1
[dev
] == SNDRV_AUTO_DMA
) {
2208 if ((dma1
[dev
] = snd_legacy_find_free_dma(possible_dmas
)) < 0) {
2209 snd_printk(KERN_ERR PFX
"unable to find a free DMA1\n");
2213 if (dma2
[dev
] == SNDRV_AUTO_DMA
) {
2214 if ((dma2
[dev
] = snd_legacy_find_free_dma(possible_dmas
)) < 0) {
2215 snd_printk(KERN_ERR PFX
"unable to find a free DMA2\n");
2220 if (port
[dev
] != SNDRV_AUTO_PORT
) {
2221 return snd_es18xx_isa_probe1(dev
, pdev
);
2223 static unsigned long possible_ports
[] = {0x220, 0x240, 0x260, 0x280};
2225 for (i
= 0; i
< ARRAY_SIZE(possible_ports
); i
++) {
2226 port
[dev
] = possible_ports
[i
];
2227 err
= snd_es18xx_isa_probe1(dev
, pdev
);
2235 static int __devexit
snd_es18xx_isa_remove(struct device
*devptr
,
2238 snd_card_free(dev_get_drvdata(devptr
));
2239 dev_set_drvdata(devptr
, NULL
);
2244 static int snd_es18xx_isa_suspend(struct device
*dev
, unsigned int n
,
2247 return snd_es18xx_suspend(dev_get_drvdata(dev
), state
);
2250 static int snd_es18xx_isa_resume(struct device
*dev
, unsigned int n
)
2252 return snd_es18xx_resume(dev_get_drvdata(dev
));
2256 #define DEV_NAME "es18xx"
2258 static struct isa_driver snd_es18xx_isa_driver
= {
2259 .match
= snd_es18xx_isa_match
,
2260 .probe
= snd_es18xx_isa_probe
,
2261 .remove
= __devexit_p(snd_es18xx_isa_remove
),
2263 .suspend
= snd_es18xx_isa_suspend
,
2264 .resume
= snd_es18xx_isa_resume
,
2273 static int __devinit
snd_audiodrive_pnp_detect(struct pnp_dev
*pdev
,
2274 const struct pnp_device_id
*id
)
2278 struct snd_card
*card
;
2280 if (pnp_device_is_isapnp(pdev
))
2281 return -ENOENT
; /* we have another procedure - card */
2282 for (; dev
< SNDRV_CARDS
; dev
++) {
2283 if (enable
[dev
] && isapnp
[dev
])
2286 if (dev
>= SNDRV_CARDS
)
2289 err
= snd_es18xx_card_new(dev
, &card
);
2292 if ((err
= snd_audiodrive_pnp(dev
, card
->private_data
, pdev
)) < 0) {
2293 snd_card_free(card
);
2296 snd_card_set_dev(card
, &pdev
->dev
);
2297 if ((err
= snd_audiodrive_probe(card
, dev
)) < 0) {
2298 snd_card_free(card
);
2301 pnp_set_drvdata(pdev
, card
);
2306 static void __devexit
snd_audiodrive_pnp_remove(struct pnp_dev
* pdev
)
2308 snd_card_free(pnp_get_drvdata(pdev
));
2309 pnp_set_drvdata(pdev
, NULL
);
2313 static int snd_audiodrive_pnp_suspend(struct pnp_dev
*pdev
, pm_message_t state
)
2315 return snd_es18xx_suspend(pnp_get_drvdata(pdev
), state
);
2317 static int snd_audiodrive_pnp_resume(struct pnp_dev
*pdev
)
2319 return snd_es18xx_resume(pnp_get_drvdata(pdev
));
2323 static struct pnp_driver es18xx_pnp_driver
= {
2324 .name
= "es18xx-pnpbios",
2325 .id_table
= snd_audiodrive_pnpbiosids
,
2326 .probe
= snd_audiodrive_pnp_detect
,
2327 .remove
= __devexit_p(snd_audiodrive_pnp_remove
),
2329 .suspend
= snd_audiodrive_pnp_suspend
,
2330 .resume
= snd_audiodrive_pnp_resume
,
2334 static int __devinit
snd_audiodrive_pnpc_detect(struct pnp_card_link
*pcard
,
2335 const struct pnp_card_device_id
*pid
)
2338 struct snd_card
*card
;
2341 for ( ; dev
< SNDRV_CARDS
; dev
++) {
2342 if (enable
[dev
] && isapnp
[dev
])
2345 if (dev
>= SNDRV_CARDS
)
2348 res
= snd_es18xx_card_new(dev
, &card
);
2352 if ((res
= snd_audiodrive_pnpc(dev
, card
->private_data
, pcard
, pid
)) < 0) {
2353 snd_card_free(card
);
2356 snd_card_set_dev(card
, &pcard
->card
->dev
);
2357 if ((res
= snd_audiodrive_probe(card
, dev
)) < 0) {
2358 snd_card_free(card
);
2362 pnp_set_card_drvdata(pcard
, card
);
2367 static void __devexit
snd_audiodrive_pnpc_remove(struct pnp_card_link
* pcard
)
2369 snd_card_free(pnp_get_card_drvdata(pcard
));
2370 pnp_set_card_drvdata(pcard
, NULL
);
2374 static int snd_audiodrive_pnpc_suspend(struct pnp_card_link
*pcard
, pm_message_t state
)
2376 return snd_es18xx_suspend(pnp_get_card_drvdata(pcard
), state
);
2379 static int snd_audiodrive_pnpc_resume(struct pnp_card_link
*pcard
)
2381 return snd_es18xx_resume(pnp_get_card_drvdata(pcard
));
2386 static struct pnp_card_driver es18xx_pnpc_driver
= {
2387 .flags
= PNP_DRIVER_RES_DISABLE
,
2389 .id_table
= snd_audiodrive_pnpids
,
2390 .probe
= snd_audiodrive_pnpc_detect
,
2391 .remove
= __devexit_p(snd_audiodrive_pnpc_remove
),
2393 .suspend
= snd_audiodrive_pnpc_suspend
,
2394 .resume
= snd_audiodrive_pnpc_resume
,
2397 #endif /* CONFIG_PNP */
2399 static int __init
alsa_card_es18xx_init(void)
2403 err
= isa_register_driver(&snd_es18xx_isa_driver
, SNDRV_CARDS
);
2408 err
= pnp_register_driver(&es18xx_pnp_driver
);
2412 err
= pnp_register_card_driver(&es18xx_pnpc_driver
);
2414 pnpc_registered
= 1;
2416 if (isa_registered
|| pnp_registered
)
2422 static void __exit
alsa_card_es18xx_exit(void)
2425 if (pnpc_registered
)
2426 pnp_unregister_card_driver(&es18xx_pnpc_driver
);
2428 pnp_unregister_driver(&es18xx_pnp_driver
);
2431 isa_unregister_driver(&snd_es18xx_isa_driver
);
2434 module_init(alsa_card_es18xx_init
)
2435 module_exit(alsa_card_es18xx_exit
)