[PATCH] Move valid_dma_direction() from x86_64 to generic code
[usb.git] / sound / oss / sb_midi.c
blobed3bd0640ffd4ecbd2967e456bdcca9509b6ec4e
1 /*
2 * sound/sb_dsp.c
4 * The low level driver for the Sound Blaster DS chips.
7 * Copyright (C) by Hannu Savolainen 1993-1997
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
14 #include <linux/spinlock.h>
16 #include "sound_config.h"
18 #include "sb.h"
19 #undef SB_TEST_IRQ
22 * The DSP channel can be used either for input or output. Variable
23 * 'sb_irq_mode' will be set when the program calls read or write first time
24 * after open. Current version doesn't support mode changes without closing
25 * and reopening the device. Support for this feature may be implemented in a
26 * future version of this driver.
30 static int sb_midi_open(int dev, int mode,
31 void (*input) (int dev, unsigned char data),
32 void (*output) (int dev)
35 sb_devc *devc = midi_devs[dev]->devc;
36 unsigned long flags;
38 if (devc == NULL)
39 return -ENXIO;
41 spin_lock_irqsave(&devc->lock, flags);
42 if (devc->opened)
44 spin_unlock_irqrestore(&devc->lock, flags);
45 return -EBUSY;
47 devc->opened = 1;
48 spin_unlock_irqrestore(&devc->lock, flags);
50 devc->irq_mode = IMODE_MIDI;
51 devc->midi_broken = 0;
53 sb_dsp_reset(devc);
55 if (!sb_dsp_command(devc, 0x35)) /* Start MIDI UART mode */
57 devc->opened = 0;
58 return -EIO;
60 devc->intr_active = 1;
62 if (mode & OPEN_READ)
64 devc->input_opened = 1;
65 devc->midi_input_intr = input;
67 return 0;
70 static void sb_midi_close(int dev)
72 sb_devc *devc = midi_devs[dev]->devc;
73 unsigned long flags;
75 if (devc == NULL)
76 return;
78 spin_lock_irqsave(&devc->lock, flags);
79 sb_dsp_reset(devc);
80 devc->intr_active = 0;
81 devc->input_opened = 0;
82 devc->opened = 0;
83 spin_unlock_irqrestore(&devc->lock, flags);
86 static int sb_midi_out(int dev, unsigned char midi_byte)
88 sb_devc *devc = midi_devs[dev]->devc;
90 if (devc == NULL)
91 return 1;
93 if (devc->midi_broken)
94 return 1;
96 if (!sb_dsp_command(devc, midi_byte))
98 devc->midi_broken = 1;
99 return 1;
101 return 1;
104 static int sb_midi_start_read(int dev)
106 return 0;
109 static int sb_midi_end_read(int dev)
111 sb_devc *devc = midi_devs[dev]->devc;
113 if (devc == NULL)
114 return -ENXIO;
116 sb_dsp_reset(devc);
117 devc->intr_active = 0;
118 return 0;
121 static int sb_midi_ioctl(int dev, unsigned cmd, void __user *arg)
123 return -EINVAL;
126 void sb_midi_interrupt(sb_devc * devc)
128 unsigned long flags;
129 unsigned char data;
131 if (devc == NULL)
132 return;
134 spin_lock_irqsave(&devc->lock, flags);
136 data = inb(DSP_READ);
137 if (devc->input_opened)
138 devc->midi_input_intr(devc->my_mididev, data);
140 spin_unlock_irqrestore(&devc->lock, flags);
143 #define MIDI_SYNTH_NAME "Sound Blaster Midi"
144 #define MIDI_SYNTH_CAPS 0
145 #include "midi_synth.h"
147 static struct midi_operations sb_midi_operations =
149 .owner = THIS_MODULE,
150 .info = {"Sound Blaster", 0, 0, SNDCARD_SB},
151 .converter = &std_midi_synth,
152 .in_info = {0},
153 .open = sb_midi_open,
154 .close = sb_midi_close,
155 .ioctl = sb_midi_ioctl,
156 .outputc = sb_midi_out,
157 .start_read = sb_midi_start_read,
158 .end_read = sb_midi_end_read,
161 void sb_dsp_midi_init(sb_devc * devc, struct module *owner)
163 int dev;
165 if (devc->model < 2) /* No MIDI support for SB 1.x */
166 return;
168 dev = sound_alloc_mididev();
170 if (dev == -1)
172 printk(KERN_ERR "sb_midi: too many MIDI devices detected\n");
173 return;
175 std_midi_synth.midi_dev = devc->my_mididev = dev;
176 midi_devs[dev] = (struct midi_operations *)kmalloc(sizeof(struct midi_operations), GFP_KERNEL);
177 if (midi_devs[dev] == NULL)
179 printk(KERN_WARNING "Sound Blaster: failed to allocate MIDI memory.\n");
180 sound_unload_mididev(dev);
181 return;
183 memcpy((char *) midi_devs[dev], (char *) &sb_midi_operations,
184 sizeof(struct midi_operations));
186 if (owner)
187 midi_devs[dev]->owner = owner;
189 midi_devs[dev]->devc = devc;
192 midi_devs[dev]->converter = (struct synth_operations *)kmalloc(sizeof(struct synth_operations), GFP_KERNEL);
193 if (midi_devs[dev]->converter == NULL)
195 printk(KERN_WARNING "Sound Blaster: failed to allocate MIDI memory.\n");
196 kfree(midi_devs[dev]);
197 sound_unload_mididev(dev);
198 return;
200 memcpy((char *) midi_devs[dev]->converter, (char *) &std_midi_synth,
201 sizeof(struct synth_operations));
203 midi_devs[dev]->converter->id = "SBMIDI";
204 sequencer_init();