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 mpu_port
; /* MPU-401 port of ESS chip */
106 unsigned long fm_port
; /* FM port */
107 unsigned long ctrl_port
; /* Control port of ESS chip */
108 struct resource
*res_port
;
109 struct resource
*res_mpu_port
;
110 struct resource
*res_ctrl_port
;
111 int irq
; /* IRQ number of ESS chip */
114 unsigned short version
; /* version of ESS chip */
115 int caps
; /* Chip capabilities */
116 unsigned short audio2_vol
; /* volume level of audio2 */
118 unsigned short active
; /* active channel mask */
119 unsigned int dma1_size
;
120 unsigned int dma2_size
;
121 unsigned int dma1_shift
;
122 unsigned int dma2_shift
;
124 struct snd_card
*card
;
126 struct snd_pcm_substream
*playback_a_substream
;
127 struct snd_pcm_substream
*capture_a_substream
;
128 struct snd_pcm_substream
*playback_b_substream
;
130 struct snd_rawmidi
*rmidi
;
132 struct snd_kcontrol
*hw_volume
;
133 struct snd_kcontrol
*hw_switch
;
134 struct snd_kcontrol
*master_volume
;
135 struct snd_kcontrol
*master_switch
;
138 spinlock_t mixer_lock
;
139 spinlock_t ctrl_lock
;
141 unsigned char pm_reg
;
145 struct snd_audiodrive
{
146 struct snd_es18xx
*chip
;
149 struct pnp_dev
*devc
;
153 #define AUDIO1_IRQ 0x01
154 #define AUDIO2_IRQ 0x02
158 #define ES18XX_PCM2 0x0001 /* Has two useable PCM */
159 #define ES18XX_SPATIALIZER 0x0002 /* Has 3D Spatializer */
160 #define ES18XX_RECMIX 0x0004 /* Has record mixer */
161 #define ES18XX_DUPLEX_MONO 0x0008 /* Has mono duplex only */
162 #define ES18XX_DUPLEX_SAME 0x0010 /* Playback and record must share the same rate */
163 #define ES18XX_NEW_RATE 0x0020 /* More precise rate setting */
164 #define ES18XX_AUXB 0x0040 /* AuxB mixer control */
165 #define ES18XX_HWV 0x0080 /* Has separate hardware volume mixer controls*/
166 #define ES18XX_MONO 0x0100 /* Mono_in mixer control */
167 #define ES18XX_I2S 0x0200 /* I2S mixer control */
168 #define ES18XX_MUTEREC 0x0400 /* Record source can be muted */
169 #define ES18XX_CONTROL 0x0800 /* Has control ports */
171 /* Power Management */
172 #define ES18XX_PM 0x07
173 #define ES18XX_PM_GPO0 0x01
174 #define ES18XX_PM_GPO1 0x02
175 #define ES18XX_PM_PDR 0x04
176 #define ES18XX_PM_ANA 0x08
177 #define ES18XX_PM_FM 0x020
178 #define ES18XX_PM_SUS 0x080
185 #define MILLISECOND 10000
187 static int snd_es18xx_dsp_command(struct snd_es18xx
*chip
, unsigned char val
)
191 for(i
= MILLISECOND
; i
; i
--)
192 if ((inb(chip
->port
+ 0x0C) & 0x80) == 0) {
193 outb(val
, chip
->port
+ 0x0C);
196 snd_printk(KERN_ERR
"dsp_command: timeout (0x%x)\n", val
);
200 static int snd_es18xx_dsp_get_byte(struct snd_es18xx
*chip
)
204 for(i
= MILLISECOND
/10; i
; i
--)
205 if (inb(chip
->port
+ 0x0C) & 0x40)
206 return inb(chip
->port
+ 0x0A);
207 snd_printk(KERN_ERR
"dsp_get_byte failed: 0x%lx = 0x%x!!!\n",
208 chip
->port
+ 0x0A, inb(chip
->port
+ 0x0A));
214 static int snd_es18xx_write(struct snd_es18xx
*chip
,
215 unsigned char reg
, unsigned char data
)
220 spin_lock_irqsave(&chip
->reg_lock
, flags
);
221 ret
= snd_es18xx_dsp_command(chip
, reg
);
224 ret
= snd_es18xx_dsp_command(chip
, data
);
226 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
228 snd_printk(KERN_DEBUG
"Reg %02x set to %02x\n", reg
, data
);
233 static int snd_es18xx_read(struct snd_es18xx
*chip
, unsigned char reg
)
237 spin_lock_irqsave(&chip
->reg_lock
, flags
);
238 ret
= snd_es18xx_dsp_command(chip
, 0xC0);
241 ret
= snd_es18xx_dsp_command(chip
, reg
);
244 data
= snd_es18xx_dsp_get_byte(chip
);
247 snd_printk(KERN_DEBUG
"Reg %02x now is %02x (%d)\n", reg
, data
, ret
);
250 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
254 /* Return old value */
255 static int snd_es18xx_bits(struct snd_es18xx
*chip
, unsigned char reg
,
256 unsigned char mask
, unsigned char val
)
259 unsigned char old
, new, oval
;
261 spin_lock_irqsave(&chip
->reg_lock
, flags
);
262 ret
= snd_es18xx_dsp_command(chip
, 0xC0);
265 ret
= snd_es18xx_dsp_command(chip
, reg
);
268 ret
= snd_es18xx_dsp_get_byte(chip
);
275 ret
= snd_es18xx_dsp_command(chip
, reg
);
278 new = (old
& ~mask
) | (val
& mask
);
279 ret
= snd_es18xx_dsp_command(chip
, new);
283 snd_printk(KERN_DEBUG
"Reg %02x was %02x, set to %02x (%d)\n",
289 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
293 static inline void snd_es18xx_mixer_write(struct snd_es18xx
*chip
,
294 unsigned char reg
, unsigned char data
)
297 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
298 outb(reg
, chip
->port
+ 0x04);
299 outb(data
, chip
->port
+ 0x05);
300 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
302 snd_printk(KERN_DEBUG
"Mixer reg %02x set to %02x\n", reg
, data
);
306 static inline int snd_es18xx_mixer_read(struct snd_es18xx
*chip
, unsigned char reg
)
310 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
311 outb(reg
, chip
->port
+ 0x04);
312 data
= inb(chip
->port
+ 0x05);
313 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
315 snd_printk(KERN_DEBUG
"Mixer reg %02x now is %02x\n", reg
, data
);
320 /* Return old value */
321 static inline int snd_es18xx_mixer_bits(struct snd_es18xx
*chip
, unsigned char reg
,
322 unsigned char mask
, unsigned char val
)
324 unsigned char old
, new, oval
;
326 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
327 outb(reg
, chip
->port
+ 0x04);
328 old
= inb(chip
->port
+ 0x05);
331 new = (old
& ~mask
) | (val
& mask
);
332 outb(new, chip
->port
+ 0x05);
334 snd_printk(KERN_DEBUG
"Mixer reg %02x was %02x, set to %02x\n",
338 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
342 static inline int snd_es18xx_mixer_writable(struct snd_es18xx
*chip
, unsigned char reg
,
345 int old
, expected
, new;
347 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
348 outb(reg
, chip
->port
+ 0x04);
349 old
= inb(chip
->port
+ 0x05);
350 expected
= old
^ mask
;
351 outb(expected
, chip
->port
+ 0x05);
352 new = inb(chip
->port
+ 0x05);
353 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
355 snd_printk(KERN_DEBUG
"Mixer reg %02x was %02x, set to %02x, now is %02x\n",
356 reg
, old
, expected
, new);
358 return expected
== new;
362 static int snd_es18xx_reset(struct snd_es18xx
*chip
)
365 outb(0x03, chip
->port
+ 0x06);
366 inb(chip
->port
+ 0x06);
367 outb(0x00, chip
->port
+ 0x06);
368 for(i
= 0; i
< MILLISECOND
&& !(inb(chip
->port
+ 0x0E) & 0x80); i
++);
369 if (inb(chip
->port
+ 0x0A) != 0xAA)
374 static int snd_es18xx_reset_fifo(struct snd_es18xx
*chip
)
376 outb(0x02, chip
->port
+ 0x06);
377 inb(chip
->port
+ 0x06);
378 outb(0x00, chip
->port
+ 0x06);
382 static struct snd_ratnum new_clocks
[2] = {
397 static struct snd_pcm_hw_constraint_ratnums new_hw_constraints_clocks
= {
402 static struct snd_ratnum old_clocks
[2] = {
417 static struct snd_pcm_hw_constraint_ratnums old_hw_constraints_clocks
= {
423 static void snd_es18xx_rate_set(struct snd_es18xx
*chip
,
424 struct snd_pcm_substream
*substream
,
427 unsigned int bits
, div0
;
428 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
429 if (chip
->caps
& ES18XX_NEW_RATE
) {
430 if (runtime
->rate_num
== new_clocks
[0].num
)
431 bits
= 128 - runtime
->rate_den
;
433 bits
= 256 - runtime
->rate_den
;
435 if (runtime
->rate_num
== old_clocks
[0].num
)
436 bits
= 256 - runtime
->rate_den
;
438 bits
= 128 - runtime
->rate_den
;
441 /* set filter register */
442 div0
= 256 - 7160000*20/(8*82*runtime
->rate
);
444 if ((chip
->caps
& ES18XX_PCM2
) && mode
== DAC2
) {
445 snd_es18xx_mixer_write(chip
, 0x70, bits
);
447 * Comment from kernel oss driver:
448 * FKS: fascinating: 0x72 doesn't seem to work.
450 snd_es18xx_write(chip
, 0xA2, div0
);
451 snd_es18xx_mixer_write(chip
, 0x72, div0
);
453 snd_es18xx_write(chip
, 0xA1, bits
);
454 snd_es18xx_write(chip
, 0xA2, div0
);
458 static int snd_es18xx_playback_hw_params(struct snd_pcm_substream
*substream
,
459 struct snd_pcm_hw_params
*hw_params
)
461 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
465 if (params_channels(hw_params
) == 2)
467 if (snd_pcm_format_width(params_format(hw_params
)) == 16)
470 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
471 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
472 (chip
->capture_a_substream
) &&
473 params_channels(hw_params
) != 1) {
474 _snd_pcm_hw_param_setempty(hw_params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
477 chip
->dma2_shift
= shift
;
479 chip
->dma1_shift
= shift
;
481 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
486 static int snd_es18xx_pcm_hw_free(struct snd_pcm_substream
*substream
)
488 return snd_pcm_lib_free_pages(substream
);
491 static int snd_es18xx_playback1_prepare(struct snd_es18xx
*chip
,
492 struct snd_pcm_substream
*substream
)
494 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
495 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
496 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
498 chip
->dma2_size
= size
;
500 snd_es18xx_rate_set(chip
, substream
, DAC2
);
502 /* Transfer Count Reload */
503 count
= 0x10000 - count
;
504 snd_es18xx_mixer_write(chip
, 0x74, count
& 0xff);
505 snd_es18xx_mixer_write(chip
, 0x76, count
>> 8);
508 snd_es18xx_mixer_bits(chip
, 0x7A, 0x07,
509 ((runtime
->channels
== 1) ? 0x00 : 0x02) |
510 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x01 : 0x00) |
511 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x04));
513 /* Set DMA controller */
514 snd_dma_program(chip
->dma2
, runtime
->dma_addr
, size
, DMA_MODE_WRITE
| DMA_AUTOINIT
);
519 static int snd_es18xx_playback1_trigger(struct snd_es18xx
*chip
,
520 struct snd_pcm_substream
*substream
,
524 case SNDRV_PCM_TRIGGER_START
:
525 case SNDRV_PCM_TRIGGER_RESUME
:
526 if (chip
->active
& DAC2
)
528 chip
->active
|= DAC2
;
531 snd_es18xx_mixer_write(chip
, 0x78, 0xb3);
533 snd_es18xx_mixer_write(chip
, 0x78, 0x93);
537 if (chip
->caps
& ES18XX_PCM2
)
538 /* Restore Audio 2 volume */
539 snd_es18xx_mixer_write(chip
, 0x7C, chip
->audio2_vol
);
541 /* Enable PCM output */
542 snd_es18xx_dsp_command(chip
, 0xD1);
545 case SNDRV_PCM_TRIGGER_STOP
:
546 case SNDRV_PCM_TRIGGER_SUSPEND
:
547 if (!(chip
->active
& DAC2
))
549 chip
->active
&= ~DAC2
;
551 snd_es18xx_mixer_write(chip
, 0x78, 0x00);
554 if (chip
->caps
& ES18XX_PCM2
)
555 /* Set Audio 2 volume to 0 */
556 snd_es18xx_mixer_write(chip
, 0x7C, 0);
558 /* Disable PCM output */
559 snd_es18xx_dsp_command(chip
, 0xD3);
569 static int snd_es18xx_capture_hw_params(struct snd_pcm_substream
*substream
,
570 struct snd_pcm_hw_params
*hw_params
)
572 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
576 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
577 chip
->playback_a_substream
&&
578 params_channels(hw_params
) != 1) {
579 _snd_pcm_hw_param_setempty(hw_params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
582 if (params_channels(hw_params
) == 2)
584 if (snd_pcm_format_width(params_format(hw_params
)) == 16)
586 chip
->dma1_shift
= shift
;
587 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
592 static int snd_es18xx_capture_prepare(struct snd_pcm_substream
*substream
)
594 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
595 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
596 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
597 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
599 chip
->dma1_size
= size
;
601 snd_es18xx_reset_fifo(chip
);
603 /* Set stereo/mono */
604 snd_es18xx_bits(chip
, 0xA8, 0x03, runtime
->channels
== 1 ? 0x02 : 0x01);
606 snd_es18xx_rate_set(chip
, substream
, ADC1
);
608 /* Transfer Count Reload */
609 count
= 0x10000 - count
;
610 snd_es18xx_write(chip
, 0xA4, count
& 0xff);
611 snd_es18xx_write(chip
, 0xA5, count
>> 8);
618 snd_es18xx_write(chip
, 0xB7,
619 snd_pcm_format_unsigned(runtime
->format
) ? 0x51 : 0x71);
620 snd_es18xx_write(chip
, 0xB7, 0x90 |
621 ((runtime
->channels
== 1) ? 0x40 : 0x08) |
622 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x04 : 0x00) |
623 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x20));
625 /* Set DMA controller */
626 snd_dma_program(chip
->dma1
, runtime
->dma_addr
, size
, DMA_MODE_READ
| DMA_AUTOINIT
);
631 static int snd_es18xx_capture_trigger(struct snd_pcm_substream
*substream
,
634 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
637 case SNDRV_PCM_TRIGGER_START
:
638 case SNDRV_PCM_TRIGGER_RESUME
:
639 if (chip
->active
& ADC1
)
641 chip
->active
|= ADC1
;
643 snd_es18xx_write(chip
, 0xB8, 0x0f);
645 case SNDRV_PCM_TRIGGER_STOP
:
646 case SNDRV_PCM_TRIGGER_SUSPEND
:
647 if (!(chip
->active
& ADC1
))
649 chip
->active
&= ~ADC1
;
651 snd_es18xx_write(chip
, 0xB8, 0x00);
660 static int snd_es18xx_playback2_prepare(struct snd_es18xx
*chip
,
661 struct snd_pcm_substream
*substream
)
663 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
664 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
665 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
667 chip
->dma1_size
= size
;
669 snd_es18xx_reset_fifo(chip
);
671 /* Set stereo/mono */
672 snd_es18xx_bits(chip
, 0xA8, 0x03, runtime
->channels
== 1 ? 0x02 : 0x01);
674 snd_es18xx_rate_set(chip
, substream
, DAC1
);
676 /* Transfer Count Reload */
677 count
= 0x10000 - count
;
678 snd_es18xx_write(chip
, 0xA4, count
& 0xff);
679 snd_es18xx_write(chip
, 0xA5, count
>> 8);
682 snd_es18xx_write(chip
, 0xB6,
683 snd_pcm_format_unsigned(runtime
->format
) ? 0x80 : 0x00);
684 snd_es18xx_write(chip
, 0xB7,
685 snd_pcm_format_unsigned(runtime
->format
) ? 0x51 : 0x71);
686 snd_es18xx_write(chip
, 0xB7, 0x90 |
687 (runtime
->channels
== 1 ? 0x40 : 0x08) |
688 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x04 : 0x00) |
689 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x20));
691 /* Set DMA controller */
692 snd_dma_program(chip
->dma1
, runtime
->dma_addr
, size
, DMA_MODE_WRITE
| DMA_AUTOINIT
);
697 static int snd_es18xx_playback2_trigger(struct snd_es18xx
*chip
,
698 struct snd_pcm_substream
*substream
,
702 case SNDRV_PCM_TRIGGER_START
:
703 case SNDRV_PCM_TRIGGER_RESUME
:
704 if (chip
->active
& DAC1
)
706 chip
->active
|= DAC1
;
708 snd_es18xx_write(chip
, 0xB8, 0x05);
713 snd_es18xx_dsp_command(chip
, 0xD1);
716 case SNDRV_PCM_TRIGGER_STOP
:
717 case SNDRV_PCM_TRIGGER_SUSPEND
:
718 if (!(chip
->active
& DAC1
))
720 chip
->active
&= ~DAC1
;
722 snd_es18xx_write(chip
, 0xB8, 0x00);
726 /* Disable Audio 1 */
727 snd_es18xx_dsp_command(chip
, 0xD3);
737 static int snd_es18xx_playback_prepare(struct snd_pcm_substream
*substream
)
739 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
740 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
741 return snd_es18xx_playback1_prepare(chip
, substream
);
743 return snd_es18xx_playback2_prepare(chip
, substream
);
746 static int snd_es18xx_playback_trigger(struct snd_pcm_substream
*substream
,
749 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
750 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
751 return snd_es18xx_playback1_trigger(chip
, substream
, cmd
);
753 return snd_es18xx_playback2_trigger(chip
, substream
, cmd
);
756 static irqreturn_t
snd_es18xx_interrupt(int irq
, void *dev_id
)
758 struct snd_es18xx
*chip
= dev_id
;
759 unsigned char status
;
761 if (chip
->caps
& ES18XX_CONTROL
) {
762 /* Read Interrupt status */
763 status
= inb(chip
->ctrl_port
+ 6);
765 /* Read Interrupt status */
766 status
= snd_es18xx_mixer_read(chip
, 0x7f) >> 4;
771 if (inb(chip
->port
+ 0x0C) & 0x01)
772 status
|= AUDIO1_IRQ
;
773 if (snd_es18xx_mixer_read(chip
, 0x7A) & 0x80)
774 status
|= AUDIO2_IRQ
;
775 if ((chip
->caps
& ES18XX_HWV
) &&
776 snd_es18xx_mixer_read(chip
, 0x64) & 0x10)
781 /* Audio 1 & Audio 2 */
782 if (status
& AUDIO2_IRQ
) {
783 if (chip
->active
& DAC2
)
784 snd_pcm_period_elapsed(chip
->playback_a_substream
);
786 snd_es18xx_mixer_bits(chip
, 0x7A, 0x80, 0x00);
788 if (status
& AUDIO1_IRQ
) {
789 /* ok.. capture is active */
790 if (chip
->active
& ADC1
)
791 snd_pcm_period_elapsed(chip
->capture_a_substream
);
792 /* ok.. playback2 is active */
793 else if (chip
->active
& DAC1
)
794 snd_pcm_period_elapsed(chip
->playback_b_substream
);
796 inb(chip
->port
+ 0x0E);
800 if ((status
& MPU_IRQ
) && chip
->rmidi
)
801 snd_mpu401_uart_interrupt(irq
, chip
->rmidi
->private_data
);
803 /* Hardware volume */
804 if (status
& HWV_IRQ
) {
806 if (chip
->caps
& ES18XX_HWV
) {
807 split
= snd_es18xx_mixer_read(chip
, 0x64) & 0x80;
808 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &chip
->hw_switch
->id
);
809 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &chip
->hw_volume
->id
);
812 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &chip
->master_switch
->id
);
813 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &chip
->master_volume
->id
);
816 snd_es18xx_mixer_write(chip
, 0x66, 0x00);
821 static snd_pcm_uframes_t
snd_es18xx_playback_pointer(struct snd_pcm_substream
*substream
)
823 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
826 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
827 if (!(chip
->active
& DAC2
))
829 pos
= snd_dma_pointer(chip
->dma2
, chip
->dma2_size
);
830 return pos
>> chip
->dma2_shift
;
832 if (!(chip
->active
& DAC1
))
834 pos
= snd_dma_pointer(chip
->dma1
, chip
->dma1_size
);
835 return pos
>> chip
->dma1_shift
;
839 static snd_pcm_uframes_t
snd_es18xx_capture_pointer(struct snd_pcm_substream
*substream
)
841 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
844 if (!(chip
->active
& ADC1
))
846 pos
= snd_dma_pointer(chip
->dma1
, chip
->dma1_size
);
847 return pos
>> chip
->dma1_shift
;
850 static struct snd_pcm_hardware snd_es18xx_playback
=
852 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
853 SNDRV_PCM_INFO_RESUME
|
854 SNDRV_PCM_INFO_MMAP_VALID
),
855 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S8
|
856 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_U16_LE
),
857 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
862 .buffer_bytes_max
= 65536,
863 .period_bytes_min
= 64,
864 .period_bytes_max
= 65536,
870 static struct snd_pcm_hardware snd_es18xx_capture
=
872 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
873 SNDRV_PCM_INFO_RESUME
|
874 SNDRV_PCM_INFO_MMAP_VALID
),
875 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S8
|
876 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_U16_LE
),
877 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
882 .buffer_bytes_max
= 65536,
883 .period_bytes_min
= 64,
884 .period_bytes_max
= 65536,
890 static int snd_es18xx_playback_open(struct snd_pcm_substream
*substream
)
892 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
893 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
895 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
896 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
897 chip
->capture_a_substream
&&
898 chip
->capture_a_substream
->runtime
->channels
!= 1)
900 chip
->playback_a_substream
= substream
;
901 } else if (substream
->number
<= 1) {
902 if (chip
->capture_a_substream
)
904 chip
->playback_b_substream
= substream
;
909 substream
->runtime
->hw
= snd_es18xx_playback
;
910 snd_pcm_hw_constraint_ratnums(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
911 (chip
->caps
& ES18XX_NEW_RATE
) ? &new_hw_constraints_clocks
: &old_hw_constraints_clocks
);
915 static int snd_es18xx_capture_open(struct snd_pcm_substream
*substream
)
917 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
918 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
920 if (chip
->playback_b_substream
)
922 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
923 chip
->playback_a_substream
&&
924 chip
->playback_a_substream
->runtime
->channels
!= 1)
926 chip
->capture_a_substream
= substream
;
927 substream
->runtime
->hw
= snd_es18xx_capture
;
928 snd_pcm_hw_constraint_ratnums(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
929 (chip
->caps
& ES18XX_NEW_RATE
) ? &new_hw_constraints_clocks
: &old_hw_constraints_clocks
);
933 static int snd_es18xx_playback_close(struct snd_pcm_substream
*substream
)
935 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
937 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
938 chip
->playback_a_substream
= NULL
;
940 chip
->playback_b_substream
= NULL
;
942 snd_pcm_lib_free_pages(substream
);
946 static int snd_es18xx_capture_close(struct snd_pcm_substream
*substream
)
948 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
950 chip
->capture_a_substream
= NULL
;
951 snd_pcm_lib_free_pages(substream
);
959 /* Record source mux routines:
960 * Depending on the chipset this mux switches between 4, 5, or 8 possible inputs.
961 * bit table for the 4/5 source mux:
968 * if it's "mixer" and it's a 5 source mux chipset then reg 7A bit 3 determines
969 * either the play mixer or the capture mixer.
971 * "map4Source" translates from source number to reg bit pattern
972 * "invMap4Source" translates from reg bit pattern to source number
975 static int snd_es18xx_info_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
977 static char *texts4Source
[4] = {
978 "Mic", "CD", "Line", "Master"
980 static char *texts5Source
[5] = {
981 "Mic", "CD", "Line", "Master", "Mix"
983 static char *texts8Source
[8] = {
984 "Mic", "Mic Master", "CD", "AOUT",
985 "Mic1", "Mix", "Line", "Master"
987 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
989 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
991 switch (chip
->version
) {
994 uinfo
->value
.enumerated
.items
= 4;
995 if (uinfo
->value
.enumerated
.item
> 3)
996 uinfo
->value
.enumerated
.item
= 3;
997 strcpy(uinfo
->value
.enumerated
.name
, texts4Source
[uinfo
->value
.enumerated
.item
]);
1001 uinfo
->value
.enumerated
.items
= 5;
1002 if (uinfo
->value
.enumerated
.item
> 4)
1003 uinfo
->value
.enumerated
.item
= 4;
1004 strcpy(uinfo
->value
.enumerated
.name
, texts5Source
[uinfo
->value
.enumerated
.item
]);
1006 case 0x1869: /* DS somewhat contradictory for 1869: could be be 5 or 8 */
1008 uinfo
->value
.enumerated
.items
= 8;
1009 if (uinfo
->value
.enumerated
.item
> 7)
1010 uinfo
->value
.enumerated
.item
= 7;
1011 strcpy(uinfo
->value
.enumerated
.name
, texts8Source
[uinfo
->value
.enumerated
.item
]);
1019 static int snd_es18xx_get_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1021 static unsigned char invMap4Source
[8] = {0, 0, 1, 1, 0, 0, 2, 3};
1022 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1023 int muxSource
= snd_es18xx_mixer_read(chip
, 0x1c) & 0x07;
1024 if (!(chip
->version
== 0x1869 || chip
->version
== 0x1879)) {
1025 muxSource
= invMap4Source
[muxSource
];
1027 (chip
->version
== 0x1887 || chip
->version
== 0x1888) &&
1028 (snd_es18xx_mixer_read(chip
, 0x7a) & 0x08)
1032 ucontrol
->value
.enumerated
.item
[0] = muxSource
;
1036 static int snd_es18xx_put_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1038 static unsigned char map4Source
[4] = {0, 2, 6, 7};
1039 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1040 unsigned char val
= ucontrol
->value
.enumerated
.item
[0];
1041 unsigned char retVal
= 0;
1043 switch (chip
->version
) {
1044 /* 5 source chips */
1050 retVal
= snd_es18xx_mixer_bits(chip
, 0x7a, 0x08, 0x08) != 0x08;
1053 retVal
= snd_es18xx_mixer_bits(chip
, 0x7a, 0x08, 0x00) != 0x00;
1054 /* 4 source chips */
1059 val
= map4Source
[val
];
1061 /* 8 source chips */
1070 return (snd_es18xx_mixer_bits(chip
, 0x1c, 0x07, val
) != val
) || retVal
;
1073 #define snd_es18xx_info_spatializer_enable snd_ctl_boolean_mono_info
1075 static int snd_es18xx_get_spatializer_enable(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1077 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1078 unsigned char val
= snd_es18xx_mixer_read(chip
, 0x50);
1079 ucontrol
->value
.integer
.value
[0] = !!(val
& 8);
1083 static int snd_es18xx_put_spatializer_enable(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1085 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1086 unsigned char oval
, nval
;
1088 nval
= ucontrol
->value
.integer
.value
[0] ? 0x0c : 0x04;
1089 oval
= snd_es18xx_mixer_read(chip
, 0x50) & 0x0c;
1090 change
= nval
!= oval
;
1092 snd_es18xx_mixer_write(chip
, 0x50, nval
& ~0x04);
1093 snd_es18xx_mixer_write(chip
, 0x50, nval
);
1098 static int snd_es18xx_info_hw_volume(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1100 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1102 uinfo
->value
.integer
.min
= 0;
1103 uinfo
->value
.integer
.max
= 63;
1107 static int snd_es18xx_get_hw_volume(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1109 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1110 ucontrol
->value
.integer
.value
[0] = snd_es18xx_mixer_read(chip
, 0x61) & 0x3f;
1111 ucontrol
->value
.integer
.value
[1] = snd_es18xx_mixer_read(chip
, 0x63) & 0x3f;
1115 #define snd_es18xx_info_hw_switch snd_ctl_boolean_stereo_info
1117 static int snd_es18xx_get_hw_switch(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1119 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1120 ucontrol
->value
.integer
.value
[0] = !(snd_es18xx_mixer_read(chip
, 0x61) & 0x40);
1121 ucontrol
->value
.integer
.value
[1] = !(snd_es18xx_mixer_read(chip
, 0x63) & 0x40);
1125 static void snd_es18xx_hwv_free(struct snd_kcontrol
*kcontrol
)
1127 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1128 chip
->master_volume
= NULL
;
1129 chip
->master_switch
= NULL
;
1130 chip
->hw_volume
= NULL
;
1131 chip
->hw_switch
= NULL
;
1134 static int snd_es18xx_reg_bits(struct snd_es18xx
*chip
, unsigned char reg
,
1135 unsigned char mask
, unsigned char val
)
1138 return snd_es18xx_mixer_bits(chip
, reg
, mask
, val
);
1140 return snd_es18xx_bits(chip
, reg
, mask
, val
);
1143 static int snd_es18xx_reg_read(struct snd_es18xx
*chip
, unsigned char reg
)
1146 return snd_es18xx_mixer_read(chip
, reg
);
1148 return snd_es18xx_read(chip
, reg
);
1151 #define ES18XX_SINGLE(xname, xindex, reg, shift, mask, invert) \
1152 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1153 .info = snd_es18xx_info_single, \
1154 .get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \
1155 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
1157 static int snd_es18xx_info_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1159 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1161 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1163 uinfo
->value
.integer
.min
= 0;
1164 uinfo
->value
.integer
.max
= mask
;
1168 static int snd_es18xx_get_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1170 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1171 int reg
= kcontrol
->private_value
& 0xff;
1172 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1173 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1174 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1177 val
= snd_es18xx_reg_read(chip
, reg
);
1178 ucontrol
->value
.integer
.value
[0] = (val
>> shift
) & mask
;
1180 ucontrol
->value
.integer
.value
[0] = mask
- ucontrol
->value
.integer
.value
[0];
1184 static int snd_es18xx_put_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1186 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1187 int reg
= kcontrol
->private_value
& 0xff;
1188 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1189 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1190 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1193 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1198 return snd_es18xx_reg_bits(chip
, reg
, mask
, val
) != val
;
1201 #define ES18XX_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
1202 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1203 .info = snd_es18xx_info_double, \
1204 .get = snd_es18xx_get_double, .put = snd_es18xx_put_double, \
1205 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
1207 static int snd_es18xx_info_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1209 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1211 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1213 uinfo
->value
.integer
.min
= 0;
1214 uinfo
->value
.integer
.max
= mask
;
1218 static int snd_es18xx_get_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1220 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1221 int left_reg
= kcontrol
->private_value
& 0xff;
1222 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
1223 int shift_left
= (kcontrol
->private_value
>> 16) & 0x07;
1224 int shift_right
= (kcontrol
->private_value
>> 19) & 0x07;
1225 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1226 int invert
= (kcontrol
->private_value
>> 22) & 1;
1227 unsigned char left
, right
;
1229 left
= snd_es18xx_reg_read(chip
, left_reg
);
1230 if (left_reg
!= right_reg
)
1231 right
= snd_es18xx_reg_read(chip
, right_reg
);
1234 ucontrol
->value
.integer
.value
[0] = (left
>> shift_left
) & mask
;
1235 ucontrol
->value
.integer
.value
[1] = (right
>> shift_right
) & mask
;
1237 ucontrol
->value
.integer
.value
[0] = mask
- ucontrol
->value
.integer
.value
[0];
1238 ucontrol
->value
.integer
.value
[1] = mask
- ucontrol
->value
.integer
.value
[1];
1243 static int snd_es18xx_put_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1245 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1246 int left_reg
= kcontrol
->private_value
& 0xff;
1247 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
1248 int shift_left
= (kcontrol
->private_value
>> 16) & 0x07;
1249 int shift_right
= (kcontrol
->private_value
>> 19) & 0x07;
1250 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1251 int invert
= (kcontrol
->private_value
>> 22) & 1;
1253 unsigned char val1
, val2
, mask1
, mask2
;
1255 val1
= ucontrol
->value
.integer
.value
[0] & mask
;
1256 val2
= ucontrol
->value
.integer
.value
[1] & mask
;
1261 val1
<<= shift_left
;
1262 val2
<<= shift_right
;
1263 mask1
= mask
<< shift_left
;
1264 mask2
= mask
<< shift_right
;
1265 if (left_reg
!= right_reg
) {
1267 if (snd_es18xx_reg_bits(chip
, left_reg
, mask1
, val1
) != val1
)
1269 if (snd_es18xx_reg_bits(chip
, right_reg
, mask2
, val2
) != val2
)
1272 change
= (snd_es18xx_reg_bits(chip
, left_reg
, mask1
| mask2
,
1273 val1
| val2
) != (val1
| val2
));
1279 * These arrays contain setup data for mixer controls.
1281 * The controls that are universal to all chipsets are fully initialized
1284 static struct snd_kcontrol_new snd_es18xx_base_controls
[] = {
1285 ES18XX_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0),
1286 ES18XX_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1),
1287 ES18XX_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0),
1288 ES18XX_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0),
1289 ES18XX_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0),
1290 ES18XX_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0),
1291 ES18XX_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0),
1292 ES18XX_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
1293 ES18XX_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0),
1295 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1296 .name
= "Capture Source",
1297 .info
= snd_es18xx_info_mux
,
1298 .get
= snd_es18xx_get_mux
,
1299 .put
= snd_es18xx_put_mux
,
1303 static struct snd_kcontrol_new snd_es18xx_recmix_controls
[] = {
1304 ES18XX_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0),
1305 ES18XX_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0),
1306 ES18XX_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0),
1307 ES18XX_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0),
1308 ES18XX_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0),
1309 ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0)
1313 * The chipset specific mixer controls
1315 static struct snd_kcontrol_new snd_es18xx_opt_speaker
=
1316 ES18XX_SINGLE("PC Speaker Playback Volume", 0, 0x3c, 0, 7, 0);
1318 static struct snd_kcontrol_new snd_es18xx_opt_1869
[] = {
1319 ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
1320 ES18XX_SINGLE("Video Playback Switch", 0, 0x7f, 0, 1, 0),
1321 ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1322 ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0)
1325 static struct snd_kcontrol_new snd_es18xx_opt_1878
=
1326 ES18XX_DOUBLE("Video Playback Volume", 0, 0x68, 0x68, 4, 0, 15, 0);
1328 static struct snd_kcontrol_new snd_es18xx_opt_1879
[] = {
1329 ES18XX_SINGLE("Video Playback Switch", 0, 0x71, 6, 1, 0),
1330 ES18XX_DOUBLE("Video Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1331 ES18XX_DOUBLE("Video Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0)
1334 static struct snd_kcontrol_new snd_es18xx_pcm1_controls
[] = {
1335 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x14, 0x14, 4, 0, 15, 0),
1338 static struct snd_kcontrol_new snd_es18xx_pcm2_controls
[] = {
1339 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0),
1340 ES18XX_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0)
1343 static struct snd_kcontrol_new snd_es18xx_spatializer_controls
[] = {
1344 ES18XX_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
1346 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1347 .name
= "3D Control - Switch",
1348 .info
= snd_es18xx_info_spatializer_enable
,
1349 .get
= snd_es18xx_get_spatializer_enable
,
1350 .put
= snd_es18xx_put_spatializer_enable
,
1354 static struct snd_kcontrol_new snd_es18xx_micpre1_control
=
1355 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0xa9, 2, 1, 0);
1357 static struct snd_kcontrol_new snd_es18xx_micpre2_control
=
1358 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0);
1360 static struct snd_kcontrol_new snd_es18xx_hw_volume_controls
[] = {
1362 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1363 .name
= "Hardware Master Playback Volume",
1364 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1365 .info
= snd_es18xx_info_hw_volume
,
1366 .get
= snd_es18xx_get_hw_volume
,
1369 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1370 .name
= "Hardware Master Playback Switch",
1371 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1372 .info
= snd_es18xx_info_hw_switch
,
1373 .get
= snd_es18xx_get_hw_switch
,
1375 ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0),
1378 static int __devinit
snd_es18xx_config_read(struct snd_es18xx
*chip
, unsigned char reg
)
1381 unsigned long flags
;
1382 spin_lock_irqsave(&chip
->ctrl_lock
, flags
);
1383 outb(reg
, chip
->ctrl_port
);
1384 data
= inb(chip
->ctrl_port
+ 1);
1385 spin_unlock_irqrestore(&chip
->ctrl_lock
, flags
);
1389 static void __devinit
snd_es18xx_config_write(struct snd_es18xx
*chip
,
1390 unsigned char reg
, unsigned char data
)
1392 /* No need for spinlocks, this function is used only in
1393 otherwise protected init code */
1394 outb(reg
, chip
->ctrl_port
);
1395 outb(data
, chip
->ctrl_port
+ 1);
1397 snd_printk(KERN_DEBUG
"Config reg %02x set to %02x\n", reg
, data
);
1401 static int __devinit
snd_es18xx_initialize(struct snd_es18xx
*chip
)
1405 /* enable extended mode */
1406 snd_es18xx_dsp_command(chip
, 0xC6);
1407 /* Reset mixer registers */
1408 snd_es18xx_mixer_write(chip
, 0x00, 0x00);
1410 /* Audio 1 DMA demand mode (4 bytes/request) */
1411 snd_es18xx_write(chip
, 0xB9, 2);
1412 if (chip
->caps
& ES18XX_CONTROL
) {
1413 /* Hardware volume IRQ */
1414 snd_es18xx_config_write(chip
, 0x27, chip
->irq
);
1415 if (chip
->fm_port
> 0 && chip
->fm_port
!= SNDRV_AUTO_PORT
) {
1417 snd_es18xx_config_write(chip
, 0x62, chip
->fm_port
>> 8);
1418 snd_es18xx_config_write(chip
, 0x63, chip
->fm_port
& 0xff);
1420 if (chip
->mpu_port
> 0 && chip
->mpu_port
!= SNDRV_AUTO_PORT
) {
1422 snd_es18xx_config_write(chip
, 0x64, chip
->mpu_port
>> 8);
1423 snd_es18xx_config_write(chip
, 0x65, chip
->mpu_port
& 0xff);
1425 snd_es18xx_config_write(chip
, 0x28, chip
->irq
);
1428 snd_es18xx_config_write(chip
, 0x70, chip
->irq
);
1430 snd_es18xx_config_write(chip
, 0x72, chip
->irq
);
1432 snd_es18xx_config_write(chip
, 0x74, chip
->dma1
);
1434 snd_es18xx_config_write(chip
, 0x75, chip
->dma2
);
1436 /* Enable Audio 1 IRQ */
1437 snd_es18xx_write(chip
, 0xB1, 0x50);
1438 /* Enable Audio 2 IRQ */
1439 snd_es18xx_mixer_write(chip
, 0x7A, 0x40);
1440 /* Enable Audio 1 DMA */
1441 snd_es18xx_write(chip
, 0xB2, 0x50);
1442 /* Enable MPU and hardware volume interrupt */
1443 snd_es18xx_mixer_write(chip
, 0x64, 0x42);
1444 /* Enable ESS wavetable input */
1445 snd_es18xx_mixer_bits(chip
, 0x48, 0x10, 0x10);
1448 int irqmask
, dma1mask
, dma2mask
;
1449 switch (chip
->irq
) {
1464 snd_printk(KERN_ERR
"invalid irq %d\n", chip
->irq
);
1467 switch (chip
->dma1
) {
1478 snd_printk(KERN_ERR
"invalid dma1 %d\n", chip
->dma1
);
1481 switch (chip
->dma2
) {
1495 snd_printk(KERN_ERR
"invalid dma2 %d\n", chip
->dma2
);
1499 /* Enable and set Audio 1 IRQ */
1500 snd_es18xx_write(chip
, 0xB1, 0x50 | (irqmask
<< 2));
1501 /* Enable and set Audio 1 DMA */
1502 snd_es18xx_write(chip
, 0xB2, 0x50 | (dma1mask
<< 2));
1503 /* Set Audio 2 DMA */
1504 snd_es18xx_mixer_bits(chip
, 0x7d, 0x07, 0x04 | dma2mask
);
1505 /* Enable Audio 2 IRQ and DMA
1506 Set capture mixer input */
1507 snd_es18xx_mixer_write(chip
, 0x7A, 0x68);
1508 /* Enable and set hardware volume interrupt */
1509 snd_es18xx_mixer_write(chip
, 0x64, 0x06);
1510 if (chip
->mpu_port
> 0 && chip
->mpu_port
!= SNDRV_AUTO_PORT
) {
1511 /* MPU401 share irq with audio
1514 snd_es18xx_mixer_write(chip
, 0x40, 0x43 | (chip
->mpu_port
& 0xf0) >> 1);
1516 snd_es18xx_mixer_write(chip
, 0x7f, ((irqmask
+ 1) << 1) | 0x01);
1518 if (chip
->caps
& ES18XX_NEW_RATE
) {
1519 /* Change behaviour of register A1
1521 2nd channel DAC asynchronous */
1522 snd_es18xx_mixer_write(chip
, 0x71, 0x32);
1524 if (!(chip
->caps
& ES18XX_PCM2
)) {
1525 /* Enable DMA FIFO */
1526 snd_es18xx_write(chip
, 0xB7, 0x80);
1528 if (chip
->caps
& ES18XX_SPATIALIZER
) {
1529 /* Set spatializer parameters to recommended values */
1530 snd_es18xx_mixer_write(chip
, 0x54, 0x8f);
1531 snd_es18xx_mixer_write(chip
, 0x56, 0x95);
1532 snd_es18xx_mixer_write(chip
, 0x58, 0x94);
1533 snd_es18xx_mixer_write(chip
, 0x5a, 0x80);
1535 /* Flip the "enable I2S" bits for those chipsets that need it */
1536 switch (chip
->version
) {
1538 //Leaving I2S enabled on the 1879 screws up the PCM playback (rate effected somehow)
1539 //so a Switch control has been added to toggle this 0x71 bit on/off:
1540 //snd_es18xx_mixer_bits(chip, 0x71, 0x40, 0x40);
1541 /* Note: we fall through on purpose here. */
1543 snd_es18xx_config_write(chip
, 0x29, snd_es18xx_config_read(chip
, 0x29) | 0x40);
1546 /* Mute input source */
1547 if (chip
->caps
& ES18XX_MUTEREC
)
1549 if (chip
->caps
& ES18XX_RECMIX
)
1550 snd_es18xx_mixer_write(chip
, 0x1c, 0x05 | mask
);
1552 snd_es18xx_mixer_write(chip
, 0x1c, 0x00 | mask
);
1553 snd_es18xx_write(chip
, 0xb4, 0x00);
1556 /* Enable PCM output */
1557 snd_es18xx_dsp_command(chip
, 0xD1);
1563 static int __devinit
snd_es18xx_identify(struct snd_es18xx
*chip
)
1568 if (snd_es18xx_reset(chip
) < 0) {
1569 snd_printk(KERN_ERR
"reset at 0x%lx failed!!!\n", chip
->port
);
1573 snd_es18xx_dsp_command(chip
, 0xe7);
1574 hi
= snd_es18xx_dsp_get_byte(chip
);
1578 lo
= snd_es18xx_dsp_get_byte(chip
);
1579 if ((lo
& 0xf0) != 0x80) {
1583 chip
->version
= 0x488;
1589 if ((lo
& 0x0f) < 8) {
1590 chip
->version
= 0x688;
1594 outb(0x40, chip
->port
+ 0x04);
1596 hi
= inb(chip
->port
+ 0x05);
1598 lo
= inb(chip
->port
+ 0x05);
1600 chip
->version
= hi
<< 8 | lo
;
1601 chip
->ctrl_port
= inb(chip
->port
+ 0x05) << 8;
1603 chip
->ctrl_port
+= inb(chip
->port
+ 0x05);
1605 if ((chip
->res_ctrl_port
= request_region(chip
->ctrl_port
, 8, "ES18xx - CTRL")) == NULL
) {
1606 snd_printk(KERN_ERR PFX
"unable go grab port 0x%lx\n", chip
->ctrl_port
);
1613 /* If has Hardware volume */
1614 if (snd_es18xx_mixer_writable(chip
, 0x64, 0x04)) {
1616 if (snd_es18xx_mixer_writable(chip
, 0x70, 0x7f)) {
1617 /* If has volume count */
1618 if (snd_es18xx_mixer_writable(chip
, 0x64, 0x20)) {
1619 chip
->version
= 0x1887;
1621 chip
->version
= 0x1888;
1624 chip
->version
= 0x1788;
1628 chip
->version
= 0x1688;
1632 static int __devinit
snd_es18xx_probe(struct snd_es18xx
*chip
)
1634 if (snd_es18xx_identify(chip
) < 0) {
1635 snd_printk(KERN_ERR PFX
"[0x%lx] ESS chip not found\n", chip
->port
);
1639 switch (chip
->version
) {
1641 chip
->caps
= ES18XX_DUPLEX_MONO
| ES18XX_DUPLEX_SAME
| ES18XX_CONTROL
;
1644 chip
->caps
= ES18XX_PCM2
| ES18XX_SPATIALIZER
| ES18XX_RECMIX
| ES18XX_NEW_RATE
| ES18XX_AUXB
| ES18XX_MONO
| ES18XX_MUTEREC
| ES18XX_CONTROL
| ES18XX_HWV
;
1647 chip
->caps
= ES18XX_DUPLEX_MONO
| ES18XX_DUPLEX_SAME
| ES18XX_I2S
| ES18XX_CONTROL
;
1650 chip
->caps
= ES18XX_PCM2
| ES18XX_SPATIALIZER
| ES18XX_RECMIX
| ES18XX_NEW_RATE
| ES18XX_AUXB
| ES18XX_I2S
| ES18XX_CONTROL
| ES18XX_HWV
;
1653 chip
->caps
= ES18XX_PCM2
| ES18XX_RECMIX
| ES18XX_AUXB
| ES18XX_DUPLEX_SAME
;
1656 chip
->caps
= ES18XX_PCM2
| ES18XX_RECMIX
| ES18XX_AUXB
| ES18XX_DUPLEX_SAME
;
1659 snd_printk(KERN_ERR
"[0x%lx] unsupported chip ES%x\n",
1660 chip
->port
, chip
->version
);
1664 snd_printd("[0x%lx] ESS%x chip found\n", chip
->port
, chip
->version
);
1666 if (chip
->dma1
== chip
->dma2
)
1667 chip
->caps
&= ~(ES18XX_PCM2
| ES18XX_DUPLEX_SAME
);
1669 return snd_es18xx_initialize(chip
);
1672 static struct snd_pcm_ops snd_es18xx_playback_ops
= {
1673 .open
= snd_es18xx_playback_open
,
1674 .close
= snd_es18xx_playback_close
,
1675 .ioctl
= snd_pcm_lib_ioctl
,
1676 .hw_params
= snd_es18xx_playback_hw_params
,
1677 .hw_free
= snd_es18xx_pcm_hw_free
,
1678 .prepare
= snd_es18xx_playback_prepare
,
1679 .trigger
= snd_es18xx_playback_trigger
,
1680 .pointer
= snd_es18xx_playback_pointer
,
1683 static struct snd_pcm_ops snd_es18xx_capture_ops
= {
1684 .open
= snd_es18xx_capture_open
,
1685 .close
= snd_es18xx_capture_close
,
1686 .ioctl
= snd_pcm_lib_ioctl
,
1687 .hw_params
= snd_es18xx_capture_hw_params
,
1688 .hw_free
= snd_es18xx_pcm_hw_free
,
1689 .prepare
= snd_es18xx_capture_prepare
,
1690 .trigger
= snd_es18xx_capture_trigger
,
1691 .pointer
= snd_es18xx_capture_pointer
,
1694 static int __devinit
snd_es18xx_pcm(struct snd_es18xx
*chip
, int device
, struct snd_pcm
** rpcm
)
1696 struct snd_pcm
*pcm
;
1702 sprintf(str
, "ES%x", chip
->version
);
1703 if (chip
->caps
& ES18XX_PCM2
)
1704 err
= snd_pcm_new(chip
->card
, str
, device
, 2, 1, &pcm
);
1706 err
= snd_pcm_new(chip
->card
, str
, device
, 1, 1, &pcm
);
1710 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_es18xx_playback_ops
);
1711 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_es18xx_capture_ops
);
1714 pcm
->private_data
= chip
;
1715 pcm
->info_flags
= 0;
1716 if (chip
->caps
& ES18XX_DUPLEX_SAME
)
1717 pcm
->info_flags
|= SNDRV_PCM_INFO_JOINT_DUPLEX
;
1718 if (! (chip
->caps
& ES18XX_PCM2
))
1719 pcm
->info_flags
|= SNDRV_PCM_INFO_HALF_DUPLEX
;
1720 sprintf(pcm
->name
, "ESS AudioDrive ES%x", chip
->version
);
1723 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1726 chip
->dma1
> 3 || chip
->dma2
> 3 ? 128*1024 : 64*1024);
1733 /* Power Management support functions */
1735 static int snd_es18xx_suspend(struct snd_card
*card
, pm_message_t state
)
1737 struct snd_audiodrive
*acard
= card
->private_data
;
1738 struct snd_es18xx
*chip
= acard
->chip
;
1740 snd_power_change_state(chip
->card
, SNDRV_CTL_POWER_D3hot
);
1742 snd_pcm_suspend_all(chip
->pcm
);
1745 chip
->pm_reg
= (unsigned char)snd_es18xx_read(chip
, ES18XX_PM
);
1746 chip
->pm_reg
|= (ES18XX_PM_FM
| ES18XX_PM_SUS
);
1747 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
);
1748 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
^= ES18XX_PM_SUS
);
1753 static int snd_es18xx_resume(struct snd_card
*card
)
1755 struct snd_audiodrive
*acard
= card
->private_data
;
1756 struct snd_es18xx
*chip
= acard
->chip
;
1758 /* restore PM register, we won't wake till (not 0x07) i/o activity though */
1759 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
^= ES18XX_PM_FM
);
1761 snd_power_change_state(chip
->card
, SNDRV_CTL_POWER_D0
);
1764 #endif /* CONFIG_PM */
1766 static int snd_es18xx_free(struct snd_es18xx
*chip
)
1768 release_and_free_resource(chip
->res_port
);
1769 release_and_free_resource(chip
->res_ctrl_port
);
1770 release_and_free_resource(chip
->res_mpu_port
);
1772 free_irq(chip
->irq
, (void *) chip
);
1773 if (chip
->dma1
>= 0) {
1774 disable_dma(chip
->dma1
);
1775 free_dma(chip
->dma1
);
1777 if (chip
->dma2
>= 0 && chip
->dma1
!= chip
->dma2
) {
1778 disable_dma(chip
->dma2
);
1779 free_dma(chip
->dma2
);
1785 static int snd_es18xx_dev_free(struct snd_device
*device
)
1787 struct snd_es18xx
*chip
= device
->device_data
;
1788 return snd_es18xx_free(chip
);
1791 static int __devinit
snd_es18xx_new_device(struct snd_card
*card
,
1793 unsigned long mpu_port
,
1794 unsigned long fm_port
,
1795 int irq
, int dma1
, int dma2
,
1796 struct snd_es18xx
** rchip
)
1798 struct snd_es18xx
*chip
;
1799 static struct snd_device_ops ops
= {
1800 .dev_free
= snd_es18xx_dev_free
,
1805 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
1808 spin_lock_init(&chip
->reg_lock
);
1809 spin_lock_init(&chip
->mixer_lock
);
1810 spin_lock_init(&chip
->ctrl_lock
);
1813 chip
->mpu_port
= mpu_port
;
1814 chip
->fm_port
= fm_port
;
1818 chip
->audio2_vol
= 0x00;
1821 if ((chip
->res_port
= request_region(port
, 16, "ES18xx")) == NULL
) {
1822 snd_es18xx_free(chip
);
1823 snd_printk(KERN_ERR PFX
"unable to grap ports 0x%lx-0x%lx\n", port
, port
+ 16 - 1);
1827 if (request_irq(irq
, snd_es18xx_interrupt
, IRQF_DISABLED
, "ES18xx", (void *) chip
)) {
1828 snd_es18xx_free(chip
);
1829 snd_printk(KERN_ERR PFX
"unable to grap IRQ %d\n", irq
);
1834 if (request_dma(dma1
, "ES18xx DMA 1")) {
1835 snd_es18xx_free(chip
);
1836 snd_printk(KERN_ERR PFX
"unable to grap DMA1 %d\n", dma1
);
1841 if (dma2
!= dma1
&& request_dma(dma2
, "ES18xx DMA 2")) {
1842 snd_es18xx_free(chip
);
1843 snd_printk(KERN_ERR PFX
"unable to grap DMA2 %d\n", dma2
);
1848 if (snd_es18xx_probe(chip
) < 0) {
1849 snd_es18xx_free(chip
);
1852 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
)) < 0) {
1853 snd_es18xx_free(chip
);
1860 static int __devinit
snd_es18xx_mixer(struct snd_es18xx
*chip
)
1862 struct snd_card
*card
;
1868 strcpy(card
->mixername
, chip
->pcm
->name
);
1870 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_base_controls
); idx
++) {
1871 struct snd_kcontrol
*kctl
;
1872 kctl
= snd_ctl_new1(&snd_es18xx_base_controls
[idx
], chip
);
1873 if (chip
->caps
& ES18XX_HWV
) {
1876 chip
->master_volume
= kctl
;
1877 kctl
->private_free
= snd_es18xx_hwv_free
;
1880 chip
->master_switch
= kctl
;
1881 kctl
->private_free
= snd_es18xx_hwv_free
;
1885 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
1888 if (chip
->caps
& ES18XX_PCM2
) {
1889 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_pcm2_controls
); idx
++) {
1890 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_pcm2_controls
[idx
], chip
))) < 0)
1894 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_pcm1_controls
); idx
++) {
1895 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_pcm1_controls
[idx
], chip
))) < 0)
1900 if (chip
->caps
& ES18XX_RECMIX
) {
1901 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_recmix_controls
); idx
++) {
1902 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_recmix_controls
[idx
], chip
))) < 0)
1906 switch (chip
->version
) {
1908 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_micpre1_control
, chip
))) < 0)
1913 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_micpre2_control
, chip
))) < 0)
1917 if (chip
->caps
& ES18XX_SPATIALIZER
) {
1918 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_spatializer_controls
); idx
++) {
1919 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_spatializer_controls
[idx
], chip
))) < 0)
1923 if (chip
->caps
& ES18XX_HWV
) {
1924 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_hw_volume_controls
); idx
++) {
1925 struct snd_kcontrol
*kctl
;
1926 kctl
= snd_ctl_new1(&snd_es18xx_hw_volume_controls
[idx
], chip
);
1928 chip
->hw_volume
= kctl
;
1930 chip
->hw_switch
= kctl
;
1931 kctl
->private_free
= snd_es18xx_hwv_free
;
1932 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
1937 /* finish initializing other chipset specific controls
1939 if (chip
->version
!= 0x1868) {
1940 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_opt_speaker
,
1945 if (chip
->version
== 0x1869) {
1946 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_opt_1869
); idx
++) {
1947 err
= snd_ctl_add(card
,
1948 snd_ctl_new1(&snd_es18xx_opt_1869
[idx
],
1953 } else if (chip
->version
== 0x1878) {
1954 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_opt_1878
,
1958 } else if (chip
->version
== 0x1879) {
1959 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_opt_1879
); idx
++) {
1960 err
= snd_ctl_add(card
,
1961 snd_ctl_new1(&snd_es18xx_opt_1879
[idx
],
1973 MODULE_AUTHOR("Christian Fischbach <fishbach@pool.informatik.rwth-aachen.de>, Abramo Bagnara <abramo@alsa-project.org>");
1974 MODULE_DESCRIPTION("ESS ES18xx AudioDrive");
1975 MODULE_LICENSE("GPL");
1976 MODULE_SUPPORTED_DEVICE("{{ESS,ES1868 PnP AudioDrive},"
1977 "{ESS,ES1869 PnP AudioDrive},"
1978 "{ESS,ES1878 PnP AudioDrive},"
1979 "{ESS,ES1879 PnP AudioDrive},"
1980 "{ESS,ES1887 PnP AudioDrive},"
1981 "{ESS,ES1888 PnP AudioDrive},"
1982 "{ESS,ES1887 AudioDrive},"
1983 "{ESS,ES1888 AudioDrive}}");
1985 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
1986 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
1987 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_ISAPNP
; /* Enable this card */
1989 static int isapnp
[SNDRV_CARDS
] = {[0 ... (SNDRV_CARDS
- 1)] = 1};
1991 static long port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
; /* 0x220,0x240,0x260,0x280 */
1993 static long mpu_port
[SNDRV_CARDS
] = {[0 ... (SNDRV_CARDS
- 1)] = -1};
1995 static long mpu_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
1997 static long fm_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
1998 static int irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
; /* 5,7,9,10 */
1999 static int dma1
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* 0,1,3 */
2000 static int dma2
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* 0,1,3 */
2002 module_param_array(index
, int, NULL
, 0444);
2003 MODULE_PARM_DESC(index
, "Index value for ES18xx soundcard.");
2004 module_param_array(id
, charp
, NULL
, 0444);
2005 MODULE_PARM_DESC(id
, "ID string for ES18xx soundcard.");
2006 module_param_array(enable
, bool, NULL
, 0444);
2007 MODULE_PARM_DESC(enable
, "Enable ES18xx soundcard.");
2009 module_param_array(isapnp
, bool, NULL
, 0444);
2010 MODULE_PARM_DESC(isapnp
, "PnP detection for specified soundcard.");
2012 module_param_array(port
, long, NULL
, 0444);
2013 MODULE_PARM_DESC(port
, "Port # for ES18xx driver.");
2014 module_param_array(mpu_port
, long, NULL
, 0444);
2015 MODULE_PARM_DESC(mpu_port
, "MPU-401 port # for ES18xx driver.");
2016 module_param_array(fm_port
, long, NULL
, 0444);
2017 MODULE_PARM_DESC(fm_port
, "FM port # for ES18xx driver.");
2018 module_param_array(irq
, int, NULL
, 0444);
2019 MODULE_PARM_DESC(irq
, "IRQ # for ES18xx driver.");
2020 module_param_array(dma1
, int, NULL
, 0444);
2021 MODULE_PARM_DESC(dma1
, "DMA 1 # for ES18xx driver.");
2022 module_param_array(dma2
, int, NULL
, 0444);
2023 MODULE_PARM_DESC(dma2
, "DMA 2 # for ES18xx driver.");
2026 static int isa_registered
;
2027 static int pnp_registered
;
2028 static int pnpc_registered
;
2030 static struct pnp_device_id snd_audiodrive_pnpbiosids
[] = {
2031 { .id
= "ESS1869" },
2032 { .id
= "ESS1879" },
2033 { .id
= "" } /* end */
2036 MODULE_DEVICE_TABLE(pnp
, snd_audiodrive_pnpbiosids
);
2038 /* PnP main device initialization */
2039 static int __devinit
snd_audiodrive_pnp_init_main(int dev
, struct pnp_dev
*pdev
)
2041 if (pnp_activate_dev(pdev
) < 0) {
2042 snd_printk(KERN_ERR PFX
"PnP configure failure (out of resources?)\n");
2045 /* ok. hack using Vendor-Defined Card-Level registers */
2046 /* skip csn and logdev initialization - already done in isapnp_configure */
2047 if (pnp_device_is_isapnp(pdev
)) {
2048 isapnp_cfg_begin(isapnp_card_number(pdev
), isapnp_csn_number(pdev
));
2049 isapnp_write_byte(0x27, pnp_irq(pdev
, 0)); /* Hardware Volume IRQ Number */
2050 if (mpu_port
[dev
] != SNDRV_AUTO_PORT
)
2051 isapnp_write_byte(0x28, pnp_irq(pdev
, 0)); /* MPU-401 IRQ Number */
2052 isapnp_write_byte(0x72, pnp_irq(pdev
, 0)); /* second IRQ */
2055 port
[dev
] = pnp_port_start(pdev
, 0);
2056 fm_port
[dev
] = pnp_port_start(pdev
, 1);
2057 mpu_port
[dev
] = pnp_port_start(pdev
, 2);
2058 dma1
[dev
] = pnp_dma(pdev
, 0);
2059 dma2
[dev
] = pnp_dma(pdev
, 1);
2060 irq
[dev
] = pnp_irq(pdev
, 0);
2061 snd_printdd("PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port
[dev
], fm_port
[dev
], mpu_port
[dev
]);
2062 snd_printdd("PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1
[dev
], dma2
[dev
], irq
[dev
]);
2066 static int __devinit
snd_audiodrive_pnp(int dev
, struct snd_audiodrive
*acard
,
2067 struct pnp_dev
*pdev
)
2070 if (snd_audiodrive_pnp_init_main(dev
, acard
->dev
) < 0)
2075 static struct pnp_card_device_id snd_audiodrive_pnpids
[] = {
2076 /* ESS 1868 (integrated on Compaq dual P-Pro motherboard and Genius 18PnP 3D) */
2077 { .id
= "ESS1868", .devs
= { { "ESS1868" }, { "ESS0000" } } },
2078 /* ESS 1868 (integrated on Maxisound Cards) */
2079 { .id
= "ESS1868", .devs
= { { "ESS8601" }, { "ESS8600" } } },
2080 /* ESS 1868 (integrated on Maxisound Cards) */
2081 { .id
= "ESS1868", .devs
= { { "ESS8611" }, { "ESS8610" } } },
2082 /* ESS ES1869 Plug and Play AudioDrive */
2083 { .id
= "ESS0003", .devs
= { { "ESS1869" }, { "ESS0006" } } },
2085 { .id
= "ESS1869", .devs
= { { "ESS1869" }, { "ESS0006" } } },
2087 { .id
= "ESS1878", .devs
= { { "ESS1878" }, { "ESS0004" } } },
2089 { .id
= "ESS1879", .devs
= { { "ESS1879" }, { "ESS0009" } } },
2091 { .id
= "" } /* end */
2094 MODULE_DEVICE_TABLE(pnp_card
, snd_audiodrive_pnpids
);
2096 static int __devinit
snd_audiodrive_pnpc(int dev
, struct snd_audiodrive
*acard
,
2097 struct pnp_card_link
*card
,
2098 const struct pnp_card_device_id
*id
)
2100 acard
->dev
= pnp_request_card_device(card
, id
->devs
[0].id
, NULL
);
2101 if (acard
->dev
== NULL
)
2104 acard
->devc
= pnp_request_card_device(card
, id
->devs
[1].id
, NULL
);
2105 if (acard
->devc
== NULL
)
2108 /* Control port initialization */
2109 if (pnp_activate_dev(acard
->devc
) < 0) {
2110 snd_printk(KERN_ERR PFX
"PnP control configure failure (out of resources?)\n");
2113 snd_printdd("pnp: port=0x%llx\n",
2114 (unsigned long long)pnp_port_start(acard
->devc
, 0));
2115 if (snd_audiodrive_pnp_init_main(dev
, acard
->dev
) < 0)
2120 #endif /* CONFIG_PNP */
2123 #define is_isapnp_selected(dev) isapnp[dev]
2125 #define is_isapnp_selected(dev) 0
2128 static int snd_es18xx_card_new(int dev
, struct snd_card
**cardp
)
2130 return snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
,
2131 sizeof(struct snd_audiodrive
), cardp
);
2134 static int __devinit
snd_audiodrive_probe(struct snd_card
*card
, int dev
)
2136 struct snd_audiodrive
*acard
= card
->private_data
;
2137 struct snd_es18xx
*chip
;
2138 struct snd_opl3
*opl3
;
2141 if ((err
= snd_es18xx_new_device(card
,
2145 irq
[dev
], dma1
[dev
], dma2
[dev
],
2150 sprintf(card
->driver
, "ES%x", chip
->version
);
2152 sprintf(card
->shortname
, "ESS AudioDrive ES%x", chip
->version
);
2153 if (dma1
[dev
] != dma2
[dev
])
2154 sprintf(card
->longname
, "%s at 0x%lx, irq %d, dma1 %d, dma2 %d",
2157 irq
[dev
], dma1
[dev
], dma2
[dev
]);
2159 sprintf(card
->longname
, "%s at 0x%lx, irq %d, dma %d",
2162 irq
[dev
], dma1
[dev
]);
2164 if ((err
= snd_es18xx_pcm(chip
, 0, NULL
)) < 0)
2167 if ((err
= snd_es18xx_mixer(chip
)) < 0)
2170 if (fm_port
[dev
] > 0 && fm_port
[dev
] != SNDRV_AUTO_PORT
) {
2171 if (snd_opl3_create(card
, chip
->fm_port
, chip
->fm_port
+ 2, OPL3_HW_OPL3
, 0, &opl3
) < 0) {
2172 snd_printk(KERN_WARNING PFX
"opl3 not detected at 0x%lx\n", chip
->fm_port
);
2174 if ((err
= snd_opl3_hwdep_new(opl3
, 0, 1, NULL
)) < 0)
2179 if (mpu_port
[dev
] > 0 && mpu_port
[dev
] != SNDRV_AUTO_PORT
) {
2180 if ((err
= snd_mpu401_uart_new(card
, 0, MPU401_HW_ES18XX
,
2187 return snd_card_register(card
);
2190 static int __devinit
snd_es18xx_isa_match(struct device
*pdev
, unsigned int dev
)
2192 return enable
[dev
] && !is_isapnp_selected(dev
);
2195 static int __devinit
snd_es18xx_isa_probe1(int dev
, struct device
*devptr
)
2197 struct snd_card
*card
;
2200 err
= snd_es18xx_card_new(dev
, &card
);
2203 snd_card_set_dev(card
, devptr
);
2204 if ((err
= snd_audiodrive_probe(card
, dev
)) < 0) {
2205 snd_card_free(card
);
2208 dev_set_drvdata(devptr
, card
);
2212 static int __devinit
snd_es18xx_isa_probe(struct device
*pdev
, unsigned int dev
)
2215 static int possible_irqs
[] = {5, 9, 10, 7, 11, 12, -1};
2216 static int possible_dmas
[] = {1, 0, 3, 5, -1};
2218 if (irq
[dev
] == SNDRV_AUTO_IRQ
) {
2219 if ((irq
[dev
] = snd_legacy_find_free_irq(possible_irqs
)) < 0) {
2220 snd_printk(KERN_ERR PFX
"unable to find a free IRQ\n");
2224 if (dma1
[dev
] == SNDRV_AUTO_DMA
) {
2225 if ((dma1
[dev
] = snd_legacy_find_free_dma(possible_dmas
)) < 0) {
2226 snd_printk(KERN_ERR PFX
"unable to find a free DMA1\n");
2230 if (dma2
[dev
] == SNDRV_AUTO_DMA
) {
2231 if ((dma2
[dev
] = snd_legacy_find_free_dma(possible_dmas
)) < 0) {
2232 snd_printk(KERN_ERR PFX
"unable to find a free DMA2\n");
2237 if (port
[dev
] != SNDRV_AUTO_PORT
) {
2238 return snd_es18xx_isa_probe1(dev
, pdev
);
2240 static unsigned long possible_ports
[] = {0x220, 0x240, 0x260, 0x280};
2242 for (i
= 0; i
< ARRAY_SIZE(possible_ports
); i
++) {
2243 port
[dev
] = possible_ports
[i
];
2244 err
= snd_es18xx_isa_probe1(dev
, pdev
);
2252 static int __devexit
snd_es18xx_isa_remove(struct device
*devptr
,
2255 snd_card_free(dev_get_drvdata(devptr
));
2256 dev_set_drvdata(devptr
, NULL
);
2261 static int snd_es18xx_isa_suspend(struct device
*dev
, unsigned int n
,
2264 return snd_es18xx_suspend(dev_get_drvdata(dev
), state
);
2267 static int snd_es18xx_isa_resume(struct device
*dev
, unsigned int n
)
2269 return snd_es18xx_resume(dev_get_drvdata(dev
));
2273 #define DEV_NAME "es18xx"
2275 static struct isa_driver snd_es18xx_isa_driver
= {
2276 .match
= snd_es18xx_isa_match
,
2277 .probe
= snd_es18xx_isa_probe
,
2278 .remove
= __devexit_p(snd_es18xx_isa_remove
),
2280 .suspend
= snd_es18xx_isa_suspend
,
2281 .resume
= snd_es18xx_isa_resume
,
2290 static int __devinit
snd_audiodrive_pnp_detect(struct pnp_dev
*pdev
,
2291 const struct pnp_device_id
*id
)
2295 struct snd_card
*card
;
2297 if (pnp_device_is_isapnp(pdev
))
2298 return -ENOENT
; /* we have another procedure - card */
2299 for (; dev
< SNDRV_CARDS
; dev
++) {
2300 if (enable
[dev
] && isapnp
[dev
])
2303 if (dev
>= SNDRV_CARDS
)
2306 err
= snd_es18xx_card_new(dev
, &card
);
2309 if ((err
= snd_audiodrive_pnp(dev
, card
->private_data
, pdev
)) < 0) {
2310 snd_card_free(card
);
2313 snd_card_set_dev(card
, &pdev
->dev
);
2314 if ((err
= snd_audiodrive_probe(card
, dev
)) < 0) {
2315 snd_card_free(card
);
2318 pnp_set_drvdata(pdev
, card
);
2323 static void __devexit
snd_audiodrive_pnp_remove(struct pnp_dev
* pdev
)
2325 snd_card_free(pnp_get_drvdata(pdev
));
2326 pnp_set_drvdata(pdev
, NULL
);
2330 static int snd_audiodrive_pnp_suspend(struct pnp_dev
*pdev
, pm_message_t state
)
2332 return snd_es18xx_suspend(pnp_get_drvdata(pdev
), state
);
2334 static int snd_audiodrive_pnp_resume(struct pnp_dev
*pdev
)
2336 return snd_es18xx_resume(pnp_get_drvdata(pdev
));
2340 static struct pnp_driver es18xx_pnp_driver
= {
2341 .name
= "es18xx-pnpbios",
2342 .id_table
= snd_audiodrive_pnpbiosids
,
2343 .probe
= snd_audiodrive_pnp_detect
,
2344 .remove
= __devexit_p(snd_audiodrive_pnp_remove
),
2346 .suspend
= snd_audiodrive_pnp_suspend
,
2347 .resume
= snd_audiodrive_pnp_resume
,
2351 static int __devinit
snd_audiodrive_pnpc_detect(struct pnp_card_link
*pcard
,
2352 const struct pnp_card_device_id
*pid
)
2355 struct snd_card
*card
;
2358 for ( ; dev
< SNDRV_CARDS
; dev
++) {
2359 if (enable
[dev
] && isapnp
[dev
])
2362 if (dev
>= SNDRV_CARDS
)
2365 res
= snd_es18xx_card_new(dev
, &card
);
2369 if ((res
= snd_audiodrive_pnpc(dev
, card
->private_data
, pcard
, pid
)) < 0) {
2370 snd_card_free(card
);
2373 snd_card_set_dev(card
, &pcard
->card
->dev
);
2374 if ((res
= snd_audiodrive_probe(card
, dev
)) < 0) {
2375 snd_card_free(card
);
2379 pnp_set_card_drvdata(pcard
, card
);
2384 static void __devexit
snd_audiodrive_pnpc_remove(struct pnp_card_link
* pcard
)
2386 snd_card_free(pnp_get_card_drvdata(pcard
));
2387 pnp_set_card_drvdata(pcard
, NULL
);
2391 static int snd_audiodrive_pnpc_suspend(struct pnp_card_link
*pcard
, pm_message_t state
)
2393 return snd_es18xx_suspend(pnp_get_card_drvdata(pcard
), state
);
2396 static int snd_audiodrive_pnpc_resume(struct pnp_card_link
*pcard
)
2398 return snd_es18xx_resume(pnp_get_card_drvdata(pcard
));
2403 static struct pnp_card_driver es18xx_pnpc_driver
= {
2404 .flags
= PNP_DRIVER_RES_DISABLE
,
2406 .id_table
= snd_audiodrive_pnpids
,
2407 .probe
= snd_audiodrive_pnpc_detect
,
2408 .remove
= __devexit_p(snd_audiodrive_pnpc_remove
),
2410 .suspend
= snd_audiodrive_pnpc_suspend
,
2411 .resume
= snd_audiodrive_pnpc_resume
,
2414 #endif /* CONFIG_PNP */
2416 static int __init
alsa_card_es18xx_init(void)
2420 err
= isa_register_driver(&snd_es18xx_isa_driver
, SNDRV_CARDS
);
2425 err
= pnp_register_driver(&es18xx_pnp_driver
);
2429 err
= pnp_register_card_driver(&es18xx_pnpc_driver
);
2431 pnpc_registered
= 1;
2433 if (isa_registered
|| pnp_registered
)
2439 static void __exit
alsa_card_es18xx_exit(void)
2442 if (pnpc_registered
)
2443 pnp_unregister_card_driver(&es18xx_pnpc_driver
);
2445 pnp_unregister_driver(&es18xx_pnp_driver
);
2448 isa_unregister_driver(&snd_es18xx_isa_driver
);
2451 module_init(alsa_card_es18xx_init
)
2452 module_exit(alsa_card_es18xx_exit
)