2 * card-als4000.c - driver for Avance Logic ALS4000 based soundcards.
3 * Copyright (C) 2000 by Bart Hartgers <bart@etpmod.phys.tue.nl>,
4 * Jaroslav Kysela <perex@suse.cz>
5 * Copyright (C) 2002 by Andreas Mohr <hw7oshyuv3001@sneakemail.com>
7 * Framework borrowed from Massimo Piccioni's card-als100.c.
11 * Since Avance does not provide any meaningful documentation, and I
12 * bought an ALS4000 based soundcard, I was forced to base this driver
13 * on reverse engineering.
15 * Note: this is no longer true. Pretty verbose chip docu (ALS4000a.PDF)
16 * can be found on the ALSA web site.
18 * The ALS4000 seems to be the PCI-cousin of the ALS100. It contains an
19 * ALS100-like SB DSP/mixer, an OPL3 synth, a MPU401 and a gameport
20 * interface. These subsystems can be mapped into ISA io-port space,
21 * using the PCI-interface. In addition, the PCI-bit provides DMA and IRQ
22 * services to the subsystems.
24 * While ALS4000 is very similar to a SoundBlaster, the differences in
25 * DMA and capturing require more changes to the SoundBlaster than
26 * desirable, so I made this separate driver.
28 * The ALS4000 can do real full duplex playback/capture.
34 * Enable/disable 3D sound:
36 * - change bit 6 (0x40) of port 0x15
41 * 0x3e (mode 3), 0x3c (mode 2), 0x3a (mode 1), 0x38 (mode 0)
44 * - value -> some port 0x0c0d
46 * This program is free software; you can redistribute it and/or modify
47 * it under the terms of the GNU General Public License as published by
48 * the Free Software Foundation; either version 2 of the License, or
49 * (at your option) any later version.
51 * This program is distributed in the hope that it will be useful,
52 * but WITHOUT ANY WARRANTY; without even the implied warranty of
53 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54 * GNU General Public License for more details.
56 * You should have received a copy of the GNU General Public License
57 * along with this program; if not, write to the Free Software
58 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
61 #include <sound/driver.h>
63 #include <linux/init.h>
64 #include <linux/pci.h>
65 #include <linux/slab.h>
66 #include <linux/gameport.h>
67 #include <linux/moduleparam.h>
68 #include <sound/core.h>
69 #include <sound/pcm.h>
70 #include <sound/rawmidi.h>
71 #include <sound/mpu401.h>
72 #include <sound/opl3.h>
74 #include <sound/initval.h>
76 MODULE_AUTHOR("Bart Hartgers <bart@etpmod.phys.tue.nl>");
77 MODULE_DESCRIPTION("Avance Logic ALS4000");
78 MODULE_LICENSE("GPL");
79 MODULE_CLASSES("{sound}");
80 MODULE_DEVICES("{{Avance Logic,ALS4000}}");
82 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
83 #define SUPPORT_JOYSTICK 1
86 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
87 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
88 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
89 #ifdef SUPPORT_JOYSTICK
90 static int joystick_port[SNDRV_CARDS];
94 module_param_array(index, int, boot_devs, 0444);
95 MODULE_PARM_DESC(index, "Index value for ALS4000 soundcard.");
96 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
97 module_param_array(id, charp, boot_devs, 0444);
98 MODULE_PARM_DESC(id, "ID string for ALS4000 soundcard.");
99 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
100 module_param_array(enable, bool, boot_devs, 0444);
101 MODULE_PARM_DESC(enable, "Enable ALS4000 soundcard.");
102 MODULE_PARM_SYNTAX(enable, SNDRV_INDEX_DESC);
103 #ifdef SUPPORT_JOYSTICK
104 module_param_array(joystick_port, int, boot_devs, 0444);
105 MODULE_PARM_DESC(joystick_port, "Joystick port address for ALS4000 soundcard. (0 = disabled)");
106 MODULE_PARM_SYNTAX(joystick_port, SNDRV_ENABLED);
113 struct resource *res_gcr;
114 #ifdef SUPPORT_JOYSTICK
115 struct gameport gameport;
116 struct resource *res_joystick;
118 } snd_card_als4000_t;
120 static struct pci_device_id snd_als4000_ids[] = {
121 { 0x4005, 0x4000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ALS4000 */
125 MODULE_DEVICE_TABLE(pci, snd_als4000_ids);
127 static inline void snd_als4000_gcr_write_addr(unsigned long port, u32 reg, u32 val)
129 outb(reg, port+0x0c);
130 outl(val, port+0x08);
133 static inline void snd_als4000_gcr_write(sb_t *sb, u32 reg, u32 val)
135 snd_als4000_gcr_write_addr(sb->alt_port, reg, val);
138 static inline u32 snd_als4000_gcr_read_addr(unsigned long port, u32 reg)
140 outb(reg, port+0x0c);
141 return inl(port+0x08);
144 static inline u32 snd_als4000_gcr_read(sb_t *sb, u32 reg)
146 return snd_als4000_gcr_read_addr(sb->alt_port, reg);
149 static void snd_als4000_set_rate(sb_t *chip, unsigned int rate)
151 if (!(chip->mode & SB_RATE_LOCK)) {
152 snd_sbdsp_command(chip, SB_DSP_SAMPLE_RATE_OUT);
153 snd_sbdsp_command(chip, rate>>8);
154 snd_sbdsp_command(chip, rate);
158 static void snd_als4000_set_capture_dma(sb_t *chip, dma_addr_t addr, unsigned size)
160 snd_als4000_gcr_write(chip, 0xa2, addr);
161 snd_als4000_gcr_write(chip, 0xa3, (size-1));
164 static void snd_als4000_set_playback_dma(sb_t *chip, dma_addr_t addr, unsigned size)
166 snd_als4000_gcr_write(chip, 0x91, addr);
167 snd_als4000_gcr_write(chip, 0x92, (size-1)|0x180000);
170 #define ALS4000_FORMAT_SIGNED (1<<0)
171 #define ALS4000_FORMAT_16BIT (1<<1)
172 #define ALS4000_FORMAT_STEREO (1<<2)
174 static int snd_als4000_get_format(snd_pcm_runtime_t *runtime)
179 if (snd_pcm_format_signed(runtime->format))
180 result |= ALS4000_FORMAT_SIGNED;
181 if (snd_pcm_format_physical_width(runtime->format) == 16)
182 result |= ALS4000_FORMAT_16BIT;
183 if (runtime->channels > 1)
184 result |= ALS4000_FORMAT_STEREO;
188 /* structure for setting up playback */
190 unsigned char dsp_cmd, dma_on, dma_off, format;
191 } playback_cmd_vals[]={
192 /* ALS4000_FORMAT_U8_MONO */
193 { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_UNS_MONO },
194 /* ALS4000_FORMAT_S8_MONO */
195 { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_SIGN_MONO },
196 /* ALS4000_FORMAT_U16L_MONO */
197 { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_UNS_MONO },
198 /* ALS4000_FORMAT_S16L_MONO */
199 { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_SIGN_MONO },
200 /* ALS4000_FORMAT_U8_STEREO */
201 { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_UNS_STEREO },
202 /* ALS4000_FORMAT_S8_STEREO */
203 { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_SIGN_STEREO },
204 /* ALS4000_FORMAT_U16L_STEREO */
205 { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_UNS_STEREO },
206 /* ALS4000_FORMAT_S16L_STEREO */
207 { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_SIGN_STEREO },
209 #define playback_cmd(chip) (playback_cmd_vals[(chip)->playback_format])
211 /* structure for setting up capture */
212 enum { CMD_WIDTH8=0x04, CMD_SIGNED=0x10, CMD_MONO=0x80, CMD_STEREO=0xA0 };
213 static unsigned char capture_cmd_vals[]=
215 CMD_WIDTH8|CMD_MONO, /* ALS4000_FORMAT_U8_MONO */
216 CMD_WIDTH8|CMD_SIGNED|CMD_MONO, /* ALS4000_FORMAT_S8_MONO */
217 CMD_MONO, /* ALS4000_FORMAT_U16L_MONO */
218 CMD_SIGNED|CMD_MONO, /* ALS4000_FORMAT_S16L_MONO */
219 CMD_WIDTH8|CMD_STEREO, /* ALS4000_FORMAT_U8_STEREO */
220 CMD_WIDTH8|CMD_SIGNED|CMD_STEREO, /* ALS4000_FORMAT_S8_STEREO */
221 CMD_STEREO, /* ALS4000_FORMAT_U16L_STEREO */
222 CMD_SIGNED|CMD_STEREO, /* ALS4000_FORMAT_S16L_STEREO */
224 #define capture_cmd(chip) (capture_cmd_vals[(chip)->capture_format])
226 static int snd_als4000_hw_params(snd_pcm_substream_t * substream,
227 snd_pcm_hw_params_t * hw_params)
229 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
232 static int snd_als4000_hw_free(snd_pcm_substream_t * substream)
234 snd_pcm_lib_free_pages(substream);
238 static int snd_als4000_capture_prepare(snd_pcm_substream_t * substream)
241 sb_t *chip = snd_pcm_substream_chip(substream);
242 snd_pcm_runtime_t *runtime = substream->runtime;
246 chip->capture_format = snd_als4000_get_format(runtime);
248 size = snd_pcm_lib_buffer_bytes(substream);
249 count = snd_pcm_lib_period_bytes(substream);
251 if (chip->capture_format & ALS4000_FORMAT_16BIT)
255 spin_lock_irqsave(&chip->reg_lock, flags);
256 snd_als4000_set_rate(chip, runtime->rate);
257 snd_als4000_set_capture_dma(chip, runtime->dma_addr, size);
258 spin_unlock_irqrestore(&chip->reg_lock, flags);
259 spin_lock_irqsave(&chip->mixer_lock, flags );
260 snd_sbmixer_write(chip, 0xdc, count);
261 snd_sbmixer_write(chip, 0xdd, count>>8);
262 spin_unlock_irqrestore(&chip->mixer_lock, flags );
266 static int snd_als4000_playback_prepare(snd_pcm_substream_t *substream)
269 sb_t *chip = snd_pcm_substream_chip(substream);
270 snd_pcm_runtime_t *runtime = substream->runtime;
274 chip->playback_format = snd_als4000_get_format(runtime);
276 size = snd_pcm_lib_buffer_bytes(substream);
277 count = snd_pcm_lib_period_bytes(substream);
279 if (chip->playback_format & ALS4000_FORMAT_16BIT)
283 /* FIXME: from second playback on, there's a lot more clicks and pops
284 * involved here than on first playback. Fiddling with
285 * tons of different settings didn't help (DMA, speaker on/off,
286 * reordering, ...). Something seems to get enabled on playback
287 * that I haven't found out how to disable again, which then causes
288 * the switching pops to reach the speakers the next time here. */
289 spin_lock_irqsave(&chip->reg_lock, flags);
290 snd_als4000_set_rate(chip, runtime->rate);
291 snd_als4000_set_playback_dma(chip, runtime->dma_addr, size);
293 /* SPEAKER_ON not needed, since dma_on seems to also enable speaker */
294 /* snd_sbdsp_command(chip, SB_DSP_SPEAKER_ON); */
295 snd_sbdsp_command(chip, playback_cmd(chip).dsp_cmd);
296 snd_sbdsp_command(chip, playback_cmd(chip).format);
297 snd_sbdsp_command(chip, count);
298 snd_sbdsp_command(chip, count>>8);
299 snd_sbdsp_command(chip, playback_cmd(chip).dma_off);
300 spin_unlock_irqrestore(&chip->reg_lock, flags);
305 static int snd_als4000_capture_trigger(snd_pcm_substream_t * substream, int cmd)
308 sb_t *chip = snd_pcm_substream_chip(substream);
311 spin_lock_irqsave(&chip->mixer_lock, flags);
312 if (cmd == SNDRV_PCM_TRIGGER_START) {
313 chip->mode |= SB_RATE_LOCK_CAPTURE;
314 snd_sbmixer_write(chip, 0xde, capture_cmd(chip));
315 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
316 chip->mode &= ~SB_RATE_LOCK_CAPTURE;
317 snd_sbmixer_write(chip, 0xde, 0);
321 spin_unlock_irqrestore(&chip->mixer_lock, flags);
325 static int snd_als4000_playback_trigger(snd_pcm_substream_t * substream, int cmd)
328 sb_t *chip = snd_pcm_substream_chip(substream);
331 spin_lock_irqsave(&chip->reg_lock, flags);
332 if (cmd == SNDRV_PCM_TRIGGER_START) {
333 chip->mode |= SB_RATE_LOCK_PLAYBACK;
334 snd_sbdsp_command(chip, playback_cmd(chip).dma_on);
335 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
336 snd_sbdsp_command(chip, playback_cmd(chip).dma_off);
337 chip->mode &= ~SB_RATE_LOCK_PLAYBACK;
341 spin_unlock_irqrestore(&chip->reg_lock, flags);
345 static snd_pcm_uframes_t snd_als4000_capture_pointer(snd_pcm_substream_t * substream)
348 sb_t *chip = snd_pcm_substream_chip(substream);
351 spin_lock_irqsave(&chip->reg_lock, flags);
352 result = snd_als4000_gcr_read(chip, 0xa4) & 0xffff;
353 spin_unlock_irqrestore(&chip->reg_lock, flags);
354 return bytes_to_frames( substream->runtime, result );
357 static snd_pcm_uframes_t snd_als4000_playback_pointer(snd_pcm_substream_t * substream)
360 sb_t *chip = snd_pcm_substream_chip(substream);
363 spin_lock_irqsave(&chip->reg_lock, flags);
364 result = snd_als4000_gcr_read(chip, 0xa0) & 0xffff;
365 spin_unlock_irqrestore(&chip->reg_lock, flags);
366 return bytes_to_frames( substream->runtime, result );
369 static irqreturn_t snd_als4000_interrupt(int irq, void *dev_id, struct pt_regs *regs)
371 sb_t *chip = snd_magic_cast(sb_t, dev_id, return IRQ_NONE);
376 /* find out which bit of the ALS4000 produced the interrupt */
377 gcr_status = inb(chip->alt_port + 0xe);
379 if ((gcr_status & 0x80) && (chip->playback_substream)) /* playback */
380 snd_pcm_period_elapsed(chip->playback_substream);
381 if ((gcr_status & 0x40) && (chip->capture_substream)) /* capturing */
382 snd_pcm_period_elapsed(chip->capture_substream);
383 if ((gcr_status & 0x10) && (chip->rmidi)) /* MPU401 interrupt */
384 snd_mpu401_uart_interrupt(irq, chip->rmidi, regs);
385 /* release the gcr */
386 outb(gcr_status, chip->alt_port + 0xe);
388 spin_lock_irqsave(&chip->mixer_lock, flags);
389 sb_status = snd_sbmixer_read(chip, SB_DSP4_IRQSTATUS);
390 spin_unlock_irqrestore(&chip->mixer_lock, flags);
392 if (sb_status & SB_IRQTYPE_8BIT)
393 snd_sb_ack_8bit(chip);
394 if (sb_status & SB_IRQTYPE_16BIT)
395 snd_sb_ack_16bit(chip);
396 if (sb_status & SB_IRQTYPE_MPUIN)
398 if (sb_status & 0x20)
399 inb(SBP(chip, RESET));
403 /*****************************************************************/
405 static snd_pcm_hardware_t snd_als4000_playback =
407 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
408 SNDRV_PCM_INFO_MMAP_VALID),
409 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 |
410 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE, /* formats */
411 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
416 .buffer_bytes_max = 65536,
417 .period_bytes_min = 64,
418 .period_bytes_max = 65536,
424 static snd_pcm_hardware_t snd_als4000_capture =
426 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
427 SNDRV_PCM_INFO_MMAP_VALID),
428 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 |
429 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE, /* formats */
430 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
435 .buffer_bytes_max = 65536,
436 .period_bytes_min = 64,
437 .period_bytes_max = 65536,
443 /*****************************************************************/
445 static int snd_als4000_playback_open(snd_pcm_substream_t * substream)
447 sb_t *chip = snd_pcm_substream_chip(substream);
448 snd_pcm_runtime_t *runtime = substream->runtime;
450 chip->playback_substream = substream;
451 runtime->hw = snd_als4000_playback;
455 static int snd_als4000_playback_close(snd_pcm_substream_t * substream)
457 sb_t *chip = snd_pcm_substream_chip(substream);
459 chip->playback_substream = NULL;
460 snd_pcm_lib_free_pages(substream);
464 static int snd_als4000_capture_open(snd_pcm_substream_t * substream)
466 sb_t *chip = snd_pcm_substream_chip(substream);
467 snd_pcm_runtime_t *runtime = substream->runtime;
469 chip->capture_substream = substream;
470 runtime->hw = snd_als4000_capture;
474 static int snd_als4000_capture_close(snd_pcm_substream_t * substream)
476 sb_t *chip = snd_pcm_substream_chip(substream);
478 chip->capture_substream = NULL;
479 snd_pcm_lib_free_pages(substream);
483 /******************************************************************/
485 static snd_pcm_ops_t snd_als4000_playback_ops = {
486 .open = snd_als4000_playback_open,
487 .close = snd_als4000_playback_close,
488 .ioctl = snd_pcm_lib_ioctl,
489 .hw_params = snd_als4000_hw_params,
490 .hw_free = snd_als4000_hw_free,
491 .prepare = snd_als4000_playback_prepare,
492 .trigger = snd_als4000_playback_trigger,
493 .pointer = snd_als4000_playback_pointer
496 static snd_pcm_ops_t snd_als4000_capture_ops = {
497 .open = snd_als4000_capture_open,
498 .close = snd_als4000_capture_close,
499 .ioctl = snd_pcm_lib_ioctl,
500 .hw_params = snd_als4000_hw_params,
501 .hw_free = snd_als4000_hw_free,
502 .prepare = snd_als4000_capture_prepare,
503 .trigger = snd_als4000_capture_trigger,
504 .pointer = snd_als4000_capture_pointer
507 static void snd_als4000_pcm_free(snd_pcm_t *pcm)
509 sb_t *chip = snd_magic_cast(sb_t, pcm->private_data, return);
511 snd_pcm_lib_preallocate_free_for_all(pcm);
514 static int __devinit snd_als4000_pcm(sb_t *chip, int device)
519 if ((err = snd_pcm_new(chip->card, "ALS4000 DSP", device, 1, 1, &pcm)) < 0)
521 pcm->private_free = snd_als4000_pcm_free;
522 pcm->private_data = chip;
523 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
524 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_als4000_playback_ops);
525 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_als4000_capture_ops);
527 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
535 /******************************************************************/
537 static void snd_als4000_set_addr(unsigned long gcr,
547 confB |= (mpu | 1) << 16;
551 confA |= (game | 1) << 16;
554 snd_als4000_gcr_write_addr(gcr, 0xa8, confA);
555 snd_als4000_gcr_write_addr(gcr, 0xa9, confB);
558 static void __devinit snd_als4000_configure(sb_t *chip)
564 /* do some more configuration */
565 spin_lock_irqsave(&chip->mixer_lock, flags);
566 tmp = snd_sbmixer_read(chip, 0xc0);
567 snd_sbmixer_write(chip, 0xc0, tmp|0x80);
568 /* always select DMA channel 0, since we do not actually use DMA */
569 snd_sbmixer_write(chip, SB_DSP4_DMASETUP, SB_DMASETUP_DMA0);
570 snd_sbmixer_write(chip, 0xc0, tmp&0x7f);
571 spin_unlock_irqrestore(&chip->mixer_lock, flags);
573 spin_lock_irqsave(&chip->reg_lock,flags);
574 /* magic number. Enables interrupts(?) */
575 snd_als4000_gcr_write(chip, 0x8c, 0x28000);
576 for(i = 0x91; i <= 0x96; ++i)
577 snd_als4000_gcr_write(chip, i, 0);
579 snd_als4000_gcr_write(chip, 0x99, snd_als4000_gcr_read(chip, 0x99));
580 spin_unlock_irqrestore(&chip->reg_lock,flags);
583 static void snd_card_als4000_free( snd_card_t *card )
585 snd_card_als4000_t * acard = (snd_card_als4000_t *)card->private_data;
586 /* make sure that interrupts are disabled */
587 snd_als4000_gcr_write_addr( acard->gcr, 0x8c, 0);
589 #ifdef SUPPORT_JOYSTICK
590 if (acard->res_joystick) {
591 if (acard->gameport.io)
592 gameport_unregister_port(&acard->gameport);
593 snd_als4000_set_addr(acard->gcr, 0, 0, 0, 0); /* disable joystick */
594 release_resource(acard->res_joystick);
595 kfree_nocheck(acard->res_joystick);
598 release_resource(acard->res_gcr);
599 kfree_nocheck(acard->res_gcr);
602 static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
603 const struct pci_device_id *pci_id)
607 snd_card_als4000_t *acard;
609 struct resource *res_gcr_port;
616 if (dev >= SNDRV_CARDS)
623 /* enable PCI device */
624 if ((err = pci_enable_device(pci)) < 0) {
627 /* check, if we can restrict PCI DMA transfers to 24 bits */
628 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 ||
629 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) {
630 snd_printk("architecture does not support 24bit PCI busmaster DMA\n");
634 gcr = pci_resource_start(pci, 0);
635 if ((res_gcr_port = request_region(gcr, 0x40, "ALS4000")) == NULL) {
636 snd_printk("unable to grab region 0x%lx-0x%lx\n", gcr, gcr + 0x40 - 1);
640 pci_read_config_word(pci, PCI_COMMAND, &word);
641 pci_write_config_word(pci, PCI_COMMAND, word | PCI_COMMAND_IO);
644 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
645 sizeof( snd_card_als4000_t ) );
647 release_resource(res_gcr_port);
648 kfree_nocheck(res_gcr_port);
652 acard = (snd_card_als4000_t *)card->private_data;
654 acard->res_gcr = res_gcr_port;
655 card->private_free = snd_card_als4000_free;
657 /* disable all legacy ISA stuff except for joystick */
658 #ifdef SUPPORT_JOYSTICK
659 if (joystick_port[dev] == 1) {
662 for (p = 0x200; p <= 0x218; p += 8) {
663 if ((acard->res_joystick = request_region(p, 8, "ALS4000 gameport")) != NULL) {
664 joystick_port[dev] = p;
668 } else if (joystick_port[dev] > 0)
669 acard->res_joystick = request_region(joystick_port[dev], 8, "ALS4000 gameport");
670 if (acard->res_joystick)
671 joystick = joystick_port[dev];
675 snd_als4000_set_addr(gcr, 0, 0, 0, joystick);
677 if ((err = snd_sbdsp_create(card,
680 snd_als4000_interrupt,
690 chip->alt_port = gcr;
691 snd_card_set_dev(card, &pci->dev);
693 snd_als4000_configure(chip);
695 strcpy(card->driver, "ALS4000");
696 strcpy(card->shortname, "Avance Logic ALS4000");
697 sprintf(card->longname, "%s at 0x%lx, irq %i",
698 card->shortname, chip->alt_port, chip->irq);
700 if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000,
701 gcr+0x30, 1, pci->irq, 0,
702 &chip->rmidi)) < 0) {
704 printk(KERN_ERR "als4000: no MPU-401device at 0x%lx ?\n", gcr+0x30);
708 if ((err = snd_als4000_pcm(chip, 0)) < 0) {
712 if ((err = snd_sbmixer_new(chip)) < 0) {
717 if (snd_opl3_create(card, gcr+0x10, gcr+0x12,
718 OPL3_HW_AUTO, 1, &opl3) < 0) {
719 printk(KERN_ERR "als4000: no OPL device at 0x%lx-0x%lx ?\n",
720 gcr+0x10, gcr+0x12 );
722 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
728 #ifdef SUPPORT_JOYSTICK
729 if (acard->res_joystick) {
730 acard->gameport.io = joystick;
731 gameport_register_port(&acard->gameport);
735 if ((err = snd_card_register(card)) < 0) {
739 pci_set_drvdata(pci, card);
744 static void __devexit snd_card_als4000_remove(struct pci_dev *pci)
746 snd_card_free(pci_get_drvdata(pci));
747 pci_set_drvdata(pci, NULL);
750 static struct pci_driver driver = {
752 .id_table = snd_als4000_ids,
753 .probe = snd_card_als4000_probe,
754 .remove = __devexit_p(snd_card_als4000_remove),
757 static int __init alsa_card_als4000_init(void)
759 return pci_module_init(&driver);
762 static void __exit alsa_card_als4000_exit(void)
764 pci_unregister_driver(&driver);
767 module_init(alsa_card_als4000_init)
768 module_exit(alsa_card_als4000_exit)