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
14 #include <linux/spinlock.h>
15 #include <linux/slab.h>
17 #include "sound_config.h"
23 * The DSP channel can be used either for input or output. Variable
24 * 'sb_irq_mode' will be set when the program calls read or write first time
25 * after open. Current version doesn't support mode changes without closing
26 * and reopening the device. Support for this feature may be implemented in a
27 * future version of this driver.
31 static int sb_midi_open(int dev, int mode,
32 void (*input) (int dev, unsigned char data),
33 void (*output) (int dev)
36 sb_devc *devc = midi_devs[dev]->devc;
42 spin_lock_irqsave(&devc->lock, flags);
45 spin_unlock_irqrestore(&devc->lock, flags);
49 spin_unlock_irqrestore(&devc->lock, flags);
51 devc->irq_mode = IMODE_MIDI;
52 devc->midi_broken = 0;
56 if (!sb_dsp_command(devc, 0x35)) /* Start MIDI UART mode */
61 devc->intr_active = 1;
65 devc->input_opened = 1;
66 devc->midi_input_intr = input;
71 static void sb_midi_close(int dev)
73 sb_devc *devc = midi_devs[dev]->devc;
79 spin_lock_irqsave(&devc->lock, flags);
81 devc->intr_active = 0;
82 devc->input_opened = 0;
84 spin_unlock_irqrestore(&devc->lock, flags);
87 static int sb_midi_out(int dev, unsigned char midi_byte)
89 sb_devc *devc = midi_devs[dev]->devc;
94 if (devc->midi_broken)
97 if (!sb_dsp_command(devc, midi_byte))
99 devc->midi_broken = 1;
105 static int sb_midi_start_read(int dev)
110 static int sb_midi_end_read(int dev)
112 sb_devc *devc = midi_devs[dev]->devc;
118 devc->intr_active = 0;
122 static int sb_midi_ioctl(int dev, unsigned cmd, void __user *arg)
127 void sb_midi_interrupt(sb_devc * devc)
135 spin_lock_irqsave(&devc->lock, flags);
137 data = inb(DSP_READ);
138 if (devc->input_opened)
139 devc->midi_input_intr(devc->my_mididev, data);
141 spin_unlock_irqrestore(&devc->lock, flags);
144 #define MIDI_SYNTH_NAME "Sound Blaster Midi"
145 #define MIDI_SYNTH_CAPS 0
146 #include "midi_synth.h"
148 static struct midi_operations sb_midi_operations =
150 .owner = THIS_MODULE,
151 .info = {"Sound Blaster", 0, 0, SNDCARD_SB},
152 .converter = &std_midi_synth,
154 .open = sb_midi_open,
155 .close = sb_midi_close,
156 .ioctl = sb_midi_ioctl,
157 .outputc = sb_midi_out,
158 .start_read = sb_midi_start_read,
159 .end_read = sb_midi_end_read,
162 void sb_dsp_midi_init(sb_devc * devc, struct module *owner)
166 if (devc->model < 2) /* No MIDI support for SB 1.x */
169 dev = sound_alloc_mididev();
173 printk(KERN_ERR "sb_midi: too many MIDI devices detected\n");
176 std_midi_synth.midi_dev = devc->my_mididev = dev;
177 midi_devs[dev] = kmalloc(sizeof(struct midi_operations), GFP_KERNEL);
178 if (midi_devs[dev] == NULL)
180 printk(KERN_WARNING "Sound Blaster: failed to allocate MIDI memory.\n");
181 sound_unload_mididev(dev);
184 memcpy((char *) midi_devs[dev], (char *) &sb_midi_operations,
185 sizeof(struct midi_operations));
188 midi_devs[dev]->owner = owner;
190 midi_devs[dev]->devc = devc;
193 midi_devs[dev]->converter = kmalloc(sizeof(struct synth_operations), GFP_KERNEL);
194 if (midi_devs[dev]->converter == NULL)
196 printk(KERN_WARNING "Sound Blaster: failed to allocate MIDI memory.\n");
197 kfree(midi_devs[dev]);
198 sound_unload_mididev(dev);
201 memcpy((char *) midi_devs[dev]->converter, (char *) &std_midi_synth,
202 sizeof(struct synth_operations));
204 midi_devs[dev]->converter->id = "SBMIDI";