2019-05-27 14:55:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
|
|
|
|
*
|
|
|
|
* Routines for control of EMU WaveTable chip
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/slab.h>
|
2005-06-23 15:09:02 +08:00
|
|
|
#include <linux/string.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/emux_synth.h>
|
|
|
|
#include <linux/init.h>
|
2011-07-16 00:38:28 +08:00
|
|
|
#include <linux/module.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "emux_voice.h"
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Takashi Iwai");
|
|
|
|
MODULE_DESCRIPTION("Routines for control of EMU WaveTable chip");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create a new hardware dependent device for Emu8000/Emu10k1
|
|
|
|
*/
|
2005-11-17 21:24:47 +08:00
|
|
|
int snd_emux_new(struct snd_emux **remu)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:24:47 +08:00
|
|
|
struct snd_emux *emu;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
*remu = NULL;
|
[ALSA] Replace with kzalloc() - others
Documentation,SA11xx UDA1341 driver,Generic drivers,MPU401 UART,OPL3
OPL4,Digigram VX core,I2C cs8427,I2C lib core,I2C tea6330t,L3 drivers
AK4114 receiver,AK4117 receiver,PDAudioCF driver,PPC PMAC driver
SPARC AMD7930 driver,SPARC cs4231 driver,Synth,Common EMU synth
USB generic driver,USB USX2Y
Replace kcalloc(1,..) with kzalloc().
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2005-09-09 20:22:34 +08:00
|
|
|
emu = kzalloc(sizeof(*emu), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (emu == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
spin_lock_init(&emu->voice_lock);
|
2006-01-16 23:31:42 +08:00
|
|
|
mutex_init(&emu->register_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
emu->client = -1;
|
2017-06-09 20:06:46 +08:00
|
|
|
#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
|
2005-04-17 06:20:36 +08:00
|
|
|
emu->oss_synth = NULL;
|
|
|
|
#endif
|
|
|
|
emu->max_voices = 0;
|
|
|
|
emu->use_time = 0;
|
|
|
|
|
2017-10-24 23:34:40 +08:00
|
|
|
timer_setup(&emu->tlist, snd_emux_timer_callback, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
emu->timer_active = 0;
|
|
|
|
|
|
|
|
*remu = emu;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:40 +08:00
|
|
|
EXPORT_SYMBOL(snd_emux_new);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
2005-11-17 21:24:47 +08:00
|
|
|
static int sf_sample_new(void *private_data, struct snd_sf_sample *sp,
|
|
|
|
struct snd_util_memhdr *hdr,
|
|
|
|
const void __user *buf, long count)
|
2005-11-17 17:50:13 +08:00
|
|
|
{
|
2005-11-17 21:24:47 +08:00
|
|
|
struct snd_emux *emu = private_data;
|
2005-11-17 17:50:13 +08:00
|
|
|
return emu->ops.sample_new(emu, sp, hdr, buf, count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:24:47 +08:00
|
|
|
static int sf_sample_free(void *private_data, struct snd_sf_sample *sp,
|
|
|
|
struct snd_util_memhdr *hdr)
|
2005-11-17 17:50:13 +08:00
|
|
|
{
|
2005-11-17 21:24:47 +08:00
|
|
|
struct snd_emux *emu = private_data;
|
2005-11-17 17:50:13 +08:00
|
|
|
return emu->ops.sample_free(emu, sp, hdr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sf_sample_reset(void *private_data)
|
|
|
|
{
|
2005-11-17 21:24:47 +08:00
|
|
|
struct snd_emux *emu = private_data;
|
2005-11-17 17:50:13 +08:00
|
|
|
emu->ops.sample_reset(emu);
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:24:47 +08:00
|
|
|
int snd_emux_register(struct snd_emux *emu, struct snd_card *card, int index, char *name)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err;
|
2005-11-17 21:24:47 +08:00
|
|
|
struct snd_sf_callback sf_cb;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-08 23:12:47 +08:00
|
|
|
if (snd_BUG_ON(!emu->hw || emu->max_voices <= 0))
|
|
|
|
return -EINVAL;
|
|
|
|
if (snd_BUG_ON(!card || !name))
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
emu->card = card;
|
2005-06-23 15:09:02 +08:00
|
|
|
emu->name = kstrdup(name, GFP_KERNEL);
|
2005-11-17 21:24:47 +08:00
|
|
|
emu->voices = kcalloc(emu->max_voices, sizeof(struct snd_emux_voice),
|
|
|
|
GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (emu->voices == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* create soundfont list */
|
|
|
|
memset(&sf_cb, 0, sizeof(sf_cb));
|
|
|
|
sf_cb.private_data = emu;
|
2005-11-17 17:50:13 +08:00
|
|
|
if (emu->ops.sample_new)
|
|
|
|
sf_cb.sample_new = sf_sample_new;
|
|
|
|
if (emu->ops.sample_free)
|
|
|
|
sf_cb.sample_free = sf_sample_free;
|
|
|
|
if (emu->ops.sample_reset)
|
|
|
|
sf_cb.sample_reset = sf_sample_reset;
|
2005-04-17 06:20:36 +08:00
|
|
|
emu->sflist = snd_sf_new(&sf_cb, emu->memhdr);
|
|
|
|
if (emu->sflist == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if ((err = snd_emux_init_hwdep(emu)) < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
snd_emux_init_voices(emu);
|
|
|
|
|
|
|
|
snd_emux_init_seq(emu, card, index);
|
2017-06-09 20:06:46 +08:00
|
|
|
#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_emux_init_seq_oss(emu);
|
|
|
|
#endif
|
|
|
|
snd_emux_init_virmidi(emu, card);
|
|
|
|
|
|
|
|
snd_emux_proc_init(emu, card, index);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:40 +08:00
|
|
|
EXPORT_SYMBOL(snd_emux_register);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
2005-11-17 21:24:47 +08:00
|
|
|
int snd_emux_free(struct snd_emux *emu)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (! emu)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&emu->voice_lock, flags);
|
|
|
|
if (emu->timer_active)
|
|
|
|
del_timer(&emu->tlist);
|
|
|
|
spin_unlock_irqrestore(&emu->voice_lock, flags);
|
|
|
|
|
|
|
|
snd_emux_proc_free(emu);
|
|
|
|
snd_emux_delete_virmidi(emu);
|
2017-06-09 20:06:46 +08:00
|
|
|
#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_emux_detach_seq_oss(emu);
|
|
|
|
#endif
|
|
|
|
snd_emux_detach_seq(emu);
|
|
|
|
snd_emux_delete_hwdep(emu);
|
2015-01-04 01:28:21 +08:00
|
|
|
snd_sf_free(emu->sflist);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(emu->voices);
|
|
|
|
kfree(emu->name);
|
|
|
|
kfree(emu);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(snd_emux_free);
|