diff options
Diffstat (limited to 'sound/sparc/amd7930.c')
| -rw-r--r-- | sound/sparc/amd7930.c | 176 |
1 files changed, 69 insertions, 107 deletions
diff --git a/sound/sparc/amd7930.c b/sound/sparc/amd7930.c index 56f17410fcea..da04ed5cbac4 100644 --- a/sound/sparc/amd7930.c +++ b/sound/sparc/amd7930.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Driver for AMD7930 sound chips found on Sparcs. * Copyright (C) 2002, 2008 David S. Miller <davem@davemloft.net> @@ -36,8 +37,9 @@ #include <linux/interrupt.h> #include <linux/moduleparam.h> #include <linux/of.h> -#include <linux/of_device.h> +#include <linux/platform_device.h> #include <linux/io.h> +#include <linux/string.h> #include <sound/core.h> #include <sound/pcm.h> @@ -46,7 +48,6 @@ #include <sound/initval.h> #include <asm/irq.h> -#include <asm/prom.h> static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ @@ -61,7 +62,6 @@ MODULE_PARM_DESC(enable, "Enable Sun AMD7930 soundcard."); MODULE_AUTHOR("Thomas K. Dyas and David S. Miller"); MODULE_DESCRIPTION("Sun AMD7930"); MODULE_LICENSE("GPL"); -MODULE_SUPPORTED_DEVICE("{{Sun,AMD7930}}"); /* Device register layout. */ @@ -346,34 +346,25 @@ static struct snd_amd7930 *amd7930_list; /* Idle the AMD7930 chip. The amd->lock is not held. */ static __inline__ void amd7930_idle(struct snd_amd7930 *amd) { - unsigned long flags; - - spin_lock_irqsave(&amd->lock, flags); + guard(spinlock_irqsave)(&amd->lock); sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR); sbus_writeb(0, amd->regs + AMD7930_DR); - spin_unlock_irqrestore(&amd->lock, flags); } /* Enable chip interrupts. The amd->lock is not held. */ static __inline__ void amd7930_enable_ints(struct snd_amd7930 *amd) { - unsigned long flags; - - spin_lock_irqsave(&amd->lock, flags); + guard(spinlock_irqsave)(&amd->lock); sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR); sbus_writeb(AM_INIT_ACTIVE, amd->regs + AMD7930_DR); - spin_unlock_irqrestore(&amd->lock, flags); } /* Disable chip interrupts. The amd->lock is not held. */ static __inline__ void amd7930_disable_ints(struct snd_amd7930 *amd) { - unsigned long flags; - - spin_lock_irqsave(&amd->lock, flags); + guard(spinlock_irqsave)(&amd->lock); sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR); sbus_writeb(AM_INIT_ACTIVE | AM_INIT_DISABLE_INTS, amd->regs + AMD7930_DR); - spin_unlock_irqrestore(&amd->lock, flags); } /* Commit amd7930_map settings to the hardware. @@ -497,34 +488,33 @@ static irqreturn_t snd_amd7930_interrupt(int irq, void *dev_id) unsigned int elapsed; u8 ir; - spin_lock(&amd->lock); - - elapsed = 0; - - ir = sbus_readb(amd->regs + AMD7930_IR); - if (ir & AMR_IR_BBUF) { - u8 byte; - - if (amd->flags & AMD7930_FLAG_PLAYBACK) { - if (amd->p_left > 0) { - byte = *(amd->p_cur++); - amd->p_left--; - sbus_writeb(byte, amd->regs + AMD7930_BBTB); - if (amd->p_left == 0) - elapsed |= AMD7930_FLAG_PLAYBACK; - } else - sbus_writeb(0, amd->regs + AMD7930_BBTB); - } else if (amd->flags & AMD7930_FLAG_CAPTURE) { - byte = sbus_readb(amd->regs + AMD7930_BBRB); - if (amd->c_left > 0) { - *(amd->c_cur++) = byte; - amd->c_left--; - if (amd->c_left == 0) - elapsed |= AMD7930_FLAG_CAPTURE; + scoped_guard(spinlock, &amd->lock) { + elapsed = 0; + + ir = sbus_readb(amd->regs + AMD7930_IR); + if (ir & AMR_IR_BBUF) { + u8 byte; + + if (amd->flags & AMD7930_FLAG_PLAYBACK) { + if (amd->p_left > 0) { + byte = *(amd->p_cur++); + amd->p_left--; + sbus_writeb(byte, amd->regs + AMD7930_BBTB); + if (amd->p_left == 0) + elapsed |= AMD7930_FLAG_PLAYBACK; + } else + sbus_writeb(0, amd->regs + AMD7930_BBTB); + } else if (amd->flags & AMD7930_FLAG_CAPTURE) { + byte = sbus_readb(amd->regs + AMD7930_BBRB); + if (amd->c_left > 0) { + *(amd->c_cur++) = byte; + amd->c_left--; + if (amd->c_left == 0) + elapsed |= AMD7930_FLAG_CAPTURE; + } } } } - spin_unlock(&amd->lock); if (elapsed & AMD7930_FLAG_PLAYBACK) snd_pcm_period_elapsed(amd->playback_substream); @@ -536,10 +526,9 @@ static irqreturn_t snd_amd7930_interrupt(int irq, void *dev_id) static int snd_amd7930_trigger(struct snd_amd7930 *amd, unsigned int flag, int cmd) { - unsigned long flags; int result = 0; - spin_lock_irqsave(&amd->lock, flags); + guard(spinlock_irqsave)(&amd->lock); if (cmd == SNDRV_PCM_TRIGGER_START) { if (!(amd->flags & flag)) { amd->flags |= flag; @@ -559,7 +548,6 @@ static int snd_amd7930_trigger(struct snd_amd7930 *amd, unsigned int flag, int c } else { result = -EINVAL; } - spin_unlock_irqrestore(&amd->lock, flags); return result; } @@ -583,10 +571,9 @@ static int snd_amd7930_playback_prepare(struct snd_pcm_substream *substream) struct snd_amd7930 *amd = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; unsigned int size = snd_pcm_lib_buffer_bytes(substream); - unsigned long flags; u8 new_mmr1; - spin_lock_irqsave(&amd->lock, flags); + guard(spinlock_irqsave)(&amd->lock); amd->flags |= AMD7930_FLAG_PLAYBACK; @@ -605,8 +592,6 @@ static int snd_amd7930_playback_prepare(struct snd_pcm_substream *substream) __amd7930_update_map(amd); } - spin_unlock_irqrestore(&amd->lock, flags); - return 0; } @@ -615,10 +600,9 @@ static int snd_amd7930_capture_prepare(struct snd_pcm_substream *substream) struct snd_amd7930 *amd = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; unsigned int size = snd_pcm_lib_buffer_bytes(substream); - unsigned long flags; u8 new_mmr1; - spin_lock_irqsave(&amd->lock, flags); + guard(spinlock_irqsave)(&amd->lock); amd->flags |= AMD7930_FLAG_CAPTURE; @@ -637,8 +621,6 @@ static int snd_amd7930_capture_prepare(struct snd_pcm_substream *substream) __amd7930_update_map(amd); } - spin_unlock_irqrestore(&amd->lock, flags); - return 0; } @@ -722,23 +704,9 @@ static int snd_amd7930_capture_close(struct snd_pcm_substream *substream) return 0; } -static int snd_amd7930_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_amd7930_hw_free(struct snd_pcm_substream *substream) -{ - return snd_pcm_lib_free_pages(substream); -} - static const struct snd_pcm_ops snd_amd7930_playback_ops = { .open = snd_amd7930_playback_open, .close = snd_amd7930_playback_close, - .ioctl = snd_pcm_lib_ioctl, - .hw_params = snd_amd7930_hw_params, - .hw_free = snd_amd7930_hw_free, .prepare = snd_amd7930_playback_prepare, .trigger = snd_amd7930_playback_trigger, .pointer = snd_amd7930_playback_pointer, @@ -747,9 +715,6 @@ static const struct snd_pcm_ops snd_amd7930_playback_ops = { static const struct snd_pcm_ops snd_amd7930_capture_ops = { .open = snd_amd7930_capture_open, .close = snd_amd7930_capture_close, - .ioctl = snd_pcm_lib_ioctl, - .hw_params = snd_amd7930_hw_params, - .hw_free = snd_amd7930_hw_free, .prepare = snd_amd7930_capture_prepare, .trigger = snd_amd7930_capture_trigger, .pointer = snd_amd7930_capture_pointer, @@ -772,12 +737,11 @@ static int snd_amd7930_pcm(struct snd_amd7930 *amd) pcm->private_data = amd; pcm->info_flags = 0; - strcpy(pcm->name, amd->card->shortname); + strscpy(pcm->name, amd->card->shortname); amd->pcm = pcm; - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, - snd_dma_continuous_data(GFP_KERNEL), - 64*1024, 64*1024); + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, + NULL, 64*1024, 64*1024); return 0; } @@ -823,7 +787,6 @@ static int snd_amd7930_get_volume(struct snd_kcontrol *kctl, struct snd_ctl_elem static int snd_amd7930_put_volume(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol) { struct snd_amd7930 *amd = snd_kcontrol_chip(kctl); - unsigned long flags; int type = kctl->private_value; int *swval, change; @@ -840,7 +803,7 @@ static int snd_amd7930_put_volume(struct snd_kcontrol *kctl, struct snd_ctl_elem break; } - spin_lock_irqsave(&amd->lock, flags); + guard(spinlock_irqsave)(&amd->lock); if (*swval != ucontrol->value.integer.value[0]) { *swval = ucontrol->value.integer.value[0] & 0xff; @@ -849,12 +812,10 @@ static int snd_amd7930_put_volume(struct snd_kcontrol *kctl, struct snd_ctl_elem } else change = 0; - spin_unlock_irqrestore(&amd->lock, flags); - return change; } -static struct snd_kcontrol_new amd7930_controls[] = { +static const struct snd_kcontrol_new amd7930_controls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Monitor Volume", @@ -893,7 +854,7 @@ static int snd_amd7930_mixer(struct snd_amd7930 *amd) return -EINVAL; card = amd->card; - strcpy(card->mixername, card->shortname); + strscpy(card->mixername, card->shortname); for (idx = 0; idx < ARRAY_SIZE(amd7930_controls); idx++) { if ((err = snd_ctl_add(card, @@ -929,7 +890,7 @@ static int snd_amd7930_dev_free(struct snd_device *device) return snd_amd7930_free(amd); } -static struct snd_device_ops snd_amd7930_dev_ops = { +static const struct snd_device_ops snd_amd7930_dev_ops = { .dev_free = snd_amd7930_dev_free, }; @@ -939,7 +900,6 @@ static int snd_amd7930_create(struct snd_card *card, struct snd_amd7930 **ramd) { struct snd_amd7930 *amd; - unsigned long flags; int err; *ramd = NULL; @@ -954,8 +914,8 @@ static int snd_amd7930_create(struct snd_card *card, amd->regs = of_ioremap(&op->resource[0], 0, resource_size(&op->resource[0]), "amd7930"); if (!amd->regs) { - snd_printk(KERN_ERR - "amd7930-%d: Unable to map chip registers.\n", dev); + dev_err(card->dev, + "amd7930-%d: Unable to map chip registers.\n", dev); kfree(amd); return -EIO; } @@ -964,8 +924,8 @@ static int snd_amd7930_create(struct snd_card *card, if (request_irq(irq, snd_amd7930_interrupt, IRQF_SHARED, "amd7930", amd)) { - snd_printk(KERN_ERR "amd7930-%d: Unable to grab IRQ %d\n", - dev, irq); + dev_err(card->dev, "amd7930-%d: Unable to grab IRQ %d\n", + dev, irq); snd_amd7930_free(amd); return -EBUSY; } @@ -973,28 +933,27 @@ static int snd_amd7930_create(struct snd_card *card, amd7930_enable_ints(amd); - spin_lock_irqsave(&amd->lock, flags); - - amd->rgain = 128; - amd->pgain = 200; - amd->mgain = 0; + scoped_guard(spinlock_irqsave, &amd->lock) { + amd->rgain = 128; + amd->pgain = 200; + amd->mgain = 0; - memset(&amd->map, 0, sizeof(amd->map)); - amd->map.mmr1 = (AM_MAP_MMR1_GX | AM_MAP_MMR1_GER | - AM_MAP_MMR1_GR | AM_MAP_MMR1_STG); - amd->map.mmr2 = (AM_MAP_MMR2_LS | AM_MAP_MMR2_AINB); + memset(&amd->map, 0, sizeof(amd->map)); + amd->map.mmr1 = (AM_MAP_MMR1_GX | AM_MAP_MMR1_GER | + AM_MAP_MMR1_GR | AM_MAP_MMR1_STG); + amd->map.mmr2 = (AM_MAP_MMR2_LS | AM_MAP_MMR2_AINB); - __amd7930_update_map(amd); - - /* Always MUX audio (Ba) to channel Bb. */ - sbus_writeb(AMR_MUX_MCR1, amd->regs + AMD7930_CR); - sbus_writeb(AM_MUX_CHANNEL_Ba | (AM_MUX_CHANNEL_Bb << 4), - amd->regs + AMD7930_DR); + __amd7930_update_map(amd); - spin_unlock_irqrestore(&amd->lock, flags); + /* Always MUX audio (Ba) to channel Bb. */ + sbus_writeb(AMR_MUX_MCR1, amd->regs + AMD7930_CR); + sbus_writeb(AM_MUX_CHANNEL_Ba | (AM_MUX_CHANNEL_Bb << 4), + amd->regs + AMD7930_DR); + } - if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, - amd, &snd_amd7930_dev_ops)) < 0) { + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, + amd, &snd_amd7930_dev_ops); + if (err < 0) { snd_amd7930_free(amd); return err; } @@ -1025,8 +984,8 @@ static int amd7930_sbus_probe(struct platform_device *op) if (err < 0) return err; - strcpy(card->driver, "AMD7930"); - strcpy(card->shortname, "Sun AMD7930"); + strscpy(card->driver, "AMD7930"); + strscpy(card->shortname, "Sun AMD7930"); sprintf(card->longname, "%s at 0x%02lx:0x%08Lx, irq %d", card->shortname, rp->flags & 0xffL, @@ -1037,13 +996,16 @@ static int amd7930_sbus_probe(struct platform_device *op) irq, dev_num, &amd)) < 0) goto out_err; - if ((err = snd_amd7930_pcm(amd)) < 0) + err = snd_amd7930_pcm(amd); + if (err < 0) goto out_err; - if ((err = snd_amd7930_mixer(amd)) < 0) + err = snd_amd7930_mixer(amd); + if (err < 0) goto out_err; - if ((err = snd_card_register(card)) < 0) + err = snd_card_register(card); + if (err < 0) goto out_err; amd->next = amd7930_list; |
