- struct cm_state *s = (struct cm_state *)file->private_data;
- unsigned long flags;
- unsigned int mask = 0;
-
- VALIDATE_STATE(s);
- if (file->f_mode & FMODE_WRITE)
- poll_wait(file, &s->midi.owait, wait);
- if (file->f_mode & FMODE_READ)
- poll_wait(file, &s->midi.iwait, wait);
- spin_lock_irqsave(&s->lock, flags);
- if (file->f_mode & FMODE_READ) {
- if (s->midi.icnt > 0)
- mask |= POLLIN | POLLRDNORM;
- }
- if (file->f_mode & FMODE_WRITE) {
- if (s->midi.ocnt < MIDIOUTBUF)
- mask |= POLLOUT | POLLWRNORM;
- }
- spin_unlock_irqrestore(&s->lock, flags);
- return mask;
-}
-
-static int cm_midi_open(struct inode *inode, struct file *file)
-{
- int minor = iminor(inode);
- struct cm_state *s = devs;
- unsigned long flags;
-
- while (s && s->dev_midi != minor)
- s = s->next;
- if (!s)
- return -ENODEV;
- VALIDATE_STATE(s);
- file->private_data = s;
- /* wait for device to become free */
- down(&s->open_sem);
- while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
- if (file->f_flags & O_NONBLOCK) {
- up(&s->open_sem);
- return -EBUSY;
- }
- up(&s->open_sem);
- interruptible_sleep_on(&s->open_wait);
- if (signal_pending(current))
- return -ERESTARTSYS;
- down(&s->open_sem);
- }
- spin_lock_irqsave(&s->lock, flags);
- if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
- s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
- s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
- /* enable MPU-401 */
- maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 4);
- outb(0xff, s->iomidi+1); /* reset command */
- if (!(inb(s->iomidi+1) & 0x80))
- inb(s->iomidi);
- outb(0x3f, s->iomidi+1); /* uart command */
- if (!(inb(s->iomidi+1) & 0x80))
- inb(s->iomidi);
- s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
- init_timer(&s->midi.timer);
- s->midi.timer.expires = jiffies+1;
- s->midi.timer.data = (unsigned long)s;
- s->midi.timer.function = cm_midi_timer;
- add_timer(&s->midi.timer);
- }
- if (file->f_mode & FMODE_READ) {
- s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
- }
- if (file->f_mode & FMODE_WRITE) {
- s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
- }
- spin_unlock_irqrestore(&s->lock, flags);
- s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
- up(&s->open_sem);
- return 0;
-}
-
-static int cm_midi_release(struct inode *inode, struct file *file)
-{
- struct cm_state *s = (struct cm_state *)file->private_data;
- DECLARE_WAITQUEUE(wait, current);
- unsigned long flags;
- unsigned count, tmo;
-
- VALIDATE_STATE(s);
- lock_kernel();
-
- if (file->f_mode & FMODE_WRITE) {
- __set_current_state(TASK_INTERRUPTIBLE);
- add_wait_queue(&s->midi.owait, &wait);
- for (;;) {
- spin_lock_irqsave(&s->lock, flags);
- count = s->midi.ocnt;
- spin_unlock_irqrestore(&s->lock, flags);
- if (count <= 0)
- break;
- if (signal_pending(current))
- break;
- if (file->f_flags & O_NONBLOCK) {
- remove_wait_queue(&s->midi.owait, &wait);
- set_current_state(TASK_RUNNING);
- unlock_kernel();
- return -EBUSY;
- }
- tmo = (count * HZ) / 3100;
- if (!schedule_timeout(tmo ? : 1) && tmo)
- printk(KERN_DEBUG "cmpci: midi timed out??\n");
- }
- remove_wait_queue(&s->midi.owait, &wait);
- set_current_state(TASK_RUNNING);
- }
- down(&s->open_sem);
- s->open_mode &= ~((file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ|FMODE_MIDI_WRITE));
- spin_lock_irqsave(&s->lock, flags);
- if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
- del_timer(&s->midi.timer);
- outb(0xff, s->iomidi+1); /* reset command */
- if (!(inb(s->iomidi+1) & 0x80))
- inb(s->iomidi);
- /* disable MPU-401 */
- maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~4, 0);
- }
- spin_unlock_irqrestore(&s->lock, flags);
- up(&s->open_sem);
- wake_up(&s->open_wait);
- unlock_kernel();
- return 0;
-}
-
-static /*const*/ struct file_operations cm_midi_fops = {
- .owner = THIS_MODULE,
- .llseek = no_llseek,
- .read = cm_midi_read,
- .write = cm_midi_write,
- .poll = cm_midi_poll,
- .open = cm_midi_open,
- .release = cm_midi_release,
-};
-#endif
-
-/* --------------------------------------------------------------------- */
-
-#ifdef CONFIG_SOUND_CMPCI_FM
-static int cm_dmfm_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
-{
- static const unsigned char op_offset[18] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
- 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15
- };
- struct cm_state *s = (struct cm_state *)file->private_data;
- struct dm_fm_voice v;
- struct dm_fm_note n;
- struct dm_fm_params p;
- unsigned int io;
- unsigned int regb;
-
- switch (cmd) {
- case FM_IOCTL_RESET:
- for (regb = 0xb0; regb < 0xb9; regb++) {
- outb(regb, s->iosynth);
- outb(0, s->iosynth+1);
- outb(regb, s->iosynth+2);
- outb(0, s->iosynth+3);
- }
- return 0;
-
- case FM_IOCTL_PLAY_NOTE:
- if (copy_from_user(&n, (void *)arg, sizeof(n)))
- return -EFAULT;
- if (n.voice >= 18)
- return -EINVAL;
- if (n.voice >= 9) {
- regb = n.voice - 9;
- io = s->iosynth+2;
- } else {
- regb = n.voice;
- io = s->iosynth;
- }
- outb(0xa0 + regb, io);
- outb(n.fnum & 0xff, io+1);
- outb(0xb0 + regb, io);
- outb(((n.fnum >> 8) & 3) | ((n.octave & 7) << 2) | ((n.key_on & 1) << 5), io+1);
- return 0;
-
- case FM_IOCTL_SET_VOICE:
- if (copy_from_user(&v, (void *)arg, sizeof(v)))
- return -EFAULT;
- if (v.voice >= 18)
- return -EINVAL;
- regb = op_offset[v.voice];
- io = s->iosynth + ((v.op & 1) << 1);
- outb(0x20 + regb, io);
- outb(((v.am & 1) << 7) | ((v.vibrato & 1) << 6) | ((v.do_sustain & 1) << 5) |
- ((v.kbd_scale & 1) << 4) | (v.harmonic & 0xf), io+1);
- outb(0x40 + regb, io);
- outb(((v.scale_level & 0x3) << 6) | (v.volume & 0x3f), io+1);
- outb(0x60 + regb, io);
- outb(((v.attack & 0xf) << 4) | (v.decay & 0xf), io+1);
- outb(0x80 + regb, io);
- outb(((v.sustain & 0xf) << 4) | (v.release & 0xf), io+1);
- outb(0xe0 + regb, io);
- outb(v.waveform & 0x7, io+1);
- if (n.voice >= 9) {
- regb = n.voice - 9;
- io = s->iosynth+2;
- } else {
- regb = n.voice;
- io = s->iosynth;
- }
- outb(0xc0 + regb, io);
- outb(((v.right & 1) << 5) | ((v.left & 1) << 4) | ((v.feedback & 7) << 1) |
- (v.connection & 1), io+1);
- return 0;
-
- case FM_IOCTL_SET_PARAMS:
- if (copy_from_user(&p, (void *)arg, sizeof(p)))
- return -EFAULT;
- outb(0x08, s->iosynth);
- outb((p.kbd_split & 1) << 6, s->iosynth+1);
- outb(0xbd, s->iosynth);
- outb(((p.am_depth & 1) << 7) | ((p.vib_depth & 1) << 6) | ((p.rhythm & 1) << 5) | ((p.bass & 1) << 4) |
- ((p.snare & 1) << 3) | ((p.tomtom & 1) << 2) | ((p.cymbal & 1) << 1) | (p.hihat & 1), s->iosynth+1);
- return 0;
-
- case FM_IOCTL_SET_OPL:
- outb(4, s->iosynth+2);
- outb(arg, s->iosynth+3);
- return 0;