diff options
Diffstat (limited to 'sound/pci/cs46xx/cs46xx_lib.c')
| -rw-r--r-- | sound/pci/cs46xx/cs46xx_lib.c | 472 |
1 files changed, 171 insertions, 301 deletions
diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c index 750eec437a79..b96ab7fd464c 100644 --- a/sound/pci/cs46xx/cs46xx_lib.c +++ b/sound/pci/cs46xx/cs46xx_lib.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) by Jaroslav Kysela <perex@perex.cz> * Abramo Bagnara <abramo@alsa-project.org> @@ -28,21 +29,6 @@ * references to be able to implement all fancy feutures * supported by the cs46xx DSP's. * Benny <benny@hostmobility.com> - * - * 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 - * */ #include <linux/delay.h> @@ -545,7 +531,7 @@ static int load_firmware(struct snd_cs46xx *chip) return err; } -int snd_cs46xx_download_image(struct snd_cs46xx *chip) +static __maybe_unused int snd_cs46xx_download_image(struct snd_cs46xx *chip) { int idx, err; unsigned int offset = 0; @@ -721,7 +707,6 @@ static void snd_cs46xx_proc_stop(struct snd_cs46xx *chip) static void snd_cs46xx_set_play_sample_rate(struct snd_cs46xx *chip, unsigned int rate) { - unsigned long flags; unsigned int tmp1, tmp2; unsigned int phiIncr; unsigned int correctionPerGOF, correctionPerSec; @@ -758,16 +743,14 @@ static void snd_cs46xx_set_play_sample_rate(struct snd_cs46xx *chip, unsigned in /* * Fill in the SampleRateConverter control block. */ - spin_lock_irqsave(&chip->reg_lock, flags); + guard(spinlock_irqsave)(&chip->reg_lock); snd_cs46xx_poke(chip, BA1_PSRC, ((correctionPerSec << 16) & 0xFFFF0000) | (correctionPerGOF & 0xFFFF)); snd_cs46xx_poke(chip, BA1_PPI, phiIncr); - spin_unlock_irqrestore(&chip->reg_lock, flags); } static void snd_cs46xx_set_capture_sample_rate(struct snd_cs46xx *chip, unsigned int rate) { - unsigned long flags; unsigned int phiIncr, coeffIncr, tmp1, tmp2; unsigned int correctionPerGOF, correctionPerSec, initialDelay; unsigned int frameGroupLength, cnt; @@ -780,7 +763,7 @@ static void snd_cs46xx_set_capture_sample_rate(struct snd_cs46xx *chip, unsigned rate = 48000 / 9; /* - * We can not capture at at rate greater than the Input Rate (48000). + * We can not capture at a rate greater than the Input Rate (48000). * Return an error if an attempt is made to stray outside that limit. */ if (rate > 48000) @@ -827,19 +810,19 @@ static void snd_cs46xx_set_capture_sample_rate(struct snd_cs46xx *chip, unsigned correctionPerGOF = tmp1 / GOF_PER_SEC; tmp1 -= correctionPerGOF * GOF_PER_SEC; correctionPerSec = tmp1; - initialDelay = ((48000 * 24) + rate - 1) / rate; + initialDelay = DIV_ROUND_UP(48000 * 24, rate); /* * Fill in the VariDecimate control block. */ - spin_lock_irqsave(&chip->reg_lock, flags); - snd_cs46xx_poke(chip, BA1_CSRC, - ((correctionPerSec << 16) & 0xFFFF0000) | (correctionPerGOF & 0xFFFF)); - snd_cs46xx_poke(chip, BA1_CCI, coeffIncr); - snd_cs46xx_poke(chip, BA1_CD, - (((BA1_VARIDEC_BUF_1 + (initialDelay << 2)) << 16) & 0xFFFF0000) | 0x80); - snd_cs46xx_poke(chip, BA1_CPI, phiIncr); - spin_unlock_irqrestore(&chip->reg_lock, flags); + scoped_guard(spinlock_irqsave, &chip->reg_lock) { + snd_cs46xx_poke(chip, BA1_CSRC, + ((correctionPerSec << 16) & 0xFFFF0000) | (correctionPerGOF & 0xFFFF)); + snd_cs46xx_poke(chip, BA1_CCI, coeffIncr); + snd_cs46xx_poke(chip, BA1_CD, + (((BA1_VARIDEC_BUF_1 + (initialDelay << 2)) << 16) & 0xFFFF0000) | 0x80); + snd_cs46xx_poke(chip, BA1_CPI, phiIncr); + } /* * Figure out the frame group length for the write back task. Basically, @@ -862,13 +845,12 @@ static void snd_cs46xx_set_capture_sample_rate(struct snd_cs46xx *chip, unsigned /* * Fill in the WriteBack control block. */ - spin_lock_irqsave(&chip->reg_lock, flags); + guard(spinlock_irqsave)(&chip->reg_lock); snd_cs46xx_poke(chip, BA1_CFG1, frameGroupLength); snd_cs46xx_poke(chip, BA1_CFG2, (0x00800000 | frameGroupLength)); snd_cs46xx_poke(chip, BA1_CCST, 0x0000FFFF); snd_cs46xx_poke(chip, BA1_CSPB, ((65536 * rate) / 24000)); snd_cs46xx_poke(chip, (BA1_CSPB + 4), 0x0000FFFF); - spin_unlock_irqrestore(&chip->reg_lock, flags); } /* @@ -983,15 +965,14 @@ static int snd_cs46xx_playback_trigger(struct snd_pcm_substream *substream, if (substream->runtime->periods != CS46XX_FRAGS) snd_cs46xx_playback_transfer(substream); #else - spin_lock(&chip->reg_lock); - if (substream->runtime->periods != CS46XX_FRAGS) - snd_cs46xx_playback_transfer(substream); - { unsigned int tmp; - tmp = snd_cs46xx_peek(chip, BA1_PCTL); - tmp &= 0x0000ffff; - snd_cs46xx_poke(chip, BA1_PCTL, chip->play_ctl | tmp); + scoped_guard(spinlock, &chip->reg_lock) { + unsigned int tmp; + if (substream->runtime->periods != CS46XX_FRAGS) + snd_cs46xx_playback_transfer(substream); + tmp = snd_cs46xx_peek(chip, BA1_PCTL); + tmp &= 0x0000ffff; + snd_cs46xx_poke(chip, BA1_PCTL, chip->play_ctl | tmp); } - spin_unlock(&chip->reg_lock); #endif break; case SNDRV_PCM_TRIGGER_STOP: @@ -1004,13 +985,12 @@ static int snd_cs46xx_playback_trigger(struct snd_pcm_substream *substream, if (!cpcm->pcm_channel->unlinked) cs46xx_dsp_pcm_unlink(chip,cpcm->pcm_channel); #else - spin_lock(&chip->reg_lock); - { unsigned int tmp; - tmp = snd_cs46xx_peek(chip, BA1_PCTL); - tmp &= 0x0000ffff; - snd_cs46xx_poke(chip, BA1_PCTL, tmp); + scoped_guard(spinlock, &chip->reg_lock) { + unsigned int tmp; + tmp = snd_cs46xx_peek(chip, BA1_PCTL); + tmp &= 0x0000ffff; + snd_cs46xx_poke(chip, BA1_PCTL, tmp); } - spin_unlock(&chip->reg_lock); #endif break; default: @@ -1026,9 +1006,8 @@ static int snd_cs46xx_capture_trigger(struct snd_pcm_substream *substream, { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); unsigned int tmp; - 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: @@ -1043,12 +1022,9 @@ static int snd_cs46xx_capture_trigger(struct snd_pcm_substream *substream, snd_cs46xx_poke(chip, BA1_CCTL, tmp); break; default: - result = -EINVAL; - break; + return -EINVAL; } - spin_unlock(&chip->reg_lock); - - return result; + return 0; } #ifdef CONFIG_SND_CS46XX_NEW_DSP @@ -1072,9 +1048,10 @@ static int _cs46xx_adjust_sample_rate (struct snd_cs46xx *chip, struct snd_cs46x int unlinked = cpcm->pcm_channel->unlinked; cs46xx_dsp_destroy_pcm_channel (chip,cpcm->pcm_channel); - if ( (cpcm->pcm_channel = cs46xx_dsp_create_pcm_channel (chip, sample_rate, cpcm, - cpcm->hw_buf.addr, - cpcm->pcm_channel_id)) == NULL) { + cpcm->pcm_channel = cs46xx_dsp_create_pcm_channel(chip, sample_rate, cpcm, + cpcm->hw_buf.addr, + cpcm->pcm_channel_id); + if (!cpcm->pcm_channel) { dev_err(chip->card->dev, "failed to re-create virtual PCM channel\n"); return -ENOMEM; @@ -1106,24 +1083,17 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream, if (snd_BUG_ON(!sample_rate)) return -ENXIO; - mutex_lock(&chip->spos_mutex); + guard(mutex)(&chip->spos_mutex); - if (_cs46xx_adjust_sample_rate (chip,cpcm,sample_rate)) { - mutex_unlock(&chip->spos_mutex); + if (_cs46xx_adjust_sample_rate(chip, cpcm, sample_rate)) return -ENXIO; - } snd_BUG_ON(!cpcm->pcm_channel); - if (!cpcm->pcm_channel) { - mutex_unlock(&chip->spos_mutex); + if (!cpcm->pcm_channel) return -ENXIO; - } - - if (cs46xx_dsp_pcm_channel_set_period (chip,cpcm->pcm_channel,period_size)) { - mutex_unlock(&chip->spos_mutex); + if (cs46xx_dsp_pcm_channel_set_period(chip, cpcm->pcm_channel, period_size)) return -EINVAL; - } dev_dbg(chip->card->dev, "period_size (%d), periods (%d) buffer_size(%d)\n", @@ -1134,9 +1104,7 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream, if (params_periods(hw_params) == CS46XX_FRAGS) { if (runtime->dma_area != cpcm->hw_buf.area) snd_pcm_lib_free_pages(substream); - runtime->dma_area = cpcm->hw_buf.area; - runtime->dma_addr = cpcm->hw_buf.addr; - runtime->dma_bytes = cpcm->hw_buf.bytes; + snd_pcm_set_runtime_buffer(substream, &cpcm->hw_buf); #ifdef CONFIG_SND_CS46XX_NEW_DSP @@ -1156,17 +1124,11 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream, #endif } else { - if (runtime->dma_area == cpcm->hw_buf.area) { - runtime->dma_area = NULL; - runtime->dma_addr = 0; - runtime->dma_bytes = 0; - } - if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) { -#ifdef CONFIG_SND_CS46XX_NEW_DSP - mutex_unlock(&chip->spos_mutex); -#endif + if (runtime->dma_area == cpcm->hw_buf.area) + snd_pcm_set_runtime_buffer(substream, NULL); + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); + if (err < 0) return err; - } #ifdef CONFIG_SND_CS46XX_NEW_DSP if (cpcm->pcm_channel_id == DSP_PCM_MAIN_CHANNEL) { @@ -1186,10 +1148,6 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream, } -#ifdef CONFIG_SND_CS46XX_NEW_DSP - mutex_unlock(&chip->spos_mutex); -#endif - return 0; } @@ -1208,9 +1166,7 @@ static int snd_cs46xx_playback_hw_free(struct snd_pcm_substream *substream) if (runtime->dma_area != cpcm->hw_buf.area) snd_pcm_lib_free_pages(substream); - runtime->dma_area = NULL; - runtime->dma_addr = 0; - runtime->dma_bytes = 0; + snd_pcm_set_runtime_buffer(substream, NULL); return 0; } @@ -1299,17 +1255,13 @@ static int snd_cs46xx_capture_hw_params(struct snd_pcm_substream *substream, if (runtime->periods == CS46XX_FRAGS) { if (runtime->dma_area != chip->capt.hw_buf.area) snd_pcm_lib_free_pages(substream); - runtime->dma_area = chip->capt.hw_buf.area; - runtime->dma_addr = chip->capt.hw_buf.addr; - runtime->dma_bytes = chip->capt.hw_buf.bytes; + snd_pcm_set_runtime_buffer(substream, &chip->capt.hw_buf); substream->ops = &snd_cs46xx_capture_ops; } else { - if (runtime->dma_area == chip->capt.hw_buf.area) { - runtime->dma_area = NULL; - runtime->dma_addr = 0; - runtime->dma_bytes = 0; - } - if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) + if (runtime->dma_area == chip->capt.hw_buf.area) + snd_pcm_set_runtime_buffer(substream, NULL); + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); + if (err < 0) return err; substream->ops = &snd_cs46xx_capture_indirect_ops; } @@ -1324,9 +1276,7 @@ static int snd_cs46xx_capture_hw_free(struct snd_pcm_substream *substream) if (runtime->dma_area != chip->capt.hw_buf.area) snd_pcm_lib_free_pages(substream); - runtime->dma_area = NULL; - runtime->dma_addr = 0; - runtime->dma_bytes = 0; + snd_pcm_set_runtime_buffer(substream, NULL); return 0; } @@ -1411,7 +1361,7 @@ static irqreturn_t snd_cs46xx_interrupt(int irq, void *dev_id) if ((status1 & HISR_MIDI) && chip->rmidi) { unsigned char c; - spin_lock(&chip->reg_lock); + guard(spinlock)(&chip->reg_lock); while ((snd_cs46xx_peekBA0(chip, BA0_MIDSR) & MIDSR_RBE) == 0) { c = snd_cs46xx_peekBA0(chip, BA0_MIDRP); if ((chip->midcr & MIDCR_RIE) == 0) @@ -1428,7 +1378,6 @@ static irqreturn_t snd_cs46xx_interrupt(int irq, void *dev_id) } snd_cs46xx_pokeBA0(chip, BA0_MIDWP, c); } - spin_unlock(&chip->reg_lock); } /* * EOI to the PCI part....reenables interrupts @@ -1508,7 +1457,7 @@ static int _cs46xx_playback_open_channel (struct snd_pcm_substream *substream,in cpcm = kzalloc(sizeof(*cpcm), GFP_KERNEL); if (cpcm == NULL) return -ENOMEM; - if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev, PAGE_SIZE, &cpcm->hw_buf) < 0) { kfree(cpcm); return -ENOMEM; @@ -1520,16 +1469,14 @@ static int _cs46xx_playback_open_channel (struct snd_pcm_substream *substream,in cpcm->substream = substream; #ifdef CONFIG_SND_CS46XX_NEW_DSP - mutex_lock(&chip->spos_mutex); - cpcm->pcm_channel = NULL; - cpcm->pcm_channel_id = pcm_channel_id; - + scoped_guard(mutex, &chip->spos_mutex) { + cpcm->pcm_channel = NULL; + cpcm->pcm_channel_id = pcm_channel_id; + } snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_period_sizes); - - mutex_unlock(&chip->spos_mutex); #else chip->playback_pcm = cpcm; /* HACK */ #endif @@ -1566,9 +1513,9 @@ static int snd_cs46xx_playback_open_iec958(struct snd_pcm_substream *substream) dev_dbg(chip->card->dev, "open raw iec958 channel\n"); - mutex_lock(&chip->spos_mutex); - cs46xx_iec958_pre_open (chip); - mutex_unlock(&chip->spos_mutex); + scoped_guard(mutex, &chip->spos_mutex) { + cs46xx_iec958_pre_open(chip); + } return _cs46xx_playback_open_channel(substream,DSP_IEC958_CHANNEL); } @@ -1584,9 +1531,9 @@ static int snd_cs46xx_playback_close_iec958(struct snd_pcm_substream *substream) err = snd_cs46xx_playback_close(substream); - mutex_lock(&chip->spos_mutex); - cs46xx_iec958_post_close (chip); - mutex_unlock(&chip->spos_mutex); + scoped_guard(mutex, &chip->spos_mutex) { + cs46xx_iec958_post_close(chip); + } return err; } @@ -1596,7 +1543,7 @@ static int snd_cs46xx_capture_open(struct snd_pcm_substream *substream) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); - if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev, PAGE_SIZE, &chip->capt.hw_buf) < 0) return -ENOMEM; chip->capt.substream = substream; @@ -1627,12 +1574,12 @@ static int snd_cs46xx_playback_close(struct snd_pcm_substream *substream) if (!cpcm) return -ENXIO; #ifdef CONFIG_SND_CS46XX_NEW_DSP - mutex_lock(&chip->spos_mutex); - if (cpcm->pcm_channel) { - cs46xx_dsp_destroy_pcm_channel(chip,cpcm->pcm_channel); - cpcm->pcm_channel = NULL; + scoped_guard(mutex, &chip->spos_mutex) { + if (cpcm->pcm_channel) { + cs46xx_dsp_destroy_pcm_channel(chip, cpcm->pcm_channel); + cpcm->pcm_channel = NULL; + } } - mutex_unlock(&chip->spos_mutex); #else chip->playback_pcm = NULL; #endif @@ -1659,7 +1606,6 @@ static int snd_cs46xx_capture_close(struct snd_pcm_substream *substream) static const struct snd_pcm_ops snd_cs46xx_playback_rear_ops = { .open = snd_cs46xx_playback_open_rear, .close = snd_cs46xx_playback_close, - .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, @@ -1670,7 +1616,6 @@ static const struct snd_pcm_ops snd_cs46xx_playback_rear_ops = { static const struct snd_pcm_ops snd_cs46xx_playback_indirect_rear_ops = { .open = snd_cs46xx_playback_open_rear, .close = snd_cs46xx_playback_close, - .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, @@ -1682,7 +1627,6 @@ static const struct snd_pcm_ops snd_cs46xx_playback_indirect_rear_ops = { static const struct snd_pcm_ops snd_cs46xx_playback_clfe_ops = { .open = snd_cs46xx_playback_open_clfe, .close = snd_cs46xx_playback_close, - .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, @@ -1693,7 +1637,6 @@ static const struct snd_pcm_ops snd_cs46xx_playback_clfe_ops = { static const struct snd_pcm_ops snd_cs46xx_playback_indirect_clfe_ops = { .open = snd_cs46xx_playback_open_clfe, .close = snd_cs46xx_playback_close, - .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, @@ -1705,7 +1648,6 @@ static const struct snd_pcm_ops snd_cs46xx_playback_indirect_clfe_ops = { static const struct snd_pcm_ops snd_cs46xx_playback_iec958_ops = { .open = snd_cs46xx_playback_open_iec958, .close = snd_cs46xx_playback_close_iec958, - .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, @@ -1716,7 +1658,6 @@ static const struct snd_pcm_ops snd_cs46xx_playback_iec958_ops = { static const struct snd_pcm_ops snd_cs46xx_playback_indirect_iec958_ops = { .open = snd_cs46xx_playback_open_iec958, .close = snd_cs46xx_playback_close_iec958, - .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, @@ -1730,7 +1671,6 @@ static const struct snd_pcm_ops snd_cs46xx_playback_indirect_iec958_ops = { static const struct snd_pcm_ops snd_cs46xx_playback_ops = { .open = snd_cs46xx_playback_open, .close = snd_cs46xx_playback_close, - .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, @@ -1741,7 +1681,6 @@ static const struct snd_pcm_ops snd_cs46xx_playback_ops = { static const struct snd_pcm_ops snd_cs46xx_playback_indirect_ops = { .open = snd_cs46xx_playback_open, .close = snd_cs46xx_playback_close, - .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, @@ -1753,7 +1692,6 @@ static const struct snd_pcm_ops snd_cs46xx_playback_indirect_ops = { static const struct snd_pcm_ops snd_cs46xx_capture_ops = { .open = snd_cs46xx_capture_open, .close = snd_cs46xx_capture_close, - .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_cs46xx_capture_hw_params, .hw_free = snd_cs46xx_capture_hw_free, .prepare = snd_cs46xx_capture_prepare, @@ -1764,7 +1702,6 @@ static const struct snd_pcm_ops snd_cs46xx_capture_ops = { static const struct snd_pcm_ops snd_cs46xx_capture_indirect_ops = { .open = snd_cs46xx_capture_open, .close = snd_cs46xx_capture_close, - .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_cs46xx_capture_hw_params, .hw_free = snd_cs46xx_capture_hw_free, .prepare = snd_cs46xx_capture_prepare, @@ -1784,7 +1721,8 @@ int snd_cs46xx_pcm(struct snd_cs46xx *chip, int device) struct snd_pcm *pcm; int err; - if ((err = snd_pcm_new(chip->card, "CS46xx", device, MAX_PLAYBACK_CHANNELS, 1, &pcm)) < 0) + err = snd_pcm_new(chip->card, "CS46xx", device, MAX_PLAYBACK_CHANNELS, 1, &pcm); + if (err < 0) return err; pcm->private_data = chip; @@ -1794,11 +1732,12 @@ int snd_cs46xx_pcm(struct snd_cs46xx *chip, int device) /* global setup */ pcm->info_flags = 0; - strcpy(pcm->name, "CS46xx"); + strscpy(pcm->name, "CS46xx"); chip->pcm = pcm; snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, - snd_dma_pci_data(chip->pci), 64*1024, 256*1024); + &chip->pci->dev, + 64*1024, 256*1024); return 0; } @@ -1810,7 +1749,8 @@ int snd_cs46xx_pcm_rear(struct snd_cs46xx *chip, int device) struct snd_pcm *pcm; int err; - if ((err = snd_pcm_new(chip->card, "CS46xx - Rear", device, MAX_PLAYBACK_CHANNELS, 0, &pcm)) < 0) + err = snd_pcm_new(chip->card, "CS46xx - Rear", device, MAX_PLAYBACK_CHANNELS, 0, &pcm); + if (err < 0) return err; pcm->private_data = chip; @@ -1819,11 +1759,12 @@ int snd_cs46xx_pcm_rear(struct snd_cs46xx *chip, int device) /* global setup */ pcm->info_flags = 0; - strcpy(pcm->name, "CS46xx - Rear"); + strscpy(pcm->name, "CS46xx - Rear"); chip->pcm_rear = pcm; snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, - snd_dma_pci_data(chip->pci), 64*1024, 256*1024); + &chip->pci->dev, + 64*1024, 256*1024); return 0; } @@ -1833,7 +1774,8 @@ int snd_cs46xx_pcm_center_lfe(struct snd_cs46xx *chip, int device) struct snd_pcm *pcm; int err; - if ((err = snd_pcm_new(chip->card, "CS46xx - Center LFE", device, MAX_PLAYBACK_CHANNELS, 0, &pcm)) < 0) + err = snd_pcm_new(chip->card, "CS46xx - Center LFE", device, MAX_PLAYBACK_CHANNELS, 0, &pcm); + if (err < 0) return err; pcm->private_data = chip; @@ -1842,11 +1784,12 @@ int snd_cs46xx_pcm_center_lfe(struct snd_cs46xx *chip, int device) /* global setup */ pcm->info_flags = 0; - strcpy(pcm->name, "CS46xx - Center LFE"); + strscpy(pcm->name, "CS46xx - Center LFE"); chip->pcm_center_lfe = pcm; snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, - snd_dma_pci_data(chip->pci), 64*1024, 256*1024); + &chip->pci->dev, + 64*1024, 256*1024); return 0; } @@ -1856,7 +1799,8 @@ int snd_cs46xx_pcm_iec958(struct snd_cs46xx *chip, int device) struct snd_pcm *pcm; int err; - if ((err = snd_pcm_new(chip->card, "CS46xx - IEC958", device, 1, 0, &pcm)) < 0) + err = snd_pcm_new(chip->card, "CS46xx - IEC958", device, 1, 0, &pcm); + if (err < 0) return err; pcm->private_data = chip; @@ -1865,11 +1809,12 @@ int snd_cs46xx_pcm_iec958(struct snd_cs46xx *chip, int device) /* global setup */ pcm->info_flags = 0; - strcpy(pcm->name, "CS46xx - IEC958"); + strscpy(pcm->name, "CS46xx - IEC958"); chip->pcm_iec958 = pcm; snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, - snd_dma_pci_data(chip->pci), 64*1024, 256*1024); + &chip->pci->dev, + 64*1024, 256*1024); return 0; } @@ -1878,13 +1823,6 @@ int snd_cs46xx_pcm_iec958(struct snd_cs46xx *chip, int device) /* * Mixer routines */ -static void snd_cs46xx_mixer_free_ac97_bus(struct snd_ac97_bus *bus) -{ - struct snd_cs46xx *chip = bus->private_data; - - chip->ac97_bus = NULL; -} - static void snd_cs46xx_mixer_free_ac97(struct snd_ac97 *ac97) { struct snd_cs46xx *chip = ac97->private_data; @@ -2016,15 +1954,15 @@ static int snd_cs46xx_iec958_put(struct snd_kcontrol *kcontrol, switch (kcontrol->private_value) { case CS46XX_MIXER_SPDIF_OUTPUT_ELEMENT: - mutex_lock(&chip->spos_mutex); - change = (chip->dsp_spos_instance->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED); - if (ucontrol->value.integer.value[0] && !change) - cs46xx_dsp_enable_spdif_out(chip); - else if (change && !ucontrol->value.integer.value[0]) - cs46xx_dsp_disable_spdif_out(chip); - - res = (change != (chip->dsp_spos_instance->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED)); - mutex_unlock(&chip->spos_mutex); + scoped_guard(mutex, &chip->spos_mutex) { + change = (chip->dsp_spos_instance->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED); + if (ucontrol->value.integer.value[0] && !change) + cs46xx_dsp_enable_spdif_out(chip); + else if (change && !ucontrol->value.integer.value[0]) + cs46xx_dsp_disable_spdif_out(chip); + + res = (change != (chip->dsp_spos_instance->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED)); + } break; case CS46XX_MIXER_SPDIF_INPUT_ELEMENT: change = chip->dsp_spos_instance->spdif_status_in; @@ -2165,12 +2103,11 @@ static int snd_cs46xx_spdif_default_get(struct snd_kcontrol *kcontrol, struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); struct dsp_spos_instance * ins = chip->dsp_spos_instance; - mutex_lock(&chip->spos_mutex); + guard(mutex)(&chip->spos_mutex); ucontrol->value.iec958.status[0] = _wrap_all_bits((ins->spdif_csuv_default >> 24) & 0xff); ucontrol->value.iec958.status[1] = _wrap_all_bits((ins->spdif_csuv_default >> 16) & 0xff); ucontrol->value.iec958.status[2] = 0; ucontrol->value.iec958.status[3] = _wrap_all_bits((ins->spdif_csuv_default) & 0xff); - mutex_unlock(&chip->spos_mutex); return 0; } @@ -2183,7 +2120,7 @@ static int snd_cs46xx_spdif_default_put(struct snd_kcontrol *kcontrol, unsigned int val; int change; - mutex_lock(&chip->spos_mutex); + guard(mutex)(&chip->spos_mutex); val = ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[0]) << 24) | ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[2]) << 16) | ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[3])) | @@ -2197,8 +2134,6 @@ static int snd_cs46xx_spdif_default_put(struct snd_kcontrol *kcontrol, if ( !(ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN) ) cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV,val); - mutex_unlock(&chip->spos_mutex); - return change; } @@ -2218,12 +2153,11 @@ static int snd_cs46xx_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); struct dsp_spos_instance * ins = chip->dsp_spos_instance; - mutex_lock(&chip->spos_mutex); + guard(mutex)(&chip->spos_mutex); ucontrol->value.iec958.status[0] = _wrap_all_bits((ins->spdif_csuv_stream >> 24) & 0xff); ucontrol->value.iec958.status[1] = _wrap_all_bits((ins->spdif_csuv_stream >> 16) & 0xff); ucontrol->value.iec958.status[2] = 0; ucontrol->value.iec958.status[3] = _wrap_all_bits((ins->spdif_csuv_stream) & 0xff); - mutex_unlock(&chip->spos_mutex); return 0; } @@ -2236,7 +2170,7 @@ static int snd_cs46xx_spdif_stream_put(struct snd_kcontrol *kcontrol, unsigned int val; int change; - mutex_lock(&chip->spos_mutex); + guard(mutex)(&chip->spos_mutex); val = ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[0]) << 24) | ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[1]) << 16) | ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[3])) | @@ -2250,15 +2184,13 @@ static int snd_cs46xx_spdif_stream_put(struct snd_kcontrol *kcontrol, if ( ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN ) cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV,val); - mutex_unlock(&chip->spos_mutex); - return change; } #endif /* CONFIG_SND_CS46XX_NEW_DSP */ -static struct snd_kcontrol_new snd_cs46xx_controls[] = { +static const struct snd_kcontrol_new snd_cs46xx_controls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "DAC Volume", @@ -2384,7 +2316,7 @@ static const struct snd_kcontrol_new snd_cs46xx_front_dup_ctl = { #ifdef CONFIG_SND_CS46XX_NEW_DSP /* Only available on the Hercules Game Theater XP soundcard */ -static struct snd_kcontrol_new snd_hercules_controls[] = { +static const struct snd_kcontrol_new snd_hercules_controls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Optical/Coaxial SPDIF Input Switch", @@ -2434,7 +2366,8 @@ static void snd_cs46xx_codec_reset (struct snd_ac97 * ac97) /* test if we can write to the record gain volume register */ snd_ac97_write(ac97, AC97_REC_GAIN, 0x8a05); - if ((err = snd_ac97_read(ac97, AC97_REC_GAIN)) == 0x8a05) + err = snd_ac97_read(ac97, AC97_REC_GAIN); + if (err == 0x8a05) return; msleep(10); @@ -2482,10 +2415,9 @@ static int cs46xx_detect_codec(struct snd_cs46xx *chip, int codec) int snd_cs46xx_mixer(struct snd_cs46xx *chip, int spdif_device) { struct snd_card *card = chip->card; - struct snd_ctl_elem_id id; int err; unsigned int idx; - static struct snd_ac97_bus_ops ops = { + static const struct snd_ac97_bus_ops ops = { #ifdef CONFIG_SND_CS46XX_NEW_DSP .reset = snd_cs46xx_codec_reset, #endif @@ -2496,9 +2428,9 @@ int snd_cs46xx_mixer(struct snd_cs46xx *chip, int spdif_device) /* detect primary codec */ chip->nr_ac97_codecs = 0; dev_dbg(chip->card->dev, "detecting primary codec\n"); - if ((err = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus)) < 0) + err = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus); + if (err < 0) return err; - chip->ac97_bus->private_free = snd_cs46xx_mixer_free_ac97_bus; if (cs46xx_detect_codec(chip, CS46XX_PRIMARY_CODEC_INDEX) < 0) return -ENXIO; @@ -2517,15 +2449,14 @@ int snd_cs46xx_mixer(struct snd_cs46xx *chip, int spdif_device) kctl = snd_ctl_new1(&snd_cs46xx_controls[idx], chip); if (kctl && kctl->id.iface == SNDRV_CTL_ELEM_IFACE_PCM) kctl->id.device = spdif_device; - if ((err = snd_ctl_add(card, kctl)) < 0) + err = snd_ctl_add(card, kctl); + if (err < 0) return err; } /* get EAPD mixer switch (for voyetra hack) */ - memset(&id, 0, sizeof(id)); - id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; - strcpy(id.name, "External Amplifier"); - chip->eapd_switch = snd_ctl_find_id(chip->card, &id); + chip->eapd_switch = snd_ctl_find_id_mixer(chip->card, + "External Amplifier"); #ifdef CONFIG_SND_CS46XX_NEW_DSP if (chip->nr_ac97_codecs == 1) { @@ -2567,7 +2498,7 @@ static int snd_cs46xx_midi_input_open(struct snd_rawmidi_substream *substream) struct snd_cs46xx *chip = substream->rmidi->private_data; chip->active_ctrl(chip, 1); - spin_lock_irq(&chip->reg_lock); + guard(spinlock_irq)(&chip->reg_lock); chip->uartm |= CS46XX_MODE_INPUT; chip->midcr |= MIDCR_RXE; chip->midi_input = substream; @@ -2576,7 +2507,6 @@ static int snd_cs46xx_midi_input_open(struct snd_rawmidi_substream *substream) } else { snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); } - spin_unlock_irq(&chip->reg_lock); return 0; } @@ -2584,16 +2514,16 @@ static int snd_cs46xx_midi_input_close(struct snd_rawmidi_substream *substream) { struct snd_cs46xx *chip = substream->rmidi->private_data; - spin_lock_irq(&chip->reg_lock); - chip->midcr &= ~(MIDCR_RXE | MIDCR_RIE); - chip->midi_input = NULL; - if (!(chip->uartm & CS46XX_MODE_OUTPUT)) { - snd_cs46xx_midi_reset(chip); - } else { - snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); + scoped_guard(spinlock_irq, &chip->reg_lock) { + chip->midcr &= ~(MIDCR_RXE | MIDCR_RIE); + chip->midi_input = NULL; + if (!(chip->uartm & CS46XX_MODE_OUTPUT)) { + snd_cs46xx_midi_reset(chip); + } else { + snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); + } + chip->uartm &= ~CS46XX_MODE_INPUT; } - chip->uartm &= ~CS46XX_MODE_INPUT; - spin_unlock_irq(&chip->reg_lock); chip->active_ctrl(chip, -1); return 0; } @@ -2604,7 +2534,7 @@ static int snd_cs46xx_midi_output_open(struct snd_rawmidi_substream *substream) chip->active_ctrl(chip, 1); - spin_lock_irq(&chip->reg_lock); + guard(spinlock_irq)(&chip->reg_lock); chip->uartm |= CS46XX_MODE_OUTPUT; chip->midcr |= MIDCR_TXE; chip->midi_output = substream; @@ -2613,7 +2543,6 @@ static int snd_cs46xx_midi_output_open(struct snd_rawmidi_substream *substream) } else { snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); } - spin_unlock_irq(&chip->reg_lock); return 0; } @@ -2621,26 +2550,25 @@ static int snd_cs46xx_midi_output_close(struct snd_rawmidi_substream *substream) { struct snd_cs46xx *chip = substream->rmidi->private_data; - spin_lock_irq(&chip->reg_lock); - chip->midcr &= ~(MIDCR_TXE | MIDCR_TIE); - chip->midi_output = NULL; - if (!(chip->uartm & CS46XX_MODE_INPUT)) { - snd_cs46xx_midi_reset(chip); - } else { - snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); + scoped_guard(spinlock_irq, &chip->reg_lock) { + chip->midcr &= ~(MIDCR_TXE | MIDCR_TIE); + chip->midi_output = NULL; + if (!(chip->uartm & CS46XX_MODE_INPUT)) { + snd_cs46xx_midi_reset(chip); + } else { + snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); + } + chip->uartm &= ~CS46XX_MODE_OUTPUT; } - chip->uartm &= ~CS46XX_MODE_OUTPUT; - spin_unlock_irq(&chip->reg_lock); chip->active_ctrl(chip, -1); return 0; } static void snd_cs46xx_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) { - unsigned long flags; struct snd_cs46xx *chip = substream->rmidi->private_data; - spin_lock_irqsave(&chip->reg_lock, flags); + guard(spinlock_irqsave)(&chip->reg_lock); if (up) { if ((chip->midcr & MIDCR_RIE) == 0) { chip->midcr |= MIDCR_RIE; @@ -2652,16 +2580,14 @@ static void snd_cs46xx_midi_input_trigger(struct snd_rawmidi_substream *substrea snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); } } - spin_unlock_irqrestore(&chip->reg_lock, flags); } static void snd_cs46xx_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) { - unsigned long flags; struct snd_cs46xx *chip = substream->rmidi->private_data; unsigned char byte; - spin_lock_irqsave(&chip->reg_lock, flags); + guard(spinlock_irqsave)(&chip->reg_lock); if (up) { if ((chip->midcr & MIDCR_TIE) == 0) { chip->midcr |= MIDCR_TIE; @@ -2682,7 +2608,6 @@ static void snd_cs46xx_midi_output_trigger(struct snd_rawmidi_substream *substre snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); } } - spin_unlock_irqrestore(&chip->reg_lock, flags); } static const struct snd_rawmidi_ops snd_cs46xx_midi_output = @@ -2704,9 +2629,10 @@ int snd_cs46xx_midi(struct snd_cs46xx *chip, int device) struct snd_rawmidi *rmidi; int err; - if ((err = snd_rawmidi_new(chip->card, "CS46XX", device, 1, 1, &rmidi)) < 0) + err = snd_rawmidi_new(chip->card, "CS46XX", device, 1, 1, &rmidi); + if (err < 0) return err; - strcpy(rmidi->name, "CS46XX"); + strscpy(rmidi->name, "CS46XX"); snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_cs46xx_midi_output); snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_cs46xx_midi_input); rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; @@ -2835,7 +2761,7 @@ static ssize_t snd_cs46xx_io_read(struct snd_info_entry *entry, return count; } -static struct snd_info_entry_ops snd_cs46xx_proc_io_ops = { +static const struct snd_info_entry_ops snd_cs46xx_proc_io_ops = { .read = snd_cs46xx_io_read, }; @@ -2922,12 +2848,12 @@ static void snd_cs46xx_hw_stop(struct snd_cs46xx *chip) } -static int snd_cs46xx_free(struct snd_cs46xx *chip) +static void snd_cs46xx_free(struct snd_card *card) { + struct snd_cs46xx *chip = card->private_data; +#ifdef CONFIG_SND_CS46XX_NEW_DSP int idx; - - if (snd_BUG_ON(!chip)) - return -EINVAL; +#endif if (chip->active_ctrl) chip->active_ctrl(chip, 1); @@ -2939,22 +2865,11 @@ static int snd_cs46xx_free(struct snd_cs46xx *chip) snd_cs46xx_proc_done(chip); - if (chip->region.idx[0].resource) - snd_cs46xx_hw_stop(chip); - - if (chip->irq >= 0) - free_irq(chip->irq, chip); + snd_cs46xx_hw_stop(chip); if (chip->active_ctrl) chip->active_ctrl(chip, -chip->amplifier); - for (idx = 0; idx < 5; idx++) { - struct snd_cs46xx_region *region = &chip->region.idx[idx]; - - iounmap(region->remap_addr); - release_and_free_resource(region->resource); - } - #ifdef CONFIG_SND_CS46XX_NEW_DSP if (chip->dsp_spos_instance) { cs46xx_dsp_spos_destroy(chip); @@ -2965,20 +2880,6 @@ static int snd_cs46xx_free(struct snd_cs46xx *chip) #else vfree(chip->ba1); #endif - -#ifdef CONFIG_PM_SLEEP - kfree(chip->saved_regs); -#endif - - pci_disable_device(chip->pci); - kfree(chip); - return 0; -} - -static int snd_cs46xx_dev_free(struct snd_device *device) -{ - struct snd_cs46xx *chip = device->device_data; - return snd_cs46xx_free(chip); } /* @@ -3546,7 +3447,8 @@ static void hercules_mixer_init (struct snd_cs46xx *chip) struct snd_kcontrol *kctl; kctl = snd_ctl_new1(&snd_hercules_controls[idx], chip); - if ((err = snd_ctl_add(card, kctl)) < 0) { + err = snd_ctl_add(card, kctl); + if (err < 0) { dev_err(card->dev, "failed to initialize Hercules mixer (%d)\n", err); @@ -3765,7 +3667,7 @@ static struct cs_card_type cards[] = { * APM support */ #ifdef CONFIG_PM_SLEEP -static unsigned int saved_regs[] = { +static const unsigned int saved_regs[] = { BA0_ACOSV, /*BA0_ASER_FADDR,*/ BA0_ASER_MASTER, @@ -3781,12 +3683,6 @@ static int snd_cs46xx_suspend(struct device *dev) snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); chip->in_suspend = 1; - snd_pcm_suspend_all(chip->pcm); -#ifdef CONFIG_SND_CS46XX_NEW_DSP - snd_pcm_suspend_all(chip->pcm_rear); - snd_pcm_suspend_all(chip->pcm_center_lfe); - snd_pcm_suspend_all(chip->pcm_iec958); -#endif // chip->ac97_powerdown = snd_cs46xx_codec_read(chip, AC97_POWER_CONTROL); // chip->ac97_general_purpose = snd_cs46xx_codec_read(chip, BA0_AC97_GENERAL_PURPOSE); @@ -3882,29 +3778,19 @@ SIMPLE_DEV_PM_OPS(snd_cs46xx_pm, snd_cs46xx_suspend, snd_cs46xx_resume); int snd_cs46xx_create(struct snd_card *card, struct pci_dev *pci, - int external_amp, int thinkpad, - struct snd_cs46xx **rchip) + int external_amp, int thinkpad) { - struct snd_cs46xx *chip; + struct snd_cs46xx *chip = card->private_data; int err, idx; struct snd_cs46xx_region *region; struct cs_card_type *cp; u16 ss_card, ss_vendor; - static struct snd_device_ops ops = { - .dev_free = snd_cs46xx_dev_free, - }; - *rchip = NULL; - /* enable PCI device */ - if ((err = pci_enable_device(pci)) < 0) + err = pcim_enable_device(pci); + if (err < 0) return err; - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } spin_lock_init(&chip->reg_lock); #ifdef CONFIG_SND_CS46XX_NEW_DSP mutex_init(&chip->spos_mutex); @@ -3912,6 +3798,10 @@ int snd_cs46xx_create(struct snd_card *card, chip->card = card; chip->pci = pci; chip->irq = -1; + + err = pcim_request_all_regions(pci, "CS46xx"); + if (err < 0) + return err; chip->ba0_addr = pci_resource_start(pci, 0); chip->ba1_addr = pci_resource_start(pci, 1); if (chip->ba0_addr == 0 || chip->ba0_addr == (unsigned long)~0 || @@ -3919,32 +3809,31 @@ int snd_cs46xx_create(struct snd_card *card, dev_err(chip->card->dev, "wrong address(es) - ba0 = 0x%lx, ba1 = 0x%lx\n", chip->ba0_addr, chip->ba1_addr); - snd_cs46xx_free(chip); return -ENOMEM; } region = &chip->region.name.ba0; - strcpy(region->name, "CS46xx_BA0"); + strscpy(region->name, "CS46xx_BA0"); region->base = chip->ba0_addr; region->size = CS46XX_BA0_SIZE; region = &chip->region.name.data0; - strcpy(region->name, "CS46xx_BA1_data0"); + strscpy(region->name, "CS46xx_BA1_data0"); region->base = chip->ba1_addr + BA1_SP_DMEM0; region->size = CS46XX_BA1_DATA0_SIZE; region = &chip->region.name.data1; - strcpy(region->name, "CS46xx_BA1_data1"); + strscpy(region->name, "CS46xx_BA1_data1"); region->base = chip->ba1_addr + BA1_SP_DMEM1; region->size = CS46XX_BA1_DATA1_SIZE; region = &chip->region.name.pmem; - strcpy(region->name, "CS46xx_BA1_pmem"); + strscpy(region->name, "CS46xx_BA1_pmem"); region->base = chip->ba1_addr + BA1_SP_PMEM; region->size = CS46XX_BA1_PRG_SIZE; region = &chip->region.name.reg; - strcpy(region->name, "CS46xx_BA1_reg"); + strscpy(region->name, "CS46xx_BA1_reg"); region->base = chip->ba1_addr + BA1_SP_REG; region->size = CS46XX_BA1_REG_SIZE; @@ -3991,64 +3880,45 @@ int snd_cs46xx_create(struct snd_card *card, for (idx = 0; idx < 5; idx++) { region = &chip->region.idx[idx]; - if ((region->resource = request_mem_region(region->base, region->size, - region->name)) == NULL) { - dev_err(chip->card->dev, - "unable to request memory region 0x%lx-0x%lx\n", - region->base, region->base + region->size - 1); - snd_cs46xx_free(chip); - return -EBUSY; - } - region->remap_addr = ioremap_nocache(region->base, region->size); + region->remap_addr = devm_ioremap(&pci->dev, region->base, + region->size); if (region->remap_addr == NULL) { dev_err(chip->card->dev, "%s ioremap problem\n", region->name); - snd_cs46xx_free(chip); return -ENOMEM; } } - if (request_irq(pci->irq, snd_cs46xx_interrupt, IRQF_SHARED, - KBUILD_MODNAME, chip)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_cs46xx_interrupt, + IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(chip->card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_cs46xx_free(chip); return -EBUSY; } chip->irq = pci->irq; + card->sync_irq = chip->irq; + card->private_free = snd_cs46xx_free; #ifdef CONFIG_SND_CS46XX_NEW_DSP chip->dsp_spos_instance = cs46xx_dsp_spos_create(chip); - if (chip->dsp_spos_instance == NULL) { - snd_cs46xx_free(chip); + if (!chip->dsp_spos_instance) return -ENOMEM; - } #endif err = snd_cs46xx_chip_init(chip); - if (err < 0) { - snd_cs46xx_free(chip); - return err; - } - - if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { - snd_cs46xx_free(chip); + if (err < 0) return err; - } snd_cs46xx_proc_init(card, chip); #ifdef CONFIG_PM_SLEEP - chip->saved_regs = kmalloc_array(ARRAY_SIZE(saved_regs), - sizeof(*chip->saved_regs), - GFP_KERNEL); - if (!chip->saved_regs) { - snd_cs46xx_free(chip); + chip->saved_regs = devm_kmalloc_array(&pci->dev, + ARRAY_SIZE(saved_regs), + sizeof(*chip->saved_regs), + GFP_KERNEL); + if (!chip->saved_regs) return -ENOMEM; - } #endif chip->active_ctrl(chip, -1); /* disable CLKRUN */ - - *rchip = chip; return 0; } |
