root/drivers/sound/uart6850.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. uart6850_input_loop
  2. m6850intr
  3. poll_uart6850
  4. uart6850_open
  5. uart6850_close
  6. uart6850_out
  7. uart6850_command
  8. uart6850_start_read
  9. uart6850_end_read
  10. uart6850_ioctl
  11. uart6850_kick
  12. uart6850_buffer_status
  13. attach_uart6850
  14. reset_uart6850
  15. probe_uart6850

   1 /*
   2  * sound/uart6850.c
   3  *
   4  * Copyright by Hannu Savolainen 1993
   5  *
   6  * Mon Nov 22 22:38:35 MET 1993 marco@driq.home.usn.nl:
   7  *      added 6850 support, used with COVOX SoundMaster II and custom cards.
   8  *
   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.
  16  *
  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
  27  * SUCH DAMAGE.
  28  *
  29  */
  30 
  31 #include "sound_config.h"
  32 
  33 #ifdef CONFIGURE_SOUNDCARD
  34 
  35 #if !defined(EXCLUDE_UART6850) && !defined(EXCLUDE_MIDI)
  36 
  37 #define DATAPORT   (uart6850_base)      /*
  38                                            * * * Midi6850 Data I/O Port on IBM
  39                                            *  */
  40 #define COMDPORT   (uart6850_base+1)    /*
  41                                            * * * Midi6850 Command Port on IBM   */
  42 #define STATPORT   (uart6850_base+1)    /*
  43                                            * * * Midi6850 Status Port on IBM   */
  44 
  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(cmd, COMDPORT)
  49 #define uart6850_read()         INB(DATAPORT)
  50 #define uart6850_write(byte)    OUTB(byte, DATAPORT)
  51 
  52 #define OUTPUT_READY    0x02    /*
  53                                    * * * Mask for Data Read Ready Bit   */
  54 #define INPUT_AVAIL     0x01    /*
  55                                    * * * Mask for Data Send Ready Bit   */
  56 
  57 #define UART_RESET      0x95    /*
  58                                    * * * 6850 Total Reset Command   */
  59 #define UART_MODE_ON    0x03    /*
  60                                    * * * 6850 Send/Receive UART Mode   */
  61 
  62 static int      uart6850_opened = 0;
  63 static int      uart6850_base = 0x330;
  64 static int      uart6850_irq;
  65 static int      uart6850_detected = 0;
  66 static int      my_dev;
  67 
  68 static int      reset_uart6850 (void);
  69 static void     (*midi_input_intr) (int dev, unsigned char data);
  70 
  71 static void
  72 uart6850_input_loop (void)
     /* [previous][next][first][last][top][bottom][index][help] */
  73 {
  74   int             count;
  75 
  76   count = 10;
  77 
  78   while (count)                 /*
  79                                  * Not timed out
  80                                  */
  81     if (input_avail ())
  82       {
  83         unsigned char   c = uart6850_read ();
  84 
  85         count = 100;
  86 
  87         if (uart6850_opened & OPEN_READ)
  88           midi_input_intr (my_dev, c);
  89       }
  90     else
  91       while (!input_avail () && count)
  92         count--;
  93 }
  94 
  95 void
  96 m6850intr (INTR_HANDLER_PARMS (irq, dummy))
     /* [previous][next][first][last][top][bottom][index][help] */
  97 {
  98   if (input_avail ())
  99     uart6850_input_loop ();
 100 }
 101 
 102 /*
 103  * It looks like there is no input interrupts in the UART mode. Let's try
 104  * polling.
 105  */
 106 
 107 static void
 108 poll_uart6850 (unsigned long dummy)
     /* [previous][next][first][last][top][bottom][index][help] */
 109 {
 110   unsigned long   flags;
 111 
 112   DEFINE_TIMER (uart6850_timer, poll_uart6850);
 113 
 114   if (!(uart6850_opened & OPEN_READ))
 115     return;                     /*
 116                                  * No longer required
 117                                  */
 118 
 119   DISABLE_INTR (flags);
 120 
 121   if (input_avail ())
 122     uart6850_input_loop ();
 123 
 124   ACTIVATE_TIMER (uart6850_timer, poll_uart6850, 1);    /*
 125                                                          * Come back later
 126                                                          */
 127 
 128   RESTORE_INTR (flags);
 129 }
 130 
 131 static int
 132 uart6850_open (int dev, int mode,
     /* [previous][next][first][last][top][bottom][index][help] */
 133                void            (*input) (int dev, unsigned char data),
 134                void            (*output) (int dev)
 135 )
 136 {
 137   if (uart6850_opened)
 138     {
 139       printk ("Midi6850: Midi busy\n");
 140       return RET_ERROR (EBUSY);
 141     }
 142 
 143   uart6850_cmd (UART_RESET);
 144 
 145   uart6850_input_loop ();
 146 
 147   midi_input_intr = input;
 148   uart6850_opened = mode;
 149   poll_uart6850 (0);            /*
 150                                  * Enable input polling
 151                                  */
 152 
 153   return 0;
 154 }
 155 
 156 static void
 157 uart6850_close (int dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 158 {
 159   uart6850_cmd (UART_MODE_ON);
 160 
 161   uart6850_opened = 0;
 162 }
 163 
 164 static int
 165 uart6850_out (int dev, unsigned char midi_byte)
     /* [previous][next][first][last][top][bottom][index][help] */
 166 {
 167   int             timeout;
 168   unsigned long   flags;
 169 
 170   /*
 171    * Test for input since pending input seems to block the output.
 172    */
 173 
 174   DISABLE_INTR (flags);
 175 
 176   if (input_avail ())
 177     uart6850_input_loop ();
 178 
 179   RESTORE_INTR (flags);
 180 
 181   /*
 182    * Sometimes it takes about 13000 loops before the output becomes ready
 183    * (After reset). Normally it takes just about 10 loops.
 184    */
 185 
 186   for (timeout = 30000; timeout > 0 && !output_ready (); timeout--);    /*
 187                                                                          * Wait
 188                                                                          */
 189 
 190   if (!output_ready ())
 191     {
 192       printk ("Midi6850: Timeout\n");
 193       return 0;
 194     }
 195 
 196   uart6850_write (midi_byte);
 197   return 1;
 198 }
 199 
 200 static int
 201 uart6850_command (int dev, unsigned char *midi_byte)
     /* [previous][next][first][last][top][bottom][index][help] */
 202 {
 203   return 1;
 204 }
 205 
 206 static int
 207 uart6850_start_read (int dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 208 {
 209   return 0;
 210 }
 211 
 212 static int
 213 uart6850_end_read (int dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 214 {
 215   return 0;
 216 }
 217 
 218 static int
 219 uart6850_ioctl (int dev, unsigned cmd, unsigned arg)
     /* [previous][next][first][last][top][bottom][index][help] */
 220 {
 221   return RET_ERROR (EINVAL);
 222 }
 223 
 224 static void
 225 uart6850_kick (int dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 226 {
 227 }
 228 
 229 static int
 230 uart6850_buffer_status (int dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 231 {
 232   return 0;                     /*
 233                                  * No data in buffers
 234                                  */
 235 }
 236 
 237 #define MIDI_SYNTH_NAME "6850 UART Midi"
 238 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
 239 #include "midi_synth.h"
 240 
 241 static struct midi_operations uart6850_operations =
 242 {
 243   {"6850 UART", 0, 0, SNDCARD_UART6850},
 244   &std_midi_synth,
 245   {0},
 246   uart6850_open,
 247   uart6850_close,
 248   uart6850_ioctl,
 249   uart6850_out,
 250   uart6850_start_read,
 251   uart6850_end_read,
 252   uart6850_kick,
 253   uart6850_command,
 254   uart6850_buffer_status
 255 };
 256 
 257 
 258 long
 259 attach_uart6850 (long mem_start, struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 260 {
 261   int             ok, timeout;
 262   unsigned long   flags;
 263 
 264   if (num_midis >= MAX_MIDI_DEV)
 265     {
 266       printk ("Sound: Too many midi devices detected\n");
 267       return mem_start;
 268     }
 269 
 270   uart6850_base = hw_config->io_base;
 271   uart6850_irq = hw_config->irq;
 272 
 273   if (!uart6850_detected)
 274     return RET_ERROR (EIO);
 275 
 276   DISABLE_INTR (flags);
 277 
 278   for (timeout = 30000; timeout < 0 && !output_ready (); timeout--);    /*
 279                                                                          * Wait
 280                                                                          */
 281   uart6850_cmd (UART_MODE_ON);
 282 
 283   ok = 1;
 284 
 285   RESTORE_INTR (flags);
 286 
 287   printk (" <6850 Midi Interface>");
 288 
 289   std_midi_synth.midi_dev = my_dev = num_midis;
 290   midi_devs[num_midis++] = &uart6850_operations;
 291   return mem_start;
 292 }
 293 
 294 static int
 295 reset_uart6850 (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 296 {
 297   uart6850_read ();
 298   return 1;                     /*
 299                                  * OK
 300                                  */
 301 }
 302 
 303 
 304 int
 305 probe_uart6850 (struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 306 {
 307   int             ok = 0;
 308 
 309   uart6850_base = hw_config->io_base;
 310   uart6850_irq = hw_config->irq;
 311 
 312   if (snd_set_irq_handler (uart6850_irq, m6850intr, "MIDI6850") < 0)
 313     return 0;
 314 
 315   ok = reset_uart6850 ();
 316 
 317   uart6850_detected = ok;
 318   return ok;
 319 }
 320 
 321 #endif
 322 
 323 #endif

/* [previous][next][first][last][top][bottom][index][help] */