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 <sound/driver.h>
81 #include <linux/init.h>
82 #include <linux/err.h>
83 #include <linux/platform_device.h>
84 #include <linux/slab.h>
85 #include <linux/pnp.h>
86 #include <linux/isapnp.h>
87 #include <linux/moduleparam.h>
90 #include <sound/core.h>
91 #include <sound/control.h>
92 #include <sound/pcm.h>
93 #include <sound/pcm_params.h>
94 #include <sound/mpu401.h>
95 #include <sound/opl3.h>
96 #define SNDRV_LEGACY_FIND_FREE_IRQ
97 #define SNDRV_LEGACY_FIND_FREE_DMA
98 #include <sound/initval.h>
100 #define PFX "es18xx: "
103 unsigned long port
; /* port of ESS chip */
104 unsigned long mpu_port
; /* MPU-401 port of ESS chip */
105 unsigned long fm_port
; /* FM port */
106 unsigned long ctrl_port
; /* Control port of ESS chip */
107 struct resource
*res_port
;
108 struct resource
*res_mpu_port
;
109 struct resource
*res_ctrl_port
;
110 int irq
; /* IRQ number of ESS chip */
113 unsigned short version
; /* version of ESS chip */
114 int caps
; /* Chip capabilities */
115 unsigned short audio2_vol
; /* volume level of audio2 */
117 unsigned short active
; /* active channel mask */
118 unsigned int dma1_size
;
119 unsigned int dma2_size
;
120 unsigned int dma1_shift
;
121 unsigned int dma2_shift
;
123 struct snd_card
*card
;
125 struct snd_pcm_substream
*playback_a_substream
;
126 struct snd_pcm_substream
*capture_a_substream
;
127 struct snd_pcm_substream
*playback_b_substream
;
129 struct snd_rawmidi
*rmidi
;
131 struct snd_kcontrol
*hw_volume
;
132 struct snd_kcontrol
*hw_switch
;
133 struct snd_kcontrol
*master_volume
;
134 struct snd_kcontrol
*master_switch
;
137 spinlock_t mixer_lock
;
138 spinlock_t ctrl_lock
;
140 unsigned char pm_reg
;
144 struct snd_audiodrive
{
145 struct snd_es18xx
*chip
;
148 struct pnp_dev
*devc
;
152 #define AUDIO1_IRQ 0x01
153 #define AUDIO2_IRQ 0x02
157 #define ES18XX_PCM2 0x0001 /* Has two useable PCM */
158 #define ES18XX_SPATIALIZER 0x0002 /* Has 3D Spatializer */
159 #define ES18XX_RECMIX 0x0004 /* Has record mixer */
160 #define ES18XX_DUPLEX_MONO 0x0008 /* Has mono duplex only */
161 #define ES18XX_DUPLEX_SAME 0x0010 /* Playback and record must share the same rate */
162 #define ES18XX_NEW_RATE 0x0020 /* More precise rate setting */
163 #define ES18XX_AUXB 0x0040 /* AuxB mixer control */
164 #define ES18XX_HWV 0x0080 /* Has seperate hardware volume mixer controls*/
165 #define ES18XX_MONO 0x0100 /* Mono_in mixer control */
166 #define ES18XX_I2S 0x0200 /* I2S mixer control */
167 #define ES18XX_MUTEREC 0x0400 /* Record source can be muted */
168 #define ES18XX_CONTROL 0x0800 /* Has control ports */
170 /* Power Management */
171 #define ES18XX_PM 0x07
172 #define ES18XX_PM_GPO0 0x01
173 #define ES18XX_PM_GPO1 0x02
174 #define ES18XX_PM_PDR 0x04
175 #define ES18XX_PM_ANA 0x08
176 #define ES18XX_PM_FM 0x020
177 #define ES18XX_PM_SUS 0x080
184 #define MILLISECOND 10000
186 static int snd_es18xx_dsp_command(struct snd_es18xx
*chip
, unsigned char val
)
190 for(i
= MILLISECOND
; i
; i
--)
191 if ((inb(chip
->port
+ 0x0C) & 0x80) == 0) {
192 outb(val
, chip
->port
+ 0x0C);
195 snd_printk(KERN_ERR
"dsp_command: timeout (0x%x)\n", val
);
199 static int snd_es18xx_dsp_get_byte(struct snd_es18xx
*chip
)
203 for(i
= MILLISECOND
/10; i
; i
--)
204 if (inb(chip
->port
+ 0x0C) & 0x40)
205 return inb(chip
->port
+ 0x0A);
206 snd_printk(KERN_ERR
"dsp_get_byte failed: 0x%lx = 0x%x!!!\n",
207 chip
->port
+ 0x0A, inb(chip
->port
+ 0x0A));
213 static int snd_es18xx_write(struct snd_es18xx
*chip
,
214 unsigned char reg
, unsigned char data
)
219 spin_lock_irqsave(&chip
->reg_lock
, flags
);
220 ret
= snd_es18xx_dsp_command(chip
, reg
);
223 ret
= snd_es18xx_dsp_command(chip
, data
);
225 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
227 snd_printk(KERN_DEBUG
"Reg %02x set to %02x\n", reg
, data
);
232 static int snd_es18xx_read(struct snd_es18xx
*chip
, unsigned char reg
)
236 spin_lock_irqsave(&chip
->reg_lock
, flags
);
237 ret
= snd_es18xx_dsp_command(chip
, 0xC0);
240 ret
= snd_es18xx_dsp_command(chip
, reg
);
243 data
= snd_es18xx_dsp_get_byte(chip
);
246 snd_printk(KERN_DEBUG
"Reg %02x now is %02x (%d)\n", reg
, data
, ret
);
249 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
253 /* Return old value */
254 static int snd_es18xx_bits(struct snd_es18xx
*chip
, unsigned char reg
,
255 unsigned char mask
, unsigned char val
)
258 unsigned char old
, new, oval
;
260 spin_lock_irqsave(&chip
->reg_lock
, flags
);
261 ret
= snd_es18xx_dsp_command(chip
, 0xC0);
264 ret
= snd_es18xx_dsp_command(chip
, reg
);
267 ret
= snd_es18xx_dsp_get_byte(chip
);
274 ret
= snd_es18xx_dsp_command(chip
, reg
);
277 new = (old
& ~mask
) | (val
& mask
);
278 ret
= snd_es18xx_dsp_command(chip
, new);
282 snd_printk(KERN_DEBUG
"Reg %02x was %02x, set to %02x (%d)\n",
288 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
292 static inline void snd_es18xx_mixer_write(struct snd_es18xx
*chip
,
293 unsigned char reg
, unsigned char data
)
296 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
297 outb(reg
, chip
->port
+ 0x04);
298 outb(data
, chip
->port
+ 0x05);
299 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
301 snd_printk(KERN_DEBUG
"Mixer reg %02x set to %02x\n", reg
, data
);
305 static inline int snd_es18xx_mixer_read(struct snd_es18xx
*chip
, unsigned char reg
)
309 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
310 outb(reg
, chip
->port
+ 0x04);
311 data
= inb(chip
->port
+ 0x05);
312 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
314 snd_printk(KERN_DEBUG
"Mixer reg %02x now is %02x\n", reg
, data
);
319 /* Return old value */
320 static inline int snd_es18xx_mixer_bits(struct snd_es18xx
*chip
, unsigned char reg
,
321 unsigned char mask
, unsigned char val
)
323 unsigned char old
, new, oval
;
325 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
326 outb(reg
, chip
->port
+ 0x04);
327 old
= inb(chip
->port
+ 0x05);
330 new = (old
& ~mask
) | (val
& mask
);
331 outb(new, chip
->port
+ 0x05);
333 snd_printk(KERN_DEBUG
"Mixer reg %02x was %02x, set to %02x\n",
337 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
341 static inline int snd_es18xx_mixer_writable(struct snd_es18xx
*chip
, unsigned char reg
,
344 int old
, expected
, new;
346 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
347 outb(reg
, chip
->port
+ 0x04);
348 old
= inb(chip
->port
+ 0x05);
349 expected
= old
^ mask
;
350 outb(expected
, chip
->port
+ 0x05);
351 new = inb(chip
->port
+ 0x05);
352 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
354 snd_printk(KERN_DEBUG
"Mixer reg %02x was %02x, set to %02x, now is %02x\n",
355 reg
, old
, expected
, new);
357 return expected
== new;
361 static int snd_es18xx_reset(struct snd_es18xx
*chip
)
364 outb(0x03, chip
->port
+ 0x06);
365 inb(chip
->port
+ 0x06);
366 outb(0x00, chip
->port
+ 0x06);
367 for(i
= 0; i
< MILLISECOND
&& !(inb(chip
->port
+ 0x0E) & 0x80); i
++);
368 if (inb(chip
->port
+ 0x0A) != 0xAA)
373 static int snd_es18xx_reset_fifo(struct snd_es18xx
*chip
)
375 outb(0x02, chip
->port
+ 0x06);
376 inb(chip
->port
+ 0x06);
377 outb(0x00, chip
->port
+ 0x06);
381 static struct snd_ratnum new_clocks
[2] = {
396 static struct snd_pcm_hw_constraint_ratnums new_hw_constraints_clocks
= {
401 static struct snd_ratnum old_clocks
[2] = {
416 static struct snd_pcm_hw_constraint_ratnums old_hw_constraints_clocks
= {
422 static void snd_es18xx_rate_set(struct snd_es18xx
*chip
,
423 struct snd_pcm_substream
*substream
,
426 unsigned int bits
, div0
;
427 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
428 if (chip
->caps
& ES18XX_NEW_RATE
) {
429 if (runtime
->rate_num
== new_clocks
[0].num
)
430 bits
= 128 - runtime
->rate_den
;
432 bits
= 256 - runtime
->rate_den
;
434 if (runtime
->rate_num
== old_clocks
[0].num
)
435 bits
= 256 - runtime
->rate_den
;
437 bits
= 128 - runtime
->rate_den
;
440 /* set filter register */
441 div0
= 256 - 7160000*20/(8*82*runtime
->rate
);
443 if ((chip
->caps
& ES18XX_PCM2
) && mode
== DAC2
) {
444 snd_es18xx_mixer_write(chip
, 0x70, bits
);
446 * Comment from kernel oss driver:
447 * FKS: fascinating: 0x72 doesn't seem to work.
449 snd_es18xx_write(chip
, 0xA2, div0
);
450 snd_es18xx_mixer_write(chip
, 0x72, div0
);
452 snd_es18xx_write(chip
, 0xA1, bits
);
453 snd_es18xx_write(chip
, 0xA2, div0
);
457 static int snd_es18xx_playback_hw_params(struct snd_pcm_substream
*substream
,
458 struct snd_pcm_hw_params
*hw_params
)
460 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
464 if (params_channels(hw_params
) == 2)
466 if (snd_pcm_format_width(params_format(hw_params
)) == 16)
469 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
470 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
471 (chip
->capture_a_substream
) &&
472 params_channels(hw_params
) != 1) {
473 _snd_pcm_hw_param_setempty(hw_params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
476 chip
->dma2_shift
= shift
;
478 chip
->dma1_shift
= shift
;
480 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
485 static int snd_es18xx_pcm_hw_free(struct snd_pcm_substream
*substream
)
487 return snd_pcm_lib_free_pages(substream
);
490 static int snd_es18xx_playback1_prepare(struct snd_es18xx
*chip
,
491 struct snd_pcm_substream
*substream
)
493 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
494 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
495 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
497 chip
->dma2_size
= size
;
499 snd_es18xx_rate_set(chip
, substream
, DAC2
);
501 /* Transfer Count Reload */
502 count
= 0x10000 - count
;
503 snd_es18xx_mixer_write(chip
, 0x74, count
& 0xff);
504 snd_es18xx_mixer_write(chip
, 0x76, count
>> 8);
507 snd_es18xx_mixer_bits(chip
, 0x7A, 0x07,
508 ((runtime
->channels
== 1) ? 0x00 : 0x02) |
509 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x01 : 0x00) |
510 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x04));
512 /* Set DMA controller */
513 snd_dma_program(chip
->dma2
, runtime
->dma_addr
, size
, DMA_MODE_WRITE
| DMA_AUTOINIT
);
518 static int snd_es18xx_playback1_trigger(struct snd_es18xx
*chip
,
519 struct snd_pcm_substream
*substream
,
523 case SNDRV_PCM_TRIGGER_START
:
524 case SNDRV_PCM_TRIGGER_RESUME
:
525 if (chip
->active
& DAC2
)
527 chip
->active
|= DAC2
;
530 snd_es18xx_mixer_write(chip
, 0x78, 0xb3);
532 snd_es18xx_mixer_write(chip
, 0x78, 0x93);
536 if (chip
->caps
& ES18XX_PCM2
)
537 /* Restore Audio 2 volume */
538 snd_es18xx_mixer_write(chip
, 0x7C, chip
->audio2_vol
);
540 /* Enable PCM output */
541 snd_es18xx_dsp_command(chip
, 0xD1);
544 case SNDRV_PCM_TRIGGER_STOP
:
545 case SNDRV_PCM_TRIGGER_SUSPEND
:
546 if (!(chip
->active
& DAC2
))
548 chip
->active
&= ~DAC2
;
550 snd_es18xx_mixer_write(chip
, 0x78, 0x00);
553 if (chip
->caps
& ES18XX_PCM2
)
554 /* Set Audio 2 volume to 0 */
555 snd_es18xx_mixer_write(chip
, 0x7C, 0);
557 /* Disable PCM output */
558 snd_es18xx_dsp_command(chip
, 0xD3);
568 static int snd_es18xx_capture_hw_params(struct snd_pcm_substream
*substream
,
569 struct snd_pcm_hw_params
*hw_params
)
571 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
575 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
576 chip
->playback_a_substream
&&
577 params_channels(hw_params
) != 1) {
578 _snd_pcm_hw_param_setempty(hw_params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
581 if (params_channels(hw_params
) == 2)
583 if (snd_pcm_format_width(params_format(hw_params
)) == 16)
585 chip
->dma1_shift
= shift
;
586 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
591 static int snd_es18xx_capture_prepare(struct snd_pcm_substream
*substream
)
593 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
594 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
595 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
596 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
598 chip
->dma1_size
= size
;
600 snd_es18xx_reset_fifo(chip
);
602 /* Set stereo/mono */
603 snd_es18xx_bits(chip
, 0xA8, 0x03, runtime
->channels
== 1 ? 0x02 : 0x01);
605 snd_es18xx_rate_set(chip
, substream
, ADC1
);
607 /* Transfer Count Reload */
608 count
= 0x10000 - count
;
609 snd_es18xx_write(chip
, 0xA4, count
& 0xff);
610 snd_es18xx_write(chip
, 0xA5, count
>> 8);
617 snd_es18xx_write(chip
, 0xB7,
618 snd_pcm_format_unsigned(runtime
->format
) ? 0x51 : 0x71);
619 snd_es18xx_write(chip
, 0xB7, 0x90 |
620 ((runtime
->channels
== 1) ? 0x40 : 0x08) |
621 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x04 : 0x00) |
622 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x20));
624 /* Set DMA controler */
625 snd_dma_program(chip
->dma1
, runtime
->dma_addr
, size
, DMA_MODE_READ
| DMA_AUTOINIT
);
630 static int snd_es18xx_capture_trigger(struct snd_pcm_substream
*substream
,
633 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
636 case SNDRV_PCM_TRIGGER_START
:
637 case SNDRV_PCM_TRIGGER_RESUME
:
638 if (chip
->active
& ADC1
)
640 chip
->active
|= ADC1
;
642 snd_es18xx_write(chip
, 0xB8, 0x0f);
644 case SNDRV_PCM_TRIGGER_STOP
:
645 case SNDRV_PCM_TRIGGER_SUSPEND
:
646 if (!(chip
->active
& ADC1
))
648 chip
->active
&= ~ADC1
;
650 snd_es18xx_write(chip
, 0xB8, 0x00);
659 static int snd_es18xx_playback2_prepare(struct snd_es18xx
*chip
,
660 struct snd_pcm_substream
*substream
)
662 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
663 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
664 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
666 chip
->dma1_size
= size
;
668 snd_es18xx_reset_fifo(chip
);
670 /* Set stereo/mono */
671 snd_es18xx_bits(chip
, 0xA8, 0x03, runtime
->channels
== 1 ? 0x02 : 0x01);
673 snd_es18xx_rate_set(chip
, substream
, DAC1
);
675 /* Transfer Count Reload */
676 count
= 0x10000 - count
;
677 snd_es18xx_write(chip
, 0xA4, count
& 0xff);
678 snd_es18xx_write(chip
, 0xA5, count
>> 8);
681 snd_es18xx_write(chip
, 0xB6,
682 snd_pcm_format_unsigned(runtime
->format
) ? 0x80 : 0x00);
683 snd_es18xx_write(chip
, 0xB7,
684 snd_pcm_format_unsigned(runtime
->format
) ? 0x51 : 0x71);
685 snd_es18xx_write(chip
, 0xB7, 0x90 |
686 (runtime
->channels
== 1 ? 0x40 : 0x08) |
687 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x04 : 0x00) |
688 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x20));
690 /* Set DMA controler */
691 snd_dma_program(chip
->dma1
, runtime
->dma_addr
, size
, DMA_MODE_WRITE
| DMA_AUTOINIT
);
696 static int snd_es18xx_playback2_trigger(struct snd_es18xx
*chip
,
697 struct snd_pcm_substream
*substream
,
701 case SNDRV_PCM_TRIGGER_START
:
702 case SNDRV_PCM_TRIGGER_RESUME
:
703 if (chip
->active
& DAC1
)
705 chip
->active
|= DAC1
;
707 snd_es18xx_write(chip
, 0xB8, 0x05);
712 snd_es18xx_dsp_command(chip
, 0xD1);
715 case SNDRV_PCM_TRIGGER_STOP
:
716 case SNDRV_PCM_TRIGGER_SUSPEND
:
717 if (!(chip
->active
& DAC1
))
719 chip
->active
&= ~DAC1
;
721 snd_es18xx_write(chip
, 0xB8, 0x00);
725 /* Disable Audio 1 */
726 snd_es18xx_dsp_command(chip
, 0xD3);
736 static int snd_es18xx_playback_prepare(struct snd_pcm_substream
*substream
)
738 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
739 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
740 return snd_es18xx_playback1_prepare(chip
, substream
);
742 return snd_es18xx_playback2_prepare(chip
, substream
);
745 static int snd_es18xx_playback_trigger(struct snd_pcm_substream
*substream
,
748 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
749 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
750 return snd_es18xx_playback1_trigger(chip
, substream
, cmd
);
752 return snd_es18xx_playback2_trigger(chip
, substream
, cmd
);
755 static irqreturn_t
snd_es18xx_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
757 struct snd_es18xx
*chip
= dev_id
;
758 unsigned char status
;
760 if (chip
->caps
& ES18XX_CONTROL
) {
761 /* Read Interrupt status */
762 status
= inb(chip
->ctrl_port
+ 6);
764 /* Read Interrupt status */
765 status
= snd_es18xx_mixer_read(chip
, 0x7f) >> 4;
770 if (inb(chip
->port
+ 0x0C) & 0x01)
771 status
|= AUDIO1_IRQ
;
772 if (snd_es18xx_mixer_read(chip
, 0x7A) & 0x80)
773 status
|= AUDIO2_IRQ
;
774 if ((chip
->caps
& ES18XX_HWV
) &&
775 snd_es18xx_mixer_read(chip
, 0x64) & 0x10)
780 /* Audio 1 & Audio 2 */
781 if (status
& AUDIO2_IRQ
) {
782 if (chip
->active
& DAC2
)
783 snd_pcm_period_elapsed(chip
->playback_a_substream
);
785 snd_es18xx_mixer_bits(chip
, 0x7A, 0x80, 0x00);
787 if (status
& AUDIO1_IRQ
) {
788 /* ok.. capture is active */
789 if (chip
->active
& ADC1
)
790 snd_pcm_period_elapsed(chip
->capture_a_substream
);
791 /* ok.. playback2 is active */
792 else if (chip
->active
& DAC1
)
793 snd_pcm_period_elapsed(chip
->playback_b_substream
);
795 inb(chip
->port
+ 0x0E);
799 if ((status
& MPU_IRQ
) && chip
->rmidi
)
800 snd_mpu401_uart_interrupt(irq
, chip
->rmidi
->private_data
, regs
);
802 /* Hardware volume */
803 if (status
& HWV_IRQ
) {
805 if (chip
->caps
& ES18XX_HWV
) {
806 split
= snd_es18xx_mixer_read(chip
, 0x64) & 0x80;
807 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &chip
->hw_switch
->id
);
808 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &chip
->hw_volume
->id
);
811 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &chip
->master_switch
->id
);
812 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &chip
->master_volume
->id
);
815 snd_es18xx_mixer_write(chip
, 0x66, 0x00);
820 static snd_pcm_uframes_t
snd_es18xx_playback_pointer(struct snd_pcm_substream
*substream
)
822 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
825 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
826 if (!(chip
->active
& DAC2
))
828 pos
= snd_dma_pointer(chip
->dma2
, chip
->dma2_size
);
829 return pos
>> chip
->dma2_shift
;
831 if (!(chip
->active
& DAC1
))
833 pos
= snd_dma_pointer(chip
->dma1
, chip
->dma1_size
);
834 return pos
>> chip
->dma1_shift
;
838 static snd_pcm_uframes_t
snd_es18xx_capture_pointer(struct snd_pcm_substream
*substream
)
840 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
843 if (!(chip
->active
& ADC1
))
845 pos
= snd_dma_pointer(chip
->dma1
, chip
->dma1_size
);
846 return pos
>> chip
->dma1_shift
;
849 static struct snd_pcm_hardware snd_es18xx_playback
=
851 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
852 SNDRV_PCM_INFO_RESUME
|
853 SNDRV_PCM_INFO_MMAP_VALID
),
854 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S8
|
855 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_U16_LE
),
856 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
861 .buffer_bytes_max
= 65536,
862 .period_bytes_min
= 64,
863 .period_bytes_max
= 65536,
869 static struct snd_pcm_hardware snd_es18xx_capture
=
871 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
872 SNDRV_PCM_INFO_RESUME
|
873 SNDRV_PCM_INFO_MMAP_VALID
),
874 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S8
|
875 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_U16_LE
),
876 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
881 .buffer_bytes_max
= 65536,
882 .period_bytes_min
= 64,
883 .period_bytes_max
= 65536,
889 static int snd_es18xx_playback_open(struct snd_pcm_substream
*substream
)
891 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
892 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
894 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
895 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
896 chip
->capture_a_substream
&&
897 chip
->capture_a_substream
->runtime
->channels
!= 1)
899 chip
->playback_a_substream
= substream
;
900 } else if (substream
->number
<= 1) {
901 if (chip
->capture_a_substream
)
903 chip
->playback_b_substream
= substream
;
908 substream
->runtime
->hw
= snd_es18xx_playback
;
909 snd_pcm_hw_constraint_ratnums(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
910 (chip
->caps
& ES18XX_NEW_RATE
) ? &new_hw_constraints_clocks
: &old_hw_constraints_clocks
);
914 static int snd_es18xx_capture_open(struct snd_pcm_substream
*substream
)
916 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
917 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
919 if (chip
->playback_b_substream
)
921 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
922 chip
->playback_a_substream
&&
923 chip
->playback_a_substream
->runtime
->channels
!= 1)
925 chip
->capture_a_substream
= substream
;
926 substream
->runtime
->hw
= snd_es18xx_capture
;
927 snd_pcm_hw_constraint_ratnums(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
928 (chip
->caps
& ES18XX_NEW_RATE
) ? &new_hw_constraints_clocks
: &old_hw_constraints_clocks
);
932 static int snd_es18xx_playback_close(struct snd_pcm_substream
*substream
)
934 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
936 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
937 chip
->playback_a_substream
= NULL
;
939 chip
->playback_b_substream
= NULL
;
941 snd_pcm_lib_free_pages(substream
);
945 static int snd_es18xx_capture_close(struct snd_pcm_substream
*substream
)
947 struct snd_es18xx
*chip
= snd_pcm_substream_chip(substream
);
949 chip
->capture_a_substream
= NULL
;
950 snd_pcm_lib_free_pages(substream
);
958 /* Record source mux routines:
959 * Depending on the chipset this mux switches between 4, 5, or 8 possible inputs.
960 * bit table for the 4/5 source mux:
967 * if it's "mixer" and it's a 5 source mux chipset then reg 7A bit 3 determines
968 * either the play mixer or the capture mixer.
970 * "map4Source" translates from source number to reg bit pattern
971 * "invMap4Source" translates from reg bit pattern to source number
974 static int snd_es18xx_info_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
976 static char *texts4Source
[4] = {
977 "Mic", "CD", "Line", "Master"
979 static char *texts5Source
[5] = {
980 "Mic", "CD", "Line", "Master", "Mix"
982 static char *texts8Source
[8] = {
983 "Mic", "Mic Master", "CD", "AOUT",
984 "Mic1", "Mix", "Line", "Master"
986 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
988 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
990 switch (chip
->version
) {
993 uinfo
->value
.enumerated
.items
= 4;
994 if (uinfo
->value
.enumerated
.item
> 3)
995 uinfo
->value
.enumerated
.item
= 3;
996 strcpy(uinfo
->value
.enumerated
.name
, texts4Source
[uinfo
->value
.enumerated
.item
]);
1000 uinfo
->value
.enumerated
.items
= 5;
1001 if (uinfo
->value
.enumerated
.item
> 4)
1002 uinfo
->value
.enumerated
.item
= 4;
1003 strcpy(uinfo
->value
.enumerated
.name
, texts5Source
[uinfo
->value
.enumerated
.item
]);
1005 case 0x1869: /* DS somewhat contradictory for 1869: could be be 5 or 8 */
1007 uinfo
->value
.enumerated
.items
= 8;
1008 if (uinfo
->value
.enumerated
.item
> 7)
1009 uinfo
->value
.enumerated
.item
= 7;
1010 strcpy(uinfo
->value
.enumerated
.name
, texts8Source
[uinfo
->value
.enumerated
.item
]);
1018 static int snd_es18xx_get_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1020 static unsigned char invMap4Source
[8] = {0, 0, 1, 1, 0, 0, 2, 3};
1021 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1022 int muxSource
= snd_es18xx_mixer_read(chip
, 0x1c) & 0x07;
1023 if (!(chip
->version
== 0x1869 || chip
->version
== 0x1879)) {
1024 muxSource
= invMap4Source
[muxSource
];
1026 (chip
->version
== 0x1887 || chip
->version
== 0x1888) &&
1027 (snd_es18xx_mixer_read(chip
, 0x7a) & 0x08)
1031 ucontrol
->value
.enumerated
.item
[0] = muxSource
;
1035 static int snd_es18xx_put_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1037 static unsigned char map4Source
[4] = {0, 2, 6, 7};
1038 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1039 unsigned char val
= ucontrol
->value
.enumerated
.item
[0];
1040 unsigned char retVal
= 0;
1042 switch (chip
->version
) {
1043 /* 5 source chips */
1049 retVal
= snd_es18xx_mixer_bits(chip
, 0x7a, 0x08, 0x08) != 0x08;
1052 retVal
= snd_es18xx_mixer_bits(chip
, 0x7a, 0x08, 0x00) != 0x00;
1053 /* 4 source chips */
1058 val
= map4Source
[val
];
1060 /* 8 source chips */
1069 return (snd_es18xx_mixer_bits(chip
, 0x1c, 0x07, val
) != val
) || retVal
;
1072 static int snd_es18xx_info_spatializer_enable(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1074 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1076 uinfo
->value
.integer
.min
= 0;
1077 uinfo
->value
.integer
.max
= 1;
1081 static int snd_es18xx_get_spatializer_enable(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1083 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1084 unsigned char val
= snd_es18xx_mixer_read(chip
, 0x50);
1085 ucontrol
->value
.integer
.value
[0] = !!(val
& 8);
1089 static int snd_es18xx_put_spatializer_enable(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1091 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1092 unsigned char oval
, nval
;
1094 nval
= ucontrol
->value
.integer
.value
[0] ? 0x0c : 0x04;
1095 oval
= snd_es18xx_mixer_read(chip
, 0x50) & 0x0c;
1096 change
= nval
!= oval
;
1098 snd_es18xx_mixer_write(chip
, 0x50, nval
& ~0x04);
1099 snd_es18xx_mixer_write(chip
, 0x50, nval
);
1104 static int snd_es18xx_info_hw_volume(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1106 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1108 uinfo
->value
.integer
.min
= 0;
1109 uinfo
->value
.integer
.max
= 63;
1113 static int snd_es18xx_get_hw_volume(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1115 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1116 ucontrol
->value
.integer
.value
[0] = snd_es18xx_mixer_read(chip
, 0x61) & 0x3f;
1117 ucontrol
->value
.integer
.value
[1] = snd_es18xx_mixer_read(chip
, 0x63) & 0x3f;
1121 static int snd_es18xx_info_hw_switch(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1123 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1125 uinfo
->value
.integer
.min
= 0;
1126 uinfo
->value
.integer
.max
= 1;
1130 static int snd_es18xx_get_hw_switch(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1132 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1133 ucontrol
->value
.integer
.value
[0] = !(snd_es18xx_mixer_read(chip
, 0x61) & 0x40);
1134 ucontrol
->value
.integer
.value
[1] = !(snd_es18xx_mixer_read(chip
, 0x63) & 0x40);
1138 static void snd_es18xx_hwv_free(struct snd_kcontrol
*kcontrol
)
1140 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1141 chip
->master_volume
= NULL
;
1142 chip
->master_switch
= NULL
;
1143 chip
->hw_volume
= NULL
;
1144 chip
->hw_switch
= NULL
;
1147 static int snd_es18xx_reg_bits(struct snd_es18xx
*chip
, unsigned char reg
,
1148 unsigned char mask
, unsigned char val
)
1151 return snd_es18xx_mixer_bits(chip
, reg
, mask
, val
);
1153 return snd_es18xx_bits(chip
, reg
, mask
, val
);
1156 static int snd_es18xx_reg_read(struct snd_es18xx
*chip
, unsigned char reg
)
1159 return snd_es18xx_mixer_read(chip
, reg
);
1161 return snd_es18xx_read(chip
, reg
);
1164 #define ES18XX_SINGLE(xname, xindex, reg, shift, mask, invert) \
1165 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1166 .info = snd_es18xx_info_single, \
1167 .get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \
1168 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
1170 static int snd_es18xx_info_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1172 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1174 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1176 uinfo
->value
.integer
.min
= 0;
1177 uinfo
->value
.integer
.max
= mask
;
1181 static int snd_es18xx_get_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1183 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1184 int reg
= kcontrol
->private_value
& 0xff;
1185 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1186 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1187 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1190 val
= snd_es18xx_reg_read(chip
, reg
);
1191 ucontrol
->value
.integer
.value
[0] = (val
>> shift
) & mask
;
1193 ucontrol
->value
.integer
.value
[0] = mask
- ucontrol
->value
.integer
.value
[0];
1197 static int snd_es18xx_put_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1199 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1200 int reg
= kcontrol
->private_value
& 0xff;
1201 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1202 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1203 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1206 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1211 return snd_es18xx_reg_bits(chip
, reg
, mask
, val
) != val
;
1214 #define ES18XX_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
1215 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1216 .info = snd_es18xx_info_double, \
1217 .get = snd_es18xx_get_double, .put = snd_es18xx_put_double, \
1218 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
1220 static int snd_es18xx_info_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1222 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1224 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1226 uinfo
->value
.integer
.min
= 0;
1227 uinfo
->value
.integer
.max
= mask
;
1231 static int snd_es18xx_get_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1233 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1234 int left_reg
= kcontrol
->private_value
& 0xff;
1235 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
1236 int shift_left
= (kcontrol
->private_value
>> 16) & 0x07;
1237 int shift_right
= (kcontrol
->private_value
>> 19) & 0x07;
1238 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1239 int invert
= (kcontrol
->private_value
>> 22) & 1;
1240 unsigned char left
, right
;
1242 left
= snd_es18xx_reg_read(chip
, left_reg
);
1243 if (left_reg
!= right_reg
)
1244 right
= snd_es18xx_reg_read(chip
, right_reg
);
1247 ucontrol
->value
.integer
.value
[0] = (left
>> shift_left
) & mask
;
1248 ucontrol
->value
.integer
.value
[1] = (right
>> shift_right
) & mask
;
1250 ucontrol
->value
.integer
.value
[0] = mask
- ucontrol
->value
.integer
.value
[0];
1251 ucontrol
->value
.integer
.value
[1] = mask
- ucontrol
->value
.integer
.value
[1];
1256 static int snd_es18xx_put_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1258 struct snd_es18xx
*chip
= snd_kcontrol_chip(kcontrol
);
1259 int left_reg
= kcontrol
->private_value
& 0xff;
1260 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
1261 int shift_left
= (kcontrol
->private_value
>> 16) & 0x07;
1262 int shift_right
= (kcontrol
->private_value
>> 19) & 0x07;
1263 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1264 int invert
= (kcontrol
->private_value
>> 22) & 1;
1266 unsigned char val1
, val2
, mask1
, mask2
;
1268 val1
= ucontrol
->value
.integer
.value
[0] & mask
;
1269 val2
= ucontrol
->value
.integer
.value
[1] & mask
;
1274 val1
<<= shift_left
;
1275 val2
<<= shift_right
;
1276 mask1
= mask
<< shift_left
;
1277 mask2
= mask
<< shift_right
;
1278 if (left_reg
!= right_reg
) {
1280 if (snd_es18xx_reg_bits(chip
, left_reg
, mask1
, val1
) != val1
)
1282 if (snd_es18xx_reg_bits(chip
, right_reg
, mask2
, val2
) != val2
)
1285 change
= (snd_es18xx_reg_bits(chip
, left_reg
, mask1
| mask2
,
1286 val1
| val2
) != (val1
| val2
));
1292 * These arrays contain setup data for mixer controls.
1294 * The controls that are universal to all chipsets are fully initialized
1297 static struct snd_kcontrol_new snd_es18xx_base_controls
[] = {
1298 ES18XX_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0),
1299 ES18XX_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1),
1300 ES18XX_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0),
1301 ES18XX_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0),
1302 ES18XX_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0),
1303 ES18XX_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0),
1304 ES18XX_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0),
1305 ES18XX_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
1306 ES18XX_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0),
1308 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1309 .name
= "Capture Source",
1310 .info
= snd_es18xx_info_mux
,
1311 .get
= snd_es18xx_get_mux
,
1312 .put
= snd_es18xx_put_mux
,
1316 static struct snd_kcontrol_new snd_es18xx_recmix_controls
[] = {
1317 ES18XX_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0),
1318 ES18XX_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0),
1319 ES18XX_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0),
1320 ES18XX_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0),
1321 ES18XX_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0),
1322 ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0)
1326 * The chipset specific mixer controls
1328 static struct snd_kcontrol_new snd_es18xx_opt_speaker
=
1329 ES18XX_SINGLE("PC Speaker Playback Volume", 0, 0x3c, 0, 7, 0);
1331 static struct snd_kcontrol_new snd_es18xx_opt_1869
[] = {
1332 ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
1333 ES18XX_SINGLE("Video Playback Switch", 0, 0x7f, 0, 1, 0),
1334 ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1335 ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0)
1338 static struct snd_kcontrol_new snd_es18xx_opt_1878
=
1339 ES18XX_DOUBLE("Video Playback Volume", 0, 0x68, 0x68, 4, 0, 15, 0);
1341 static struct snd_kcontrol_new snd_es18xx_opt_1879
[] = {
1342 ES18XX_SINGLE("Video Playback Switch", 0, 0x71, 6, 1, 0),
1343 ES18XX_DOUBLE("Video Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1344 ES18XX_DOUBLE("Video Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0)
1347 static struct snd_kcontrol_new snd_es18xx_pcm1_controls
[] = {
1348 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x14, 0x14, 4, 0, 15, 0),
1351 static struct snd_kcontrol_new snd_es18xx_pcm2_controls
[] = {
1352 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0),
1353 ES18XX_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0)
1356 static struct snd_kcontrol_new snd_es18xx_spatializer_controls
[] = {
1357 ES18XX_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
1359 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1360 .name
= "3D Control - Switch",
1361 .info
= snd_es18xx_info_spatializer_enable
,
1362 .get
= snd_es18xx_get_spatializer_enable
,
1363 .put
= snd_es18xx_put_spatializer_enable
,
1367 static struct snd_kcontrol_new snd_es18xx_micpre1_control
=
1368 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0xa9, 2, 1, 0);
1370 static struct snd_kcontrol_new snd_es18xx_micpre2_control
=
1371 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0);
1373 static struct snd_kcontrol_new snd_es18xx_hw_volume_controls
[] = {
1375 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1376 .name
= "Hardware Master Playback Volume",
1377 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1378 .info
= snd_es18xx_info_hw_volume
,
1379 .get
= snd_es18xx_get_hw_volume
,
1382 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1383 .name
= "Hardware Master Playback Switch",
1384 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1385 .info
= snd_es18xx_info_hw_switch
,
1386 .get
= snd_es18xx_get_hw_switch
,
1388 ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0),
1391 static int __devinit
snd_es18xx_config_read(struct snd_es18xx
*chip
, unsigned char reg
)
1394 unsigned long flags
;
1395 spin_lock_irqsave(&chip
->ctrl_lock
, flags
);
1396 outb(reg
, chip
->ctrl_port
);
1397 data
= inb(chip
->ctrl_port
+ 1);
1398 spin_unlock_irqrestore(&chip
->ctrl_lock
, flags
);
1402 static void __devinit
snd_es18xx_config_write(struct snd_es18xx
*chip
,
1403 unsigned char reg
, unsigned char data
)
1405 /* No need for spinlocks, this function is used only in
1406 otherwise protected init code */
1407 outb(reg
, chip
->ctrl_port
);
1408 outb(data
, chip
->ctrl_port
+ 1);
1410 snd_printk(KERN_DEBUG
"Config reg %02x set to %02x\n", reg
, data
);
1414 static int __devinit
snd_es18xx_initialize(struct snd_es18xx
*chip
)
1418 /* enable extended mode */
1419 snd_es18xx_dsp_command(chip
, 0xC6);
1420 /* Reset mixer registers */
1421 snd_es18xx_mixer_write(chip
, 0x00, 0x00);
1423 /* Audio 1 DMA demand mode (4 bytes/request) */
1424 snd_es18xx_write(chip
, 0xB9, 2);
1425 if (chip
->caps
& ES18XX_CONTROL
) {
1426 /* Hardware volume IRQ */
1427 snd_es18xx_config_write(chip
, 0x27, chip
->irq
);
1428 if (chip
->fm_port
> 0 && chip
->fm_port
!= SNDRV_AUTO_PORT
) {
1430 snd_es18xx_config_write(chip
, 0x62, chip
->fm_port
>> 8);
1431 snd_es18xx_config_write(chip
, 0x63, chip
->fm_port
& 0xff);
1433 if (chip
->mpu_port
> 0 && chip
->mpu_port
!= SNDRV_AUTO_PORT
) {
1435 snd_es18xx_config_write(chip
, 0x64, chip
->mpu_port
>> 8);
1436 snd_es18xx_config_write(chip
, 0x65, chip
->mpu_port
& 0xff);
1438 snd_es18xx_config_write(chip
, 0x28, chip
->irq
);
1441 snd_es18xx_config_write(chip
, 0x70, chip
->irq
);
1443 snd_es18xx_config_write(chip
, 0x72, chip
->irq
);
1445 snd_es18xx_config_write(chip
, 0x74, chip
->dma1
);
1447 snd_es18xx_config_write(chip
, 0x75, chip
->dma2
);
1449 /* Enable Audio 1 IRQ */
1450 snd_es18xx_write(chip
, 0xB1, 0x50);
1451 /* Enable Audio 2 IRQ */
1452 snd_es18xx_mixer_write(chip
, 0x7A, 0x40);
1453 /* Enable Audio 1 DMA */
1454 snd_es18xx_write(chip
, 0xB2, 0x50);
1455 /* Enable MPU and hardware volume interrupt */
1456 snd_es18xx_mixer_write(chip
, 0x64, 0x42);
1459 int irqmask
, dma1mask
, dma2mask
;
1460 switch (chip
->irq
) {
1475 snd_printk(KERN_ERR
"invalid irq %d\n", chip
->irq
);
1478 switch (chip
->dma1
) {
1489 snd_printk(KERN_ERR
"invalid dma1 %d\n", chip
->dma1
);
1492 switch (chip
->dma2
) {
1506 snd_printk(KERN_ERR
"invalid dma2 %d\n", chip
->dma2
);
1510 /* Enable and set Audio 1 IRQ */
1511 snd_es18xx_write(chip
, 0xB1, 0x50 | (irqmask
<< 2));
1512 /* Enable and set Audio 1 DMA */
1513 snd_es18xx_write(chip
, 0xB2, 0x50 | (dma1mask
<< 2));
1514 /* Set Audio 2 DMA */
1515 snd_es18xx_mixer_bits(chip
, 0x7d, 0x07, 0x04 | dma2mask
);
1516 /* Enable Audio 2 IRQ and DMA
1517 Set capture mixer input */
1518 snd_es18xx_mixer_write(chip
, 0x7A, 0x68);
1519 /* Enable and set hardware volume interrupt */
1520 snd_es18xx_mixer_write(chip
, 0x64, 0x06);
1521 if (chip
->mpu_port
> 0 && chip
->mpu_port
!= SNDRV_AUTO_PORT
) {
1522 /* MPU401 share irq with audio
1525 snd_es18xx_mixer_write(chip
, 0x40, 0x43 | (chip
->mpu_port
& 0xf0) >> 1);
1527 snd_es18xx_mixer_write(chip
, 0x7f, ((irqmask
+ 1) << 1) | 0x01);
1529 if (chip
->caps
& ES18XX_NEW_RATE
) {
1530 /* Change behaviour of register A1
1532 2nd channel DAC asynchronous */
1533 snd_es18xx_mixer_write(chip
, 0x71, 0x32);
1535 if (!(chip
->caps
& ES18XX_PCM2
)) {
1536 /* Enable DMA FIFO */
1537 snd_es18xx_write(chip
, 0xB7, 0x80);
1539 if (chip
->caps
& ES18XX_SPATIALIZER
) {
1540 /* Set spatializer parameters to recommended values */
1541 snd_es18xx_mixer_write(chip
, 0x54, 0x8f);
1542 snd_es18xx_mixer_write(chip
, 0x56, 0x95);
1543 snd_es18xx_mixer_write(chip
, 0x58, 0x94);
1544 snd_es18xx_mixer_write(chip
, 0x5a, 0x80);
1546 /* Flip the "enable I2S" bits for those chipsets that need it */
1547 switch (chip
->version
) {
1549 //Leaving I2S enabled on the 1879 screws up the PCM playback (rate effected somehow)
1550 //so a Switch control has been added to toggle this 0x71 bit on/off:
1551 //snd_es18xx_mixer_bits(chip, 0x71, 0x40, 0x40);
1552 /* Note: we fall through on purpose here. */
1554 snd_es18xx_config_write(chip
, 0x29, snd_es18xx_config_read(chip
, 0x29) | 0x40);
1557 /* Mute input source */
1558 if (chip
->caps
& ES18XX_MUTEREC
)
1560 if (chip
->caps
& ES18XX_RECMIX
)
1561 snd_es18xx_mixer_write(chip
, 0x1c, 0x05 | mask
);
1563 snd_es18xx_mixer_write(chip
, 0x1c, 0x00 | mask
);
1564 snd_es18xx_write(chip
, 0xb4, 0x00);
1567 /* Enable PCM output */
1568 snd_es18xx_dsp_command(chip
, 0xD1);
1574 static int __devinit
snd_es18xx_identify(struct snd_es18xx
*chip
)
1579 if (snd_es18xx_reset(chip
) < 0) {
1580 snd_printk(KERN_ERR
"reset at 0x%lx failed!!!\n", chip
->port
);
1584 snd_es18xx_dsp_command(chip
, 0xe7);
1585 hi
= snd_es18xx_dsp_get_byte(chip
);
1589 lo
= snd_es18xx_dsp_get_byte(chip
);
1590 if ((lo
& 0xf0) != 0x80) {
1594 chip
->version
= 0x488;
1600 if ((lo
& 0x0f) < 8) {
1601 chip
->version
= 0x688;
1605 outb(0x40, chip
->port
+ 0x04);
1607 hi
= inb(chip
->port
+ 0x05);
1609 lo
= inb(chip
->port
+ 0x05);
1611 chip
->version
= hi
<< 8 | lo
;
1612 chip
->ctrl_port
= inb(chip
->port
+ 0x05) << 8;
1614 chip
->ctrl_port
+= inb(chip
->port
+ 0x05);
1616 if ((chip
->res_ctrl_port
= request_region(chip
->ctrl_port
, 8, "ES18xx - CTRL")) == NULL
) {
1617 snd_printk(KERN_ERR PFX
"unable go grab port 0x%lx\n", chip
->ctrl_port
);
1624 /* If has Hardware volume */
1625 if (snd_es18xx_mixer_writable(chip
, 0x64, 0x04)) {
1627 if (snd_es18xx_mixer_writable(chip
, 0x70, 0x7f)) {
1628 /* If has volume count */
1629 if (snd_es18xx_mixer_writable(chip
, 0x64, 0x20)) {
1630 chip
->version
= 0x1887;
1632 chip
->version
= 0x1888;
1635 chip
->version
= 0x1788;
1639 chip
->version
= 0x1688;
1643 static int __devinit
snd_es18xx_probe(struct snd_es18xx
*chip
)
1645 if (snd_es18xx_identify(chip
) < 0) {
1646 snd_printk(KERN_ERR PFX
"[0x%lx] ESS chip not found\n", chip
->port
);
1650 switch (chip
->version
) {
1652 chip
->caps
= ES18XX_DUPLEX_MONO
| ES18XX_DUPLEX_SAME
| ES18XX_CONTROL
;
1655 chip
->caps
= ES18XX_PCM2
| ES18XX_SPATIALIZER
| ES18XX_RECMIX
| ES18XX_NEW_RATE
| ES18XX_AUXB
| ES18XX_MONO
| ES18XX_MUTEREC
| ES18XX_CONTROL
| ES18XX_HWV
;
1658 chip
->caps
= ES18XX_DUPLEX_MONO
| ES18XX_DUPLEX_SAME
| ES18XX_I2S
| ES18XX_CONTROL
;
1661 chip
->caps
= ES18XX_PCM2
| ES18XX_SPATIALIZER
| ES18XX_RECMIX
| ES18XX_NEW_RATE
| ES18XX_AUXB
| ES18XX_I2S
| ES18XX_CONTROL
| ES18XX_HWV
;
1664 chip
->caps
= ES18XX_PCM2
| ES18XX_RECMIX
| ES18XX_AUXB
| ES18XX_DUPLEX_SAME
;
1667 chip
->caps
= ES18XX_PCM2
| ES18XX_RECMIX
| ES18XX_AUXB
| ES18XX_DUPLEX_SAME
;
1670 snd_printk(KERN_ERR
"[0x%lx] unsupported chip ES%x\n",
1671 chip
->port
, chip
->version
);
1675 snd_printd("[0x%lx] ESS%x chip found\n", chip
->port
, chip
->version
);
1677 if (chip
->dma1
== chip
->dma2
)
1678 chip
->caps
&= ~(ES18XX_PCM2
| ES18XX_DUPLEX_SAME
);
1680 return snd_es18xx_initialize(chip
);
1683 static struct snd_pcm_ops snd_es18xx_playback_ops
= {
1684 .open
= snd_es18xx_playback_open
,
1685 .close
= snd_es18xx_playback_close
,
1686 .ioctl
= snd_pcm_lib_ioctl
,
1687 .hw_params
= snd_es18xx_playback_hw_params
,
1688 .hw_free
= snd_es18xx_pcm_hw_free
,
1689 .prepare
= snd_es18xx_playback_prepare
,
1690 .trigger
= snd_es18xx_playback_trigger
,
1691 .pointer
= snd_es18xx_playback_pointer
,
1694 static struct snd_pcm_ops snd_es18xx_capture_ops
= {
1695 .open
= snd_es18xx_capture_open
,
1696 .close
= snd_es18xx_capture_close
,
1697 .ioctl
= snd_pcm_lib_ioctl
,
1698 .hw_params
= snd_es18xx_capture_hw_params
,
1699 .hw_free
= snd_es18xx_pcm_hw_free
,
1700 .prepare
= snd_es18xx_capture_prepare
,
1701 .trigger
= snd_es18xx_capture_trigger
,
1702 .pointer
= snd_es18xx_capture_pointer
,
1705 static int __devinit
snd_es18xx_pcm(struct snd_es18xx
*chip
, int device
, struct snd_pcm
** rpcm
)
1707 struct snd_pcm
*pcm
;
1713 sprintf(str
, "ES%x", chip
->version
);
1714 if (chip
->caps
& ES18XX_PCM2
)
1715 err
= snd_pcm_new(chip
->card
, str
, device
, 2, 1, &pcm
);
1717 err
= snd_pcm_new(chip
->card
, str
, device
, 1, 1, &pcm
);
1721 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_es18xx_playback_ops
);
1722 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_es18xx_capture_ops
);
1725 pcm
->private_data
= chip
;
1726 pcm
->info_flags
= 0;
1727 if (chip
->caps
& ES18XX_DUPLEX_SAME
)
1728 pcm
->info_flags
|= SNDRV_PCM_INFO_JOINT_DUPLEX
;
1729 if (! (chip
->caps
& ES18XX_PCM2
))
1730 pcm
->info_flags
|= SNDRV_PCM_INFO_HALF_DUPLEX
;
1731 sprintf(pcm
->name
, "ESS AudioDrive ES%x", chip
->version
);
1734 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1737 chip
->dma1
> 3 || chip
->dma2
> 3 ? 128*1024 : 64*1024);
1744 /* Power Management support functions */
1746 static int snd_es18xx_suspend(struct snd_card
*card
, pm_message_t state
)
1748 struct snd_audiodrive
*acard
= card
->private_data
;
1749 struct snd_es18xx
*chip
= acard
->chip
;
1751 snd_power_change_state(chip
->card
, SNDRV_CTL_POWER_D3hot
);
1753 snd_pcm_suspend_all(chip
->pcm
);
1756 chip
->pm_reg
= (unsigned char)snd_es18xx_read(chip
, ES18XX_PM
);
1757 chip
->pm_reg
|= (ES18XX_PM_FM
| ES18XX_PM_SUS
);
1758 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
);
1759 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
^= ES18XX_PM_SUS
);
1764 static int snd_es18xx_resume(struct snd_card
*card
)
1766 struct snd_audiodrive
*acard
= card
->private_data
;
1767 struct snd_es18xx
*chip
= acard
->chip
;
1769 /* restore PM register, we won't wake till (not 0x07) i/o activity though */
1770 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
^= ES18XX_PM_FM
);
1772 snd_power_change_state(chip
->card
, SNDRV_CTL_POWER_D0
);
1775 #endif /* CONFIG_PM */
1777 static int snd_es18xx_free(struct snd_es18xx
*chip
)
1779 release_and_free_resource(chip
->res_port
);
1780 release_and_free_resource(chip
->res_ctrl_port
);
1781 release_and_free_resource(chip
->res_mpu_port
);
1783 free_irq(chip
->irq
, (void *) chip
);
1784 if (chip
->dma1
>= 0) {
1785 disable_dma(chip
->dma1
);
1786 free_dma(chip
->dma1
);
1788 if (chip
->dma2
>= 0 && chip
->dma1
!= chip
->dma2
) {
1789 disable_dma(chip
->dma2
);
1790 free_dma(chip
->dma2
);
1796 static int snd_es18xx_dev_free(struct snd_device
*device
)
1798 struct snd_es18xx
*chip
= device
->device_data
;
1799 return snd_es18xx_free(chip
);
1802 static int __devinit
snd_es18xx_new_device(struct snd_card
*card
,
1804 unsigned long mpu_port
,
1805 unsigned long fm_port
,
1806 int irq
, int dma1
, int dma2
,
1807 struct snd_es18xx
** rchip
)
1809 struct snd_es18xx
*chip
;
1810 static struct snd_device_ops ops
= {
1811 .dev_free
= snd_es18xx_dev_free
,
1816 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
1819 spin_lock_init(&chip
->reg_lock
);
1820 spin_lock_init(&chip
->mixer_lock
);
1821 spin_lock_init(&chip
->ctrl_lock
);
1824 chip
->mpu_port
= mpu_port
;
1825 chip
->fm_port
= fm_port
;
1829 chip
->audio2_vol
= 0x00;
1832 if ((chip
->res_port
= request_region(port
, 16, "ES18xx")) == NULL
) {
1833 snd_es18xx_free(chip
);
1834 snd_printk(KERN_ERR PFX
"unable to grap ports 0x%lx-0x%lx\n", port
, port
+ 16 - 1);
1838 if (request_irq(irq
, snd_es18xx_interrupt
, SA_INTERRUPT
, "ES18xx", (void *) chip
)) {
1839 snd_es18xx_free(chip
);
1840 snd_printk(KERN_ERR PFX
"unable to grap IRQ %d\n", irq
);
1845 if (request_dma(dma1
, "ES18xx DMA 1")) {
1846 snd_es18xx_free(chip
);
1847 snd_printk(KERN_ERR PFX
"unable to grap DMA1 %d\n", dma1
);
1852 if (dma2
!= dma1
&& request_dma(dma2
, "ES18xx DMA 2")) {
1853 snd_es18xx_free(chip
);
1854 snd_printk(KERN_ERR PFX
"unable to grap DMA2 %d\n", dma2
);
1859 if (snd_es18xx_probe(chip
) < 0) {
1860 snd_es18xx_free(chip
);
1863 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
)) < 0) {
1864 snd_es18xx_free(chip
);
1871 static int __devinit
snd_es18xx_mixer(struct snd_es18xx
*chip
)
1873 struct snd_card
*card
;
1879 strcpy(card
->mixername
, chip
->pcm
->name
);
1881 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_base_controls
); idx
++) {
1882 struct snd_kcontrol
*kctl
;
1883 kctl
= snd_ctl_new1(&snd_es18xx_base_controls
[idx
], chip
);
1884 if (chip
->caps
& ES18XX_HWV
) {
1887 chip
->master_volume
= kctl
;
1888 kctl
->private_free
= snd_es18xx_hwv_free
;
1891 chip
->master_switch
= kctl
;
1892 kctl
->private_free
= snd_es18xx_hwv_free
;
1896 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
1899 if (chip
->caps
& ES18XX_PCM2
) {
1900 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_pcm2_controls
); idx
++) {
1901 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_pcm2_controls
[idx
], chip
))) < 0)
1905 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_pcm1_controls
); idx
++) {
1906 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_pcm1_controls
[idx
], chip
))) < 0)
1911 if (chip
->caps
& ES18XX_RECMIX
) {
1912 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_recmix_controls
); idx
++) {
1913 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_recmix_controls
[idx
], chip
))) < 0)
1917 switch (chip
->version
) {
1919 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_micpre1_control
, chip
))) < 0)
1924 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_micpre2_control
, chip
))) < 0)
1928 if (chip
->caps
& ES18XX_SPATIALIZER
) {
1929 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_spatializer_controls
); idx
++) {
1930 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_spatializer_controls
[idx
], chip
))) < 0)
1934 if (chip
->caps
& ES18XX_HWV
) {
1935 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_hw_volume_controls
); idx
++) {
1936 struct snd_kcontrol
*kctl
;
1937 kctl
= snd_ctl_new1(&snd_es18xx_hw_volume_controls
[idx
], chip
);
1939 chip
->hw_volume
= kctl
;
1941 chip
->hw_switch
= kctl
;
1942 kctl
->private_free
= snd_es18xx_hwv_free
;
1943 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
1948 /* finish initializing other chipset specific controls
1950 if (chip
->version
!= 0x1868) {
1951 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_opt_speaker
,
1956 if (chip
->version
== 0x1869) {
1957 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_opt_1869
); idx
++) {
1958 err
= snd_ctl_add(card
,
1959 snd_ctl_new1(&snd_es18xx_opt_1869
[idx
],
1964 } else if (chip
->version
== 0x1878) {
1965 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_opt_1878
,
1969 } else if (chip
->version
== 0x1879) {
1970 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_opt_1879
); idx
++) {
1971 err
= snd_ctl_add(card
,
1972 snd_ctl_new1(&snd_es18xx_opt_1879
[idx
],
1984 MODULE_AUTHOR("Christian Fischbach <fishbach@pool.informatik.rwth-aachen.de>, Abramo Bagnara <abramo@alsa-project.org>");
1985 MODULE_DESCRIPTION("ESS ES18xx AudioDrive");
1986 MODULE_LICENSE("GPL");
1987 MODULE_SUPPORTED_DEVICE("{{ESS,ES1868 PnP AudioDrive},"
1988 "{ESS,ES1869 PnP AudioDrive},"
1989 "{ESS,ES1878 PnP AudioDrive},"
1990 "{ESS,ES1879 PnP AudioDrive},"
1991 "{ESS,ES1887 PnP AudioDrive},"
1992 "{ESS,ES1888 PnP AudioDrive},"
1993 "{ESS,ES1887 AudioDrive},"
1994 "{ESS,ES1888 AudioDrive}}");
1996 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
1997 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
1998 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_ISAPNP
; /* Enable this card */
2000 static int isapnp
[SNDRV_CARDS
] = {[0 ... (SNDRV_CARDS
- 1)] = 1};
2002 static long port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
; /* 0x220,0x240,0x260,0x280 */
2004 static long mpu_port
[SNDRV_CARDS
] = {[0 ... (SNDRV_CARDS
- 1)] = -1};
2006 static long mpu_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
2008 static long fm_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
2009 static int irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
; /* 5,7,9,10 */
2010 static int dma1
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* 0,1,3 */
2011 static int dma2
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* 0,1,3 */
2013 module_param_array(index
, int, NULL
, 0444);
2014 MODULE_PARM_DESC(index
, "Index value for ES18xx soundcard.");
2015 module_param_array(id
, charp
, NULL
, 0444);
2016 MODULE_PARM_DESC(id
, "ID string for ES18xx soundcard.");
2017 module_param_array(enable
, bool, NULL
, 0444);
2018 MODULE_PARM_DESC(enable
, "Enable ES18xx soundcard.");
2020 module_param_array(isapnp
, bool, NULL
, 0444);
2021 MODULE_PARM_DESC(isapnp
, "PnP detection for specified soundcard.");
2023 module_param_array(port
, long, NULL
, 0444);
2024 MODULE_PARM_DESC(port
, "Port # for ES18xx driver.");
2025 module_param_array(mpu_port
, long, NULL
, 0444);
2026 MODULE_PARM_DESC(mpu_port
, "MPU-401 port # for ES18xx driver.");
2027 module_param_array(fm_port
, long, NULL
, 0444);
2028 MODULE_PARM_DESC(fm_port
, "FM port # for ES18xx driver.");
2029 module_param_array(irq
, int, NULL
, 0444);
2030 MODULE_PARM_DESC(irq
, "IRQ # for ES18xx driver.");
2031 module_param_array(dma1
, int, NULL
, 0444);
2032 MODULE_PARM_DESC(dma1
, "DMA 1 # for ES18xx driver.");
2033 module_param_array(dma2
, int, NULL
, 0444);
2034 MODULE_PARM_DESC(dma2
, "DMA 2 # for ES18xx driver.");
2036 static struct platform_device
*platform_devices
[SNDRV_CARDS
];
2039 static int pnp_registered
;
2041 static struct pnp_card_device_id snd_audiodrive_pnpids
[] = {
2042 /* ESS 1868 (integrated on Compaq dual P-Pro motherboard and Genius 18PnP 3D) */
2043 { .id
= "ESS1868", .devs
= { { "ESS1868" }, { "ESS0000" } } },
2044 /* ESS 1868 (integrated on Maxisound Cards) */
2045 { .id
= "ESS1868", .devs
= { { "ESS8601" }, { "ESS8600" } } },
2046 /* ESS 1868 (integrated on Maxisound Cards) */
2047 { .id
= "ESS1868", .devs
= { { "ESS8611" }, { "ESS8610" } } },
2048 /* ESS ES1869 Plug and Play AudioDrive */
2049 { .id
= "ESS0003", .devs
= { { "ESS1869" }, { "ESS0006" } } },
2051 { .id
= "ESS1869", .devs
= { { "ESS1869" }, { "ESS0006" } } },
2053 { .id
= "ESS1878", .devs
= { { "ESS1878" }, { "ESS0004" } } },
2055 { .id
= "ESS1879", .devs
= { { "ESS1879" }, { "ESS0009" } } },
2057 { .id
= "" } /* end */
2060 MODULE_DEVICE_TABLE(pnp_card
, snd_audiodrive_pnpids
);
2062 static int __devinit
snd_audiodrive_pnp(int dev
, struct snd_audiodrive
*acard
,
2063 struct pnp_card_link
*card
,
2064 const struct pnp_card_device_id
*id
)
2066 struct pnp_dev
*pdev
;
2067 struct pnp_resource_table
* cfg
= kmalloc(sizeof(struct pnp_resource_table
), GFP_KERNEL
);
2072 acard
->dev
= pnp_request_card_device(card
, id
->devs
[0].id
, NULL
);
2073 if (acard
->dev
== NULL
) {
2077 acard
->devc
= pnp_request_card_device(card
, id
->devs
[1].id
, NULL
);
2078 if (acard
->devc
== NULL
) {
2082 /* Control port initialization */
2083 err
= pnp_activate_dev(acard
->devc
);
2085 snd_printk(KERN_ERR PFX
"PnP control configure failure (out of resources?)\n");
2089 snd_printdd("pnp: port=0x%lx\n", pnp_port_start(acard
->devc
, 0));
2090 /* PnP initialization */
2092 pnp_init_resource_table(cfg
);
2093 if (port
[dev
] != SNDRV_AUTO_PORT
)
2094 pnp_resource_change(&cfg
->port_resource
[0], port
[dev
], 16);
2095 if (fm_port
[dev
] != SNDRV_AUTO_PORT
)
2096 pnp_resource_change(&cfg
->port_resource
[1], fm_port
[dev
], 4);
2097 if (mpu_port
[dev
] != SNDRV_AUTO_PORT
)
2098 pnp_resource_change(&cfg
->port_resource
[2], mpu_port
[dev
], 2);
2099 if (dma1
[dev
] != SNDRV_AUTO_DMA
)
2100 pnp_resource_change(&cfg
->dma_resource
[0], dma1
[dev
], 1);
2101 if (dma2
[dev
] != SNDRV_AUTO_DMA
)
2102 pnp_resource_change(&cfg
->dma_resource
[1], dma2
[dev
], 1);
2103 if (irq
[dev
] != SNDRV_AUTO_IRQ
)
2104 pnp_resource_change(&cfg
->irq_resource
[0], irq
[dev
], 1);
2105 err
= pnp_manual_config_dev(pdev
, cfg
, 0);
2107 snd_printk(KERN_ERR PFX
"PnP manual resources are invalid, using auto config\n");
2108 err
= pnp_activate_dev(pdev
);
2110 snd_printk(KERN_ERR PFX
"PnP configure failure (out of resources?)\n");
2114 /* ok. hack using Vendor-Defined Card-Level registers */
2115 /* skip csn and logdev initialization - already done in isapnp_configure */
2116 if (pnp_device_is_isapnp(pdev
)) {
2117 isapnp_cfg_begin(isapnp_card_number(pdev
), isapnp_csn_number(pdev
));
2118 isapnp_write_byte(0x27, pnp_irq(pdev
, 0)); /* Hardware Volume IRQ Number */
2119 if (mpu_port
[dev
] != SNDRV_AUTO_PORT
)
2120 isapnp_write_byte(0x28, pnp_irq(pdev
, 0)); /* MPU-401 IRQ Number */
2121 isapnp_write_byte(0x72, pnp_irq(pdev
, 0)); /* second IRQ */
2124 snd_printk(KERN_ERR PFX
"unable to install ISA PnP hack, expect malfunction\n");
2126 port
[dev
] = pnp_port_start(pdev
, 0);
2127 fm_port
[dev
] = pnp_port_start(pdev
, 1);
2128 mpu_port
[dev
] = pnp_port_start(pdev
, 2);
2129 dma1
[dev
] = pnp_dma(pdev
, 0);
2130 dma2
[dev
] = pnp_dma(pdev
, 1);
2131 irq
[dev
] = pnp_irq(pdev
, 0);
2132 snd_printdd("PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port
[dev
], fm_port
[dev
], mpu_port
[dev
]);
2133 snd_printdd("PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1
[dev
], dma2
[dev
], irq
[dev
]);
2137 #endif /* CONFIG_PNP */
2140 #define is_isapnp_selected(dev) isapnp[dev]
2142 #define is_isapnp_selected(dev) 0
2145 static struct snd_card
*snd_es18xx_card_new(int dev
)
2147 return snd_card_new(index
[dev
], id
[dev
], THIS_MODULE
,
2148 sizeof(struct snd_audiodrive
));
2151 static int __devinit
snd_audiodrive_probe(struct snd_card
*card
, int dev
)
2153 struct snd_audiodrive
*acard
= card
->private_data
;
2154 struct snd_es18xx
*chip
;
2155 struct snd_opl3
*opl3
;
2158 if ((err
= snd_es18xx_new_device(card
,
2162 irq
[dev
], dma1
[dev
], dma2
[dev
],
2167 sprintf(card
->driver
, "ES%x", chip
->version
);
2169 sprintf(card
->shortname
, "ESS AudioDrive ES%x", chip
->version
);
2170 if (dma1
[dev
] != dma2
[dev
])
2171 sprintf(card
->longname
, "%s at 0x%lx, irq %d, dma1 %d, dma2 %d",
2174 irq
[dev
], dma1
[dev
], dma2
[dev
]);
2176 sprintf(card
->longname
, "%s at 0x%lx, irq %d, dma %d",
2179 irq
[dev
], dma1
[dev
]);
2181 if ((err
= snd_es18xx_pcm(chip
, 0, NULL
)) < 0)
2184 if ((err
= snd_es18xx_mixer(chip
)) < 0)
2187 if (fm_port
[dev
] > 0 && fm_port
[dev
] != SNDRV_AUTO_PORT
) {
2188 if (snd_opl3_create(card
, chip
->fm_port
, chip
->fm_port
+ 2, OPL3_HW_OPL3
, 0, &opl3
) < 0) {
2189 snd_printk(KERN_WARNING PFX
"opl3 not detected at 0x%lx\n", chip
->fm_port
);
2191 if ((err
= snd_opl3_hwdep_new(opl3
, 0, 1, NULL
)) < 0)
2196 if (mpu_port
[dev
] > 0 && mpu_port
[dev
] != SNDRV_AUTO_PORT
) {
2197 if ((err
= snd_mpu401_uart_new(card
, 0, MPU401_HW_ES18XX
,
2204 return snd_card_register(card
);
2207 static int __devinit
snd_es18xx_nonpnp_probe1(int dev
, struct platform_device
*devptr
)
2209 struct snd_card
*card
;
2212 card
= snd_es18xx_card_new(dev
);
2215 snd_card_set_dev(card
, &devptr
->dev
);
2216 if ((err
= snd_audiodrive_probe(card
, dev
)) < 0) {
2217 snd_card_free(card
);
2220 platform_set_drvdata(devptr
, card
);
2224 static int __devinit
snd_es18xx_nonpnp_probe(struct platform_device
*pdev
)
2228 static int possible_irqs
[] = {5, 9, 10, 7, 11, 12, -1};
2229 static int possible_dmas
[] = {1, 0, 3, 5, -1};
2231 if (irq
[dev
] == SNDRV_AUTO_IRQ
) {
2232 if ((irq
[dev
] = snd_legacy_find_free_irq(possible_irqs
)) < 0) {
2233 snd_printk(KERN_ERR PFX
"unable to find a free IRQ\n");
2237 if (dma1
[dev
] == SNDRV_AUTO_DMA
) {
2238 if ((dma1
[dev
] = snd_legacy_find_free_dma(possible_dmas
)) < 0) {
2239 snd_printk(KERN_ERR PFX
"unable to find a free DMA1\n");
2243 if (dma2
[dev
] == SNDRV_AUTO_DMA
) {
2244 if ((dma2
[dev
] = snd_legacy_find_free_dma(possible_dmas
)) < 0) {
2245 snd_printk(KERN_ERR PFX
"unable to find a free DMA2\n");
2250 if (port
[dev
] != SNDRV_AUTO_PORT
) {
2251 return snd_es18xx_nonpnp_probe1(dev
, pdev
);
2253 static unsigned long possible_ports
[] = {0x220, 0x240, 0x260, 0x280};
2255 for (i
= 0; i
< ARRAY_SIZE(possible_ports
); i
++) {
2256 port
[dev
] = possible_ports
[i
];
2257 err
= snd_es18xx_nonpnp_probe1(dev
, pdev
);
2265 static int __devexit
snd_es18xx_nonpnp_remove(struct platform_device
*devptr
)
2267 snd_card_free(platform_get_drvdata(devptr
));
2268 platform_set_drvdata(devptr
, NULL
);
2273 static int snd_es18xx_nonpnp_suspend(struct platform_device
*dev
, pm_message_t state
)
2275 return snd_es18xx_suspend(platform_get_drvdata(dev
), state
);
2278 static int snd_es18xx_nonpnp_resume(struct platform_device
*dev
)
2280 return snd_es18xx_resume(platform_get_drvdata(dev
));
2284 #define ES18XX_DRIVER "snd_es18xx"
2286 static struct platform_driver snd_es18xx_nonpnp_driver
= {
2287 .probe
= snd_es18xx_nonpnp_probe
,
2288 .remove
= __devexit_p(snd_es18xx_nonpnp_remove
),
2290 .suspend
= snd_es18xx_nonpnp_suspend
,
2291 .resume
= snd_es18xx_nonpnp_resume
,
2294 .name
= ES18XX_DRIVER
2300 static unsigned int __devinitdata es18xx_pnp_devices
;
2302 static int __devinit
snd_audiodrive_pnp_detect(struct pnp_card_link
*pcard
,
2303 const struct pnp_card_device_id
*pid
)
2306 struct snd_card
*card
;
2309 for ( ; dev
< SNDRV_CARDS
; dev
++) {
2310 if (enable
[dev
] && isapnp
[dev
])
2313 if (dev
>= SNDRV_CARDS
)
2316 card
= snd_es18xx_card_new(dev
);
2320 if ((res
= snd_audiodrive_pnp(dev
, card
->private_data
, pcard
, pid
)) < 0) {
2321 snd_card_free(card
);
2324 snd_card_set_dev(card
, &pcard
->card
->dev
);
2325 if ((res
= snd_audiodrive_probe(card
, dev
)) < 0) {
2326 snd_card_free(card
);
2330 pnp_set_card_drvdata(pcard
, card
);
2332 es18xx_pnp_devices
++;
2336 static void __devexit
snd_audiodrive_pnp_remove(struct pnp_card_link
* pcard
)
2338 snd_card_free(pnp_get_card_drvdata(pcard
));
2339 pnp_set_card_drvdata(pcard
, NULL
);
2343 static int snd_audiodrive_pnp_suspend(struct pnp_card_link
*pcard
, pm_message_t state
)
2345 return snd_es18xx_suspend(pnp_get_card_drvdata(pcard
), state
);
2348 static int snd_audiodrive_pnp_resume(struct pnp_card_link
*pcard
)
2350 return snd_es18xx_resume(pnp_get_card_drvdata(pcard
));
2355 static struct pnp_card_driver es18xx_pnpc_driver
= {
2356 .flags
= PNP_DRIVER_RES_DISABLE
,
2358 .id_table
= snd_audiodrive_pnpids
,
2359 .probe
= snd_audiodrive_pnp_detect
,
2360 .remove
= __devexit_p(snd_audiodrive_pnp_remove
),
2362 .suspend
= snd_audiodrive_pnp_suspend
,
2363 .resume
= snd_audiodrive_pnp_resume
,
2366 #endif /* CONFIG_PNP */
2368 static void __init_or_module
snd_es18xx_unregister_all(void)
2374 pnp_unregister_card_driver(&es18xx_pnpc_driver
);
2376 for (i
= 0; i
< ARRAY_SIZE(platform_devices
); ++i
)
2377 platform_device_unregister(platform_devices
[i
]);
2378 platform_driver_unregister(&snd_es18xx_nonpnp_driver
);
2381 static int __init
alsa_card_es18xx_init(void)
2383 int i
, err
, cards
= 0;
2385 if ((err
= platform_driver_register(&snd_es18xx_nonpnp_driver
)) < 0)
2388 for (i
= 0; i
< SNDRV_CARDS
; i
++) {
2389 struct platform_device
*device
;
2390 if (! enable
[i
] || is_isapnp_selected(i
))
2392 device
= platform_device_register_simple(ES18XX_DRIVER
,
2396 if (!platform_get_drvdata(device
)) {
2397 platform_device_unregister(device
);
2400 platform_devices
[i
] = device
;
2405 err
= pnp_register_card_driver(&es18xx_pnpc_driver
);
2408 cards
+= es18xx_pnp_devices
;
2414 snd_printk(KERN_ERR
"ESS AudioDrive ES18xx soundcard not found or device busy\n");
2416 snd_es18xx_unregister_all();
2422 static void __exit
alsa_card_es18xx_exit(void)
2424 snd_es18xx_unregister_all();
2427 module_init(alsa_card_es18xx_init
)
2428 module_exit(alsa_card_es18xx_exit
)