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/config.h>
15 #include "sound_config.h"
24 * The DSP channel can be used either for input or output. Variable
25 * 'sb_irq_mode' will be set when the program calls read or write first time
26 * after open. Current version doesn't support mode changes without closing
27 * and reopening the device. Support for this feature may be implemented in a
28 * future version of this driver.
32 static int sb_midi_open(int dev
, int mode
,
33 void (*input
) (int dev
, unsigned char data
),
34 void (*output
) (int dev
)
37 sb_devc
*devc
= midi_devs
[dev
]->devc
;
53 devc
->irq_mode
= IMODE_MIDI
;
54 devc
->midi_broken
= 0;
58 if (!sb_dsp_command(devc
, 0x35)) /* Start MIDI UART mode */
63 devc
->intr_active
= 1;
67 devc
->input_opened
= 1;
68 devc
->midi_input_intr
= input
;
73 static void sb_midi_close(int dev
)
75 sb_devc
*devc
= midi_devs
[dev
]->devc
;
84 devc
->intr_active
= 0;
85 devc
->input_opened
= 0;
90 static int sb_midi_out(int dev
, unsigned char midi_byte
)
92 sb_devc
*devc
= midi_devs
[dev
]->devc
;
97 if (devc
->midi_broken
)
100 if (!sb_dsp_command(devc
, midi_byte
))
102 devc
->midi_broken
= 1;
108 static int sb_midi_start_read(int dev
)
113 static int sb_midi_end_read(int dev
)
115 sb_devc
*devc
= midi_devs
[dev
]->devc
;
121 devc
->intr_active
= 0;
125 static int sb_midi_ioctl(int dev
, unsigned cmd
, caddr_t arg
)
130 void sb_midi_interrupt(sb_devc
* devc
)
141 data
= inb(DSP_READ
);
142 if (devc
->input_opened
)
143 devc
->midi_input_intr(devc
->my_mididev
, data
);
145 restore_flags(flags
);
148 #define MIDI_SYNTH_NAME "Sound Blaster Midi"
149 #define MIDI_SYNTH_CAPS 0
150 #include "midi_synth.h"
152 static struct midi_operations sb_midi_operations
=
155 "Sound Blaster", 0, 0, SNDCARD_SB
171 void sb_dsp_midi_init(sb_devc
* devc
)
175 if (devc
->model
< 2) /* No MIDI support for SB 1.x */
178 dev
= sound_alloc_mididev();
182 printk(KERN_ERR
"sb_midi: too many MIDI devices detected\n");
185 std_midi_synth
.midi_dev
= devc
->my_mididev
= dev
;
186 midi_devs
[dev
] = (struct midi_operations
*)kmalloc(sizeof(struct midi_operations
), GFP_KERNEL
);
187 if (midi_devs
[dev
] == NULL
)
189 printk(KERN_WARNING
"Sound Blaster: failed to allocate MIDI memory.\n");
190 sound_unload_mididev(dev
);
193 memcpy((char *) midi_devs
[dev
], (char *) &sb_midi_operations
,
194 sizeof(struct midi_operations
));
196 midi_devs
[dev
]->devc
= devc
;
199 midi_devs
[dev
]->converter
= (struct synth_operations
*)kmalloc(sizeof(struct synth_operations
), GFP_KERNEL
);
200 if (midi_devs
[dev
]->converter
== NULL
)
202 printk(KERN_WARNING
"Sound Blaster: failed to allocate MIDI memory.\n");
203 kfree(midi_devs
[dev
]);
204 sound_unload_mididev(dev
);
207 memcpy((char *) midi_devs
[dev
]->converter
, (char *) &std_midi_synth
,
208 sizeof(struct synth_operations
));
210 midi_devs
[dev
]->converter
->id
= "SBMIDI";