Lines Matching refs:dev
83 static void drain_midi_queue(int dev) in drain_midi_queue() argument
90 if (midi_devs[dev]->buffer_status != NULL) in drain_midi_queue()
91 wait_event_interruptible_timeout(midi_sleeper[dev], in drain_midi_queue()
92 !midi_devs[dev]->buffer_status(dev), HZ/10); in drain_midi_queue()
95 static void midi_input_intr(int dev, unsigned char data) in midi_input_intr() argument
97 if (midi_in_buf[dev] == NULL) in midi_input_intr()
107 if (SPACE_AVAIL(midi_in_buf[dev])) { in midi_input_intr()
108 QUEUE_BYTE(midi_in_buf[dev], data); in midi_input_intr()
109 wake_up(&input_sleeper[dev]); in midi_input_intr()
113 static void midi_output_intr(int dev) in midi_output_intr() argument
123 int dev; in midi_poll() local
128 for (dev = 0; dev < num_midis; dev++) in midi_poll()
129 if (midi_devs[dev] != NULL && midi_out_buf[dev] != NULL) in midi_poll()
131 while (DATA_AVAIL(midi_out_buf[dev])) in midi_poll()
134 int c = midi_out_buf[dev]->queue[midi_out_buf[dev]->head]; in midi_poll()
137 ok = midi_devs[dev]->outputc(dev, c); in midi_poll()
141 midi_out_buf[dev]->head = (midi_out_buf[dev]->head + 1) % MAX_QUEUE_SIZE; in midi_poll()
142 midi_out_buf[dev]->len--; in midi_poll()
145 if (DATA_AVAIL(midi_out_buf[dev]) < 100) in midi_poll()
146 wake_up(&midi_sleeper[dev]); in midi_poll()
157 int MIDIbuf_open(int dev, struct file *file) in MIDIbuf_open() argument
161 dev = dev >> 4; in MIDIbuf_open()
169 if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL) in MIDIbuf_open()
175 module_put(midi_devs[dev]->owner); in MIDIbuf_open()
177 if ((err = midi_devs[dev]->open(dev, mode, in MIDIbuf_open()
181 parms[dev].prech_timeout = MAX_SCHEDULE_TIMEOUT; in MIDIbuf_open()
182 midi_in_buf[dev] = vmalloc(sizeof(struct midi_buf)); in MIDIbuf_open()
184 if (midi_in_buf[dev] == NULL) in MIDIbuf_open()
187 midi_devs[dev]->close(dev); in MIDIbuf_open()
190 midi_in_buf[dev]->len = midi_in_buf[dev]->head = midi_in_buf[dev]->tail = 0; in MIDIbuf_open()
192 midi_out_buf[dev] = vmalloc(sizeof(struct midi_buf)); in MIDIbuf_open()
194 if (midi_out_buf[dev] == NULL) in MIDIbuf_open()
197 midi_devs[dev]->close(dev); in MIDIbuf_open()
198 vfree(midi_in_buf[dev]); in MIDIbuf_open()
199 midi_in_buf[dev] = NULL; in MIDIbuf_open()
202 midi_out_buf[dev]->len = midi_out_buf[dev]->head = midi_out_buf[dev]->tail = 0; in MIDIbuf_open()
205 init_waitqueue_head(&midi_sleeper[dev]); in MIDIbuf_open()
206 init_waitqueue_head(&input_sleeper[dev]); in MIDIbuf_open()
216 void MIDIbuf_release(int dev, struct file *file) in MIDIbuf_release() argument
220 dev = dev >> 4; in MIDIbuf_release()
223 if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL) in MIDIbuf_release()
232 midi_devs[dev]->outputc(dev, 0xfe); /* in MIDIbuf_release()
237 wait_event_interruptible(midi_sleeper[dev], in MIDIbuf_release()
238 !DATA_AVAIL(midi_out_buf[dev])); in MIDIbuf_release()
243 drain_midi_queue(dev); /* in MIDIbuf_release()
248 midi_devs[dev]->close(dev); in MIDIbuf_release()
253 vfree(midi_in_buf[dev]); in MIDIbuf_release()
254 vfree(midi_out_buf[dev]); in MIDIbuf_release()
255 midi_in_buf[dev] = NULL; in MIDIbuf_release()
256 midi_out_buf[dev] = NULL; in MIDIbuf_release()
258 module_put(midi_devs[dev]->owner); in MIDIbuf_release()
261 int MIDIbuf_write(int dev, struct file *file, const char __user *buf, int count) in MIDIbuf_write() argument
266 dev = dev >> 4; in MIDIbuf_write()
275 n = SPACE_AVAIL(midi_out_buf[dev]); in MIDIbuf_write()
286 if (wait_event_interruptible(midi_sleeper[dev], in MIDIbuf_write()
287 SPACE_AVAIL(midi_out_buf[dev]))) in MIDIbuf_write()
292 n = SPACE_AVAIL(midi_out_buf[dev]); in MIDIbuf_write()
306 QUEUE_BYTE(midi_out_buf[dev], tmp_data); in MIDIbuf_write()
315 int MIDIbuf_read(int dev, struct file *file, char __user *buf, int count) in MIDIbuf_read() argument
320 dev = dev >> 4; in MIDIbuf_read()
322 if (!DATA_AVAIL(midi_in_buf[dev])) { /* in MIDIbuf_read()
329 wait_event_interruptible_timeout(input_sleeper[dev], in MIDIbuf_read()
330 DATA_AVAIL(midi_in_buf[dev]), in MIDIbuf_read()
331 parms[dev].prech_timeout); in MIDIbuf_read()
336 if (c == 0 && DATA_AVAIL(midi_in_buf[dev])) /* in MIDIbuf_read()
340 n = DATA_AVAIL(midi_in_buf[dev]); in MIDIbuf_read()
348 REMOVE_BYTE(midi_in_buf[dev], tmp_data); in MIDIbuf_read()
364 int MIDIbuf_ioctl(int dev, struct file *file, in MIDIbuf_ioctl() argument
369 dev = dev >> 4; in MIDIbuf_ioctl()
373 if (midi_devs[dev]->coproc) /* Coprocessor ioctl */ in MIDIbuf_ioctl()
374 return midi_devs[dev]->coproc->ioctl(midi_devs[dev]->coproc->devc, cmd, arg, 0); in MIDIbuf_ioctl()
388 parms[dev].prech_timeout = val; in MIDIbuf_ioctl()
392 if (!midi_devs[dev]->ioctl) in MIDIbuf_ioctl()
394 return midi_devs[dev]->ioctl(dev, cmd, arg); in MIDIbuf_ioctl()
400 unsigned int MIDIbuf_poll(int dev, struct file *file, poll_table * wait) in MIDIbuf_poll() argument
404 dev = dev >> 4; in MIDIbuf_poll()
407 poll_wait(file, &input_sleeper[dev], wait); in MIDIbuf_poll()
408 if (DATA_AVAIL(midi_in_buf[dev])) in MIDIbuf_poll()
412 poll_wait(file, &midi_sleeper[dev], wait); in MIDIbuf_poll()
413 if (!SPACE_AVAIL(midi_out_buf[dev])) in MIDIbuf_poll()
420 int MIDIbuf_avail(int dev) in MIDIbuf_avail() argument
422 if (midi_in_buf[dev]) in MIDIbuf_avail()
423 return DATA_AVAIL (midi_in_buf[dev]); in MIDIbuf_avail()