cachefiles: fix the race between cachefiles_bury_object() and rmdir(2)
[linux/fpc-iii.git] / sound / drivers / opl3 / opl3_oss.c
blob869220ced4edd0bfb93efa78e13f1fedba032f76
1 /*
2 * Interface for OSS sequencer emulation
4 * Copyright (C) 2000 Uros Bizjak <uros@kss-loka.si>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/export.h>
22 #include "opl3_voice.h"
24 static int snd_opl3_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure);
25 static int snd_opl3_close_seq_oss(struct snd_seq_oss_arg *arg);
26 static int snd_opl3_ioctl_seq_oss(struct snd_seq_oss_arg *arg, unsigned int cmd, unsigned long ioarg);
27 static int snd_opl3_load_patch_seq_oss(struct snd_seq_oss_arg *arg, int format, const char __user *buf, int offs, int count);
28 static int snd_opl3_reset_seq_oss(struct snd_seq_oss_arg *arg);
30 /* operators */
32 static struct snd_seq_oss_callback oss_callback = {
33 .owner = THIS_MODULE,
34 .open = snd_opl3_open_seq_oss,
35 .close = snd_opl3_close_seq_oss,
36 .ioctl = snd_opl3_ioctl_seq_oss,
37 .load_patch = snd_opl3_load_patch_seq_oss,
38 .reset = snd_opl3_reset_seq_oss,
41 static int snd_opl3_oss_event_input(struct snd_seq_event *ev, int direct,
42 void *private_data, int atomic, int hop)
44 struct snd_opl3 *opl3 = private_data;
46 if (ev->type != SNDRV_SEQ_EVENT_OSS)
47 snd_midi_process_event(&opl3_ops, ev, opl3->oss_chset);
48 return 0;
51 /* ------------------------------ */
53 static void snd_opl3_oss_free_port(void *private_data)
55 struct snd_opl3 *opl3 = private_data;
57 snd_midi_channel_free_set(opl3->oss_chset);
60 static int snd_opl3_oss_create_port(struct snd_opl3 * opl3)
62 struct snd_seq_port_callback callbacks;
63 char name[32];
64 int voices, opl_ver;
66 voices = (opl3->hardware < OPL3_HW_OPL3) ?
67 MAX_OPL2_VOICES : MAX_OPL3_VOICES;
68 opl3->oss_chset = snd_midi_channel_alloc_set(voices);
69 if (opl3->oss_chset == NULL)
70 return -ENOMEM;
71 opl3->oss_chset->private_data = opl3;
73 memset(&callbacks, 0, sizeof(callbacks));
74 callbacks.owner = THIS_MODULE;
75 callbacks.event_input = snd_opl3_oss_event_input;
76 callbacks.private_free = snd_opl3_oss_free_port;
77 callbacks.private_data = opl3;
79 opl_ver = (opl3->hardware & OPL3_HW_MASK) >> 8;
80 sprintf(name, "OPL%i OSS Port", opl_ver);
82 opl3->oss_chset->client = opl3->seq_client;
83 opl3->oss_chset->port = snd_seq_event_port_attach(opl3->seq_client, &callbacks,
84 SNDRV_SEQ_PORT_CAP_WRITE,
85 SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |
86 SNDRV_SEQ_PORT_TYPE_MIDI_GM |
87 SNDRV_SEQ_PORT_TYPE_HARDWARE |
88 SNDRV_SEQ_PORT_TYPE_SYNTHESIZER,
89 voices, voices,
90 name);
91 if (opl3->oss_chset->port < 0) {
92 int port;
93 port = opl3->oss_chset->port;
94 snd_midi_channel_free_set(opl3->oss_chset);
95 return port;
97 return 0;
100 /* ------------------------------ */
102 /* register OSS synth */
103 void snd_opl3_init_seq_oss(struct snd_opl3 *opl3, char *name)
105 struct snd_seq_oss_reg *arg;
106 struct snd_seq_device *dev;
108 if (snd_seq_device_new(opl3->card, 0, SNDRV_SEQ_DEV_ID_OSS,
109 sizeof(struct snd_seq_oss_reg), &dev) < 0)
110 return;
112 opl3->oss_seq_dev = dev;
113 strlcpy(dev->name, name, sizeof(dev->name));
114 arg = SNDRV_SEQ_DEVICE_ARGPTR(dev);
115 arg->type = SYNTH_TYPE_FM;
116 if (opl3->hardware < OPL3_HW_OPL3) {
117 arg->subtype = FM_TYPE_ADLIB;
118 arg->nvoices = MAX_OPL2_VOICES;
119 } else {
120 arg->subtype = FM_TYPE_OPL3;
121 arg->nvoices = MAX_OPL3_VOICES;
123 arg->oper = oss_callback;
124 arg->private_data = opl3;
126 if (snd_opl3_oss_create_port(opl3)) {
127 /* register to OSS synth table */
128 snd_device_register(opl3->card, dev);
132 /* unregister */
133 void snd_opl3_free_seq_oss(struct snd_opl3 *opl3)
135 if (opl3->oss_seq_dev) {
136 /* The instance should have been released in prior */
137 opl3->oss_seq_dev = NULL;
141 /* ------------------------------ */
143 /* open OSS sequencer */
144 static int snd_opl3_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure)
146 struct snd_opl3 *opl3 = closure;
147 int err;
149 if (snd_BUG_ON(!arg))
150 return -ENXIO;
152 if ((err = snd_opl3_synth_setup(opl3)) < 0)
153 return err;
155 /* fill the argument data */
156 arg->private_data = opl3;
157 arg->addr.client = opl3->oss_chset->client;
158 arg->addr.port = opl3->oss_chset->port;
160 if ((err = snd_opl3_synth_use_inc(opl3)) < 0)
161 return err;
163 opl3->synth_mode = SNDRV_OPL3_MODE_SYNTH;
164 return 0;
167 /* close OSS sequencer */
168 static int snd_opl3_close_seq_oss(struct snd_seq_oss_arg *arg)
170 struct snd_opl3 *opl3;
172 if (snd_BUG_ON(!arg))
173 return -ENXIO;
174 opl3 = arg->private_data;
176 snd_opl3_synth_cleanup(opl3);
178 snd_opl3_synth_use_dec(opl3);
179 return 0;
182 /* load patch */
184 /* from sound_config.h */
185 #define SBFM_MAXINSTR 256
187 static int snd_opl3_load_patch_seq_oss(struct snd_seq_oss_arg *arg, int format,
188 const char __user *buf, int offs, int count)
190 struct snd_opl3 *opl3;
191 struct sbi_instrument sbi;
192 char name[32];
193 int err, type;
195 if (snd_BUG_ON(!arg))
196 return -ENXIO;
197 opl3 = arg->private_data;
199 if (format == FM_PATCH)
200 type = FM_PATCH_OPL2;
201 else if (format == OPL3_PATCH)
202 type = FM_PATCH_OPL3;
203 else
204 return -EINVAL;
206 if (count < (int)sizeof(sbi)) {
207 snd_printk(KERN_ERR "FM Error: Patch record too short\n");
208 return -EINVAL;
210 if (copy_from_user(&sbi, buf, sizeof(sbi)))
211 return -EFAULT;
213 if (sbi.channel < 0 || sbi.channel >= SBFM_MAXINSTR) {
214 snd_printk(KERN_ERR "FM Error: Invalid instrument number %d\n",
215 sbi.channel);
216 return -EINVAL;
219 memset(name, 0, sizeof(name));
220 sprintf(name, "Chan%d", sbi.channel);
222 err = snd_opl3_load_patch(opl3, sbi.channel, 127, type, name, NULL,
223 sbi.operators);
224 if (err < 0)
225 return err;
227 return sizeof(sbi);
230 /* ioctl */
231 static int snd_opl3_ioctl_seq_oss(struct snd_seq_oss_arg *arg, unsigned int cmd,
232 unsigned long ioarg)
234 if (snd_BUG_ON(!arg))
235 return -ENXIO;
236 switch (cmd) {
237 case SNDCTL_FM_LOAD_INSTR:
238 snd_printk(KERN_ERR "OPL3: "
239 "Obsolete ioctl(SNDCTL_FM_LOAD_INSTR) used. "
240 "Fix the program.\n");
241 return -EINVAL;
243 case SNDCTL_SYNTH_MEMAVL:
244 return 0x7fffffff;
246 case SNDCTL_FM_4OP_ENABLE:
247 // handled automatically by OPL instrument type
248 return 0;
250 default:
251 return -EINVAL;
253 return 0;
256 /* reset device */
257 static int snd_opl3_reset_seq_oss(struct snd_seq_oss_arg *arg)
259 if (snd_BUG_ON(!arg))
260 return -ENXIO;
262 return 0;