aboutsummaryrefslogtreecommitdiff
path: root/sound/drivers/opl3/opl3_oss.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/drivers/opl3/opl3_oss.c')
-rw-r--r--sound/drivers/opl3/opl3_oss.c227
1 files changed, 78 insertions, 149 deletions
diff --git a/sound/drivers/opl3/opl3_oss.c b/sound/drivers/opl3/opl3_oss.c
index 21a2b409d6d..c1cb249acfa 100644
--- a/sound/drivers/opl3/opl3_oss.c
+++ b/sound/drivers/opl3/opl3_oss.c
@@ -18,14 +18,14 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include <linux/export.h>
#include "opl3_voice.h"
-#include <linux/slab.h>
-static int snd_opl3_open_seq_oss(snd_seq_oss_arg_t *arg, void *closure);
-static int snd_opl3_close_seq_oss(snd_seq_oss_arg_t *arg);
-static int snd_opl3_ioctl_seq_oss(snd_seq_oss_arg_t *arg, unsigned int cmd, unsigned long ioarg);
-static int snd_opl3_load_patch_seq_oss(snd_seq_oss_arg_t *arg, int format, const char __user *buf, int offs, int count);
-static int snd_opl3_reset_seq_oss(snd_seq_oss_arg_t *arg);
+static int snd_opl3_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure);
+static int snd_opl3_close_seq_oss(struct snd_seq_oss_arg *arg);
+static int snd_opl3_ioctl_seq_oss(struct snd_seq_oss_arg *arg, unsigned int cmd, unsigned long ioarg);
+static int snd_opl3_load_patch_seq_oss(struct snd_seq_oss_arg *arg, int format, const char __user *buf, int offs, int count);
+static int snd_opl3_reset_seq_oss(struct snd_seq_oss_arg *arg);
/* */
@@ -43,9 +43,9 @@ static inline void snd_leave_user(mm_segment_t fs)
/* operators */
-extern snd_midi_op_t opl3_ops;
+extern struct snd_midi_op opl3_ops;
-static snd_seq_oss_callback_t oss_callback = {
+static struct snd_seq_oss_callback oss_callback = {
.owner = THIS_MODULE,
.open = snd_opl3_open_seq_oss,
.close = snd_opl3_close_seq_oss,
@@ -54,10 +54,10 @@ static snd_seq_oss_callback_t oss_callback = {
.reset = snd_opl3_reset_seq_oss,
};
-static int snd_opl3_oss_event_input(snd_seq_event_t *ev, int direct,
+static int snd_opl3_oss_event_input(struct snd_seq_event *ev, int direct,
void *private_data, int atomic, int hop)
{
- opl3_t *opl3 = private_data;
+ struct snd_opl3 *opl3 = private_data;
if (ev->type != SNDRV_SEQ_EVENT_OSS)
snd_midi_process_event(&opl3_ops, ev, opl3->oss_chset);
@@ -68,14 +68,14 @@ static int snd_opl3_oss_event_input(snd_seq_event_t *ev, int direct,
static void snd_opl3_oss_free_port(void *private_data)
{
- opl3_t *opl3 = private_data;
+ struct snd_opl3 *opl3 = private_data;
snd_midi_channel_free_set(opl3->oss_chset);
}
-static int snd_opl3_oss_create_port(opl3_t * opl3)
+static int snd_opl3_oss_create_port(struct snd_opl3 * opl3)
{
- snd_seq_port_callback_t callbacks;
+ struct snd_seq_port_callback callbacks;
char name[32];
int voices, opl_ver;
@@ -100,12 +100,15 @@ static int snd_opl3_oss_create_port(opl3_t * opl3)
SNDRV_SEQ_PORT_CAP_WRITE,
SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |
SNDRV_SEQ_PORT_TYPE_MIDI_GM |
- SNDRV_SEQ_PORT_TYPE_SYNTH,
+ SNDRV_SEQ_PORT_TYPE_HARDWARE |
+ SNDRV_SEQ_PORT_TYPE_SYNTHESIZER,
voices, voices,
name);
if (opl3->oss_chset->port < 0) {
+ int port;
+ port = opl3->oss_chset->port;
snd_midi_channel_free_set(opl3->oss_chset);
- return opl3->oss_chset->port;
+ return port;
}
return 0;
}
@@ -113,13 +116,13 @@ static int snd_opl3_oss_create_port(opl3_t * opl3)
/* ------------------------------ */
/* register OSS synth */
-void snd_opl3_init_seq_oss(opl3_t *opl3, char *name)
+void snd_opl3_init_seq_oss(struct snd_opl3 *opl3, char *name)
{
- snd_seq_oss_reg_t *arg;
- snd_seq_device_t *dev;
+ struct snd_seq_oss_reg *arg;
+ struct snd_seq_device *dev;
if (snd_seq_device_new(opl3->card, 0, SNDRV_SEQ_DEV_ID_OSS,
- sizeof(snd_seq_oss_reg_t), &dev) < 0)
+ sizeof(struct snd_seq_oss_reg), &dev) < 0)
return;
opl3->oss_seq_dev = dev;
@@ -136,17 +139,17 @@ void snd_opl3_init_seq_oss(opl3_t *opl3, char *name)
arg->oper = oss_callback;
arg->private_data = opl3;
- snd_opl3_oss_create_port(opl3);
-
- /* register to OSS synth table */
- snd_device_register(opl3->card, dev);
+ if (snd_opl3_oss_create_port(opl3)) {
+ /* register to OSS synth table */
+ snd_device_register(opl3->card, dev);
+ }
}
/* unregister */
-void snd_opl3_free_seq_oss(opl3_t *opl3)
+void snd_opl3_free_seq_oss(struct snd_opl3 *opl3)
{
if (opl3->oss_seq_dev) {
- snd_device_free(opl3->card, opl3->oss_seq_dev);
+ /* The instance should have been released in prior */
opl3->oss_seq_dev = NULL;
}
}
@@ -154,12 +157,13 @@ void snd_opl3_free_seq_oss(opl3_t *opl3)
/* ------------------------------ */
/* open OSS sequencer */
-static int snd_opl3_open_seq_oss(snd_seq_oss_arg_t *arg, void *closure)
+static int snd_opl3_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure)
{
- opl3_t *opl3 = closure;
+ struct snd_opl3 *opl3 = closure;
int err;
- snd_assert(arg != NULL, return -ENXIO);
+ if (snd_BUG_ON(!arg))
+ return -ENXIO;
if ((err = snd_opl3_synth_setup(opl3)) < 0)
return err;
@@ -177,11 +181,12 @@ static int snd_opl3_open_seq_oss(snd_seq_oss_arg_t *arg, void *closure)
}
/* close OSS sequencer */
-static int snd_opl3_close_seq_oss(snd_seq_oss_arg_t *arg)
+static int snd_opl3_close_seq_oss(struct snd_seq_oss_arg *arg)
{
- opl3_t *opl3;
+ struct snd_opl3 *opl3;
- snd_assert(arg != NULL, return -ENXIO);
+ if (snd_BUG_ON(!arg))
+ return -ENXIO;
opl3 = arg->private_data;
snd_opl3_synth_cleanup(opl3);
@@ -192,143 +197,66 @@ static int snd_opl3_close_seq_oss(snd_seq_oss_arg_t *arg)
/* load patch */
-/* offsets for SBI params */
-#define AM_VIB 0
-#define KSL_LEVEL 2
-#define ATTACK_DECAY 4
-#define SUSTAIN_RELEASE 6
-#define WAVE_SELECT 8
-
-/* offset for SBI instrument */
-#define CONNECTION 10
-#define OFFSET_4OP 11
-
/* from sound_config.h */
#define SBFM_MAXINSTR 256
-static int snd_opl3_load_patch_seq_oss(snd_seq_oss_arg_t *arg, int format,
+static int snd_opl3_load_patch_seq_oss(struct snd_seq_oss_arg *arg, int format,
const char __user *buf, int offs, int count)
{
- opl3_t *opl3;
- int err = -EINVAL;
+ struct snd_opl3 *opl3;
+ struct sbi_instrument sbi;
+ char name[32];
+ int err, type;
- snd_assert(arg != NULL, return -ENXIO);
+ if (snd_BUG_ON(!arg))
+ return -ENXIO;
opl3 = arg->private_data;
- if ((format == FM_PATCH) || (format == OPL3_PATCH)) {
- struct sbi_instrument sbi;
+ if (format == FM_PATCH)
+ type = FM_PATCH_OPL2;
+ else if (format == OPL3_PATCH)
+ type = FM_PATCH_OPL3;
+ else
+ return -EINVAL;
- size_t size;
- snd_seq_instr_header_t *put;
- snd_seq_instr_data_t *data;
- fm_xinstrument_t *xinstr;
+ if (count < (int)sizeof(sbi)) {
+ snd_printk(KERN_ERR "FM Error: Patch record too short\n");
+ return -EINVAL;
+ }
+ if (copy_from_user(&sbi, buf, sizeof(sbi)))
+ return -EFAULT;
- snd_seq_event_t ev;
- int i;
+ if (sbi.channel < 0 || sbi.channel >= SBFM_MAXINSTR) {
+ snd_printk(KERN_ERR "FM Error: Invalid instrument number %d\n",
+ sbi.channel);
+ return -EINVAL;
+ }
- mm_segment_t fs;
+ memset(name, 0, sizeof(name));
+ sprintf(name, "Chan%d", sbi.channel);
- if (count < (int)sizeof(sbi)) {
- snd_printk("FM Error: Patch record too short\n");
- return -EINVAL;
- }
- if (copy_from_user(&sbi, buf, sizeof(sbi)))
- return -EFAULT;
+ err = snd_opl3_load_patch(opl3, sbi.channel, 127, type, name, NULL,
+ sbi.operators);
+ if (err < 0)
+ return err;
- if (sbi.channel < 0 || sbi.channel >= SBFM_MAXINSTR) {
- snd_printk("FM Error: Invalid instrument number %d\n", sbi.channel);
- return -EINVAL;
- }
-
- size = sizeof(*put) + sizeof(fm_xinstrument_t);
- put = kzalloc(size, GFP_KERNEL);
- if (put == NULL)
- return -ENOMEM;
- /* build header */
- data = &put->data;
- data->type = SNDRV_SEQ_INSTR_ATYPE_DATA;
- strcpy(data->data.format, SNDRV_SEQ_INSTR_ID_OPL2_3);
- /* build data section */
- xinstr = (fm_xinstrument_t *)(data + 1);
- xinstr->stype = FM_STRU_INSTR;
-
- for (i = 0; i < 2; i++) {
- xinstr->op[i].am_vib = sbi.operators[AM_VIB + i];
- xinstr->op[i].ksl_level = sbi.operators[KSL_LEVEL + i];
- xinstr->op[i].attack_decay = sbi.operators[ATTACK_DECAY + i];
- xinstr->op[i].sustain_release = sbi.operators[SUSTAIN_RELEASE + i];
- xinstr->op[i].wave_select = sbi.operators[WAVE_SELECT + i];
- }
- xinstr->feedback_connection[0] = sbi.operators[CONNECTION];
-
- if (format == OPL3_PATCH) {
- xinstr->type = FM_PATCH_OPL3;
- for (i = 0; i < 2; i++) {
- xinstr->op[i+2].am_vib = sbi.operators[OFFSET_4OP + AM_VIB + i];
- xinstr->op[i+2].ksl_level = sbi.operators[OFFSET_4OP + KSL_LEVEL + i];
- xinstr->op[i+2].attack_decay = sbi.operators[OFFSET_4OP + ATTACK_DECAY + i];
- xinstr->op[i+2].sustain_release = sbi.operators[OFFSET_4OP + SUSTAIN_RELEASE + i];
- xinstr->op[i+2].wave_select = sbi.operators[OFFSET_4OP + WAVE_SELECT + i];
- }
- xinstr->feedback_connection[1] = sbi.operators[OFFSET_4OP + CONNECTION];
- } else {
- xinstr->type = FM_PATCH_OPL2;
- }
-
- put->id.instr.std = SNDRV_SEQ_INSTR_TYPE2_OPL2_3;
- put->id.instr.bank = 127;
- put->id.instr.prg = sbi.channel;
- put->cmd = SNDRV_SEQ_INSTR_PUT_CMD_CREATE;
-
- memset (&ev, 0, sizeof(ev));
- ev.source.client = SNDRV_SEQ_CLIENT_OSS;
- ev.dest = arg->addr;
-
- ev.flags = SNDRV_SEQ_EVENT_LENGTH_VARUSR;
- ev.queue = SNDRV_SEQ_QUEUE_DIRECT;
-
- fs = snd_enter_user();
- __again:
- ev.type = SNDRV_SEQ_EVENT_INSTR_PUT;
- ev.data.ext.len = size;
- ev.data.ext.ptr = put;
-
- err = snd_seq_instr_event(&opl3->fm_ops, opl3->ilist, &ev,
- opl3->seq_client, 0, 0);
- if (err == -EBUSY) {
- snd_seq_instr_header_t remove;
-
- memset (&remove, 0, sizeof(remove));
- remove.cmd = SNDRV_SEQ_INSTR_FREE_CMD_SINGLE;
- remove.id.instr = put->id.instr;
-
- /* remove instrument */
- ev.type = SNDRV_SEQ_EVENT_INSTR_FREE;
- ev.data.ext.len = sizeof(remove);
- ev.data.ext.ptr = &remove;
-
- snd_seq_instr_event(&opl3->fm_ops, opl3->ilist, &ev,
- opl3->seq_client, 0, 0);
- goto __again;
- }
- snd_leave_user(fs);
-
- kfree(put);
- }
- return err;
+ return sizeof(sbi);
}
/* ioctl */
-static int snd_opl3_ioctl_seq_oss(snd_seq_oss_arg_t *arg, unsigned int cmd,
+static int snd_opl3_ioctl_seq_oss(struct snd_seq_oss_arg *arg, unsigned int cmd,
unsigned long ioarg)
{
- opl3_t *opl3;
+ struct snd_opl3 *opl3;
- snd_assert(arg != NULL, return -ENXIO);
+ if (snd_BUG_ON(!arg))
+ return -ENXIO;
opl3 = arg->private_data;
switch (cmd) {
case SNDCTL_FM_LOAD_INSTR:
- snd_printk("OPL3: Obsolete ioctl(SNDCTL_FM_LOAD_INSTR) used. Fix the program.\n");
+ snd_printk(KERN_ERR "OPL3: "
+ "Obsolete ioctl(SNDCTL_FM_LOAD_INSTR) used. "
+ "Fix the program.\n");
return -EINVAL;
case SNDCTL_SYNTH_MEMAVL:
@@ -345,11 +273,12 @@ static int snd_opl3_ioctl_seq_oss(snd_seq_oss_arg_t *arg, unsigned int cmd,
}
/* reset device */
-static int snd_opl3_reset_seq_oss(snd_seq_oss_arg_t *arg)
+static int snd_opl3_reset_seq_oss(struct snd_seq_oss_arg *arg)
{
- opl3_t *opl3;
+ struct snd_opl3 *opl3;
- snd_assert(arg != NULL, return -ENXIO);
+ if (snd_BUG_ON(!arg))
+ return -ENXIO;
opl3 = arg->private_data;
return 0;