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>
16 #include "sound_config.h"
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
;
41 spin_lock_irqsave(&devc
->lock
, flags
);
44 spin_unlock_irqrestore(&devc
->lock
, flags
);
48 spin_unlock_irqrestore(&devc
->lock
, flags
);
50 devc
->irq_mode
= IMODE_MIDI
;
51 devc
->midi_broken
= 0;
55 if (!sb_dsp_command(devc
, 0x35)) /* Start MIDI UART mode */
60 devc
->intr_active
= 1;
64 devc
->input_opened
= 1;
65 devc
->midi_input_intr
= input
;
70 static void sb_midi_close(int dev
)
72 sb_devc
*devc
= midi_devs
[dev
]->devc
;
78 spin_lock_irqsave(&devc
->lock
, flags
);
80 devc
->intr_active
= 0;
81 devc
->input_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
;
93 if (devc
->midi_broken
)
96 if (!sb_dsp_command(devc
, midi_byte
))
98 devc
->midi_broken
= 1;
104 static int sb_midi_start_read(int dev
)
109 static int sb_midi_end_read(int dev
)
111 sb_devc
*devc
= midi_devs
[dev
]->devc
;
117 devc
->intr_active
= 0;
121 static int sb_midi_ioctl(int dev
, unsigned cmd
, void __user
*arg
)
126 void sb_midi_interrupt(sb_devc
* devc
)
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
,
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
)
165 if (devc
->model
< 2) /* No MIDI support for SB 1.x */
168 dev
= sound_alloc_mididev();
172 printk(KERN_ERR
"sb_midi: too many MIDI devices detected\n");
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
);
183 memcpy((char *) midi_devs
[dev
], (char *) &sb_midi_operations
,
184 sizeof(struct midi_operations
));
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
);
200 memcpy((char *) midi_devs
[dev
]->converter
, (char *) &std_midi_synth
,
201 sizeof(struct synth_operations
));
203 midi_devs
[dev
]->converter
->id
= "SBMIDI";