2 * Driver for generic ESS AudioDrive ES18xx soundcards
3 * Copyright (c) by Christian Fischbach <fishbach@pool.informatik.rwth-aachen.de>
4 * Copyright (c) by Abramo Bagnara <abramo@alsa-project.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * - There are pops (we can't delay in trigger function, cause midlevel
26 * often need to trigger down and then up very quickly).
28 * - Support for 16 bit DMA seems to be broken. I've no hardware to tune it.
33 * - The chip has one half duplex pcm (with very limited full duplex support).
35 * - Duplex stereophonic sound is impossible.
36 * - Record and playback must share the same frequency rate.
38 * - The driver use dma2 for playback and dma1 for capture.
44 * - there are a first full duplex pcm and a second playback only pcm
45 * (incompatible with first pcm capture)
47 * - there is support for the capture volume and ESS Spatializer 3D effect.
49 * - contrarily to some pages in DS_1869.PDF the rates can be set
54 * - There is a major trouble I noted:
56 * using both channel for playback stereo 16 bit samples at 44100 Hz
57 * the second pcm (Audio1) DMA slows down irregularly and sound is garbled.
59 * The same happens using Audio1 for captureing.
61 * The Windows driver does not suffer of this (although it use Audio1
62 * only for captureing). I'm unable to discover why.
67 #include <sound/driver.h>
70 #include <linux/init.h>
72 #include <linux/slab.h>
73 #include <linux/pnp.h>
74 #include <linux/isapnp.h>
75 #include <linux/moduleparam.h>
76 #include <sound/core.h>
77 #include <sound/control.h>
78 #include <sound/pcm.h>
79 #include <sound/pcm_params.h>
80 #include <sound/mpu401.h>
81 #include <sound/opl3.h>
82 #define SNDRV_LEGACY_AUTO_PROBE
83 #define SNDRV_LEGACY_FIND_FREE_IRQ
84 #define SNDRV_LEGACY_FIND_FREE_DMA
85 #include <sound/initval.h>
87 #define PFX "es18xx: "
90 unsigned long port
; /* port of ESS chip */
91 unsigned long mpu_port
; /* MPU-401 port of ESS chip */
92 unsigned long fm_port
; /* FM port */
93 unsigned long ctrl_port
; /* Control port of ESS chip */
94 struct resource
*res_port
;
95 struct resource
*res_mpu_port
;
96 struct resource
*res_ctrl_port
;
97 int irq
; /* IRQ number of ESS chip */
100 unsigned short version
; /* version of ESS chip */
101 int caps
; /* Chip capabilities */
102 unsigned short audio2_vol
; /* volume level of audio2 */
104 unsigned short active
; /* active channel mask */
105 unsigned int dma1_size
;
106 unsigned int dma2_size
;
107 unsigned int dma1_shift
;
108 unsigned int dma2_shift
;
112 snd_pcm_substream_t
*playback_a_substream
;
113 snd_pcm_substream_t
*capture_a_substream
;
114 snd_pcm_substream_t
*playback_b_substream
;
116 snd_rawmidi_t
*rmidi
;
118 snd_kcontrol_t
*hw_volume
;
119 snd_kcontrol_t
*hw_switch
;
120 snd_kcontrol_t
*master_volume
;
121 snd_kcontrol_t
*master_switch
;
124 spinlock_t mixer_lock
;
125 spinlock_t ctrl_lock
;
127 unsigned char pm_reg
;
131 #define AUDIO1_IRQ 0x01
132 #define AUDIO2_IRQ 0x02
136 #define ES18XX_PCM2 0x0001 /* Has two useable PCM */
137 #define ES18XX_SPATIALIZER 0x0002 /* Has 3D Spatializer */
138 #define ES18XX_RECMIX 0x0004 /* Has record mixer */
139 #define ES18XX_DUPLEX_MONO 0x0008 /* Has mono duplex only */
140 #define ES18XX_DUPLEX_SAME 0x0010 /* Playback and record must share the same rate */
141 #define ES18XX_NEW_RATE 0x0020 /* More precise rate setting */
142 #define ES18XX_AUXB 0x0040 /* AuxB mixer control */
143 #define ES18XX_HWV 0x0080 /* Has hardware volume */
144 #define ES18XX_MONO 0x0100 /* Mono_in mixer control */
145 #define ES18XX_I2S 0x0200 /* I2S mixer control */
146 #define ES18XX_MUTEREC 0x0400 /* Record source can be muted */
147 #define ES18XX_CONTROL 0x0800 /* Has control ports */
149 /* Power Management */
150 #define ES18XX_PM 0x07
151 #define ES18XX_PM_GPO0 0x01
152 #define ES18XX_PM_GPO1 0x02
153 #define ES18XX_PM_PDR 0x04
154 #define ES18XX_PM_ANA 0x08
155 #define ES18XX_PM_FM 0x020
156 #define ES18XX_PM_SUS 0x080
158 typedef struct _snd_es18xx es18xx_t
;
165 #define MILLISECOND 10000
167 static int snd_es18xx_dsp_command(es18xx_t
*chip
, unsigned char val
)
171 for(i
= MILLISECOND
; i
; i
--)
172 if ((inb(chip
->port
+ 0x0C) & 0x80) == 0) {
173 outb(val
, chip
->port
+ 0x0C);
176 snd_printk("dsp_command: timeout (0x%x)\n", val
);
180 static int snd_es18xx_dsp_get_byte(es18xx_t
*chip
)
184 for(i
= MILLISECOND
/10; i
; i
--)
185 if (inb(chip
->port
+ 0x0C) & 0x40)
186 return inb(chip
->port
+ 0x0A);
187 snd_printk("dsp_get_byte failed: 0x%lx = 0x%x!!!\n", chip
->port
+ 0x0A, inb(chip
->port
+ 0x0A));
193 static int snd_es18xx_write(es18xx_t
*chip
,
194 unsigned char reg
, unsigned char data
)
199 spin_lock_irqsave(&chip
->reg_lock
, flags
);
200 ret
= snd_es18xx_dsp_command(chip
, reg
);
203 ret
= snd_es18xx_dsp_command(chip
, data
);
205 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
207 snd_printk("Reg %02x set to %02x\n", reg
, data
);
212 static int snd_es18xx_read(es18xx_t
*chip
, unsigned char reg
)
216 spin_lock_irqsave(&chip
->reg_lock
, flags
);
217 ret
= snd_es18xx_dsp_command(chip
, 0xC0);
220 ret
= snd_es18xx_dsp_command(chip
, reg
);
223 data
= snd_es18xx_dsp_get_byte(chip
);
226 snd_printk("Reg %02x now is %02x (%d)\n", reg
, data
, ret
);
229 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
233 /* Return old value */
234 static int snd_es18xx_bits(es18xx_t
*chip
, unsigned char reg
,
235 unsigned char mask
, unsigned char val
)
238 unsigned char old
, new, oval
;
240 spin_lock_irqsave(&chip
->reg_lock
, flags
);
241 ret
= snd_es18xx_dsp_command(chip
, 0xC0);
244 ret
= snd_es18xx_dsp_command(chip
, reg
);
247 ret
= snd_es18xx_dsp_get_byte(chip
);
254 ret
= snd_es18xx_dsp_command(chip
, reg
);
257 new = (old
& ~mask
) | (val
& mask
);
258 ret
= snd_es18xx_dsp_command(chip
, new);
262 snd_printk("Reg %02x was %02x, set to %02x (%d)\n", reg
, old
, new, ret
);
267 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
271 static inline void snd_es18xx_mixer_write(es18xx_t
*chip
,
272 unsigned char reg
, unsigned char data
)
275 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
276 outb(reg
, chip
->port
+ 0x04);
277 outb(data
, chip
->port
+ 0x05);
278 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
280 snd_printk("Mixer reg %02x set to %02x\n", reg
, data
);
284 static inline int snd_es18xx_mixer_read(es18xx_t
*chip
, unsigned char reg
)
288 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
289 outb(reg
, chip
->port
+ 0x04);
290 data
= inb(chip
->port
+ 0x05);
291 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
293 snd_printk("Mixer reg %02x now is %02x\n", reg
, data
);
298 /* Return old value */
299 static inline int snd_es18xx_mixer_bits(es18xx_t
*chip
, unsigned char reg
,
300 unsigned char mask
, unsigned char val
)
302 unsigned char old
, new, oval
;
304 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
305 outb(reg
, chip
->port
+ 0x04);
306 old
= inb(chip
->port
+ 0x05);
309 new = (old
& ~mask
) | (val
& mask
);
310 outb(new, chip
->port
+ 0x05);
312 snd_printk("Mixer reg %02x was %02x, set to %02x\n", reg
, old
, new);
315 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
319 static inline int snd_es18xx_mixer_writable(es18xx_t
*chip
, unsigned char reg
,
322 int old
, expected
, new;
324 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
325 outb(reg
, chip
->port
+ 0x04);
326 old
= inb(chip
->port
+ 0x05);
327 expected
= old
^ mask
;
328 outb(expected
, chip
->port
+ 0x05);
329 new = inb(chip
->port
+ 0x05);
330 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
332 snd_printk("Mixer reg %02x was %02x, set to %02x, now is %02x\n", reg
, old
, expected
, new);
334 return expected
== new;
338 static int snd_es18xx_reset(es18xx_t
*chip
)
341 outb(0x03, chip
->port
+ 0x06);
342 inb(chip
->port
+ 0x06);
343 outb(0x00, chip
->port
+ 0x06);
344 for(i
= 0; i
< MILLISECOND
&& !(inb(chip
->port
+ 0x0E) & 0x80); i
++);
345 if (inb(chip
->port
+ 0x0A) != 0xAA)
350 static int snd_es18xx_reset_fifo(es18xx_t
*chip
)
352 outb(0x02, chip
->port
+ 0x06);
353 inb(chip
->port
+ 0x06);
354 outb(0x00, chip
->port
+ 0x06);
358 static ratnum_t new_clocks
[2] = {
373 static snd_pcm_hw_constraint_ratnums_t new_hw_constraints_clocks
= {
378 static ratnum_t old_clocks
[2] = {
393 static snd_pcm_hw_constraint_ratnums_t old_hw_constraints_clocks
= {
399 static void snd_es18xx_rate_set(es18xx_t
*chip
,
400 snd_pcm_substream_t
*substream
,
403 unsigned int bits
, div0
;
404 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
405 if (chip
->caps
& ES18XX_NEW_RATE
) {
406 if (runtime
->rate_num
== new_clocks
[0].num
)
407 bits
= 128 - runtime
->rate_den
;
409 bits
= 256 - runtime
->rate_den
;
411 if (runtime
->rate_num
== old_clocks
[0].num
)
412 bits
= 256 - runtime
->rate_den
;
414 bits
= 128 - runtime
->rate_den
;
417 /* set filter register */
418 div0
= 256 - 7160000*20/(8*82*runtime
->rate
);
420 if ((chip
->caps
& ES18XX_PCM2
) && mode
== DAC2
) {
421 snd_es18xx_mixer_write(chip
, 0x70, bits
);
423 * Comment from kernel oss driver:
424 * FKS: fascinating: 0x72 doesn't seem to work.
426 snd_es18xx_write(chip
, 0xA2, div0
);
427 snd_es18xx_mixer_write(chip
, 0x72, div0
);
429 snd_es18xx_write(chip
, 0xA1, bits
);
430 snd_es18xx_write(chip
, 0xA2, div0
);
434 static int snd_es18xx_playback_hw_params(snd_pcm_substream_t
* substream
,
435 snd_pcm_hw_params_t
* hw_params
)
437 es18xx_t
*chip
= snd_pcm_substream_chip(substream
);
441 if (params_channels(hw_params
) == 2)
443 if (snd_pcm_format_width(params_format(hw_params
)) == 16)
446 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
447 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
448 (chip
->capture_a_substream
) &&
449 params_channels(hw_params
) != 1) {
450 _snd_pcm_hw_param_setempty(hw_params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
453 chip
->dma2_shift
= shift
;
455 chip
->dma1_shift
= shift
;
457 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
462 static int snd_es18xx_pcm_hw_free(snd_pcm_substream_t
* substream
)
464 return snd_pcm_lib_free_pages(substream
);
467 static int snd_es18xx_playback1_prepare(es18xx_t
*chip
,
468 snd_pcm_substream_t
*substream
)
470 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
471 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
472 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
474 chip
->dma2_size
= size
;
476 snd_es18xx_rate_set(chip
, substream
, DAC2
);
478 /* Transfer Count Reload */
479 count
= 0x10000 - count
;
480 snd_es18xx_mixer_write(chip
, 0x74, count
& 0xff);
481 snd_es18xx_mixer_write(chip
, 0x76, count
>> 8);
484 snd_es18xx_mixer_bits(chip
, 0x7A, 0x07,
485 ((runtime
->channels
== 1) ? 0x00 : 0x02) |
486 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x01 : 0x00) |
487 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x04));
489 /* Set DMA controller */
490 snd_dma_program(chip
->dma2
, runtime
->dma_addr
, size
, DMA_MODE_WRITE
| DMA_AUTOINIT
);
495 static int snd_es18xx_playback1_trigger(es18xx_t
*chip
,
496 snd_pcm_substream_t
* substream
,
500 case SNDRV_PCM_TRIGGER_START
:
501 case SNDRV_PCM_TRIGGER_RESUME
:
502 if (chip
->active
& DAC2
)
504 chip
->active
|= DAC2
;
507 snd_es18xx_mixer_write(chip
, 0x78, 0xb3);
509 snd_es18xx_mixer_write(chip
, 0x78, 0x93);
513 if (chip
->caps
& ES18XX_PCM2
)
514 /* Restore Audio 2 volume */
515 snd_es18xx_mixer_write(chip
, 0x7C, chip
->audio2_vol
);
517 /* Enable PCM output */
518 snd_es18xx_dsp_command(chip
, 0xD1);
521 case SNDRV_PCM_TRIGGER_STOP
:
522 case SNDRV_PCM_TRIGGER_SUSPEND
:
523 if (!(chip
->active
& DAC2
))
525 chip
->active
&= ~DAC2
;
527 snd_es18xx_mixer_write(chip
, 0x78, 0x00);
530 if (chip
->caps
& ES18XX_PCM2
)
531 /* Set Audio 2 volume to 0 */
532 snd_es18xx_mixer_write(chip
, 0x7C, 0);
534 /* Disable PCM output */
535 snd_es18xx_dsp_command(chip
, 0xD3);
545 static int snd_es18xx_capture_hw_params(snd_pcm_substream_t
* substream
,
546 snd_pcm_hw_params_t
* hw_params
)
548 es18xx_t
*chip
= snd_pcm_substream_chip(substream
);
552 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
553 chip
->playback_a_substream
&&
554 params_channels(hw_params
) != 1) {
555 _snd_pcm_hw_param_setempty(hw_params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
558 if (params_channels(hw_params
) == 2)
560 if (snd_pcm_format_width(params_format(hw_params
)) == 16)
562 chip
->dma1_shift
= shift
;
563 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
568 static int snd_es18xx_capture_prepare(snd_pcm_substream_t
*substream
)
570 es18xx_t
*chip
= snd_pcm_substream_chip(substream
);
571 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
572 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
573 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
575 chip
->dma1_size
= size
;
577 snd_es18xx_reset_fifo(chip
);
579 /* Set stereo/mono */
580 snd_es18xx_bits(chip
, 0xA8, 0x03, runtime
->channels
== 1 ? 0x02 : 0x01);
582 snd_es18xx_rate_set(chip
, substream
, ADC1
);
584 /* Transfer Count Reload */
585 count
= 0x10000 - count
;
586 snd_es18xx_write(chip
, 0xA4, count
& 0xff);
587 snd_es18xx_write(chip
, 0xA5, count
>> 8);
594 snd_es18xx_write(chip
, 0xB7,
595 snd_pcm_format_unsigned(runtime
->format
) ? 0x51 : 0x71);
596 snd_es18xx_write(chip
, 0xB7, 0x90 |
597 ((runtime
->channels
== 1) ? 0x40 : 0x08) |
598 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x04 : 0x00) |
599 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x20));
601 /* Set DMA controler */
602 snd_dma_program(chip
->dma1
, runtime
->dma_addr
, size
, DMA_MODE_READ
| DMA_AUTOINIT
);
607 static int snd_es18xx_capture_trigger(snd_pcm_substream_t
*substream
,
610 es18xx_t
*chip
= snd_pcm_substream_chip(substream
);
613 case SNDRV_PCM_TRIGGER_START
:
614 case SNDRV_PCM_TRIGGER_RESUME
:
615 if (chip
->active
& ADC1
)
617 chip
->active
|= ADC1
;
619 snd_es18xx_write(chip
, 0xB8, 0x0f);
621 case SNDRV_PCM_TRIGGER_STOP
:
622 case SNDRV_PCM_TRIGGER_SUSPEND
:
623 if (!(chip
->active
& ADC1
))
625 chip
->active
&= ~ADC1
;
627 snd_es18xx_write(chip
, 0xB8, 0x00);
636 static int snd_es18xx_playback2_prepare(es18xx_t
*chip
,
637 snd_pcm_substream_t
*substream
)
639 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
640 unsigned int size
= snd_pcm_lib_buffer_bytes(substream
);
641 unsigned int count
= snd_pcm_lib_period_bytes(substream
);
643 chip
->dma1_size
= size
;
645 snd_es18xx_reset_fifo(chip
);
647 /* Set stereo/mono */
648 snd_es18xx_bits(chip
, 0xA8, 0x03, runtime
->channels
== 1 ? 0x02 : 0x01);
650 snd_es18xx_rate_set(chip
, substream
, DAC1
);
652 /* Transfer Count Reload */
653 count
= 0x10000 - count
;
654 snd_es18xx_write(chip
, 0xA4, count
& 0xff);
655 snd_es18xx_write(chip
, 0xA5, count
>> 8);
658 snd_es18xx_write(chip
, 0xB6,
659 snd_pcm_format_unsigned(runtime
->format
) ? 0x80 : 0x00);
660 snd_es18xx_write(chip
, 0xB7,
661 snd_pcm_format_unsigned(runtime
->format
) ? 0x51 : 0x71);
662 snd_es18xx_write(chip
, 0xB7, 0x90 |
663 (runtime
->channels
== 1 ? 0x40 : 0x08) |
664 (snd_pcm_format_width(runtime
->format
) == 16 ? 0x04 : 0x00) |
665 (snd_pcm_format_unsigned(runtime
->format
) ? 0x00 : 0x20));
667 /* Set DMA controler */
668 snd_dma_program(chip
->dma1
, runtime
->dma_addr
, size
, DMA_MODE_WRITE
| DMA_AUTOINIT
);
673 static int snd_es18xx_playback2_trigger(es18xx_t
*chip
,
674 snd_pcm_substream_t
*substream
,
678 case SNDRV_PCM_TRIGGER_START
:
679 case SNDRV_PCM_TRIGGER_RESUME
:
680 if (chip
->active
& DAC1
)
682 chip
->active
|= DAC1
;
684 snd_es18xx_write(chip
, 0xB8, 0x05);
689 snd_es18xx_dsp_command(chip
, 0xD1);
692 case SNDRV_PCM_TRIGGER_STOP
:
693 case SNDRV_PCM_TRIGGER_SUSPEND
:
694 if (!(chip
->active
& DAC1
))
696 chip
->active
&= ~DAC1
;
698 snd_es18xx_write(chip
, 0xB8, 0x00);
702 /* Disable Audio 1 */
703 snd_es18xx_dsp_command(chip
, 0xD3);
713 static int snd_es18xx_playback_prepare(snd_pcm_substream_t
*substream
)
715 es18xx_t
*chip
= snd_pcm_substream_chip(substream
);
716 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
717 return snd_es18xx_playback1_prepare(chip
, substream
);
719 return snd_es18xx_playback2_prepare(chip
, substream
);
722 static int snd_es18xx_playback_trigger(snd_pcm_substream_t
*substream
,
725 es18xx_t
*chip
= snd_pcm_substream_chip(substream
);
726 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
727 return snd_es18xx_playback1_trigger(chip
, substream
, cmd
);
729 return snd_es18xx_playback2_trigger(chip
, substream
, cmd
);
732 static irqreturn_t
snd_es18xx_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
734 es18xx_t
*chip
= dev_id
;
735 unsigned char status
;
737 if (chip
->caps
& ES18XX_CONTROL
) {
738 /* Read Interrupt status */
739 status
= inb(chip
->ctrl_port
+ 6);
741 /* Read Interrupt status */
742 status
= snd_es18xx_mixer_read(chip
, 0x7f) >> 4;
747 if (inb(chip
->port
+ 0x0C) & 0x01)
748 status
|= AUDIO1_IRQ
;
749 if (snd_es18xx_mixer_read(chip
, 0x7A) & 0x80)
750 status
|= AUDIO2_IRQ
;
751 if ((chip
->caps
& ES18XX_HWV
) &&
752 snd_es18xx_mixer_read(chip
, 0x64) & 0x10)
757 /* Audio 1 & Audio 2 */
758 if (status
& AUDIO2_IRQ
) {
759 if (chip
->active
& DAC2
)
760 snd_pcm_period_elapsed(chip
->playback_a_substream
);
762 snd_es18xx_mixer_bits(chip
, 0x7A, 0x80, 0x00);
764 if (status
& AUDIO1_IRQ
) {
765 /* ok.. capture is active */
766 if (chip
->active
& ADC1
)
767 snd_pcm_period_elapsed(chip
->capture_a_substream
);
768 /* ok.. playback2 is active */
769 else if (chip
->active
& DAC1
)
770 snd_pcm_period_elapsed(chip
->playback_b_substream
);
772 inb(chip
->port
+ 0x0E);
776 if ((status
& MPU_IRQ
) && chip
->rmidi
)
777 snd_mpu401_uart_interrupt(irq
, chip
->rmidi
->private_data
, regs
);
779 /* Hardware volume */
780 if (status
& HWV_IRQ
) {
781 int split
= snd_es18xx_mixer_read(chip
, 0x64) & 0x80;
782 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &chip
->hw_switch
->id
);
783 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &chip
->hw_volume
->id
);
785 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &chip
->master_switch
->id
);
786 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &chip
->master_volume
->id
);
789 snd_es18xx_mixer_write(chip
, 0x66, 0x00);
794 static snd_pcm_uframes_t
snd_es18xx_playback_pointer(snd_pcm_substream_t
* substream
)
796 es18xx_t
*chip
= snd_pcm_substream_chip(substream
);
799 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
800 if (!(chip
->active
& DAC2
))
802 pos
= snd_dma_pointer(chip
->dma2
, chip
->dma2_size
);
803 return pos
>> chip
->dma2_shift
;
805 if (!(chip
->active
& DAC1
))
807 pos
= snd_dma_pointer(chip
->dma1
, chip
->dma1_size
);
808 return pos
>> chip
->dma1_shift
;
812 static snd_pcm_uframes_t
snd_es18xx_capture_pointer(snd_pcm_substream_t
* substream
)
814 es18xx_t
*chip
= snd_pcm_substream_chip(substream
);
817 if (!(chip
->active
& ADC1
))
819 pos
= snd_dma_pointer(chip
->dma1
, chip
->dma1_size
);
820 return pos
>> chip
->dma1_shift
;
823 static snd_pcm_hardware_t snd_es18xx_playback
=
825 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
826 SNDRV_PCM_INFO_RESUME
|
827 SNDRV_PCM_INFO_MMAP_VALID
),
828 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S8
|
829 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_U16_LE
),
830 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
835 .buffer_bytes_max
= 65536,
836 .period_bytes_min
= 64,
837 .period_bytes_max
= 65536,
843 static snd_pcm_hardware_t snd_es18xx_capture
=
845 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
846 SNDRV_PCM_INFO_RESUME
|
847 SNDRV_PCM_INFO_MMAP_VALID
),
848 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S8
|
849 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_U16_LE
),
850 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
855 .buffer_bytes_max
= 65536,
856 .period_bytes_min
= 64,
857 .period_bytes_max
= 65536,
863 static int snd_es18xx_playback_open(snd_pcm_substream_t
* substream
)
865 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
866 es18xx_t
*chip
= snd_pcm_substream_chip(substream
);
868 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
)) {
869 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
870 chip
->capture_a_substream
&&
871 chip
->capture_a_substream
->runtime
->channels
!= 1)
873 chip
->playback_a_substream
= substream
;
874 } else if (substream
->number
<= 1) {
875 if (chip
->capture_a_substream
)
877 chip
->playback_b_substream
= substream
;
882 substream
->runtime
->hw
= snd_es18xx_playback
;
883 snd_pcm_hw_constraint_ratnums(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
884 (chip
->caps
& ES18XX_NEW_RATE
) ? &new_hw_constraints_clocks
: &old_hw_constraints_clocks
);
888 static int snd_es18xx_capture_open(snd_pcm_substream_t
* substream
)
890 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
891 es18xx_t
*chip
= snd_pcm_substream_chip(substream
);
893 if (chip
->playback_b_substream
)
895 if ((chip
->caps
& ES18XX_DUPLEX_MONO
) &&
896 chip
->playback_a_substream
&&
897 chip
->playback_a_substream
->runtime
->channels
!= 1)
899 chip
->capture_a_substream
= substream
;
900 substream
->runtime
->hw
= snd_es18xx_capture
;
901 snd_pcm_hw_constraint_ratnums(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
902 (chip
->caps
& ES18XX_NEW_RATE
) ? &new_hw_constraints_clocks
: &old_hw_constraints_clocks
);
906 static int snd_es18xx_playback_close(snd_pcm_substream_t
* substream
)
908 es18xx_t
*chip
= snd_pcm_substream_chip(substream
);
910 if (substream
->number
== 0 && (chip
->caps
& ES18XX_PCM2
))
911 chip
->playback_a_substream
= NULL
;
913 chip
->playback_b_substream
= NULL
;
915 snd_pcm_lib_free_pages(substream
);
919 static int snd_es18xx_capture_close(snd_pcm_substream_t
* substream
)
921 es18xx_t
*chip
= snd_pcm_substream_chip(substream
);
923 chip
->capture_a_substream
= NULL
;
924 snd_pcm_lib_free_pages(substream
);
932 static int snd_es18xx_info_mux(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
934 static char *texts
[8] = {
935 "Mic", "Mic Master", "CD", "AOUT",
936 "Mic1", "Mix", "Line", "Master"
939 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
941 uinfo
->value
.enumerated
.items
= 8;
942 if (uinfo
->value
.enumerated
.item
> 7)
943 uinfo
->value
.enumerated
.item
= 7;
944 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
948 static int snd_es18xx_get_mux(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
950 es18xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
951 ucontrol
->value
.enumerated
.item
[0] = snd_es18xx_mixer_read(chip
, 0x1c) & 0x07;
955 static int snd_es18xx_put_mux(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
957 es18xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
958 unsigned char val
= ucontrol
->value
.enumerated
.item
[0];
962 return snd_es18xx_mixer_bits(chip
, 0x1c, 0x07, val
) != val
;
965 static int snd_es18xx_info_spatializer_enable(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
967 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
969 uinfo
->value
.integer
.min
= 0;
970 uinfo
->value
.integer
.max
= 1;
974 static int snd_es18xx_get_spatializer_enable(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
976 es18xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
977 unsigned char val
= snd_es18xx_mixer_read(chip
, 0x50);
978 ucontrol
->value
.integer
.value
[0] = !!(val
& 8);
982 static int snd_es18xx_put_spatializer_enable(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
984 es18xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
985 unsigned char oval
, nval
;
987 nval
= ucontrol
->value
.integer
.value
[0] ? 0x0c : 0x04;
988 oval
= snd_es18xx_mixer_read(chip
, 0x50) & 0x0c;
989 change
= nval
!= oval
;
991 snd_es18xx_mixer_write(chip
, 0x50, nval
& ~0x04);
992 snd_es18xx_mixer_write(chip
, 0x50, nval
);
997 static int snd_es18xx_info_hw_volume(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
999 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1001 uinfo
->value
.integer
.min
= 0;
1002 uinfo
->value
.integer
.max
= 63;
1006 static int snd_es18xx_get_hw_volume(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1008 es18xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1009 ucontrol
->value
.integer
.value
[0] = snd_es18xx_mixer_read(chip
, 0x61) & 0x3f;
1010 ucontrol
->value
.integer
.value
[1] = snd_es18xx_mixer_read(chip
, 0x63) & 0x3f;
1014 static int snd_es18xx_info_hw_switch(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1016 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1018 uinfo
->value
.integer
.min
= 0;
1019 uinfo
->value
.integer
.max
= 1;
1023 static int snd_es18xx_get_hw_switch(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1025 es18xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1026 ucontrol
->value
.integer
.value
[0] = !(snd_es18xx_mixer_read(chip
, 0x61) & 0x40);
1027 ucontrol
->value
.integer
.value
[1] = !(snd_es18xx_mixer_read(chip
, 0x63) & 0x40);
1031 static void snd_es18xx_hwv_free(snd_kcontrol_t
*kcontrol
)
1033 es18xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1034 chip
->master_volume
= NULL
;
1035 chip
->master_switch
= NULL
;
1036 chip
->hw_volume
= NULL
;
1037 chip
->hw_switch
= NULL
;
1040 static int snd_es18xx_reg_bits(es18xx_t
*chip
, unsigned char reg
,
1041 unsigned char mask
, unsigned char val
)
1044 return snd_es18xx_mixer_bits(chip
, reg
, mask
, val
);
1046 return snd_es18xx_bits(chip
, reg
, mask
, val
);
1049 static int snd_es18xx_reg_read(es18xx_t
*chip
, unsigned char reg
)
1052 return snd_es18xx_mixer_read(chip
, reg
);
1054 return snd_es18xx_read(chip
, reg
);
1057 #define ES18XX_SINGLE(xname, xindex, reg, shift, mask, invert) \
1058 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1059 .info = snd_es18xx_info_single, \
1060 .get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \
1061 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
1063 static int snd_es18xx_info_single(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1065 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1067 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1069 uinfo
->value
.integer
.min
= 0;
1070 uinfo
->value
.integer
.max
= mask
;
1074 static int snd_es18xx_get_single(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1076 es18xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1077 int reg
= kcontrol
->private_value
& 0xff;
1078 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1079 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1080 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1083 val
= snd_es18xx_reg_read(chip
, reg
);
1084 ucontrol
->value
.integer
.value
[0] = (val
>> shift
) & mask
;
1086 ucontrol
->value
.integer
.value
[0] = mask
- ucontrol
->value
.integer
.value
[0];
1090 static int snd_es18xx_put_single(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1092 es18xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1093 int reg
= kcontrol
->private_value
& 0xff;
1094 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1095 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1096 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1099 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1104 return snd_es18xx_reg_bits(chip
, reg
, mask
, val
) != val
;
1107 #define ES18XX_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
1108 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1109 .info = snd_es18xx_info_double, \
1110 .get = snd_es18xx_get_double, .put = snd_es18xx_put_double, \
1111 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
1113 static int snd_es18xx_info_double(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1115 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1117 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1119 uinfo
->value
.integer
.min
= 0;
1120 uinfo
->value
.integer
.max
= mask
;
1124 static int snd_es18xx_get_double(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1126 es18xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1127 int left_reg
= kcontrol
->private_value
& 0xff;
1128 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
1129 int shift_left
= (kcontrol
->private_value
>> 16) & 0x07;
1130 int shift_right
= (kcontrol
->private_value
>> 19) & 0x07;
1131 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1132 int invert
= (kcontrol
->private_value
>> 22) & 1;
1133 unsigned char left
, right
;
1135 left
= snd_es18xx_reg_read(chip
, left_reg
);
1136 if (left_reg
!= right_reg
)
1137 right
= snd_es18xx_reg_read(chip
, right_reg
);
1140 ucontrol
->value
.integer
.value
[0] = (left
>> shift_left
) & mask
;
1141 ucontrol
->value
.integer
.value
[1] = (right
>> shift_right
) & mask
;
1143 ucontrol
->value
.integer
.value
[0] = mask
- ucontrol
->value
.integer
.value
[0];
1144 ucontrol
->value
.integer
.value
[1] = mask
- ucontrol
->value
.integer
.value
[1];
1149 static int snd_es18xx_put_double(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1151 es18xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1152 int left_reg
= kcontrol
->private_value
& 0xff;
1153 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
1154 int shift_left
= (kcontrol
->private_value
>> 16) & 0x07;
1155 int shift_right
= (kcontrol
->private_value
>> 19) & 0x07;
1156 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1157 int invert
= (kcontrol
->private_value
>> 22) & 1;
1159 unsigned char val1
, val2
, mask1
, mask2
;
1161 val1
= ucontrol
->value
.integer
.value
[0] & mask
;
1162 val2
= ucontrol
->value
.integer
.value
[1] & mask
;
1167 val1
<<= shift_left
;
1168 val2
<<= shift_right
;
1169 mask1
= mask
<< shift_left
;
1170 mask2
= mask
<< shift_right
;
1171 if (left_reg
!= right_reg
) {
1173 if (snd_es18xx_reg_bits(chip
, left_reg
, mask1
, val1
) != val1
)
1175 if (snd_es18xx_reg_bits(chip
, right_reg
, mask2
, val2
) != val2
)
1178 change
= (snd_es18xx_reg_bits(chip
, left_reg
, mask1
| mask2
,
1179 val1
| val2
) != (val1
| val2
));
1184 static snd_kcontrol_new_t snd_es18xx_base_controls
[] = {
1185 ES18XX_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0),
1186 ES18XX_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1),
1187 ES18XX_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0),
1188 ES18XX_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0),
1189 ES18XX_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0),
1190 ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1191 ES18XX_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0),
1192 ES18XX_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0),
1193 ES18XX_SINGLE("PC Speaker Playback Volume", 0, 0x3c, 0, 7, 0),
1194 ES18XX_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
1195 ES18XX_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0),
1196 ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
1198 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1199 .name
= "Capture Source",
1200 .info
= snd_es18xx_info_mux
,
1201 .get
= snd_es18xx_get_mux
,
1202 .put
= snd_es18xx_put_mux
,
1206 static snd_kcontrol_new_t snd_es18xx_mono_in_control
=
1207 ES18XX_DOUBLE("Mono Input Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0);
1209 static snd_kcontrol_new_t snd_es18xx_recmix_controls
[] = {
1210 ES18XX_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0),
1211 ES18XX_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0),
1212 ES18XX_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0),
1213 ES18XX_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0),
1214 ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0),
1215 ES18XX_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0),
1216 ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0)
1219 static snd_kcontrol_new_t snd_es18xx_pcm1_controls
[] = {
1220 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x14, 0x14, 4, 0, 15, 0),
1223 static snd_kcontrol_new_t snd_es18xx_pcm2_controls
[] = {
1224 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0),
1225 ES18XX_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0)
1228 static snd_kcontrol_new_t snd_es18xx_spatializer_controls
[] = {
1229 ES18XX_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
1231 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1232 .name
= "3D Control - Switch",
1233 .info
= snd_es18xx_info_spatializer_enable
,
1234 .get
= snd_es18xx_get_spatializer_enable
,
1235 .put
= snd_es18xx_put_spatializer_enable
,
1239 static snd_kcontrol_new_t snd_es18xx_micpre1_control
=
1240 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0xa9, 2, 1, 0);
1242 static snd_kcontrol_new_t snd_es18xx_micpre2_control
=
1243 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0);
1245 static snd_kcontrol_new_t snd_es18xx_hw_volume_controls
[] = {
1247 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1248 .name
= "Hardware Master Playback Volume",
1249 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1250 .info
= snd_es18xx_info_hw_volume
,
1251 .get
= snd_es18xx_get_hw_volume
,
1254 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1255 .name
= "Hardware Master Playback Switch",
1256 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1257 .info
= snd_es18xx_info_hw_switch
,
1258 .get
= snd_es18xx_get_hw_switch
,
1260 ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0),
1264 static int __devinit
snd_es18xx_config_read(es18xx_t
*chip
, unsigned char reg
)
1267 unsigned long flags
;
1268 spin_lock_irqsave(&chip
->ctrl_lock
, flags
);
1269 outb(reg
, chip
->ctrl_port
);
1270 data
= inb(chip
->ctrl_port
+ 1);
1271 spin_unlock_irqrestore(&chip
->ctrl_lock
, flags
);
1276 static void __devinit
snd_es18xx_config_write(es18xx_t
*chip
,
1277 unsigned char reg
, unsigned char data
)
1279 /* No need for spinlocks, this function is used only in
1280 otherwise protected init code */
1281 outb(reg
, chip
->ctrl_port
);
1282 outb(data
, chip
->ctrl_port
+ 1);
1284 snd_printk("Config reg %02x set to %02x\n", reg
, data
);
1288 static int __devinit
snd_es18xx_initialize(es18xx_t
*chip
)
1292 /* enable extended mode */
1293 snd_es18xx_dsp_command(chip
, 0xC6);
1294 /* Reset mixer registers */
1295 snd_es18xx_mixer_write(chip
, 0x00, 0x00);
1297 /* Audio 1 DMA demand mode (4 bytes/request) */
1298 snd_es18xx_write(chip
, 0xB9, 2);
1299 if (chip
->caps
& ES18XX_CONTROL
) {
1300 /* Hardware volume IRQ */
1301 snd_es18xx_config_write(chip
, 0x27, chip
->irq
);
1302 if (chip
->fm_port
> 0 && chip
->fm_port
!= SNDRV_AUTO_PORT
) {
1304 snd_es18xx_config_write(chip
, 0x62, chip
->fm_port
>> 8);
1305 snd_es18xx_config_write(chip
, 0x63, chip
->fm_port
& 0xff);
1307 if (chip
->mpu_port
> 0 && chip
->mpu_port
!= SNDRV_AUTO_PORT
) {
1309 snd_es18xx_config_write(chip
, 0x64, chip
->mpu_port
>> 8);
1310 snd_es18xx_config_write(chip
, 0x65, chip
->mpu_port
& 0xff);
1312 snd_es18xx_config_write(chip
, 0x28, chip
->irq
);
1315 snd_es18xx_config_write(chip
, 0x70, chip
->irq
);
1317 snd_es18xx_config_write(chip
, 0x72, chip
->irq
);
1319 snd_es18xx_config_write(chip
, 0x74, chip
->dma1
);
1321 snd_es18xx_config_write(chip
, 0x75, chip
->dma2
);
1323 /* Enable Audio 1 IRQ */
1324 snd_es18xx_write(chip
, 0xB1, 0x50);
1325 /* Enable Audio 2 IRQ */
1326 snd_es18xx_mixer_write(chip
, 0x7A, 0x40);
1327 /* Enable Audio 1 DMA */
1328 snd_es18xx_write(chip
, 0xB2, 0x50);
1329 /* Enable MPU and hardware volume interrupt */
1330 snd_es18xx_mixer_write(chip
, 0x64, 0x42);
1333 int irqmask
, dma1mask
, dma2mask
;
1334 switch (chip
->irq
) {
1349 snd_printk("invalid irq %d\n", chip
->irq
);
1352 switch (chip
->dma1
) {
1363 snd_printk("invalid dma1 %d\n", chip
->dma1
);
1366 switch (chip
->dma2
) {
1380 snd_printk("invalid dma2 %d\n", chip
->dma2
);
1384 /* Enable and set Audio 1 IRQ */
1385 snd_es18xx_write(chip
, 0xB1, 0x50 | (irqmask
<< 2));
1386 /* Enable and set Audio 1 DMA */
1387 snd_es18xx_write(chip
, 0xB2, 0x50 | (dma1mask
<< 2));
1388 /* Set Audio 2 DMA */
1389 snd_es18xx_mixer_bits(chip
, 0x7d, 0x07, 0x04 | dma2mask
);
1390 /* Enable Audio 2 IRQ and DMA
1391 Set capture mixer input */
1392 snd_es18xx_mixer_write(chip
, 0x7A, 0x68);
1393 /* Enable and set hardware volume interrupt */
1394 snd_es18xx_mixer_write(chip
, 0x64, 0x06);
1395 if (chip
->mpu_port
> 0 && chip
->mpu_port
!= SNDRV_AUTO_PORT
) {
1396 /* MPU401 share irq with audio
1399 snd_es18xx_mixer_write(chip
, 0x40, 0x43 | (chip
->mpu_port
& 0xf0) >> 1);
1401 snd_es18xx_mixer_write(chip
, 0x7f, ((irqmask
+ 1) << 1) | 0x01);
1403 if (chip
->caps
& ES18XX_NEW_RATE
) {
1404 /* Change behaviour of register A1
1406 2nd channel DAC asynchronous */
1407 snd_es18xx_mixer_write(chip
, 0x71, 0x32);
1409 if (!(chip
->caps
& ES18XX_PCM2
)) {
1410 /* Enable DMA FIFO */
1411 snd_es18xx_write(chip
, 0xB7, 0x80);
1413 if (chip
->caps
& ES18XX_SPATIALIZER
) {
1414 /* Set spatializer parameters to recommended values */
1415 snd_es18xx_mixer_write(chip
, 0x54, 0x8f);
1416 snd_es18xx_mixer_write(chip
, 0x56, 0x95);
1417 snd_es18xx_mixer_write(chip
, 0x58, 0x94);
1418 snd_es18xx_mixer_write(chip
, 0x5a, 0x80);
1420 /* Mute input source */
1421 if (chip
->caps
& ES18XX_MUTEREC
)
1423 if (chip
->caps
& ES18XX_RECMIX
)
1424 snd_es18xx_mixer_write(chip
, 0x1c, 0x05 | mask
);
1426 snd_es18xx_mixer_write(chip
, 0x1c, 0x00 | mask
);
1427 snd_es18xx_write(chip
, 0xb4, 0x00);
1430 /* Enable PCM output */
1431 snd_es18xx_dsp_command(chip
, 0xD1);
1437 static int __devinit
snd_es18xx_identify(es18xx_t
*chip
)
1442 if (snd_es18xx_reset(chip
) < 0) {
1443 snd_printk("reset at 0x%lx failed!!!\n", chip
->port
);
1447 snd_es18xx_dsp_command(chip
, 0xe7);
1448 hi
= snd_es18xx_dsp_get_byte(chip
);
1452 lo
= snd_es18xx_dsp_get_byte(chip
);
1453 if ((lo
& 0xf0) != 0x80) {
1457 chip
->version
= 0x488;
1463 if ((lo
& 0x0f) < 8) {
1464 chip
->version
= 0x688;
1468 outb(0x40, chip
->port
+ 0x04);
1469 hi
= inb(chip
->port
+ 0x05);
1470 lo
= inb(chip
->port
+ 0x05);
1472 chip
->version
= hi
<< 8 | lo
;
1473 chip
->ctrl_port
= inb(chip
->port
+ 0x05) << 8;
1474 chip
->ctrl_port
+= inb(chip
->port
+ 0x05);
1476 if ((chip
->res_ctrl_port
= request_region(chip
->ctrl_port
, 8, "ES18xx - CTRL")) == NULL
) {
1477 snd_printk(KERN_ERR PFX
"unable go grab port 0x%lx\n", chip
->ctrl_port
);
1484 /* If has Hardware volume */
1485 if (snd_es18xx_mixer_writable(chip
, 0x64, 0x04)) {
1487 if (snd_es18xx_mixer_writable(chip
, 0x70, 0x7f)) {
1488 /* If has volume count */
1489 if (snd_es18xx_mixer_writable(chip
, 0x64, 0x20)) {
1490 chip
->version
= 0x1887;
1492 chip
->version
= 0x1888;
1495 chip
->version
= 0x1788;
1499 chip
->version
= 0x1688;
1503 static int __devinit
snd_es18xx_probe(es18xx_t
*chip
)
1505 if (snd_es18xx_identify(chip
) < 0) {
1506 snd_printk(KERN_ERR PFX
"[0x%lx] ESS chip not found\n", chip
->port
);
1510 switch (chip
->version
) {
1512 chip
->caps
= ES18XX_DUPLEX_MONO
| ES18XX_DUPLEX_SAME
| ES18XX_CONTROL
| ES18XX_HWV
;
1515 chip
->caps
= ES18XX_PCM2
| ES18XX_SPATIALIZER
| ES18XX_RECMIX
| ES18XX_NEW_RATE
| ES18XX_AUXB
| ES18XX_MONO
| ES18XX_MUTEREC
| ES18XX_CONTROL
| ES18XX_HWV
;
1518 chip
->caps
= ES18XX_DUPLEX_MONO
| ES18XX_DUPLEX_SAME
| ES18XX_I2S
| ES18XX_CONTROL
| ES18XX_HWV
;
1521 chip
->caps
= ES18XX_PCM2
| ES18XX_SPATIALIZER
| ES18XX_RECMIX
| ES18XX_NEW_RATE
| ES18XX_AUXB
| ES18XX_I2S
| ES18XX_CONTROL
| ES18XX_HWV
;
1524 chip
->caps
= ES18XX_PCM2
| ES18XX_RECMIX
| ES18XX_AUXB
| ES18XX_DUPLEX_SAME
| ES18XX_HWV
;
1527 chip
->caps
= ES18XX_PCM2
| ES18XX_RECMIX
| ES18XX_AUXB
| ES18XX_DUPLEX_SAME
| ES18XX_HWV
;
1530 snd_printk("[0x%lx] unsupported chip ES%x\n",
1531 chip
->port
, chip
->version
);
1535 snd_printd("[0x%lx] ESS%x chip found\n", chip
->port
, chip
->version
);
1537 if (chip
->dma1
== chip
->dma2
)
1538 chip
->caps
&= ~(ES18XX_PCM2
| ES18XX_DUPLEX_SAME
);
1540 return snd_es18xx_initialize(chip
);
1543 static snd_pcm_ops_t snd_es18xx_playback_ops
= {
1544 .open
= snd_es18xx_playback_open
,
1545 .close
= snd_es18xx_playback_close
,
1546 .ioctl
= snd_pcm_lib_ioctl
,
1547 .hw_params
= snd_es18xx_playback_hw_params
,
1548 .hw_free
= snd_es18xx_pcm_hw_free
,
1549 .prepare
= snd_es18xx_playback_prepare
,
1550 .trigger
= snd_es18xx_playback_trigger
,
1551 .pointer
= snd_es18xx_playback_pointer
,
1554 static snd_pcm_ops_t snd_es18xx_capture_ops
= {
1555 .open
= snd_es18xx_capture_open
,
1556 .close
= snd_es18xx_capture_close
,
1557 .ioctl
= snd_pcm_lib_ioctl
,
1558 .hw_params
= snd_es18xx_capture_hw_params
,
1559 .hw_free
= snd_es18xx_pcm_hw_free
,
1560 .prepare
= snd_es18xx_capture_prepare
,
1561 .trigger
= snd_es18xx_capture_trigger
,
1562 .pointer
= snd_es18xx_capture_pointer
,
1565 static void snd_es18xx_pcm_free(snd_pcm_t
*pcm
)
1567 es18xx_t
*codec
= pcm
->private_data
;
1569 snd_pcm_lib_preallocate_free_for_all(pcm
);
1572 static int __devinit
snd_es18xx_pcm(es18xx_t
*chip
, int device
, snd_pcm_t
** rpcm
)
1580 sprintf(str
, "ES%x", chip
->version
);
1581 if (chip
->caps
& ES18XX_PCM2
) {
1582 err
= snd_pcm_new(chip
->card
, str
, device
, 2, 1, &pcm
);
1584 err
= snd_pcm_new(chip
->card
, str
, device
, 1, 1, &pcm
);
1589 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_es18xx_playback_ops
);
1590 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_es18xx_capture_ops
);
1593 pcm
->private_data
= chip
;
1594 pcm
->private_free
= snd_es18xx_pcm_free
;
1595 pcm
->info_flags
= 0;
1596 if (chip
->caps
& ES18XX_DUPLEX_SAME
)
1597 pcm
->info_flags
|= SNDRV_PCM_INFO_JOINT_DUPLEX
;
1598 if (! (chip
->caps
& ES18XX_PCM2
))
1599 pcm
->info_flags
|= SNDRV_PCM_INFO_HALF_DUPLEX
;
1600 sprintf(pcm
->name
, "ESS AudioDrive ES%x", chip
->version
);
1603 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1606 chip
->dma1
> 3 || chip
->dma2
> 3 ? 128*1024 : 64*1024);
1613 /* Power Management support functions */
1615 static int snd_es18xx_suspend(snd_card_t
*card
, pm_message_t state
)
1617 es18xx_t
*chip
= card
->pm_private_data
;
1619 snd_pcm_suspend_all(chip
->pcm
);
1622 chip
->pm_reg
= (unsigned char)snd_es18xx_read(chip
, ES18XX_PM
);
1623 chip
->pm_reg
|= (ES18XX_PM_FM
| ES18XX_PM_SUS
);
1624 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
);
1625 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
^= ES18XX_PM_SUS
);
1630 static int snd_es18xx_resume(snd_card_t
*card
)
1632 es18xx_t
*chip
= card
->pm_private_data
;
1634 /* restore PM register, we won't wake till (not 0x07) i/o activity though */
1635 snd_es18xx_write(chip
, ES18XX_PM
, chip
->pm_reg
^= ES18XX_PM_FM
);
1639 #endif /* CONFIG_PM */
1641 static int snd_es18xx_free(es18xx_t
*chip
)
1643 if (chip
->res_port
) {
1644 release_resource(chip
->res_port
);
1645 kfree_nocheck(chip
->res_port
);
1647 if (chip
->res_ctrl_port
) {
1648 release_resource(chip
->res_ctrl_port
);
1649 kfree_nocheck(chip
->res_ctrl_port
);
1651 if (chip
->res_mpu_port
) {
1652 release_resource(chip
->res_mpu_port
);
1653 kfree_nocheck(chip
->res_mpu_port
);
1656 free_irq(chip
->irq
, (void *) chip
);
1657 if (chip
->dma1
>= 0) {
1658 disable_dma(chip
->dma1
);
1659 free_dma(chip
->dma1
);
1661 if (chip
->dma2
>= 0 && chip
->dma1
!= chip
->dma2
) {
1662 disable_dma(chip
->dma2
);
1663 free_dma(chip
->dma2
);
1669 static int snd_es18xx_dev_free(snd_device_t
*device
)
1671 es18xx_t
*chip
= device
->device_data
;
1672 return snd_es18xx_free(chip
);
1675 static int __devinit
snd_es18xx_new_device(snd_card_t
* card
,
1677 unsigned long mpu_port
,
1678 unsigned long fm_port
,
1679 int irq
, int dma1
, int dma2
,
1683 static snd_device_ops_t ops
= {
1684 .dev_free
= snd_es18xx_dev_free
,
1689 chip
= kcalloc(1, sizeof(*chip
), GFP_KERNEL
);
1692 spin_lock_init(&chip
->reg_lock
);
1693 spin_lock_init(&chip
->mixer_lock
);
1694 spin_lock_init(&chip
->ctrl_lock
);
1697 chip
->mpu_port
= mpu_port
;
1698 chip
->fm_port
= fm_port
;
1702 chip
->audio2_vol
= 0x00;
1705 if ((chip
->res_port
= request_region(port
, 16, "ES18xx")) == NULL
) {
1706 snd_es18xx_free(chip
);
1707 snd_printk(KERN_ERR PFX
"unable to grap ports 0x%lx-0x%lx\n", port
, port
+ 16 - 1);
1711 if (request_irq(irq
, snd_es18xx_interrupt
, SA_INTERRUPT
, "ES18xx", (void *) chip
)) {
1712 snd_es18xx_free(chip
);
1713 snd_printk(KERN_ERR PFX
"unable to grap IRQ %d\n", irq
);
1718 if (request_dma(dma1
, "ES18xx DMA 1")) {
1719 snd_es18xx_free(chip
);
1720 snd_printk(KERN_ERR PFX
"unable to grap DMA1 %d\n", dma1
);
1725 if (dma2
!= dma1
&& request_dma(dma2
, "ES18xx DMA 2")) {
1726 snd_es18xx_free(chip
);
1727 snd_printk(KERN_ERR PFX
"unable to grap DMA2 %d\n", dma2
);
1732 if (snd_es18xx_probe(chip
) < 0) {
1733 snd_es18xx_free(chip
);
1736 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
)) < 0) {
1737 snd_es18xx_free(chip
);
1744 static int __devinit
snd_es18xx_mixer(es18xx_t
*chip
)
1752 strcpy(card
->mixername
, chip
->pcm
->name
);
1754 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_base_controls
); idx
++) {
1755 snd_kcontrol_t
*kctl
;
1756 kctl
= snd_ctl_new1(&snd_es18xx_base_controls
[idx
], chip
);
1757 if (chip
->caps
& ES18XX_HWV
) {
1760 chip
->master_volume
= kctl
;
1761 kctl
->private_free
= snd_es18xx_hwv_free
;
1764 chip
->master_switch
= kctl
;
1765 kctl
->private_free
= snd_es18xx_hwv_free
;
1769 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
1772 if (chip
->caps
& ES18XX_PCM2
) {
1773 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_pcm2_controls
); idx
++) {
1774 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_pcm2_controls
[idx
], chip
))) < 0)
1778 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_pcm1_controls
); idx
++) {
1779 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_pcm1_controls
[idx
], chip
))) < 0)
1784 if (chip
->caps
& ES18XX_MONO
) {
1785 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_mono_in_control
, chip
))) < 0)
1788 if (chip
->caps
& ES18XX_RECMIX
) {
1789 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_recmix_controls
); idx
++) {
1790 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_recmix_controls
[idx
], chip
))) < 0)
1794 switch (chip
->version
) {
1796 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_micpre1_control
, chip
))) < 0)
1801 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_micpre2_control
, chip
))) < 0)
1805 if (chip
->caps
& ES18XX_SPATIALIZER
) {
1806 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_spatializer_controls
); idx
++) {
1807 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es18xx_spatializer_controls
[idx
], chip
))) < 0)
1811 if (chip
->caps
& ES18XX_HWV
) {
1812 for (idx
= 0; idx
< ARRAY_SIZE(snd_es18xx_hw_volume_controls
); idx
++) {
1813 snd_kcontrol_t
*kctl
;
1814 kctl
= snd_ctl_new1(&snd_es18xx_hw_volume_controls
[idx
], chip
);
1816 chip
->hw_volume
= kctl
;
1818 chip
->hw_switch
= kctl
;
1819 kctl
->private_free
= snd_es18xx_hwv_free
;
1820 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
1831 MODULE_AUTHOR("Christian Fischbach <fishbach@pool.informatik.rwth-aachen.de>, Abramo Bagnara <abramo@alsa-project.org>");
1832 MODULE_DESCRIPTION("ESS ES18xx AudioDrive");
1833 MODULE_LICENSE("GPL");
1834 MODULE_SUPPORTED_DEVICE("{{ESS,ES1868 PnP AudioDrive},"
1835 "{ESS,ES1869 PnP AudioDrive},"
1836 "{ESS,ES1878 PnP AudioDrive},"
1837 "{ESS,ES1879 PnP AudioDrive},"
1838 "{ESS,ES1887 PnP AudioDrive},"
1839 "{ESS,ES1888 PnP AudioDrive},"
1840 "{ESS,ES1887 AudioDrive},"
1841 "{ESS,ES1888 AudioDrive}}");
1843 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
1844 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
1845 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_ISAPNP
; /* Enable this card */
1847 static int isapnp
[SNDRV_CARDS
] = {[0 ... (SNDRV_CARDS
- 1)] = 1};
1849 static long port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
; /* 0x220,0x240,0x260,0x280 */
1851 static long mpu_port
[SNDRV_CARDS
] = {[0 ... (SNDRV_CARDS
- 1)] = -1};
1853 static long mpu_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
1855 static long fm_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
1856 static int irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
; /* 5,7,9,10 */
1857 static int dma1
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* 0,1,3 */
1858 static int dma2
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* 0,1,3 */
1860 module_param_array(index
, int, NULL
, 0444);
1861 MODULE_PARM_DESC(index
, "Index value for ES18xx soundcard.");
1862 module_param_array(id
, charp
, NULL
, 0444);
1863 MODULE_PARM_DESC(id
, "ID string for ES18xx soundcard.");
1864 module_param_array(enable
, bool, NULL
, 0444);
1865 MODULE_PARM_DESC(enable
, "Enable ES18xx soundcard.");
1867 module_param_array(isapnp
, bool, NULL
, 0444);
1868 MODULE_PARM_DESC(isapnp
, "PnP detection for specified soundcard.");
1870 module_param_array(port
, long, NULL
, 0444);
1871 MODULE_PARM_DESC(port
, "Port # for ES18xx driver.");
1872 module_param_array(mpu_port
, long, NULL
, 0444);
1873 MODULE_PARM_DESC(mpu_port
, "MPU-401 port # for ES18xx driver.");
1874 module_param_array(fm_port
, long, NULL
, 0444);
1875 MODULE_PARM_DESC(fm_port
, "FM port # for ES18xx driver.");
1876 module_param_array(irq
, int, NULL
, 0444);
1877 MODULE_PARM_DESC(irq
, "IRQ # for ES18xx driver.");
1878 module_param_array(dma1
, int, NULL
, 0444);
1879 MODULE_PARM_DESC(dma1
, "DMA 1 # for ES18xx driver.");
1880 module_param_array(dma2
, int, NULL
, 0444);
1881 MODULE_PARM_DESC(dma2
, "DMA 2 # for ES18xx driver.");
1883 struct snd_audiodrive
{
1885 struct pnp_dev
*dev
;
1886 struct pnp_dev
*devc
;
1890 static snd_card_t
*snd_audiodrive_legacy
[SNDRV_CARDS
] = SNDRV_DEFAULT_PTR
;
1894 static struct pnp_card_device_id snd_audiodrive_pnpids
[] = {
1895 /* ESS 1868 (integrated on Compaq dual P-Pro motherboard and Genius 18PnP 3D) */
1896 { .id
= "ESS1868", .devs
= { { "ESS1868" }, { "ESS0000" } } },
1897 /* ESS 1868 (integrated on Maxisound Cards) */
1898 { .id
= "ESS1868", .devs
= { { "ESS8601" }, { "ESS8600" } } },
1899 /* ESS 1868 (integrated on Maxisound Cards) */
1900 { .id
= "ESS1868", .devs
= { { "ESS8611" }, { "ESS8610" } } },
1901 /* ESS ES1869 Plug and Play AudioDrive */
1902 { .id
= "ESS0003", .devs
= { { "ESS1869" }, { "ESS0006" } } },
1904 { .id
= "ESS1869", .devs
= { { "ESS1869" }, { "ESS0006" } } },
1906 { .id
= "ESS1878", .devs
= { { "ESS1878" }, { "ESS0004" } } },
1908 { .id
= "ESS1879", .devs
= { { "ESS1879" }, { "ESS0009" } } },
1910 { .id
= "" } /* end */
1913 MODULE_DEVICE_TABLE(pnp_card
, snd_audiodrive_pnpids
);
1915 static int __devinit
snd_audiodrive_pnp(int dev
, struct snd_audiodrive
*acard
,
1916 struct pnp_card_link
*card
,
1917 const struct pnp_card_device_id
*id
)
1919 struct pnp_dev
*pdev
;
1920 struct pnp_resource_table
* cfg
= kmalloc(sizeof(struct pnp_resource_table
), GFP_KERNEL
);
1925 acard
->dev
= pnp_request_card_device(card
, id
->devs
[0].id
, NULL
);
1926 if (acard
->dev
== NULL
) {
1930 acard
->devc
= pnp_request_card_device(card
, id
->devs
[1].id
, NULL
);
1931 if (acard
->devc
== NULL
) {
1935 /* Control port initialization */
1936 err
= pnp_activate_dev(acard
->devc
);
1938 snd_printk(KERN_ERR PFX
"PnP control configure failure (out of resources?)\n");
1941 snd_printdd("pnp: port=0x%lx\n", pnp_port_start(acard
->devc
, 0));
1942 /* PnP initialization */
1944 pnp_init_resource_table(cfg
);
1945 if (port
[dev
] != SNDRV_AUTO_PORT
)
1946 pnp_resource_change(&cfg
->port_resource
[0], port
[dev
], 16);
1947 if (fm_port
[dev
] != SNDRV_AUTO_PORT
)
1948 pnp_resource_change(&cfg
->port_resource
[1], fm_port
[dev
], 4);
1949 if (mpu_port
[dev
] != SNDRV_AUTO_PORT
)
1950 pnp_resource_change(&cfg
->port_resource
[2], mpu_port
[dev
], 2);
1951 if (dma1
[dev
] != SNDRV_AUTO_DMA
)
1952 pnp_resource_change(&cfg
->dma_resource
[0], dma1
[dev
], 1);
1953 if (dma2
[dev
] != SNDRV_AUTO_DMA
)
1954 pnp_resource_change(&cfg
->dma_resource
[1], dma2
[dev
], 1);
1955 if (irq
[dev
] != SNDRV_AUTO_IRQ
)
1956 pnp_resource_change(&cfg
->irq_resource
[0], irq
[dev
], 1);
1957 err
= pnp_manual_config_dev(pdev
, cfg
, 0);
1959 snd_printk(KERN_ERR PFX
"PnP manual resources are invalid, using auto config\n");
1960 err
= pnp_activate_dev(pdev
);
1962 snd_printk(KERN_ERR PFX
"PnP configure failure (out of resources?)\n");
1966 /* ok. hack using Vendor-Defined Card-Level registers */
1967 /* skip csn and logdev initialization - already done in isapnp_configure */
1968 if (pnp_device_is_isapnp(pdev
)) {
1969 isapnp_cfg_begin(isapnp_card_number(pdev
), isapnp_csn_number(pdev
));
1970 isapnp_write_byte(0x27, pnp_irq(pdev
, 0)); /* Hardware Volume IRQ Number */
1971 if (mpu_port
[dev
] != SNDRV_AUTO_PORT
)
1972 isapnp_write_byte(0x28, pnp_irq(pdev
, 0)); /* MPU-401 IRQ Number */
1973 isapnp_write_byte(0x72, pnp_irq(pdev
, 0)); /* second IRQ */
1976 snd_printk(KERN_ERR PFX
"unable to install ISA PnP hack, expect malfunction\n");
1978 port
[dev
] = pnp_port_start(pdev
, 0);
1979 fm_port
[dev
] = pnp_port_start(pdev
, 1);
1980 mpu_port
[dev
] = pnp_port_start(pdev
, 2);
1981 dma1
[dev
] = pnp_dma(pdev
, 0);
1982 dma2
[dev
] = pnp_dma(pdev
, 1);
1983 irq
[dev
] = pnp_irq(pdev
, 0);
1984 snd_printdd("PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port
[dev
], fm_port
[dev
], mpu_port
[dev
]);
1985 snd_printdd("PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1
[dev
], dma2
[dev
], irq
[dev
]);
1989 #endif /* CONFIG_PNP */
1991 static int __devinit
snd_audiodrive_probe(int dev
, struct pnp_card_link
*pcard
,
1992 const struct pnp_card_device_id
*pid
)
1994 static int possible_irqs
[] = {5, 9, 10, 7, 11, 12, -1};
1995 static int possible_dmas
[] = {1, 0, 3, 5, -1};
1996 int xirq
, xdma1
, xdma2
;
1998 struct snd_audiodrive
*acard
;
1999 snd_rawmidi_t
*rmidi
= NULL
;
2004 card
= snd_card_new(index
[dev
], id
[dev
], THIS_MODULE
,
2005 sizeof(struct snd_audiodrive
));
2008 acard
= (struct snd_audiodrive
*)card
->private_data
;
2011 if ((err
= snd_audiodrive_pnp(dev
, acard
, pcard
, pid
)) < 0) {
2012 snd_card_free(card
);
2015 snd_card_set_dev(card
, &pcard
->card
->dev
);
2020 if (xirq
== SNDRV_AUTO_IRQ
) {
2021 if ((xirq
= snd_legacy_find_free_irq(possible_irqs
)) < 0) {
2022 snd_card_free(card
);
2023 snd_printk("unable to find a free IRQ\n");
2028 if (xdma1
== SNDRV_AUTO_DMA
) {
2029 if ((xdma1
= snd_legacy_find_free_dma(possible_dmas
)) < 0) {
2030 snd_card_free(card
);
2031 snd_printk("unable to find a free DMA1\n");
2036 if (xdma2
== SNDRV_AUTO_DMA
) {
2037 if ((xdma2
= snd_legacy_find_free_dma(possible_dmas
)) < 0) {
2038 snd_card_free(card
);
2039 snd_printk("unable to find a free DMA2\n");
2044 if ((err
= snd_es18xx_new_device(card
,
2050 snd_card_free(card
);
2054 sprintf(card
->driver
, "ES%x", chip
->version
);
2055 sprintf(card
->shortname
, "ESS AudioDrive ES%x", chip
->version
);
2057 sprintf(card
->longname
, "%s at 0x%lx, irq %d, dma1 %d, dma2 %d",
2060 xirq
, xdma1
, xdma2
);
2062 sprintf(card
->longname
, "%s at 0x%lx, irq %d, dma %d",
2067 if ((err
= snd_es18xx_pcm(chip
, 0, NULL
)) < 0) {
2068 snd_card_free(card
);
2071 if ((err
= snd_es18xx_mixer(chip
)) < 0) {
2072 snd_card_free(card
);
2076 if (fm_port
[dev
] > 0 && fm_port
[dev
] != SNDRV_AUTO_PORT
) {
2077 if (snd_opl3_create(card
, chip
->fm_port
, chip
->fm_port
+ 2, OPL3_HW_OPL3
, 0, &opl3
) < 0) {
2078 snd_printk(KERN_ERR PFX
"opl3 not detected at 0x%lx\n", chip
->fm_port
);
2080 if ((err
= snd_opl3_hwdep_new(opl3
, 0, 1, NULL
)) < 0) {
2081 snd_card_free(card
);
2087 if (mpu_port
[dev
] > 0 && mpu_port
[dev
] != SNDRV_AUTO_PORT
) {
2088 if ((err
= snd_mpu401_uart_new(card
, 0, MPU401_HW_ES18XX
,
2092 snd_card_free(card
);
2095 chip
->rmidi
= rmidi
;
2098 /* Power Management */
2099 snd_card_set_isa_pm_callback(card
, snd_es18xx_suspend
, snd_es18xx_resume
, chip
);
2101 if ((err
= snd_card_register(card
)) < 0) {
2102 snd_card_free(card
);
2106 pnp_set_card_drvdata(pcard
, card
);
2108 snd_audiodrive_legacy
[dev
] = card
;
2112 static int __devinit
snd_audiodrive_probe_legacy_port(unsigned long xport
)
2117 for ( ; dev
< SNDRV_CARDS
; dev
++) {
2118 if (!enable
[dev
] || port
[dev
] != SNDRV_AUTO_PORT
)
2125 res
= snd_audiodrive_probe(dev
, NULL
, NULL
);
2127 port
[dev
] = SNDRV_AUTO_PORT
;
2135 static int __devinit
snd_audiodrive_pnp_detect(struct pnp_card_link
*card
,
2136 const struct pnp_card_device_id
*id
)
2141 for ( ; dev
< SNDRV_CARDS
; dev
++) {
2142 if (!enable
[dev
] || !isapnp
[dev
])
2144 res
= snd_audiodrive_probe(dev
, card
, id
);
2154 static void __devexit
snd_audiodrive_pnp_remove(struct pnp_card_link
* pcard
)
2156 snd_card_t
*card
= (snd_card_t
*) pnp_get_card_drvdata(pcard
);
2158 snd_card_disconnect(card
);
2159 snd_card_free_in_thread(card
);
2162 static struct pnp_card_driver es18xx_pnpc_driver
= {
2163 .flags
= PNP_DRIVER_RES_DISABLE
,
2165 .id_table
= snd_audiodrive_pnpids
,
2166 .probe
= snd_audiodrive_pnp_detect
,
2167 .remove
= __devexit_p(snd_audiodrive_pnp_remove
),
2169 #endif /* CONFIG_PNP */
2171 static int __init
alsa_card_es18xx_init(void)
2173 static unsigned long possible_ports
[] = {0x220, 0x240, 0x260, 0x280, -1};
2174 int dev
, cards
= 0, i
;
2176 /* legacy non-auto cards at first */
2177 for (dev
= 0; dev
< SNDRV_CARDS
; dev
++) {
2178 if (!enable
[dev
] || port
[dev
] == SNDRV_AUTO_PORT
)
2184 if (snd_audiodrive_probe(dev
, NULL
, NULL
) >= 0)
2187 /* legacy auto configured cards */
2188 i
= snd_legacy_auto_probe(possible_ports
, snd_audiodrive_probe_legacy_port
);
2193 /* ISA PnP cards at last */
2194 i
= pnp_register_card_driver(&es18xx_pnpc_driver
);
2201 pnp_unregister_card_driver(&es18xx_pnpc_driver
);
2204 snd_printk(KERN_ERR
"ESS AudioDrive ES18xx soundcard not found or device busy\n");
2211 static void __exit
alsa_card_es18xx_exit(void)
2216 /* PnP cards first */
2217 pnp_unregister_card_driver(&es18xx_pnpc_driver
);
2219 for(idx
= 0; idx
< SNDRV_CARDS
; idx
++)
2220 snd_card_free(snd_audiodrive_legacy
[idx
]);
2223 module_init(alsa_card_es18xx_init
)
2224 module_exit(alsa_card_es18xx_exit
)