vserver 2.0 rc7
[linux-2.6.git] / sound / pci / azt3328.c
index 9dc7de8..b8ae534 100644 (file)
 MODULE_AUTHOR("Andreas Mohr <hw7oshyuv3001@sneakemail.com>");
 MODULE_DESCRIPTION("Aztech AZF3328 (PCI168)");
 MODULE_LICENSE("GPL");
-MODULE_CLASSES("{sound}");
-MODULE_DEVICES("{{Aztech,AZF3328}}");
+MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
 
 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
 #define SUPPORT_JOYSTICK 1
@@ -161,48 +160,36 @@ MODULE_DEVICES("{{Aztech,AZF3328}}");
 #endif
            
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
-static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
-static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable this card */
-#ifdef SUPPORT_JOYSTICK
-static int joystick[SNDRV_CARDS];
-#endif
-static int boot_devs;
-
-module_param_array(index, int, boot_devs, 0444);
+module_param_array(index, int, NULL, 0444);
 MODULE_PARM_DESC(index, "Index value for AZF3328 soundcard.");
-MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
-module_param_array(id, charp, boot_devs, 0444);
+
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
+module_param_array(id, charp, NULL, 0444);
 MODULE_PARM_DESC(id, "ID string for AZF3328 soundcard.");
-MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
-module_param_array(enable, bool, boot_devs, 0444);
+
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable this card */
+module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "Enable AZF3328 soundcard.");
-MODULE_PARM_SYNTAX(enable, SNDRV_INDEX_DESC);
+
 #ifdef SUPPORT_JOYSTICK
-module_param_array(joystick, bool, boot_devs, 0444);
+static int joystick[SNDRV_CARDS];
+module_param_array(joystick, bool, NULL, 0444);
 MODULE_PARM_DESC(joystick, "Enable joystick for AZF3328 soundcard.");
-MODULE_PARM_SYNTAX(joystick, SNDRV_BOOLEAN_FALSE_DESC);
 #endif
 
 typedef struct _snd_azf3328 azf3328_t;
-#define chip_t azf3328_t
 
 struct _snd_azf3328 {
        int irq;
 
        unsigned long codec_port;
-       struct resource *res_codec_port;
        unsigned long io2_port;
-       struct resource *res_io2_port;
        unsigned long mpu_port;
-       struct resource *res_mpu_port;
        unsigned long synth_port;
-       struct resource *res_synth_port;
        unsigned long mixer_port;
-       struct resource *res_mixer_port;
 
 #ifdef SUPPORT_JOYSTICK
-       struct gameport gameport;
-       struct resource *res_joystick;
+       struct gameport *gameport;
 #endif
 
        struct pci_dev *pci;
@@ -226,17 +213,17 @@ static struct pci_device_id snd_azf3328_ids[] = {
 
 MODULE_DEVICE_TABLE(pci, snd_azf3328_ids);
 
-void snd_azf3328_io2_write(azf3328_t *chip, int reg, unsigned char value)
+static inline void snd_azf3328_io2_write(azf3328_t *chip, int reg, unsigned char value)
 {
        outb(value, chip->io2_port + reg);
 }
 
-unsigned char snd_azf3328_io2_read(azf3328_t *chip, int reg)
+static inline unsigned char snd_azf3328_io2_read(azf3328_t *chip, int reg)
 {
        return inb(chip->io2_port + reg);
 }
 
-void snd_azf3328_mixer_write(azf3328_t *chip, int reg, unsigned long value, int type)
+static void snd_azf3328_mixer_write(azf3328_t *chip, int reg, unsigned long value, int type)
 {
        switch(type) {
        case WORD_VALUE:
@@ -251,26 +238,7 @@ void snd_azf3328_mixer_write(azf3328_t *chip, int reg, unsigned long value, int
        }
 }
 
-unsigned long snd_azf3328_mixer_read(azf3328_t *chip, int reg, int type)
-{
-       unsigned long res = 0;
-
-       switch(type) {
-       case WORD_VALUE:
-               res = (unsigned long)inw(chip->mixer_port + reg);
-               break;
-       case DWORD_VALUE:
-               res = (unsigned long)inl(chip->mixer_port + reg);
-               break;
-       case BYTE_VALUE:
-               res = (unsigned long)inb(chip->mixer_port + reg);
-               break;
-       }
-
-       return res;
-}
-
-void snd_azf3328_mixer_set_mute(azf3328_t *chip, int reg, int do_mute)
+static void snd_azf3328_mixer_set_mute(azf3328_t *chip, int reg, int do_mute)
 {
        unsigned char oldval;
 
@@ -284,7 +252,7 @@ void snd_azf3328_mixer_set_mute(azf3328_t *chip, int reg, int do_mute)
        outb(oldval, chip->mixer_port + reg + 1);
 }
 
-void snd_azf3328_mixer_write_volume_gradually(azf3328_t *chip, int reg, unsigned char dst_vol_left, unsigned char dst_vol_right, int chan_sel, int delay)
+static void snd_azf3328_mixer_write_volume_gradually(azf3328_t *chip, int reg, unsigned char dst_vol_left, unsigned char dst_vol_right, int chan_sel, int delay)
 {
        unsigned char curr_vol_left = 0, curr_vol_right = 0;
        int left_done = 0, right_done = 0;
@@ -553,8 +521,6 @@ static int snd_azf3328_put_mixer_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_va
        return (nreg != oreg);
 }
 
-#define NUM_CONTROLS(ary) (sizeof(ary) / sizeof(snd_kcontrol_new_t))
-
 static snd_kcontrol_new_t snd_azf3328_mixer_controls[] __devinitdata = {
        AZF3328_MIXER_SWITCH("Master Playback Switch", IDX_MIXER_PLAY_MASTER, 15, 1),
        AZF3328_MIXER_VOL_STEREO("Master Playback Volume", IDX_MIXER_PLAY_MASTER, 0x1f, 1),
@@ -650,7 +616,7 @@ static int __devinit snd_azf3328_mixer_new(azf3328_t *chip)
        
        /* add mixer controls */
        sw = snd_azf3328_mixer_controls;
-       for (idx = 0; idx < NUM_CONTROLS(snd_azf3328_mixer_controls); idx++, sw++) {
+       for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_mixer_controls); idx++, sw++) {
                if ((err = snd_ctl_add(chip->card, snd_ctl_new1(sw, chip))) < 0)
                        return err;
        }
@@ -813,7 +779,6 @@ static int snd_azf3328_capture_prepare(snd_pcm_substream_t * substream)
 
 static int snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd)
 {
-       unsigned long flags;
        azf3328_t *chip = snd_pcm_substream_chip(substream);
        snd_pcm_runtime_t *runtime = substream->runtime;
        int result = 0;
@@ -830,7 +795,7 @@ static int snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd
 
                snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT, runtime->rate, snd_pcm_format_width(runtime->format), runtime->channels);
 
-               spin_lock_irqsave(&chip->reg_lock, flags);
+               spin_lock(&chip->reg_lock);
                /* stop playback */
                status1 = inw(chip->codec_port+IDX_IO_PLAY_FLAGS);
                status1 &= ~DMA_RESUME;
@@ -838,12 +803,12 @@ static int snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd
            
                /* FIXME: clear interrupts or what??? */
                outw(0xffff, chip->codec_port+IDX_IO_PLAY_IRQMASK);
-               spin_unlock_irqrestore(&chip->reg_lock, flags);
+               spin_unlock(&chip->reg_lock);
 
                snd_azf3328_setdmaa(chip, runtime->dma_addr, snd_pcm_lib_period_bytes(substream), snd_pcm_lib_buffer_bytes(substream), 0);
 
-               spin_lock_irqsave(&chip->reg_lock, flags);
-#if WIN9X
+               spin_lock(&chip->reg_lock);
+#ifdef WIN9X
                /* FIXME: enable playback/recording??? */
                status1 |= DMA_PLAY_SOMETHING1 | DMA_PLAY_SOMETHING2;
                outw(status1, chip->codec_port+IDX_IO_PLAY_FLAGS);
@@ -858,7 +823,7 @@ static int snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd
                outw(DMA_PLAY_SOMETHING1|DMA_PLAY_SOMETHING2, chip->codec_port+IDX_IO_PLAY_FLAGS);
                outw(DMA_RESUME|SOMETHING_ALMOST_ALWAYS_SET|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port+IDX_IO_PLAY_FLAGS);
 #endif
-               spin_unlock_irqrestore(&chip->reg_lock, flags);
+               spin_unlock(&chip->reg_lock);
 
                /* now unmute WaveOut */
                snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0);
@@ -870,7 +835,7 @@ static int snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd
                /* mute WaveOut */
                snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
 
-               spin_lock_irqsave(&chip->reg_lock, flags);
+               spin_lock(&chip->reg_lock);
                /* stop playback */
                status1 = inw(chip->codec_port+IDX_IO_PLAY_FLAGS);
 
@@ -882,7 +847,7 @@ static int snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd
 
                status1 &= ~DMA_PLAY_SOMETHING1;
                outw(status1, chip->codec_port+IDX_IO_PLAY_FLAGS);
-               spin_unlock_irqrestore(&chip->reg_lock, flags);
+               spin_unlock(&chip->reg_lock);
            
                /* now unmute WaveOut */
                snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0);
@@ -906,7 +871,6 @@ static int snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd
  * should actually be triggered like that */
 static int snd_azf3328_capture_trigger(snd_pcm_substream_t * substream, int cmd)
 {
-       unsigned long flags;
        azf3328_t *chip = snd_pcm_substream_chip(substream);
        snd_pcm_runtime_t *runtime = substream->runtime;
        int result = 0;
@@ -920,7 +884,7 @@ static int snd_azf3328_capture_trigger(snd_pcm_substream_t * substream, int cmd)
 
                snd_azf3328_setfmt(chip, IDX_IO_REC_SOUNDFORMAT, runtime->rate, snd_pcm_format_width(runtime->format), runtime->channels);
 
-               spin_lock_irqsave(&chip->reg_lock, flags);
+               spin_lock(&chip->reg_lock);
                /* stop recording */
                status1 = inw(chip->codec_port+IDX_IO_REC_FLAGS);
                status1 &= ~DMA_RESUME;
@@ -928,12 +892,12 @@ static int snd_azf3328_capture_trigger(snd_pcm_substream_t * substream, int cmd)
            
                /* FIXME: clear interrupts or what??? */
                outw(0xffff, chip->codec_port+IDX_IO_REC_IRQMASK);
-               spin_unlock_irqrestore(&chip->reg_lock, flags);
+               spin_unlock(&chip->reg_lock);
 
                snd_azf3328_setdmaa(chip, runtime->dma_addr, snd_pcm_lib_period_bytes(substream), snd_pcm_lib_buffer_bytes(substream), 1);
 
-               spin_lock_irqsave(&chip->reg_lock, flags);
-#if WIN9X
+               spin_lock(&chip->reg_lock);
+#ifdef WIN9X
                /* FIXME: enable playback/recording??? */
                status1 |= DMA_PLAY_SOMETHING1 | DMA_PLAY_SOMETHING2;
                outw(status1, chip->codec_port+IDX_IO_REC_FLAGS);
@@ -948,13 +912,13 @@ static int snd_azf3328_capture_trigger(snd_pcm_substream_t * substream, int cmd)
                outw(DMA_PLAY_SOMETHING1|DMA_PLAY_SOMETHING2, chip->codec_port+IDX_IO_REC_FLAGS);
                outw(DMA_RESUME|SOMETHING_ALMOST_ALWAYS_SET|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port+IDX_IO_REC_FLAGS);
 #endif
-               spin_unlock_irqrestore(&chip->reg_lock, flags);
+               spin_unlock(&chip->reg_lock);
 
                snd_azf3328_dbgio(chip, "trigger2");
                chip->is_playing = 1;
                break;
         case SNDRV_PCM_TRIGGER_STOP:
-               spin_lock_irqsave(&chip->reg_lock, flags);
+               spin_lock(&chip->reg_lock);
                /* stop recording */
                status1 = inw(chip->codec_port+IDX_IO_REC_FLAGS);
 
@@ -966,7 +930,7 @@ static int snd_azf3328_capture_trigger(snd_pcm_substream_t * substream, int cmd)
 
                status1 &= ~DMA_PLAY_SOMETHING1;
                outw(status1, chip->codec_port+IDX_IO_REC_FLAGS);
-               spin_unlock_irqrestore(&chip->reg_lock, flags);
+               spin_unlock(&chip->reg_lock);
            
                chip->is_playing = 0;
                break;
@@ -990,16 +954,13 @@ static snd_pcm_uframes_t snd_azf3328_playback_pointer(snd_pcm_substream_t * subs
        unsigned long bufptr, playptr;
        unsigned long result;
        snd_pcm_uframes_t frmres;
-       unsigned long flags;
 
-       spin_lock_irqsave(&chip->reg_lock, flags);
-#if QUERY_HARDWARE
+#ifdef QUERY_HARDWARE
        bufptr = inl(chip->codec_port+IDX_IO_PLAY_DMA_START_1);
 #else
        bufptr = substream->runtime->dma_addr;
 #endif
        playptr = inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS);
-       spin_unlock_irqrestore(&chip->reg_lock, flags);
 
        result = playptr - bufptr;
        frmres = bytes_to_frames( substream->runtime, result );
@@ -1013,16 +974,13 @@ static snd_pcm_uframes_t snd_azf3328_capture_pointer(snd_pcm_substream_t * subst
        unsigned long bufptr, recptr;
        unsigned long result;
        snd_pcm_uframes_t frmres;
-       unsigned long flags;
 
-       spin_lock_irqsave(&chip->reg_lock, flags);
-#if QUERY_HARDWARE
+#ifdef QUERY_HARDWARE
        bufptr = inl(chip->codec_port+IDX_IO_REC_DMA_START_1);
 #else
        bufptr = substream->runtime->dma_addr;
 #endif
        recptr = inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS);
-       spin_unlock_irqrestore(&chip->reg_lock, flags);
 
        result = recptr - bufptr;
        frmres = bytes_to_frames( substream->runtime, result );
@@ -1032,7 +990,7 @@ static snd_pcm_uframes_t snd_azf3328_capture_pointer(snd_pcm_substream_t * subst
 
 static irqreturn_t snd_azf3328_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
-       azf3328_t *chip = snd_magic_cast(azf3328_t, dev_id, return IRQ_NONE);
+       azf3328_t *chip = dev_id;
        unsigned int status, which;
        static unsigned long count;
 
@@ -1232,7 +1190,7 @@ static snd_pcm_ops_t snd_azf3328_capture_ops = {
 
 static void snd_azf3328_pcm_free(snd_pcm_t *pcm)
 {
-       azf3328_t *chip = snd_magic_cast(azf3328_t, pcm->private_data, return);
+       azf3328_t *chip = pcm->private_data;
        chip->pcm = NULL;
        snd_pcm_lib_preallocate_free_for_all(pcm);
 }
@@ -1263,6 +1221,63 @@ static int __devinit snd_azf3328_pcm(azf3328_t *chip, int device)
 
 /******************************************************************/
 
+#ifdef SUPPORT_JOYSTICK
+static int __devinit snd_azf3328_config_joystick(azf3328_t *chip, int dev)
+{
+       struct gameport *gp;
+       struct resource *r;
+
+       if (!joystick[dev])
+               return -ENODEV;
+
+       if (!(r = request_region(0x200, 8, "AZF3328 gameport"))) {
+               printk(KERN_WARNING "azt3328: cannot reserve joystick ports\n");
+               return -EBUSY;
+       }
+
+       chip->gameport = gp = gameport_allocate_port();
+       if (!gp) {
+               printk(KERN_ERR "azt3328: cannot allocate memory for gameport\n");
+               release_resource(r);
+               kfree_nocheck(r);
+               return -ENOMEM;
+       }
+
+       gameport_set_name(gp, "AZF3328 Gameport");
+       gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
+       gameport_set_dev_parent(gp, &chip->pci->dev);
+       gp->io = 0x200;
+       gameport_set_port_data(gp, r);
+
+       snd_azf3328_io2_write(chip, IDX_IO2_LEGACY_ADDR,
+                             snd_azf3328_io2_read(chip, IDX_IO2_LEGACY_ADDR) | LEGACY_JOY);
+
+       gameport_register_port(chip->gameport);
+
+       return 0;
+}
+
+static void snd_azf3328_free_joystick(azf3328_t *chip)
+{
+       if (chip->gameport) {
+               struct resource *r = gameport_get_port_data(chip->gameport);
+
+               gameport_unregister_port(chip->gameport);
+               chip->gameport = NULL;
+               /* disable gameport */
+               snd_azf3328_io2_write(chip, IDX_IO2_LEGACY_ADDR,
+                                     snd_azf3328_io2_read(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY);
+               release_resource(r);
+               kfree_nocheck(r);
+       }
+}
+#else
+static inline int snd_azf3328_config_joystick(azf3328_t *chip, int dev) { return -ENOSYS; }
+static inline void snd_azf3328_free_joystick(azf3328_t *chip) { }
+#endif
+
+/******************************************************************/
+
 static int snd_azf3328_free(azf3328_t *chip)
 {
         if (chip->irq < 0)
@@ -1277,46 +1292,19 @@ static int snd_azf3328_free(azf3328_t *chip)
 
         synchronize_irq(chip->irq);
       __end_hw:
-#ifdef SUPPORT_JOYSTICK
-       if (chip->res_joystick) {
-               gameport_unregister_port(&chip->gameport);
-               /* disable gameport */
-               snd_azf3328_io2_write(chip, IDX_IO2_LEGACY_ADDR,
-                                     snd_azf3328_io2_read(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY);
-               release_resource(chip->res_joystick);
-               kfree_nocheck(chip->res_joystick);
-       }
-#endif
-        if (chip->res_codec_port) {
-               release_resource(chip->res_codec_port);
-               kfree_nocheck(chip->res_codec_port);
-       }
-        if (chip->res_io2_port) {
-               release_resource(chip->res_io2_port);
-               kfree_nocheck(chip->res_io2_port);
-       }
-        if (chip->res_mpu_port) {
-               release_resource(chip->res_mpu_port);
-               kfree_nocheck(chip->res_mpu_port);
-       }
-        if (chip->res_synth_port) {
-               release_resource(chip->res_synth_port);
-               kfree_nocheck(chip->res_synth_port);
-       }
-        if (chip->res_mixer_port) {
-               release_resource(chip->res_mixer_port);
-               kfree_nocheck(chip->res_mixer_port);
-       }
+       snd_azf3328_free_joystick(chip);
         if (chip->irq >= 0)
                free_irq(chip->irq, (void *)chip);
+       pci_release_regions(chip->pci);
+       pci_disable_device(chip->pci);
 
-        snd_magic_kfree(chip);
+        kfree(chip);
         return 0;
 }
 
 static int snd_azf3328_dev_free(snd_device_t *device)
 {
-       azf3328_t *chip = snd_magic_cast(azf3328_t, device->device_data, return -ENXIO);
+       azf3328_t *chip = device->device_data;
        return snd_azf3328_free(chip);
 }
 
@@ -1345,7 +1333,6 @@ static int __devinit snd_azf3328_create(snd_card_t * card,
                                          unsigned long device_type,
                                          azf3328_t ** rchip)
 {
-       unsigned long flags;
        azf3328_t *chip;
        int err;
        static snd_device_ops_t ops = {
@@ -1358,9 +1345,11 @@ static int __devinit snd_azf3328_create(snd_card_t * card,
        if ((err = pci_enable_device(pci)) < 0)
                return err;
 
-       chip = snd_magic_kcalloc(azf3328_t, 0, GFP_KERNEL);
-       if (chip == NULL)
+       chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
+       if (chip == NULL) {
+               pci_disable_device(pci);
                return -ENOMEM;
+       }
        spin_lock_init(&chip->reg_lock);
        chip->card = card;
        chip->pci = pci;
@@ -1370,39 +1359,21 @@ static int __devinit snd_azf3328_create(snd_card_t * card,
        if (pci_set_dma_mask(pci, 0x00ffffff) < 0 ||
            pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) {
                snd_printk("architecture does not support 24bit PCI busmaster DMA\n");
+               pci_disable_device(pci);
                return -ENXIO;
        }
 
-       chip->codec_port = pci_resource_start(pci, 0);
-       if ((chip->res_codec_port = request_region(chip->codec_port, 0x80, "Aztech AZF3328 I/O")) == NULL) {
-               snd_printk("unable to grab I/O port at 0x%lx-0x%lx\n", chip->codec_port, chip->codec_port + 0x80 - 1);
-               snd_azf3328_free(chip);
-               return -EBUSY;
+       if ((err = pci_request_regions(pci, "Aztech AZF3328")) < 0) {
+               kfree(chip);
+               pci_disable_device(pci);
+               return err;
        }
+
+       chip->codec_port = pci_resource_start(pci, 0);
        chip->io2_port = pci_resource_start(pci, 1);
-       if ((chip->res_io2_port = request_region(chip->io2_port, 0x08, "Aztech AZF3328 I/O 2")) == NULL) {
-               snd_printk("unable to grab I/O 2 port at 0x%lx-0x%lx\n", chip->io2_port, chip->io2_port + 0x08 - 1);
-               snd_azf3328_free(chip);
-               return -EBUSY;
-       }
        chip->mpu_port = pci_resource_start(pci, 2);
-       if ((chip->res_mpu_port = request_region(chip->mpu_port, 0x04, "Aztech AZF3328 MPU401")) == NULL) {
-               snd_printk("unable to grab MPU401 port at 0x%lx-0x%lx\n", chip->mpu_port, chip->mpu_port + 0x04 - 1);
-               snd_azf3328_free(chip);
-               return -EBUSY;
-       }
        chip->synth_port = pci_resource_start(pci, 3);
-       if ((chip->res_synth_port = request_region(chip->synth_port, 0x08, "Aztech AZF3328 OPL3")) == NULL) {
-               snd_printk("unable to grab OPL3 port at 0x%lx-0x%lx\n", chip->synth_port, chip->synth_port + 0x08 - 1);
-               snd_azf3328_free(chip);
-               return -EBUSY;
-       }
        chip->mixer_port = pci_resource_start(pci, 4);
-       if ((chip->res_mixer_port = request_region(chip->mixer_port, 0x40, "Aztech AZF3328 Mixer")) == NULL) {
-                snd_printk("unable to grab mixer port at 0x%lx-0x%lx\n", chip->mixer_port, chip->mixer_port + 0x40 - 1);
-               snd_azf3328_free(chip);
-               return -EBUSY;
-       }
 
        if (request_irq(pci->irq, snd_azf3328_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) {
                snd_printk("unable to grab IRQ %d\n", pci->irq);
@@ -1420,28 +1391,28 @@ static int __devinit snd_azf3328_create(snd_card_t * card,
        for (tmp=0; tmp <= 0x01; tmp += 1)
                snd_azf3328_dbgmisc("0x%02x: opl 0x%04x, mpu300 0x%04x, mpu310 0x%04x, mpu320 0x%04x, mpu330 0x%04x\n", tmp, inb(0x388 + tmp), inb(0x300 + tmp), inb(0x310 + tmp), inb(0x320 + tmp), inb(0x330 + tmp));
 
-       /* create mixer interface & switches */
-       if ((err = snd_azf3328_mixer_new(chip)) < 0)
-               return err;
-
        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
                snd_azf3328_free(chip);
                return err;
        }
 
+       /* create mixer interface & switches */
+       if ((err = snd_azf3328_mixer_new(chip)) < 0)
+               return err;
+
 #if 0
        /* set very low bitrate to reduce noise and power consumption? */
        snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT, 5512, 8, 1);
 #endif
 
        /* standard chip init stuff */
-       spin_lock_irqsave(&chip->reg_lock, flags);
+       spin_lock_irq(&chip->reg_lock);
        outb(DMA_PLAY_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port + IDX_IO_PLAY_FLAGS);
        outb(DMA_PLAY_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port + IDX_IO_SOMETHING_FLAGS);
        outb(DMA_PLAY_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port + IDX_IO_REC_FLAGS);
        outb(0x0, chip->codec_port + IDX_IO_IRQ63H);
 
-       spin_unlock_irqrestore(&chip->reg_lock, flags);
+       spin_unlock_irq(&chip->reg_lock);
 
        snd_card_set_dev(card, &pci->dev);
 
@@ -1449,28 +1420,6 @@ static int __devinit snd_azf3328_create(snd_card_t * card,
        return 0;
 }
 
-#ifdef SUPPORT_JOYSTICK
-static void __devinit snd_azf3328_config_joystick(azf3328_t *chip, int joystick)
-{
-       unsigned char val;
-
-       if (joystick == 1) {
-               if ((chip->res_joystick = request_region(0x200, 8, "AZF3328 gameport")) != NULL)
-                       chip->gameport.io = 0x200;
-       }
-
-       val = inb(chip->io2_port + IDX_IO2_LEGACY_ADDR);
-       if (chip->res_joystick)
-               val |= LEGACY_JOY;
-       else
-               val &= ~LEGACY_JOY;
-
-       outb(val, chip->io2_port + IDX_IO2_LEGACY_ADDR);
-       if (chip->res_joystick)
-               gameport_register_port(&chip->gameport);
-}
-#endif
-
 static int __devinit snd_azf3328_probe(struct pci_dev *pci,
                                          const struct pci_device_id *pci_id)
 {
@@ -1541,9 +1490,9 @@ static int __devinit snd_azf3328_probe(struct pci_dev *pci,
 "azt3328: Feel free to contact hw7oshyuv3001@sneakemail.com for bug reports etc.!\n");
 #endif
 
-#ifdef SUPPORT_JOYSTICK
-       snd_azf3328_config_joystick(chip, joystick[dev]);
-#endif
+       if (snd_azf3328_config_joystick(chip, dev) < 0)
+               snd_azf3328_io2_write(chip, IDX_IO2_LEGACY_ADDR,
+                             snd_azf3328_io2_read(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY);
 
        pci_set_drvdata(pci, card);
        dev++;