X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fpci%2Fazt3328.c;h=c3d65d90fce66652daad76a7af5576a69af6f991;hb=c7b5ebbddf7bcd3651947760f423e3783bbe6573;hp=2c4ee8159984ccd78ca4575efb58d26e96f0b19a;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c index 2c4ee8159..c3d65d90f 100644 --- a/sound/pci/azt3328.c +++ b/sound/pci/azt3328.c @@ -98,21 +98,20 @@ #include #include #include +#include #include #include #include #include #include #include -#define SNDRV_GET_ID #include #include "azt3328.h" MODULE_AUTHOR("Andreas Mohr "); 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 @@ -166,38 +165,29 @@ 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_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param_array(index, int, boot_devs, 0444); MODULE_PARM_DESC(index, "Index value for AZF3328 soundcard."); -MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC); -MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s"); +module_param_array(id, charp, boot_devs, 0444); MODULE_PARM_DESC(id, "ID string for AZF3328 soundcard."); -MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC); -MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param_array(enable, bool, boot_devs, 0444); MODULE_PARM_DESC(enable, "Enable AZF3328 soundcard."); -MODULE_PARM_SYNTAX(enable, SNDRV_INDEX_DESC); #ifdef SUPPORT_JOYSTICK -MODULE_PARM(joystick, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param_array(joystick, bool, boot_devs, 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; @@ -552,8 +542,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), @@ -649,7 +637,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; } @@ -812,7 +800,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; @@ -829,7 +816,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; @@ -837,12 +824,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); @@ -857,7 +844,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); @@ -869,7 +856,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); @@ -881,7 +868,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); @@ -905,7 +892,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; @@ -919,7 +905,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; @@ -927,12 +913,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); @@ -947,13 +933,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); @@ -965,7 +951,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; @@ -989,16 +975,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 ); @@ -1012,16 +995,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 ); @@ -1031,7 +1011,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; @@ -1231,7 +1211,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); } @@ -1267,6 +1247,10 @@ static int snd_azf3328_free(azf3328_t *chip) if (chip->irq < 0) goto __end_hw; + /* reset (close) mixer */ + snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1); /* first mute master volume */ + snd_azf3328_mixer_write(chip, IDX_MIXER_RESET, 0x0, WORD_VALUE); + /* interrupt setup - mask everything */ /* FIXME */ @@ -1282,36 +1266,17 @@ static int snd_azf3328_free(azf3328_t *chip) 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); - } if (chip->irq >= 0) free_irq(chip->irq, (void *)chip); + pci_release_regions(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); } @@ -1340,7 +1305,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 = { @@ -1353,7 +1317,7 @@ 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); + chip = kcalloc(1, sizeof(*chip), GFP_KERNEL); if (chip == NULL) return -ENOMEM; spin_lock_init(&chip->reg_lock); @@ -1368,36 +1332,16 @@ static int __devinit snd_azf3328_create(snd_card_t * card, 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); + 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); @@ -1430,13 +1374,13 @@ static int __devinit snd_azf3328_create(snd_card_t * card, #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); @@ -1540,7 +1484,7 @@ static int __devinit snd_azf3328_probe(struct pci_dev *pci, snd_azf3328_config_joystick(chip, joystick[dev]); #endif - pci_set_drvdata(pci, chip); + pci_set_drvdata(pci, card); dev++; snd_azf3328_dbgcallleave(); @@ -1549,16 +1493,8 @@ static int __devinit snd_azf3328_probe(struct pci_dev *pci, static void __devexit snd_azf3328_remove(struct pci_dev *pci) { - azf3328_t *chip = snd_magic_cast(azf3328_t, pci_get_drvdata(pci), return); - snd_azf3328_dbgcallenter(); - - /* reset (close) mixer */ - snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1); /* first mute master volume */ - snd_azf3328_mixer_write(chip, IDX_MIXER_RESET, 0x0, WORD_VALUE); - - if (chip) - snd_card_free(chip->card); + snd_card_free(pci_get_drvdata(pci)); pci_set_drvdata(pci, NULL); snd_azf3328_dbgcallleave(); } @@ -1573,18 +1509,10 @@ static struct pci_driver driver = { static int __init alsa_card_azf3328_init(void) { int err; - snd_azf3328_dbgcallenter(); - - if ((err = pci_module_init(&driver)) < 0) - { -#ifdef MODULE - printk(KERN_ERR "azt3328: no AZF3328 based soundcards found or device busy\n"); -#endif - return err; - } + err = pci_module_init(&driver); snd_azf3328_dbgcallleave(); - return 0; + return err; } static void __exit alsa_card_azf3328_exit(void) @@ -1596,31 +1524,3 @@ static void __exit alsa_card_azf3328_exit(void) module_init(alsa_card_azf3328_init) module_exit(alsa_card_azf3328_exit) - -#ifndef MODULE - -/* format is: snd-azf3328=enable,index,id,joystick */ - -static int __init alsa_card_azf3328_setup(char *str) -{ - static unsigned __initdata nr_dev = 0; - - snd_azf3328_dbgcallenter(); - - if (nr_dev >= SNDRV_CARDS) - return 0; - (void)(get_option(&str,&enable[nr_dev]) == 2 && - get_option(&str,&index[nr_dev]) == 2 && - get_id(&str,&id[nr_dev]) == 2 -#ifdef SUPPORT_JOYSTICK - && get_option(&str,&joystick[nr_dev]) == 2 -#endif - ); - nr_dev++; - snd_azf3328_dbgcallleave(); - return 1; -} - -__setup("snd-azt3328=", alsa_card_azf3328_setup); - -#endif /* ifndef MODULE */