diff options
Diffstat (limited to 'sound/pci/als4000.c')
| -rw-r--r-- | sound/pci/als4000.c | 244 |
1 files changed, 92 insertions, 152 deletions
diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c index 7844a75d8ed9..33034e07b3d6 100644 --- a/sound/pci/als4000.c +++ b/sound/pci/als4000.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * card-als4000.c - driver for Avance Logic ALS4000 based soundcards. * Copyright (C) 2000 by Bart Hartgers <bart@etpmod.phys.tue.nl>, @@ -6,21 +7,6 @@ * * Framework borrowed from Massimo Piccioni's card-als100.c. * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * * NOTES * * Since Avance does not provide any meaningful documentation, and I @@ -82,7 +68,6 @@ MODULE_AUTHOR("Bart Hartgers <bart@etpmod.phys.tue.nl>, Andreas Mohr"); MODULE_DESCRIPTION("Avance Logic ALS4000"); MODULE_LICENSE("GPL"); -MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS4000}}"); #if IS_REACHABLE(CONFIG_GAMEPORT) #define SUPPORT_JOYSTICK 1 @@ -368,18 +353,6 @@ CMD_SIGNED|CMD_STEREO, /* ALS4000_FORMAT_S16L_STEREO */ }; #define capture_cmd(chip) (capture_cmd_vals[(chip)->capture_format]) -static int snd_als4000_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *hw_params) -{ - return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); -} - -static int snd_als4000_hw_free(struct snd_pcm_substream *substream) -{ - snd_pcm_lib_free_pages(substream); - return 0; -} - static int snd_als4000_capture_prepare(struct snd_pcm_substream *substream) { struct snd_sb *chip = snd_pcm_substream_chip(substream); @@ -396,14 +369,14 @@ static int snd_als4000_capture_prepare(struct snd_pcm_substream *substream) count >>= 1; count--; - spin_lock_irq(&chip->reg_lock); - snd_als4000_set_rate(chip, runtime->rate); - snd_als4000_set_capture_dma(chip, runtime->dma_addr, size); - spin_unlock_irq(&chip->reg_lock); - spin_lock_irq(&chip->mixer_lock); - snd_als4_cr_write(chip, ALS4K_CR1C_FIFO2_BLOCK_LENGTH_LO, count & 0xff); - snd_als4_cr_write(chip, ALS4K_CR1D_FIFO2_BLOCK_LENGTH_HI, count >> 8); - spin_unlock_irq(&chip->mixer_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { + snd_als4000_set_rate(chip, runtime->rate); + snd_als4000_set_capture_dma(chip, runtime->dma_addr, size); + } + scoped_guard(spinlock_irq, &chip->mixer_lock) { + snd_als4_cr_write(chip, ALS4K_CR1C_FIFO2_BLOCK_LENGTH_LO, count & 0xff); + snd_als4_cr_write(chip, ALS4K_CR1D_FIFO2_BLOCK_LENGTH_HI, count >> 8); + } return 0; } @@ -429,7 +402,7 @@ static int snd_als4000_playback_prepare(struct snd_pcm_substream *substream) * reordering, ...). Something seems to get enabled on playback * that I haven't found out how to disable again, which then causes * the switching pops to reach the speakers the next time here. */ - spin_lock_irq(&chip->reg_lock); + guard(spinlock_irq)(&chip->reg_lock); snd_als4000_set_rate(chip, runtime->rate); snd_als4000_set_playback_dma(chip, runtime->dma_addr, size); @@ -440,7 +413,6 @@ static int snd_als4000_playback_prepare(struct snd_pcm_substream *substream) snd_sbdsp_command(chip, count & 0xff); snd_sbdsp_command(chip, count >> 8); snd_sbdsp_command(chip, playback_cmd(chip).dma_off); - spin_unlock_irq(&chip->reg_lock); return 0; } @@ -456,7 +428,7 @@ static int snd_als4000_capture_trigger(struct snd_pcm_substream *substream, int Probably need to take reg_lock as outer (or inner??) lock, too. (or serialize both lock operations? probably not, though... - racy?) */ - spin_lock(&chip->mixer_lock); + guard(spinlock)(&chip->mixer_lock); switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: @@ -474,7 +446,6 @@ static int snd_als4000_capture_trigger(struct snd_pcm_substream *substream, int result = -EINVAL; break; } - spin_unlock(&chip->mixer_lock); return result; } @@ -483,7 +454,7 @@ static int snd_als4000_playback_trigger(struct snd_pcm_substream *substream, int struct snd_sb *chip = snd_pcm_substream_chip(substream); int result = 0; - spin_lock(&chip->reg_lock); + guard(spinlock)(&chip->reg_lock); switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: @@ -499,7 +470,6 @@ static int snd_als4000_playback_trigger(struct snd_pcm_substream *substream, int result = -EINVAL; break; } - spin_unlock(&chip->reg_lock); return result; } @@ -508,9 +478,9 @@ static snd_pcm_uframes_t snd_als4000_capture_pointer(struct snd_pcm_substream *s struct snd_sb *chip = snd_pcm_substream_chip(substream); unsigned int result; - spin_lock(&chip->reg_lock); - result = snd_als4k_gcr_read(chip, ALS4K_GCRA4_FIFO2_CURRENT_ADDR); - spin_unlock(&chip->reg_lock); + scoped_guard(spinlock, &chip->reg_lock) { + result = snd_als4k_gcr_read(chip, ALS4K_GCRA4_FIFO2_CURRENT_ADDR); + } result &= 0xffff; return bytes_to_frames( substream->runtime, result ); } @@ -520,9 +490,9 @@ static snd_pcm_uframes_t snd_als4000_playback_pointer(struct snd_pcm_substream * struct snd_sb *chip = snd_pcm_substream_chip(substream); unsigned result; - spin_lock(&chip->reg_lock); - result = snd_als4k_gcr_read(chip, ALS4K_GCRA0_FIFO1_CURRENT_ADDR); - spin_unlock(&chip->reg_lock); + scoped_guard(spinlock, &chip->reg_lock) { + result = snd_als4k_gcr_read(chip, ALS4K_GCRA0_FIFO1_CURRENT_ADDR); + } result &= 0xffff; return bytes_to_frames( substream->runtime, result ); } @@ -563,10 +533,10 @@ static irqreturn_t snd_als4000_interrupt(int irq, void *dev_id) snd_als4k_iobase_writeb(chip->alt_port, ALS4K_IOB_0E_IRQTYPE_SB_CR1E_MPU, pci_irqstatus); - spin_lock(&chip->mixer_lock); - /* SPECS_PAGE: 20 */ - sb_irqstatus = snd_sbmixer_read(chip, SB_DSP4_IRQSTATUS); - spin_unlock(&chip->mixer_lock); + scoped_guard(spinlock, &chip->mixer_lock) { + /* SPECS_PAGE: 20 */ + sb_irqstatus = snd_sbmixer_read(chip, SB_DSP4_IRQSTATUS); + } if (sb_irqstatus & SB_IRQTYPE_8BIT) snd_sb_ack_8bit(chip); @@ -592,7 +562,7 @@ static irqreturn_t snd_als4000_interrupt(int irq, void *dev_id) /*****************************************************************/ -static struct snd_pcm_hardware snd_als4000_playback = +static const struct snd_pcm_hardware snd_als4000_playback = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP_VALID), @@ -611,7 +581,7 @@ static struct snd_pcm_hardware snd_als4000_playback = .fifo_size = 0 }; -static struct snd_pcm_hardware snd_als4000_capture = +static const struct snd_pcm_hardware snd_als4000_capture = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP_VALID), @@ -647,7 +617,6 @@ static int snd_als4000_playback_close(struct snd_pcm_substream *substream) struct snd_sb *chip = snd_pcm_substream_chip(substream); chip->playback_substream = NULL; - snd_pcm_lib_free_pages(substream); return 0; } @@ -666,7 +635,6 @@ static int snd_als4000_capture_close(struct snd_pcm_substream *substream) struct snd_sb *chip = snd_pcm_substream_chip(substream); chip->capture_substream = NULL; - snd_pcm_lib_free_pages(substream); return 0; } @@ -675,9 +643,6 @@ static int snd_als4000_capture_close(struct snd_pcm_substream *substream) static const struct snd_pcm_ops snd_als4000_playback_ops = { .open = snd_als4000_playback_open, .close = snd_als4000_playback_close, - .ioctl = snd_pcm_lib_ioctl, - .hw_params = snd_als4000_hw_params, - .hw_free = snd_als4000_hw_free, .prepare = snd_als4000_playback_prepare, .trigger = snd_als4000_playback_trigger, .pointer = snd_als4000_playback_pointer @@ -686,9 +651,6 @@ static const struct snd_pcm_ops snd_als4000_playback_ops = { static const struct snd_pcm_ops snd_als4000_capture_ops = { .open = snd_als4000_capture_open, .close = snd_als4000_capture_close, - .ioctl = snd_pcm_lib_ioctl, - .hw_params = snd_als4000_hw_params, - .hw_free = snd_als4000_hw_free, .prepare = snd_als4000_capture_prepare, .trigger = snd_als4000_capture_trigger, .pointer = snd_als4000_capture_pointer @@ -707,8 +669,8 @@ static int snd_als4000_pcm(struct snd_sb *chip, int device) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_als4000_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_als4000_capture_ops); - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), - 64*1024, 64*1024); + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, + &chip->pci->dev, 64*1024, 64*1024); chip->pcm = pcm; @@ -744,18 +706,18 @@ static void snd_als4000_configure(struct snd_sb *chip) int i; /* do some more configuration */ - spin_lock_irq(&chip->mixer_lock); - tmp = snd_als4_cr_read(chip, ALS4K_CR0_SB_CONFIG); - snd_als4_cr_write(chip, ALS4K_CR0_SB_CONFIG, - tmp|ALS4K_CR0_MX80_81_REG_WRITE_ENABLE); - /* always select DMA channel 0, since we do not actually use DMA - * SPECS_PAGE: 19/20 */ - snd_sbmixer_write(chip, SB_DSP4_DMASETUP, SB_DMASETUP_DMA0); - snd_als4_cr_write(chip, ALS4K_CR0_SB_CONFIG, - tmp & ~ALS4K_CR0_MX80_81_REG_WRITE_ENABLE); - spin_unlock_irq(&chip->mixer_lock); + scoped_guard(spinlock_irq, &chip->mixer_lock) { + tmp = snd_als4_cr_read(chip, ALS4K_CR0_SB_CONFIG); + snd_als4_cr_write(chip, ALS4K_CR0_SB_CONFIG, + tmp|ALS4K_CR0_MX80_81_REG_WRITE_ENABLE); + /* always select DMA channel 0, since we do not actually use DMA + * SPECS_PAGE: 19/20 */ + snd_sbmixer_write(chip, SB_DSP4_DMASETUP, SB_DMASETUP_DMA0); + snd_als4_cr_write(chip, ALS4K_CR0_SB_CONFIG, + tmp & ~ALS4K_CR0_MX80_81_REG_WRITE_ENABLE); + } - spin_lock_irq(&chip->reg_lock); + guard(spinlock_irq)(&chip->reg_lock); /* enable interrupts */ snd_als4k_gcr_write(chip, ALS4K_GCR8C_MISC_CTRL, ALS4K_GCR8C_IRQ_MASK_CTRL_ENABLE); @@ -766,7 +728,6 @@ static void snd_als4000_configure(struct snd_sb *chip) /* enable burst mode to prevent dropouts during high PCI bus usage */ snd_als4k_gcr_write(chip, ALS4K_GCR99_DMA_EMULATION_CTRL, (snd_als4k_gcr_read(chip, ALS4K_GCR99_DMA_EMULATION_CTRL) & ~0x07) | 0x04); - spin_unlock_irq(&chip->reg_lock); } #ifdef SUPPORT_JOYSTICK @@ -781,13 +742,15 @@ static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev) if (joystick_port[dev] == 1) { /* auto-detect */ for (io_port = 0x200; io_port <= 0x218; io_port += 8) { - r = request_region(io_port, 8, "ALS4000 gameport"); + r = devm_request_region(&acard->pci->dev, io_port, 8, + "ALS4000 gameport"); if (r) break; } } else { io_port = joystick_port[dev]; - r = request_region(io_port, 8, "ALS4000 gameport"); + r = devm_request_region(&acard->pci->dev, io_port, 8, + "ALS4000 gameport"); } if (!r) { @@ -798,7 +761,6 @@ static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev) acard->gameport = gp = gameport_allocate_port(); if (!gp) { dev_err(&acard->pci->dev, "cannot allocate memory for gameport\n"); - release_and_free_resource(r); return -ENOMEM; } @@ -806,7 +768,6 @@ static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev) gameport_set_phys(gp, "pci%s/gameport0", pci_name(acard->pci)); gameport_set_dev_parent(gp, &acard->pci->dev); gp->io = io_port; - gameport_set_port_data(gp, r); /* Enable legacy joystick port */ snd_als4000_set_addr(acard->iobase, 0, 0, 0, 1); @@ -819,15 +780,11 @@ static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev) static void snd_als4000_free_gameport(struct snd_card_als4000 *acard) { if (acard->gameport) { - struct resource *r = gameport_get_port_data(acard->gameport); - gameport_unregister_port(acard->gameport); acard->gameport = NULL; /* disable joystick */ snd_als4000_set_addr(acard->iobase, 0, 0, 0, 0); - - release_and_free_resource(r); } } #else @@ -843,12 +800,10 @@ static void snd_card_als4000_free( struct snd_card *card ) snd_als4k_gcr_write_addr(acard->iobase, ALS4K_GCR8C_MISC_CTRL, 0); /* free resources */ snd_als4000_free_gameport(acard); - pci_release_regions(acard->pci); - pci_disable_device(acard->pci); } -static int snd_card_als4000_probe(struct pci_dev *pci, - const struct pci_device_id *pci_id) +static int __snd_card_als4000_probe(struct pci_dev *pci, + const struct pci_device_id *pci_id) { static int dev; struct snd_card *card; @@ -867,35 +822,30 @@ static int snd_card_als4000_probe(struct pci_dev *pci, } /* enable PCI device */ - if ((err = pci_enable_device(pci)) < 0) { + err = pcim_enable_device(pci); + if (err < 0) return err; - } + /* check, if we can restrict PCI DMA transfers to 24 bits */ - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(24)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(24))) { dev_err(&pci->dev, "architecture does not support 24bit PCI busmaster DMA\n"); - pci_disable_device(pci); return -ENXIO; } - if ((err = pci_request_regions(pci, "ALS4000")) < 0) { - pci_disable_device(pci); + err = pcim_request_all_regions(pci, "ALS4000"); + if (err < 0) return err; - } iobase = pci_resource_start(pci, 0); pci_read_config_word(pci, PCI_COMMAND, &word); pci_write_config_word(pci, PCI_COMMAND, word | PCI_COMMAND_IO); pci_set_master(pci); - err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, - sizeof(*acard) /* private_data: acard */, - &card); - if (err < 0) { - pci_release_regions(pci); - pci_disable_device(pci); + err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, + sizeof(*acard) /* private_data: acard */, + &card); + if (err < 0) return err; - } acard = card->private_data; acard->pci = pci; @@ -905,17 +855,17 @@ static int snd_card_als4000_probe(struct pci_dev *pci, /* disable all legacy ISA stuff */ snd_als4000_set_addr(acard->iobase, 0, 0, 0, 0); - if ((err = snd_sbdsp_create(card, - iobase + ALS4K_IOB_10_ADLIB_ADDR0, - pci->irq, + err = snd_sbdsp_create(card, + iobase + ALS4K_IOB_10_ADLIB_ADDR0, + pci->irq, /* internally registered as IRQF_SHARED in case of ALS4000 SB */ - snd_als4000_interrupt, - -1, - -1, - SB_HW_ALS4000, - &chip)) < 0) { - goto out_err; - } + snd_als4000_interrupt, + -1, + -1, + SB_HW_ALS4000, + &chip); + if (err < 0) + return err; acard->chip = chip; chip->pci = pci; @@ -923,19 +873,20 @@ static int snd_card_als4000_probe(struct pci_dev *pci, snd_als4000_configure(chip); - strcpy(card->driver, "ALS4000"); - strcpy(card->shortname, "Avance Logic ALS4000"); + strscpy(card->driver, "ALS4000"); + strscpy(card->shortname, "Avance Logic ALS4000"); sprintf(card->longname, "%s at 0x%lx, irq %i", card->shortname, chip->alt_port, chip->irq); - if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000, - iobase + ALS4K_IOB_30_MIDI_DATA, - MPU401_INFO_INTEGRATED | - MPU401_INFO_IRQ_HOOK, - -1, &chip->rmidi)) < 0) { + err = snd_mpu401_uart_new(card, 0, MPU401_HW_ALS4000, + iobase + ALS4K_IOB_30_MIDI_DATA, + MPU401_INFO_INTEGRATED | + MPU401_INFO_IRQ_HOOK, + -1, &chip->rmidi); + if (err < 0) { dev_err(&pci->dev, "no MPU-401 device at 0x%lx?\n", iobase + ALS4K_IOB_30_MIDI_DATA); - goto out_err; + return err; } /* FIXME: ALS4000 has interesting MPU401 configuration features * at ALS4K_CR1A_MPU401_UART_MODE_CONTROL @@ -943,12 +894,13 @@ static int snd_card_als4000_probe(struct pci_dev *pci, * however there doesn't seem to be an ALSA API for this... * SPECS_PAGE: 21 */ - if ((err = snd_als4000_pcm(chip, 0)) < 0) { - goto out_err; - } - if ((err = snd_sbmixer_new(chip)) < 0) { - goto out_err; - } + err = snd_als4000_pcm(chip, 0); + if (err < 0) + return err; + + err = snd_sbmixer_new(chip); + if (err < 0) + return err; if (snd_opl3_create(card, iobase + ALS4K_IOB_10_ADLIB_ADDR0, @@ -958,34 +910,28 @@ static int snd_card_als4000_probe(struct pci_dev *pci, iobase + ALS4K_IOB_10_ADLIB_ADDR0, iobase + ALS4K_IOB_12_ADLIB_ADDR2); } else { - if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { - goto out_err; - } + err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); + if (err < 0) + return err; } snd_als4000_create_gameport(acard, dev); - if ((err = snd_card_register(card)) < 0) { - goto out_err; - } + err = snd_card_register(card); + if (err < 0) + return err; + pci_set_drvdata(pci, card); dev++; - err = 0; - goto out; - -out_err: - snd_card_free(card); - -out: - return err; + return 0; } -static void snd_card_als4000_remove(struct pci_dev *pci) +static int snd_card_als4000_probe(struct pci_dev *pci, + const struct pci_device_id *pci_id) { - snd_card_free(pci_get_drvdata(pci)); + return snd_card_free_on_error(&pci->dev, __snd_card_als4000_probe(pci, pci_id)); } -#ifdef CONFIG_PM_SLEEP static int snd_als4000_suspend(struct device *dev) { struct snd_card *card = dev_get_drvdata(dev); @@ -994,7 +940,6 @@ static int snd_als4000_suspend(struct device *dev) snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); - snd_pcm_suspend_all(chip->pcm); snd_sbmixer_suspend(chip); return 0; } @@ -1018,19 +963,14 @@ static int snd_als4000_resume(struct device *dev) return 0; } -static SIMPLE_DEV_PM_OPS(snd_als4000_pm, snd_als4000_suspend, snd_als4000_resume); -#define SND_ALS4000_PM_OPS &snd_als4000_pm -#else -#define SND_ALS4000_PM_OPS NULL -#endif /* CONFIG_PM_SLEEP */ +static DEFINE_SIMPLE_DEV_PM_OPS(snd_als4000_pm, snd_als4000_suspend, snd_als4000_resume); static struct pci_driver als4000_driver = { .name = KBUILD_MODNAME, .id_table = snd_als4000_ids, .probe = snd_card_als4000_probe, - .remove = snd_card_als4000_remove, .driver = { - .pm = SND_ALS4000_PM_OPS, + .pm = &snd_als4000_pm, }, }; |
