4 * Copyright by Hannu Savolainen 1993
6 * Mon Nov 22 22:38:35 MET 1993 marco@driq.home.usn.nl: added 6850 support, used
7 * with COVOX SoundMaster II and custom cards.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are
11 * met: 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 2.
13 * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <i386/isa/sound/sound_config.h>
36 /* #if defined(CONFIG_UART6850) && defined(CONFIG_MIDI) */
38 #define DATAPORT (uart6850_base) /* * * Midi6850 Data I/O Port on IBM */
39 #define COMDPORT (uart6850_base+1) /* * * Midi6850 Command Port on IBM */
40 #define STATPORT (uart6850_base+1) /* * * Midi6850 Status Port on IBM */
42 #define uart6850_status() inb( STATPORT)
43 #define input_avail() (uart6850_status()&INPUT_AVAIL)
44 #define output_ready() (uart6850_status()&OUTPUT_READY)
45 #define uart6850_cmd(cmd) outb( COMDPORT, cmd)
46 #define uart6850_read() inb( DATAPORT)
47 #define uart6850_write(byte) outb( DATAPORT, byte)
49 #define OUTPUT_READY 0x02 /* * * Mask for Data Read Ready Bit */
50 #define INPUT_AVAIL 0x01 /* * * Mask for Data Send Ready Bit */
52 #define UART_RESET 0x95 /* * * 6850 Total Reset Command */
53 #define UART_MODE_ON 0x03 /* * * 6850 Send/Receive UART Mode */
55 static int uart6850_opened = 0;
56 static int uart6850_base = 0x330;
57 static int uart6850_irq;
58 static int uart6850_detected = 0;
61 static int reset_uart6850(void);
62 static void (*midi_input_intr) (int dev, u_char data);
63 static void poll_uart6850(void *dummy);
66 static sound_os_info *uart6850_osp;
69 uart6850_input_loop(void)
75 while (count) /* Not timed out */
77 u_char c = uart6850_read();
81 if (uart6850_opened & OPEN_READ)
82 midi_input_intr(my_dev, c);
84 while (!input_avail() && count)
92 uart6850_input_loop();
96 * It looks like there is no input interrupts in the UART mode. Let's try
101 poll_uart6850(void * dummy)
105 if (!(uart6850_opened & OPEN_READ))
106 return; /* Device has been closed */
111 uart6850_input_loop();
114 timeout( poll_uart6850, 0, 1); /* Come back later */
120 uart6850_open(int dev, int mode,
121 void (*input) (int dev, u_char data),
122 void (*output) (int dev)
125 if (uart6850_opened) {
126 printf("Midi6850: Midi busy\n");
129 uart6850_cmd(UART_RESET);
131 uart6850_input_loop();
133 midi_input_intr = input;
134 uart6850_opened = mode;
135 poll_uart6850(0); /* Enable input polling */
141 uart6850_close(int dev)
143 uart6850_cmd(UART_MODE_ON);
149 uart6850_out(int dev, u_char midi_byte)
155 * Test for input since pending input seems to block the output.
161 uart6850_input_loop();
166 * Sometimes it takes about 13000 loops before the output becomes
167 * ready (After reset). Normally it takes just about 10 loops.
170 for (timeout = 30000; timeout > 0 && !output_ready(); timeout--); /* Wait */
172 if (!output_ready()) {
173 printf("Midi6850: Timeout\n");
176 uart6850_write(midi_byte);
181 uart6850_command(int dev, u_char *midi_byte)
187 uart6850_start_read(int dev)
193 uart6850_end_read(int dev)
199 uart6850_ioctl(int dev, u_int cmd, ioctl_arg arg)
205 uart6850_kick(int dev)
210 uart6850_buffer_status(int dev)
212 return 0; /* No data in buffers */
215 #define MIDI_SYNTH_NAME "6850 UART Midi"
216 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
217 #include <i386/isa/sound/midi_synth.h>
219 static struct midi_operations uart6850_operations =
221 {"6850 UART", 0, 0, SNDCARD_UART6850},
232 uart6850_buffer_status
237 attach_uart6850(struct address_info * hw_config)
242 if (num_midis >= MAX_MIDI_DEV) {
243 printf("Sound: Too many midi devices detected\n");
246 uart6850_base = hw_config->io_base;
247 uart6850_osp = hw_config->osp;
248 uart6850_irq = hw_config->irq;
250 if (!uart6850_detected)
255 for (timeout = 30000; timeout < 0 && !output_ready(); timeout--); /* Wait */
256 uart6850_cmd(UART_MODE_ON);
262 conf_printf("6850 Midi Interface", hw_config);
264 std_midi_synth.midi_dev = my_dev = num_midis;
265 midi_devs[num_midis++] = &uart6850_operations;
278 probe_uart6850(struct address_info * hw_config)
282 uart6850_osp = hw_config->osp;
283 uart6850_base = hw_config->io_base;
284 uart6850_irq = hw_config->irq;
286 if (snd_set_irq_handler(uart6850_irq, m6850intr, uart6850_osp) < 0)
289 ok = reset_uart6850();
291 uart6850_detected = ok;