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 <sound/core.h>
68 #include <sound/pcm.h>
69 #include <sound/rawmidi.h>
70 #include <sound/mpu401.h>
71 #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];
93 MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
94 MODULE_PARM_DESC(index, "Index value for ALS4000 soundcard.");
95 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
96 MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
97 MODULE_PARM_DESC(id, "ID string for ALS4000 soundcard.");
98 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
99 MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
100 MODULE_PARM_DESC(enable, "Enable ALS4000 soundcard.");
101 MODULE_PARM_SYNTAX(enable, SNDRV_INDEX_DESC);
102 #ifdef SUPPORT_JOYSTICK
103 MODULE_PARM(joystick_port, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
104 MODULE_PARM_DESC(joystick_port, "Joystick port address for ALS4000 soundcard. (0 = disabled)");
105 MODULE_PARM_SYNTAX(joystick_port, SNDRV_ENABLED);
112 struct resource *res_gcr;
113 #ifdef SUPPORT_JOYSTICK
114 struct gameport gameport;
115 struct resource *res_joystick;
117 } snd_card_als4000_t;
119 static struct pci_device_id snd_als4000_ids[] = {
120 { 0x4005, 0x4000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ALS4000 */
124 MODULE_DEVICE_TABLE(pci, snd_als4000_ids);
126 static inline void snd_als4000_gcr_write_addr(unsigned long port, u32 reg, u32 val)
128 outb(reg, port+0x0c);
129 outl(val, port+0x08);
132 static inline void snd_als4000_gcr_write(sb_t *sb, u32 reg, u32 val)
134 snd_als4000_gcr_write_addr(sb->alt_port, reg, val);
137 static inline u32 snd_als4000_gcr_read_addr(unsigned long port, u32 reg)
139 outb(reg, port+0x0c);
140 return inl(port+0x08);
143 static inline u32 snd_als4000_gcr_read(sb_t *sb, u32 reg)
145 return snd_als4000_gcr_read_addr(sb->alt_port, reg);
148 static void snd_als4000_set_rate(sb_t *chip, unsigned int rate)
150 if (!(chip->mode & SB_RATE_LOCK)) {
151 snd_sbdsp_command(chip, SB_DSP_SAMPLE_RATE_OUT);
152 snd_sbdsp_command(chip, rate>>8);
153 snd_sbdsp_command(chip, rate);
157 static void snd_als4000_set_capture_dma(sb_t *chip, dma_addr_t addr, unsigned size)
159 snd_als4000_gcr_write(chip, 0xa2, addr);
160 snd_als4000_gcr_write(chip, 0xa3, (size-1));
163 static void snd_als4000_set_playback_dma(sb_t *chip, dma_addr_t addr, unsigned size)
165 snd_als4000_gcr_write(chip, 0x91, addr);
166 snd_als4000_gcr_write(chip, 0x92, (size-1)|0x180000);
169 #define ALS4000_FORMAT_SIGNED (1<<0)
170 #define ALS4000_FORMAT_16BIT (1<<1)
171 #define ALS4000_FORMAT_STEREO (1<<2)
173 static int snd_als4000_get_format(snd_pcm_runtime_t *runtime)
178 if (snd_pcm_format_signed(runtime->format))
179 result |= ALS4000_FORMAT_SIGNED;
180 if (snd_pcm_format_physical_width(runtime->format) == 16)
181 result |= ALS4000_FORMAT_16BIT;
182 if (runtime->channels > 1)
183 result |= ALS4000_FORMAT_STEREO;
187 /* structure for setting up playback */
189 unsigned char dsp_cmd, dma_on, dma_off, format;
190 } playback_cmd_vals[]={
191 /* ALS4000_FORMAT_U8_MONO */
192 { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_UNS_MONO },
193 /* ALS4000_FORMAT_S8_MONO */
194 { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_SIGN_MONO },
195 /* ALS4000_FORMAT_U16L_MONO */
196 { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_UNS_MONO },
197 /* ALS4000_FORMAT_S16L_MONO */
198 { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_SIGN_MONO },
199 /* ALS4000_FORMAT_U8_STEREO */
200 { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_UNS_STEREO },
201 /* ALS4000_FORMAT_S8_STEREO */
202 { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_SIGN_STEREO },
203 /* ALS4000_FORMAT_U16L_STEREO */
204 { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_UNS_STEREO },
205 /* ALS4000_FORMAT_S16L_STEREO */
206 { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_SIGN_STEREO },
208 #define playback_cmd(chip) (playback_cmd_vals[(chip)->playback_format])
210 /* structure for setting up capture */
211 enum { CMD_WIDTH8=0x04, CMD_SIGNED=0x10, CMD_MONO=0x80, CMD_STEREO=0xA0 };
212 static unsigned char capture_cmd_vals[]=
214 CMD_WIDTH8|CMD_MONO, /* ALS4000_FORMAT_U8_MONO */
215 CMD_WIDTH8|CMD_SIGNED|CMD_MONO, /* ALS4000_FORMAT_S8_MONO */
216 CMD_MONO, /* ALS4000_FORMAT_U16L_MONO */
217 CMD_SIGNED|CMD_MONO, /* ALS4000_FORMAT_S16L_MONO */
218 CMD_WIDTH8|CMD_STEREO, /* ALS4000_FORMAT_U8_STEREO */
219 CMD_WIDTH8|CMD_SIGNED|CMD_STEREO, /* ALS4000_FORMAT_S8_STEREO */
220 CMD_STEREO, /* ALS4000_FORMAT_U16L_STEREO */
221 CMD_SIGNED|CMD_STEREO, /* ALS4000_FORMAT_S16L_STEREO */
223 #define capture_cmd(chip) (capture_cmd_vals[(chip)->capture_format])
225 static int snd_als4000_hw_params(snd_pcm_substream_t * substream,
226 snd_pcm_hw_params_t * hw_params)
228 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
231 static int snd_als4000_hw_free(snd_pcm_substream_t * substream)
233 snd_pcm_lib_free_pages(substream);
237 static int snd_als4000_capture_prepare(snd_pcm_substream_t * substream)
240 sb_t *chip = snd_pcm_substream_chip(substream);
241 snd_pcm_runtime_t *runtime = substream->runtime;
245 chip->capture_format = snd_als4000_get_format(runtime);
247 size = snd_pcm_lib_buffer_bytes(substream);
248 count = snd_pcm_lib_period_bytes(substream);
250 if (chip->capture_format & ALS4000_FORMAT_16BIT)
254 spin_lock_irqsave(&chip->reg_lock, flags);
255 snd_als4000_set_rate(chip, runtime->rate);
256 snd_als4000_set_capture_dma(chip, runtime->dma_addr, size);
257 spin_unlock_irqrestore(&chip->reg_lock, flags);
258 spin_lock_irqsave(&chip->mixer_lock, flags );
259 snd_sbmixer_write(chip, 0xdc, count);
260 snd_sbmixer_write(chip, 0xdd, count>>8);
261 spin_unlock_irqrestore(&chip->mixer_lock, flags );
265 static int snd_als4000_playback_prepare(snd_pcm_substream_t *substream)
268 sb_t *chip = snd_pcm_substream_chip(substream);
269 snd_pcm_runtime_t *runtime = substream->runtime;
273 chip->playback_format = snd_als4000_get_format(runtime);
275 size = snd_pcm_lib_buffer_bytes(substream);
276 count = snd_pcm_lib_period_bytes(substream);
278 if (chip->playback_format & ALS4000_FORMAT_16BIT)
282 /* FIXME: from second playback on, there's a lot more clicks and pops
283 * involved here than on first playback. Fiddling with
284 * tons of different settings didn't help (DMA, speaker on/off,
285 * reordering, ...). Something seems to get enabled on playback
286 * that I haven't found out how to disable again, which then causes
287 * the switching pops to reach the speakers the next time here. */
288 spin_lock_irqsave(&chip->reg_lock, flags);
289 snd_als4000_set_rate(chip, runtime->rate);
290 snd_als4000_set_playback_dma(chip, runtime->dma_addr, size);
292 /* SPEAKER_ON not needed, since dma_on seems to also enable speaker */
293 /* snd_sbdsp_command(chip, SB_DSP_SPEAKER_ON); */
294 snd_sbdsp_command(chip, playback_cmd(chip).dsp_cmd);
295 snd_sbdsp_command(chip, playback_cmd(chip).format);
296 snd_sbdsp_command(chip, count);
297 snd_sbdsp_command(chip, count>>8);
298 snd_sbdsp_command(chip, playback_cmd(chip).dma_off);
299 spin_unlock_irqrestore(&chip->reg_lock, flags);
304 static int snd_als4000_capture_trigger(snd_pcm_substream_t * substream, int cmd)
307 sb_t *chip = snd_pcm_substream_chip(substream);
310 spin_lock_irqsave(&chip->mixer_lock, flags);
311 if (cmd == SNDRV_PCM_TRIGGER_START) {
312 chip->mode |= SB_RATE_LOCK_CAPTURE;
313 snd_sbmixer_write(chip, 0xde, capture_cmd(chip));
314 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
315 chip->mode &= ~SB_RATE_LOCK_CAPTURE;
316 snd_sbmixer_write(chip, 0xde, 0);
320 spin_unlock_irqrestore(&chip->mixer_lock, flags);
324 static int snd_als4000_playback_trigger(snd_pcm_substream_t * substream, int cmd)
327 sb_t *chip = snd_pcm_substream_chip(substream);
330 spin_lock_irqsave(&chip->reg_lock, flags);
331 if (cmd == SNDRV_PCM_TRIGGER_START) {
332 chip->mode |= SB_RATE_LOCK_PLAYBACK;
333 snd_sbdsp_command(chip, playback_cmd(chip).dma_on);
334 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
335 snd_sbdsp_command(chip, playback_cmd(chip).dma_off);
336 chip->mode &= ~SB_RATE_LOCK_PLAYBACK;
340 spin_unlock_irqrestore(&chip->reg_lock, flags);
344 static snd_pcm_uframes_t snd_als4000_capture_pointer(snd_pcm_substream_t * substream)
347 sb_t *chip = snd_pcm_substream_chip(substream);
350 spin_lock_irqsave(&chip->reg_lock, flags);
351 result = snd_als4000_gcr_read(chip, 0xa4) & 0xffff;
352 spin_unlock_irqrestore(&chip->reg_lock, flags);
353 return bytes_to_frames( substream->runtime, result );
356 static snd_pcm_uframes_t snd_als4000_playback_pointer(snd_pcm_substream_t * substream)
359 sb_t *chip = snd_pcm_substream_chip(substream);
362 spin_lock_irqsave(&chip->reg_lock, flags);
363 result = snd_als4000_gcr_read(chip, 0xa0) & 0xffff;
364 spin_unlock_irqrestore(&chip->reg_lock, flags);
365 return bytes_to_frames( substream->runtime, result );
368 static irqreturn_t snd_als4000_interrupt(int irq, void *dev_id, struct pt_regs *regs)
370 sb_t *chip = snd_magic_cast(sb_t, dev_id, return IRQ_NONE);
375 /* find out which bit of the ALS4000 produced the interrupt */
376 gcr_status = inb(chip->alt_port + 0xe);
378 if ((gcr_status & 0x80) && (chip->playback_substream)) /* playback */
379 snd_pcm_period_elapsed(chip->playback_substream);
380 if ((gcr_status & 0x40) && (chip->capture_substream)) /* capturing */
381 snd_pcm_period_elapsed(chip->capture_substream);
382 if ((gcr_status & 0x10) && (chip->rmidi)) /* MPU401 interrupt */
383 snd_mpu401_uart_interrupt(irq, chip->rmidi, regs);
384 /* release the gcr */
385 outb(gcr_status, chip->alt_port + 0xe);
387 spin_lock_irqsave(&chip->mixer_lock, flags);
388 sb_status = snd_sbmixer_read(chip, SB_DSP4_IRQSTATUS);
389 spin_unlock_irqrestore(&chip->mixer_lock, flags);
391 if (sb_status & SB_IRQTYPE_8BIT)
392 snd_sb_ack_8bit(chip);
393 if (sb_status & SB_IRQTYPE_16BIT)
394 snd_sb_ack_16bit(chip);
395 if (sb_status & SB_IRQTYPE_MPUIN)
397 if (sb_status & 0x20)
398 inb(SBP(chip, RESET));
402 /*****************************************************************/
404 static snd_pcm_hardware_t snd_als4000_playback =
406 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
407 SNDRV_PCM_INFO_MMAP_VALID),
408 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 |
409 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE, /* formats */
410 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
415 .buffer_bytes_max = 65536,
416 .period_bytes_min = 64,
417 .period_bytes_max = 65536,
423 static snd_pcm_hardware_t snd_als4000_capture =
425 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
426 SNDRV_PCM_INFO_MMAP_VALID),
427 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 |
428 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE, /* formats */
429 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
434 .buffer_bytes_max = 65536,
435 .period_bytes_min = 64,
436 .period_bytes_max = 65536,
442 /*****************************************************************/
444 static int snd_als4000_playback_open(snd_pcm_substream_t * substream)
446 sb_t *chip = snd_pcm_substream_chip(substream);
447 snd_pcm_runtime_t *runtime = substream->runtime;
449 chip->playback_substream = substream;
450 runtime->hw = snd_als4000_playback;
454 static int snd_als4000_playback_close(snd_pcm_substream_t * substream)
456 sb_t *chip = snd_pcm_substream_chip(substream);
458 chip->playback_substream = NULL;
459 snd_pcm_lib_free_pages(substream);
463 static int snd_als4000_capture_open(snd_pcm_substream_t * substream)
465 sb_t *chip = snd_pcm_substream_chip(substream);
466 snd_pcm_runtime_t *runtime = substream->runtime;
468 chip->capture_substream = substream;
469 runtime->hw = snd_als4000_capture;
473 static int snd_als4000_capture_close(snd_pcm_substream_t * substream)
475 sb_t *chip = snd_pcm_substream_chip(substream);
477 chip->capture_substream = NULL;
478 snd_pcm_lib_free_pages(substream);
482 /******************************************************************/
484 static snd_pcm_ops_t snd_als4000_playback_ops = {
485 .open = snd_als4000_playback_open,
486 .close = snd_als4000_playback_close,
487 .ioctl = snd_pcm_lib_ioctl,
488 .hw_params = snd_als4000_hw_params,
489 .hw_free = snd_als4000_hw_free,
490 .prepare = snd_als4000_playback_prepare,
491 .trigger = snd_als4000_playback_trigger,
492 .pointer = snd_als4000_playback_pointer
495 static snd_pcm_ops_t snd_als4000_capture_ops = {
496 .open = snd_als4000_capture_open,
497 .close = snd_als4000_capture_close,
498 .ioctl = snd_pcm_lib_ioctl,
499 .hw_params = snd_als4000_hw_params,
500 .hw_free = snd_als4000_hw_free,
501 .prepare = snd_als4000_capture_prepare,
502 .trigger = snd_als4000_capture_trigger,
503 .pointer = snd_als4000_capture_pointer
506 static void snd_als4000_pcm_free(snd_pcm_t *pcm)
508 sb_t *chip = snd_magic_cast(sb_t, pcm->private_data, return);
510 snd_pcm_lib_preallocate_free_for_all(pcm);
513 static int __devinit snd_als4000_pcm(sb_t *chip, int device)
518 if ((err = snd_pcm_new(chip->card, "ALS4000 DSP", device, 1, 1, &pcm)) < 0)
520 pcm->private_free = snd_als4000_pcm_free;
521 pcm->private_data = chip;
522 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
523 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_als4000_playback_ops);
524 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_als4000_capture_ops);
526 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
534 /******************************************************************/
536 static void snd_als4000_set_addr(unsigned long gcr,
546 confB |= (mpu | 1) << 16;
550 confA |= (game | 1) << 16;
553 snd_als4000_gcr_write_addr(gcr, 0xa8, confA);
554 snd_als4000_gcr_write_addr(gcr, 0xa9, confB);
557 static void __devinit snd_als4000_configure(sb_t *chip)
563 /* do some more configuration */
564 spin_lock_irqsave(&chip->mixer_lock, flags);
565 tmp = snd_sbmixer_read(chip, 0xc0);
566 snd_sbmixer_write(chip, 0xc0, tmp|0x80);
567 /* always select DMA channel 0, since we do not actually use DMA */
568 snd_sbmixer_write(chip, SB_DSP4_DMASETUP, SB_DMASETUP_DMA0);
569 snd_sbmixer_write(chip, 0xc0, tmp&0x7f);
570 spin_unlock_irqrestore(&chip->mixer_lock, flags);
572 spin_lock_irqsave(&chip->reg_lock,flags);
573 /* magic number. Enables interrupts(?) */
574 snd_als4000_gcr_write(chip, 0x8c, 0x28000);
575 for(i = 0x91; i <= 0x96; ++i)
576 snd_als4000_gcr_write(chip, i, 0);
578 snd_als4000_gcr_write(chip, 0x99, snd_als4000_gcr_read(chip, 0x99));
579 spin_unlock_irqrestore(&chip->reg_lock,flags);
582 static void snd_card_als4000_free( snd_card_t *card )
584 snd_card_als4000_t * acard = (snd_card_als4000_t *)card->private_data;
585 /* make sure that interrupts are disabled */
586 snd_als4000_gcr_write_addr( acard->gcr, 0x8c, 0);
588 #ifdef SUPPORT_JOYSTICK
589 if (acard->res_joystick) {
590 if (acard->gameport.io)
591 gameport_unregister_port(&acard->gameport);
592 snd_als4000_set_addr(acard->gcr, 0, 0, 0, 0); /* disable joystick */
593 release_resource(acard->res_joystick);
594 kfree_nocheck(acard->res_joystick);
597 release_resource(acard->res_gcr);
598 kfree_nocheck(acard->res_gcr);
601 static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
602 const struct pci_device_id *pci_id)
606 snd_card_als4000_t *acard;
608 struct resource *res_gcr_port;
615 if (dev >= SNDRV_CARDS)
622 /* enable PCI device */
623 if ((err = pci_enable_device(pci)) < 0) {
626 /* check, if we can restrict PCI DMA transfers to 24 bits */
627 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 ||
628 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) {
629 snd_printk("architecture does not support 24bit PCI busmaster DMA\n");
633 gcr = pci_resource_start(pci, 0);
634 if ((res_gcr_port = request_region(gcr, 0x40, "ALS4000")) == NULL) {
635 snd_printk("unable to grab region 0x%lx-0x%lx\n", gcr, gcr + 0x40 - 1);
639 pci_read_config_word(pci, PCI_COMMAND, &word);
640 pci_write_config_word(pci, PCI_COMMAND, word | PCI_COMMAND_IO);
643 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
644 sizeof( snd_card_als4000_t ) );
646 release_resource(res_gcr_port);
647 kfree_nocheck(res_gcr_port);
651 acard = (snd_card_als4000_t *)card->private_data;
653 acard->res_gcr = res_gcr_port;
654 card->private_free = snd_card_als4000_free;
656 /* disable all legacy ISA stuff except for joystick */
657 #ifdef SUPPORT_JOYSTICK
658 if (joystick_port[dev] == 1) {
661 for (p = 0x200; p <= 0x218; p += 8) {
662 if ((acard->res_joystick = request_region(p, 8, "ALS4000 gameport")) != NULL) {
663 joystick_port[dev] = p;
667 } else if (joystick_port[dev] > 0)
668 acard->res_joystick = request_region(joystick_port[dev], 8, "ALS4000 gameport");
669 if (acard->res_joystick)
670 joystick = joystick_port[dev];
674 snd_als4000_set_addr(gcr, 0, 0, 0, joystick);
676 if ((err = snd_sbdsp_create(card,
679 snd_als4000_interrupt,
689 chip->alt_port = gcr;
690 snd_card_set_dev(card, &pci->dev);
692 snd_als4000_configure(chip);
694 strcpy(card->driver, "ALS4000");
695 strcpy(card->shortname, "Avance Logic ALS4000");
696 sprintf(card->longname, "%s at 0x%lx, irq %i",
697 card->shortname, chip->alt_port, chip->irq);
699 if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000,
700 gcr+0x30, 1, pci->irq, 0,
701 &chip->rmidi)) < 0) {
703 printk(KERN_ERR "als4000: no MPU-401device at 0x%lx ?\n", gcr+0x30);
707 if ((err = snd_als4000_pcm(chip, 0)) < 0) {
711 if ((err = snd_sbmixer_new(chip)) < 0) {
716 if (snd_opl3_create(card, gcr+0x10, gcr+0x12,
717 OPL3_HW_AUTO, 1, &opl3) < 0) {
718 printk(KERN_ERR "als4000: no OPL device at 0x%lx-0x%lx ?\n",
719 gcr+0x10, gcr+0x12 );
721 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
727 #ifdef SUPPORT_JOYSTICK
728 if (acard->res_joystick) {
729 acard->gameport.io = joystick;
730 gameport_register_port(&acard->gameport);
734 if ((err = snd_card_register(card)) < 0) {
738 pci_set_drvdata(pci, card);
743 static void __devexit snd_card_als4000_remove(struct pci_dev *pci)
745 snd_card_free(pci_get_drvdata(pci));
746 pci_set_drvdata(pci, NULL);
749 static struct pci_driver driver = {
751 .id_table = snd_als4000_ids,
752 .probe = snd_card_als4000_probe,
753 .remove = __devexit_p(snd_card_als4000_remove),
756 static int __init alsa_card_als4000_init(void)
760 if ((err = pci_module_init(&driver)) < 0) {
762 printk(KERN_ERR "no ALS4000 based soundcards found or device busy\n");
769 static void __exit alsa_card_als4000_exit(void)
771 pci_unregister_driver(&driver);
774 module_init(alsa_card_als4000_init)
775 module_exit(alsa_card_als4000_exit)
779 /* format is: snd-als4000=enable,index,id,joystick_port */
781 static int __init alsa_card_als4000_setup(char *str)
783 static unsigned __initdata nr_dev = 0;
785 if (nr_dev >= SNDRV_CARDS)
787 (void)(get_option(&str,&enable[nr_dev]) == 2 &&
788 get_option(&str,&index[nr_dev]) == 2 &&
789 get_id(&str,&id[nr_dev]) == 2
790 #ifdef SUPPORT_JOYSTICK
791 && get_option(&str,&joystick_port[nr_dev]) == 2
798 __setup("snd-als4000=", alsa_card_als4000_setup);
800 #endif /* ifndef MODULE */