diff options
Diffstat (limited to 'sound/isa/sb/emu8000.c')
| -rw-r--r-- | sound/isa/sb/emu8000.c | 214 |
1 files changed, 77 insertions, 137 deletions
diff --git a/sound/isa/sb/emu8000.c b/sound/isa/sb/emu8000.c index d56973b770c7..12c296ee34ec 100644 --- a/sound/isa/sb/emu8000.c +++ b/sound/isa/sb/emu8000.c @@ -1,23 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) by Jaroslav Kysela <perex@perex.cz> * and (c) 1999 Steve Ratcliffe <steve@parabola.demon.co.uk> * Copyright (C) 1999-2000 Takashi Iwai <tiwai@suse.de> * * Routines for control of EMU8000 chip - * - * 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/wait.h> @@ -27,6 +14,7 @@ #include <linux/export.h> #include <linux/delay.h> #include <linux/io.h> +#include <linux/string.h> #include <sound/core.h> #include <sound/emu8000.h> #include <sound/emu8000_reg.h> @@ -47,60 +35,49 @@ /* Write a word */ void snd_emu8000_poke(struct snd_emu8000 *emu, unsigned int port, unsigned int reg, unsigned int val) { - unsigned long flags; - spin_lock_irqsave(&emu->reg_lock, flags); + guard(spinlock_irqsave)(&emu->reg_lock); if (reg != emu->last_reg) { outw((unsigned short)reg, EMU8000_PTR(emu)); /* Set register */ emu->last_reg = reg; } outw((unsigned short)val, port); /* Send data */ - spin_unlock_irqrestore(&emu->reg_lock, flags); } /* Read a word */ unsigned short snd_emu8000_peek(struct snd_emu8000 *emu, unsigned int port, unsigned int reg) { - unsigned short res; - unsigned long flags; - spin_lock_irqsave(&emu->reg_lock, flags); + guard(spinlock_irqsave)(&emu->reg_lock); if (reg != emu->last_reg) { outw((unsigned short)reg, EMU8000_PTR(emu)); /* Set register */ emu->last_reg = reg; } - res = inw(port); /* Read data */ - spin_unlock_irqrestore(&emu->reg_lock, flags); - return res; + return inw(port); /* Read data */ } /* Write a double word */ void snd_emu8000_poke_dw(struct snd_emu8000 *emu, unsigned int port, unsigned int reg, unsigned int val) { - unsigned long flags; - spin_lock_irqsave(&emu->reg_lock, flags); + guard(spinlock_irqsave)(&emu->reg_lock); if (reg != emu->last_reg) { outw((unsigned short)reg, EMU8000_PTR(emu)); /* Set register */ emu->last_reg = reg; } outw((unsigned short)val, port); /* Send low word of data */ outw((unsigned short)(val>>16), port+2); /* Send high word of data */ - spin_unlock_irqrestore(&emu->reg_lock, flags); } /* Read a double word */ unsigned int snd_emu8000_peek_dw(struct snd_emu8000 *emu, unsigned int port, unsigned int reg) { unsigned short low; - unsigned int res; - unsigned long flags; - spin_lock_irqsave(&emu->reg_lock, flags); + + guard(spinlock_irqsave)(&emu->reg_lock); if (reg != emu->last_reg) { outw((unsigned short)reg, EMU8000_PTR(emu)); /* Set register */ emu->last_reg = reg; } low = inw(port); /* Read low word of data */ - res = low + (inw(port+2) << 16); - spin_unlock_irqrestore(&emu->reg_lock, flags); - return res; + return low + (inw(port+2) << 16); } /* @@ -173,8 +150,8 @@ snd_emu8000_detect(struct snd_emu8000 *emu) if ((EMU8000_HWCF2_READ(emu) & 0x0003) != 0x0003) return -ENODEV; - snd_printdd("EMU8000 [0x%lx]: Synth chip found\n", - emu->port1); + dev_dbg(emu->card->dev, "EMU8000 [0x%lx]: Synth chip found\n", + emu->port1); return 0; } @@ -235,7 +212,7 @@ init_dma(struct snd_emu8000 *emu) /* * initialization arrays; from ADIP */ -static unsigned short init1[128] = { +static const unsigned short init1[128] = { 0x03ff, 0x0030, 0x07ff, 0x0130, 0x0bff, 0x0230, 0x0fff, 0x0330, 0x13ff, 0x0430, 0x17ff, 0x0530, 0x1bff, 0x0630, 0x1fff, 0x0730, 0x23ff, 0x0830, 0x27ff, 0x0930, 0x2bff, 0x0a30, 0x2fff, 0x0b30, @@ -257,7 +234,7 @@ static unsigned short init1[128] = { 0xf3ff, 0x0c30, 0xf7ff, 0x0d30, 0xfbff, 0x0e30, 0xffff, 0x0f30, }; -static unsigned short init2[128] = { +static const unsigned short init2[128] = { 0x03ff, 0x8030, 0x07ff, 0x8130, 0x0bff, 0x8230, 0x0fff, 0x8330, 0x13ff, 0x8430, 0x17ff, 0x8530, 0x1bff, 0x8630, 0x1fff, 0x8730, 0x23ff, 0x8830, 0x27ff, 0x8930, 0x2bff, 0x8a30, 0x2fff, 0x8b30, @@ -279,7 +256,7 @@ static unsigned short init2[128] = { 0xf3ff, 0x8c30, 0xf7ff, 0x8d30, 0xfbff, 0x8e30, 0xffff, 0x8f30, }; -static unsigned short init3[128] = { +static const unsigned short init3[128] = { 0x0C10, 0x8470, 0x14FE, 0xB488, 0x167F, 0xA470, 0x18E7, 0x84B5, 0x1B6E, 0x842A, 0x1F1D, 0x852A, 0x0DA3, 0x8F7C, 0x167E, 0xF254, 0x0000, 0x842A, 0x0001, 0x852A, 0x18E6, 0x8BAA, 0x1B6D, 0xF234, @@ -301,7 +278,7 @@ static unsigned short init3[128] = { 0x1342, 0xD36E, 0x3EC7, 0xB3FF, 0x0000, 0x8365, 0x1420, 0x9570, }; -static unsigned short init4[128] = { +static const unsigned short init4[128] = { 0x0C10, 0x8470, 0x14FE, 0xB488, 0x167F, 0xA470, 0x18E7, 0x84B5, 0x1B6E, 0x842A, 0x1F1D, 0x852A, 0x0DA3, 0x0F7C, 0x167E, 0x7254, 0x0000, 0x842A, 0x0001, 0x852A, 0x18E6, 0x0BAA, 0x1B6D, 0x7234, @@ -328,10 +305,10 @@ static unsigned short init4[128] = { * is meant to work */ static void -send_array(struct snd_emu8000 *emu, unsigned short *data, int size) +send_array(struct snd_emu8000 *emu, const unsigned short *data, int size) { int i; - unsigned short *p; + const unsigned short *p; p = data; for (i = 0; i < size; i++, p++) @@ -468,8 +445,6 @@ skip_detect: /*exported*/ void snd_emu8000_init_fm(struct snd_emu8000 *emu) { - unsigned long flags; - /* Initialize the last two channels for DRAM refresh and producing the reverb and chorus effects for Yamaha OPL-3 synthesizer */ @@ -491,12 +466,12 @@ snd_emu8000_init_fm(struct snd_emu8000 *emu) snd_emu8000_poke((emu), EMU8000_DATA0(emu), EMU8000_CMD(1, (30)), 0); - spin_lock_irqsave(&emu->reg_lock, flags); - while (!(inw(EMU8000_PTR(emu)) & 0x1000)) - ; - while ((inw(EMU8000_PTR(emu)) & 0x1000)) - ; - spin_unlock_irqrestore(&emu->reg_lock, flags); + scoped_guard(spinlock_irqsave, &emu->reg_lock) { + while (!(inw(EMU8000_PTR(emu)) & 0x1000)) + ; + while ((inw(EMU8000_PTR(emu)) & 0x1000)) + ; + } snd_emu8000_poke((emu), EMU8000_DATA0(emu), EMU8000_CMD(1, (30)), 0x4828); /* this is really odd part.. */ outb(0x3C, EMU8000_PTR(emu)); @@ -561,7 +536,7 @@ snd_emu8000_init_hw(struct snd_emu8000 *emu) * Bass/Treble Equalizer *----------------------------------------------------------------*/ -static unsigned short bass_parm[12][3] = { +static const unsigned short bass_parm[12][3] = { {0xD26A, 0xD36A, 0x0000}, /* -12 dB */ {0xD25B, 0xD35B, 0x0000}, /* -8 */ {0xD24C, 0xD34C, 0x0000}, /* -6 */ @@ -576,7 +551,7 @@ static unsigned short bass_parm[12][3] = { {0xC26A, 0xC36A, 0x0002}, /* +12 dB */ }; -static unsigned short treble_parm[12][9] = { +static const unsigned short treble_parm[12][9] = { {0x821E, 0xC26A, 0x031E, 0xC36A, 0x021E, 0xD208, 0x831E, 0xD308, 0x0001}, /* -12 dB */ {0x821E, 0xC25B, 0x031E, 0xC35B, 0x021E, 0xD208, 0x831E, 0xD308, 0x0001}, {0x821E, 0xC24C, 0x031E, 0xC34C, 0x021E, 0xD208, 0x831E, 0xD308, 0x0001}, @@ -665,7 +640,7 @@ snd_emu8000_load_chorus_fx(struct snd_emu8000 *emu, int mode, const void __user { struct soundfont_chorus_fx rec; if (mode < SNDRV_EMU8000_CHORUS_PREDEFINED || mode >= SNDRV_EMU8000_CHORUS_NUMBERS) { - snd_printk(KERN_WARNING "invalid chorus mode %d for uploading\n", mode); + dev_warn(emu->card->dev, "invalid chorus mode %d for uploading\n", mode); return -EINVAL; } if (len < (long)sizeof(rec) || copy_from_user(&rec, buf, sizeof(rec))) @@ -793,7 +768,7 @@ snd_emu8000_load_reverb_fx(struct snd_emu8000 *emu, int mode, const void __user struct soundfont_reverb_fx rec; if (mode < SNDRV_EMU8000_REVERB_PREDEFINED || mode >= SNDRV_EMU8000_REVERB_NUMBERS) { - snd_printk(KERN_WARNING "invalid reverb mode %d for uploading\n", mode); + dev_warn(emu->card->dev, "invalid reverb mode %d for uploading\n", mode); return -EINVAL; } if (len < (long)sizeof(rec) || copy_from_user(&rec, buf, sizeof(rec))) @@ -850,25 +825,24 @@ static int mixer_bass_treble_get(struct snd_kcontrol *kcontrol, struct snd_ctl_e static int mixer_bass_treble_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu8000 *emu = snd_kcontrol_chip(kcontrol); - unsigned long flags; int change; unsigned short val1; val1 = ucontrol->value.integer.value[0] % 12; - spin_lock_irqsave(&emu->control_lock, flags); - if (kcontrol->private_value) { - change = val1 != emu->treble_level; - emu->treble_level = val1; - } else { - change = val1 != emu->bass_level; - emu->bass_level = val1; + scoped_guard(spinlock_irqsave, &emu->control_lock) { + if (kcontrol->private_value) { + change = val1 != emu->treble_level; + emu->treble_level = val1; + } else { + change = val1 != emu->bass_level; + emu->bass_level = val1; + } } - spin_unlock_irqrestore(&emu->control_lock, flags); snd_emu8000_update_equalizer(emu); return change; } -static struct snd_kcontrol_new mixer_bass_control = +static const struct snd_kcontrol_new mixer_bass_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Synth Tone Control - Bass", @@ -878,7 +852,7 @@ static struct snd_kcontrol_new mixer_bass_control = .private_value = 0, }; -static struct snd_kcontrol_new mixer_treble_control = +static const struct snd_kcontrol_new mixer_treble_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Synth Tone Control - Treble", @@ -911,21 +885,20 @@ static int mixer_chorus_reverb_get(struct snd_kcontrol *kcontrol, struct snd_ctl static int mixer_chorus_reverb_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu8000 *emu = snd_kcontrol_chip(kcontrol); - unsigned long flags; int change; unsigned short val1; - spin_lock_irqsave(&emu->control_lock, flags); - if (kcontrol->private_value) { - val1 = ucontrol->value.integer.value[0] % SNDRV_EMU8000_CHORUS_NUMBERS; - change = val1 != emu->chorus_mode; - emu->chorus_mode = val1; - } else { - val1 = ucontrol->value.integer.value[0] % SNDRV_EMU8000_REVERB_NUMBERS; - change = val1 != emu->reverb_mode; - emu->reverb_mode = val1; + scoped_guard(spinlock_irqsave, &emu->control_lock) { + if (kcontrol->private_value) { + val1 = ucontrol->value.integer.value[0] % SNDRV_EMU8000_CHORUS_NUMBERS; + change = val1 != emu->chorus_mode; + emu->chorus_mode = val1; + } else { + val1 = ucontrol->value.integer.value[0] % SNDRV_EMU8000_REVERB_NUMBERS; + change = val1 != emu->reverb_mode; + emu->reverb_mode = val1; + } } - spin_unlock_irqrestore(&emu->control_lock, flags); if (change) { if (kcontrol->private_value) snd_emu8000_update_chorus_mode(emu); @@ -935,7 +908,7 @@ static int mixer_chorus_reverb_put(struct snd_kcontrol *kcontrol, struct snd_ctl return change; } -static struct snd_kcontrol_new mixer_chorus_mode_control = +static const struct snd_kcontrol_new mixer_chorus_mode_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Chorus Mode", @@ -945,7 +918,7 @@ static struct snd_kcontrol_new mixer_chorus_mode_control = .private_value = 1, }; -static struct snd_kcontrol_new mixer_reverb_mode_control = +static const struct snd_kcontrol_new mixer_reverb_mode_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Reverb Mode", @@ -978,26 +951,25 @@ static int mixer_fm_depth_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem static int mixer_fm_depth_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu8000 *emu = snd_kcontrol_chip(kcontrol); - unsigned long flags; int change; unsigned short val1; val1 = ucontrol->value.integer.value[0] % 256; - spin_lock_irqsave(&emu->control_lock, flags); - if (kcontrol->private_value) { - change = val1 != emu->fm_chorus_depth; - emu->fm_chorus_depth = val1; - } else { - change = val1 != emu->fm_reverb_depth; - emu->fm_reverb_depth = val1; + scoped_guard(spinlock_irqsave, &emu->control_lock) { + if (kcontrol->private_value) { + change = val1 != emu->fm_chorus_depth; + emu->fm_chorus_depth = val1; + } else { + change = val1 != emu->fm_reverb_depth; + emu->fm_reverb_depth = val1; + } } - spin_unlock_irqrestore(&emu->control_lock, flags); if (change) snd_emu8000_init_fm(emu); return change; } -static struct snd_kcontrol_new mixer_fm_chorus_depth_control = +static const struct snd_kcontrol_new mixer_fm_chorus_depth_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "FM Chorus Depth", @@ -1007,7 +979,7 @@ static struct snd_kcontrol_new mixer_fm_chorus_depth_control = .private_value = 1, }; -static struct snd_kcontrol_new mixer_fm_reverb_depth_control = +static const struct snd_kcontrol_new mixer_fm_reverb_depth_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "FM Reverb Depth", @@ -1018,7 +990,7 @@ static struct snd_kcontrol_new mixer_fm_reverb_depth_control = }; -static struct snd_kcontrol_new *mixer_defs[EMU8000_NUM_CONTROLS] = { +static const struct snd_kcontrol_new *mixer_defs[EMU8000_NUM_CONTROLS] = { &mixer_bass_control, &mixer_treble_control, &mixer_chorus_mode_control, @@ -1033,6 +1005,7 @@ static struct snd_kcontrol_new *mixer_defs[EMU8000_NUM_CONTROLS] = { static int snd_emu8000_create_mixer(struct snd_card *card, struct snd_emu8000 *emu) { + struct snd_kcontrol *kctl; int i, err = 0; if (snd_BUG_ON(!emu || !card)) @@ -1042,42 +1015,20 @@ snd_emu8000_create_mixer(struct snd_card *card, struct snd_emu8000 *emu) memset(emu->controls, 0, sizeof(emu->controls)); for (i = 0; i < EMU8000_NUM_CONTROLS; i++) { - if ((err = snd_ctl_add(card, emu->controls[i] = snd_ctl_new1(mixer_defs[i], emu))) < 0) + kctl = snd_ctl_new1(mixer_defs[i], emu); + err = snd_ctl_add(card, kctl); + if (err < 0) goto __error; + emu->controls[i] = kctl; } return 0; __error: - for (i = 0; i < EMU8000_NUM_CONTROLS; i++) { - down_write(&card->controls_rwsem); - if (emu->controls[i]) - snd_ctl_remove(card, emu->controls[i]); - up_write(&card->controls_rwsem); - } + for (i = 0; i < EMU8000_NUM_CONTROLS; i++) + snd_ctl_remove(card, emu->controls[i]); return err; } - -/* - * free resources - */ -static int snd_emu8000_free(struct snd_emu8000 *hw) -{ - release_and_free_resource(hw->res_port1); - release_and_free_resource(hw->res_port2); - release_and_free_resource(hw->res_port3); - kfree(hw); - return 0; -} - -/* - */ -static int snd_emu8000_dev_free(struct snd_device *device) -{ - struct snd_emu8000 *hw = device->device_data; - return snd_emu8000_free(hw); -} - /* * initialize and register emu8000 synth device. */ @@ -1088,9 +1039,6 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports, struct snd_seq_device *awe; struct snd_emu8000 *hw; int err; - static struct snd_device_ops ops = { - .dev_free = snd_emu8000_dev_free, - }; if (awe_ret) *awe_ret = NULL; @@ -1098,7 +1046,7 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports, if (seq_ports <= 0) return 0; - hw = kzalloc(sizeof(*hw), GFP_KERNEL); + hw = devm_kzalloc(card->dev, sizeof(*hw), GFP_KERNEL); if (hw == NULL) return -ENOMEM; spin_lock_init(&hw->reg_lock); @@ -1106,11 +1054,11 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports, hw->port1 = port; hw->port2 = port + 0x400; hw->port3 = port + 0x800; - if (!(hw->res_port1 = request_region(hw->port1, 4, "Emu8000-1")) || - !(hw->res_port2 = request_region(hw->port2, 4, "Emu8000-2")) || - !(hw->res_port3 = request_region(hw->port3, 4, "Emu8000-3"))) { - snd_printk(KERN_ERR "sbawe: can't grab ports 0x%lx, 0x%lx, 0x%lx\n", hw->port1, hw->port2, hw->port3); - snd_emu8000_free(hw); + if (!devm_request_region(card->dev, hw->port1, 4, "Emu8000-1") || + !devm_request_region(card->dev, hw->port2, 4, "Emu8000-2") || + !devm_request_region(card->dev, hw->port3, 4, "Emu8000-3")) { + dev_err(card->dev, "sbawe: can't grab ports 0x%lx, 0x%lx, 0x%lx\n", + hw->port1, hw->port2, hw->port3); return -EBUSY; } hw->mem_size = 0; @@ -1123,25 +1071,17 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports, hw->fm_chorus_depth = 0; hw->fm_reverb_depth = 0; - if (snd_emu8000_detect(hw) < 0) { - snd_emu8000_free(hw); + if (snd_emu8000_detect(hw) < 0) return -ENODEV; - } snd_emu8000_init_hw(hw); - if ((err = snd_emu8000_create_mixer(card, hw)) < 0) { - snd_emu8000_free(hw); - return err; - } - - if ((err = snd_device_new(card, SNDRV_DEV_CODEC, hw, &ops)) < 0) { - snd_emu8000_free(hw); + err = snd_emu8000_create_mixer(card, hw); + if (err < 0) return err; - } #if IS_ENABLED(CONFIG_SND_SEQUENCER) if (snd_seq_device_new(card, index, SNDRV_SEQ_DEV_ID_EMU8000, sizeof(struct snd_emu8000*), &awe) >= 0) { - strcpy(awe->name, "EMU-8000"); + strscpy(awe->name, "EMU-8000"); *(struct snd_emu8000 **)SNDRV_SEQ_DEVICE_ARGPTR(awe) = hw; } #else |
