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
29 * $DragonFly: src/sys/dev/sound/isa/i386/uart/Attic/uart6850.c,v 1.2 2004/09/19 16:51:03 joerg Exp $
32 #include <sys/types.h>
33 #include <sys/callout.h>
34 #include <dev/sound/isa/i386/sound_config.h>
39 /* #if defined(CONFIG_UART6850) && defined(CONFIG_MIDI) */
41 #define DATAPORT (uart6850_base) /* * * Midi6850 Data I/O Port on IBM */
42 #define COMDPORT (uart6850_base+1) /* * * Midi6850 Command Port on IBM */
43 #define STATPORT (uart6850_base+1) /* * * Midi6850 Status Port on IBM */
45 #define uart6850_status() inb( STATPORT)
46 #define input_avail() (uart6850_status()&INPUT_AVAIL)
47 #define output_ready() (uart6850_status()&OUTPUT_READY)
48 #define uart6850_cmd(cmd) outb( COMDPORT, cmd)
49 #define uart6850_read() inb( DATAPORT)
50 #define uart6850_write(byte) outb( DATAPORT, byte)
52 #define OUTPUT_READY 0x02 /* * * Mask for Data Read Ready Bit */
53 #define INPUT_AVAIL 0x01 /* * * Mask for Data Send Ready Bit */
55 #define UART_RESET 0x95 /* * * 6850 Total Reset Command */
56 #define UART_MODE_ON 0x03 /* * * 6850 Send/Receive UART Mode */
58 static int uart6850_opened = 0;
59 static int uart6850_base = 0x330;
60 static int uart6850_irq;
61 static int uart6850_detected = 0;
64 static int reset_uart6850(void);
65 static void (*midi_input_intr) (int dev, u_char data);
66 static void poll_uart6850(void *dummy);
68 static sound_os_info *uart6850_osp;
70 static struct callout uart6850_ch;
71 SYSINIT(uart6850, SI_SUB_DRIVERS, SI_ORDER_ANY, callout_init, &uart6850_ch);
74 uart6850_input_loop(void)
80 while (count) /* Not timed out */
82 u_char c = uart6850_read();
86 if (uart6850_opened & OPEN_READ)
87 midi_input_intr(my_dev, c);
89 while (!input_avail() && count)
97 uart6850_input_loop();
101 * It looks like there is no input interrupts in the UART mode. Let's try
106 poll_uart6850(void * dummy)
110 if (!(uart6850_opened & OPEN_READ))
111 return; /* Device has been closed */
116 uart6850_input_loop();
118 callout_reset(&uart6850_ch, 1, poll_uart6850, NULL); /* Come back later */
124 uart6850_open(int dev, int mode,
125 void (*input) (int dev, u_char data),
126 void (*output) (int dev)
129 if (uart6850_opened) {
130 printf("Midi6850: Midi busy\n");
133 uart6850_cmd(UART_RESET);
135 uart6850_input_loop();
137 midi_input_intr = input;
138 uart6850_opened = mode;
139 poll_uart6850(0); /* Enable input polling */
145 uart6850_close(int dev)
147 uart6850_cmd(UART_MODE_ON);
153 uart6850_out(int dev, u_char midi_byte)
159 * Test for input since pending input seems to block the output.
165 uart6850_input_loop();
170 * Sometimes it takes about 13000 loops before the output becomes
171 * ready (After reset). Normally it takes just about 10 loops.
174 for (timeout = 30000; timeout > 0 && !output_ready(); timeout--); /* Wait */
176 if (!output_ready()) {
177 printf("Midi6850: Timeout\n");
180 uart6850_write(midi_byte);
185 uart6850_command(int dev, u_char *midi_byte)
191 uart6850_start_read(int dev)
197 uart6850_end_read(int dev)
203 uart6850_ioctl(int dev, u_int cmd, ioctl_arg arg)
209 uart6850_kick(int dev)
214 uart6850_buffer_status(int dev)
216 return 0; /* No data in buffers */
219 #define MIDI_SYNTH_NAME "6850 UART Midi"
220 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
221 #include <i386/isa/sound/midi_synth.h>
223 static struct midi_operations uart6850_operations =
225 {"6850 UART", 0, 0, SNDCARD_UART6850},
236 uart6850_buffer_status
241 attach_uart6850(struct address_info * hw_config)
246 if (num_midis >= MAX_MIDI_DEV) {
247 printf("Sound: Too many midi devices detected\n");
250 uart6850_base = hw_config->io_base;
251 uart6850_osp = hw_config->osp;
252 uart6850_irq = hw_config->irq;
254 if (!uart6850_detected)
259 for (timeout = 30000; timeout < 0 && !output_ready(); timeout--); /* Wait */
260 uart6850_cmd(UART_MODE_ON);
266 conf_printf("6850 Midi Interface", hw_config);
268 std_midi_synth.midi_dev = my_dev = num_midis;
269 midi_devs[num_midis++] = &uart6850_operations;
282 probe_uart6850(struct address_info * hw_config)
286 uart6850_osp = hw_config->osp;
287 uart6850_base = hw_config->io_base;
288 uart6850_irq = hw_config->irq;
290 if (snd_set_irq_handler(uart6850_irq, m6850intr, uart6850_osp) < 0)
293 ok = reset_uart6850();
295 uart6850_detected = ok;