root/drivers/sound/sb_dsp.c

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

DEFINITIONS

This source file includes following definitions.
  1. sb_dsp_command
  2. ess_write
  3. ess_read
  4. sbintr
  5. sb_get_irq
  6. sb_free_irq
  7. sb_reset_dsp
  8. dsp_speaker
  9. ess_speed
  10. dsp_speed
  11. dsp_set_stereo
  12. sb_dsp_output_block
  13. actually_output_block
  14. sb_dsp_start_input
  15. actually_start_input
  16. sb_dsp_trigger
  17. dsp_cleanup
  18. sb_dsp_prepare_for_input
  19. sb_dsp_prepare_for_output
  20. sb_dsp_halt_xfer
  21. verify_irq
  22. sb_dsp_open
  23. sb_dsp_close
  24. dsp_set_bits
  25. sb_dsp_ioctl
  26. sb_dsp_reset
  27. get_sb_byte
  28. smw_putmem
  29. smw_getmem
  30. initialize_smw
  31. initialize_ProSonic16
  32. sb_dsp_detect
  33. ess_init
  34. ess_midi_init
  35. Jazz16_midi_init
  36. Jazz16_set_dma16
  37. dsp_get_vers
  38. sb_dsp_init
  39. sb_dsp_unload
  40. sb_dsp_disable_midi

   1 /*
   2  * sound/sb_dsp.c
   3  *
   4  * The low level driver for the SoundBlaster DSP chip (SB1.0 to 2.1, SB Pro).
   5  */
   6 /*
   7  * Copyright by Hannu Savolainen 1993-1996
   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 #include <linux/config.h>
  30 
  31 /*
  32  * Modified:
  33  *      Hunyue Yau      Jan 6 1994
  34  *      Added code to support Sound Galaxy NX Pro
  35  *
  36  *      JRA Gibson      April 1995
  37  *      Code added for MV ProSonic/Jazz 16 in 16 bit mode
  38  */
  39 
  40 #include "sound_config.h"
  41 
  42 #if defined(CONFIG_SB)
  43 
  44 #include "sb.h"
  45 #include "sb_mixer.h"
  46 #undef SB_TEST_IRQ
  47 
  48 int             sbc_base = 0;
  49 static int      sbc_irq = 0, sbc_dma;
  50 static int      open_mode = 0;  /* Read, write or both */
  51 int             Jazz16_detected = 0;
  52 int             AudioDrive = 0; /* 1=ES1688 detected */
  53 static int      ess_mpu_irq = 0;
  54 int             sb_no_recording = 0;
  55 static int      dsp_count = 0;
  56 static int      trigger_bits;
  57 static int      mpu_base = 0, mpu_irq = 0;
  58 static int      sb16_inited = 0;
  59 
  60 /*
  61  * The DSP channel can be used either for input or output. Variable
  62  * 'sb_irq_mode' will be set when the program calls read or write first time
  63  * after open. Current version doesn't support mode changes without closing
  64  * and reopening the device. Support for this feature may be implemented in a
  65  * future version of this driver.
  66  */
  67 
  68 int             sb_dsp_ok = 0;  /*
  69 
  70 
  71                                  * *  * * Set to 1 after successful
  72                                  * initialization  *  */
  73 static int      midi_disabled = 0;
  74 int             sb_dsp_highspeed = 0;
  75 int             sbc_major = 0, sbc_minor = 0;
  76 static int      dsp_stereo = 0;
  77 static int      dsp_current_speed = DSP_DEFAULT_SPEED;
  78 static int      dsp_requested_speed = DSP_DEFAULT_SPEED;
  79 static int      sb16 = 0;
  80 static int      irq_verified = 0;
  81 
  82 int             sb_midi_mode = NORMAL_MIDI;
  83 int             sb_midi_busy = 0;
  84 int             sb_dsp_busy = 0;
  85 
  86 volatile int    sb_irq_mode = IMODE_NONE;
  87 static volatile int irq_ok = 0;
  88 
  89 static int      dma8 = 1;
  90 static int      dsp_16bit = 0;
  91 
  92 /* 16 bit support
  93  */
  94 
  95 static int      dma16 = 1;
  96 
  97 static int      dsp_set_bits (int arg);
  98 static int      initialize_ProSonic16 (void);
  99 
 100 /* end of 16 bit support
 101  */
 102 
 103 int             sb_duplex_midi = 0;
 104 static int      my_dev = 0;
 105 
 106 volatile int    sb_intr_active = 0;
 107 
 108 static int      dsp_speed (int);
 109 static int      dsp_set_stereo (int mode);
 110 static void     sb_dsp_reset (int dev);
 111 static void     dsp_get_vers (struct address_info *hw_config);
 112 int            *sb_osp = NULL;
 113 
 114 #if defined(CONFIG_MIDI) || defined(CONFIG_AUDIO)
 115 
 116 /*
 117  * Common code for the midi and pcm functions
 118  */
 119 
 120 int
 121 sb_dsp_command (unsigned char val)
     /* [previous][next][first][last][top][bottom][index][help] */
 122 {
 123   int             i;
 124   unsigned long   limit;
 125 
 126   limit = jiffies + HZ / 10;    /*
 127                                    * The timeout is 0.1 secods
 128                                  */
 129 
 130   /*
 131    * Note! the i<500000 is an emergency exit. The sb_dsp_command() is sometimes
 132    * called while interrupts are disabled. This means that the timer is
 133    * disabled also. However the timeout situation is a abnormal condition.
 134    * Normally the DSP should be ready to accept commands after just couple of
 135    * loops.
 136    */
 137 
 138   for (i = 0; i < 500000 && jiffies < limit; i++)
 139     {
 140       if ((inb (DSP_STATUS) & 0x80) == 0)
 141         {
 142           outb (val, DSP_COMMAND);
 143           return 1;
 144         }
 145     }
 146 
 147   printk ("SoundBlaster: DSP Command(%x) Timeout.\n", val);
 148   return 0;
 149 }
 150 
 151 static int
 152 ess_write (unsigned char reg, unsigned char data)
     /* [previous][next][first][last][top][bottom][index][help] */
 153 {
 154   /* Write a byte to an extended mode register of ES1688 */
 155 
 156   if (!sb_dsp_command (reg))
 157     return 0;
 158 
 159   return sb_dsp_command (data);
 160 }
 161 
 162 static int
 163 ess_read (unsigned char reg)
     /* [previous][next][first][last][top][bottom][index][help] */
 164 {
 165 /* Read a byte from an extended mode register of ES1688 */
 166 
 167   int             i;
 168 
 169   if (!sb_dsp_command (0xc0))   /* Read register command */
 170     return -1;
 171 
 172   if (!sb_dsp_command (reg))
 173     return -1;
 174 
 175   for (i = 1000; i; i--)
 176     {
 177       if (inb (DSP_DATA_AVAIL) & 0x80)
 178         return inb (DSP_READ);
 179     }
 180 
 181   return -1;
 182 }
 183 
 184 void
 185 sbintr (int irq, void *dev_id, struct pt_regs *dummy)
     /* [previous][next][first][last][top][bottom][index][help] */
 186 {
 187   int             status;
 188 
 189   if (sb16 && !AudioDrive)
 190     {
 191       unsigned char   src = sb_getmixer (IRQ_STAT);     /* Interrupt source register */
 192 
 193       if (src & 3)
 194         sb16_dsp_interrupt (irq);
 195 
 196 #ifdef CONFIG_MIDI
 197       if (src & 4)
 198         sb16midiintr (irq);     /*
 199                                  * SB MPU401 interrupt
 200                                  */
 201 #endif
 202 
 203       if (!(src & 1))
 204         return;                 /*
 205                                  * Not a DSP interupt
 206                                  */
 207     }
 208 
 209   status = inb (DSP_DATA_AVAIL);        /*
 210                                            * Clear interrupt
 211                                          */
 212   if (sb_intr_active)
 213     switch (sb_irq_mode)
 214       {
 215       case IMODE_OUTPUT:
 216         if (!AudioDrive)
 217           sb_intr_active = 0;
 218         DMAbuf_outputintr (my_dev, 1);
 219         break;
 220 
 221       case IMODE_INPUT:
 222         if (!AudioDrive)
 223           sb_intr_active = 0;
 224         DMAbuf_inputintr (my_dev);
 225         break;
 226 
 227       case IMODE_INIT:
 228         sb_intr_active = 0;
 229         irq_ok = 1;
 230         break;
 231 
 232       case IMODE_MIDI:
 233 #ifdef CONFIG_MIDI
 234         sb_midi_interrupt (irq);
 235 #endif
 236         break;
 237 
 238       default:
 239         printk ("SoundBlaster: Unexpected interrupt\n");
 240       }
 241 }
 242 
 243 int
 244 sb_get_irq (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 245 {
 246   return 0;
 247 }
 248 
 249 void
 250 sb_free_irq (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 251 {
 252 }
 253 
 254 int
 255 sb_reset_dsp (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 256 {
 257   int             loopc;
 258 
 259   if (AudioDrive)
 260     outb (3, DSP_RESET);        /* Reset FIFO too */
 261   else
 262     outb (1, DSP_RESET);
 263 
 264   tenmicrosec (sb_osp);
 265   outb (0, DSP_RESET);
 266   tenmicrosec (sb_osp);
 267   tenmicrosec (sb_osp);
 268   tenmicrosec (sb_osp);
 269 
 270   for (loopc = 0; loopc < 1000 && !(inb (DSP_DATA_AVAIL) & 0x80); loopc++);
 271 
 272   if (inb (DSP_READ) != 0xAA)
 273     return 0;                   /* Sorry */
 274 
 275   if (AudioDrive)
 276     sb_dsp_command (0xc6);      /* Enable extended mode */
 277 
 278   return 1;
 279 }
 280 
 281 #endif
 282 
 283 #ifdef CONFIG_AUDIO
 284 
 285 static void
 286 dsp_speaker (char state)
     /* [previous][next][first][last][top][bottom][index][help] */
 287 {
 288   if (state)
 289     sb_dsp_command (DSP_CMD_SPKON);
 290   else
 291     sb_dsp_command (DSP_CMD_SPKOFF);
 292 }
 293 
 294 static int
 295 ess_speed (int speed)
     /* [previous][next][first][last][top][bottom][index][help] */
 296 {
 297   int             divider;
 298   unsigned char   bits = 0;
 299 
 300   if (speed < 4000)
 301     speed = 4000;
 302   else if (speed > 48000)
 303     speed = 48000;
 304 
 305   if (speed > 22000)
 306     {
 307       bits = 0x80;
 308       divider = 256 - (795500 + speed / 2) / speed;
 309       dsp_current_speed = 795500 / (256 - divider);
 310     }
 311   else
 312     {
 313       divider = 128 - (397700 + speed / 2) / speed;
 314       dsp_current_speed = 397700 / (128 - divider);
 315     }
 316 
 317   bits |= (unsigned char) divider;
 318   ess_write (0xa1, bits);
 319 
 320 /*
 321  * Set filter divider register
 322  */
 323 
 324   speed = (speed * 9) / 20;     /* Set filter rolloff to 90% of speed/2 */
 325   divider = 256 - 7160000 / (speed * 82);
 326   ess_write (0xa2, divider);
 327 
 328   return dsp_current_speed;
 329 }
 330 
 331 static int
 332 dsp_speed (int speed)
     /* [previous][next][first][last][top][bottom][index][help] */
 333 {
 334   unsigned char   tconst;
 335   unsigned long   flags;
 336   int             max_speed = 44100;
 337 
 338   dsp_requested_speed = speed;
 339 
 340   if (AudioDrive)
 341     return ess_speed (speed);
 342 
 343   if (speed < 4000)
 344     speed = 4000;
 345 
 346   /*
 347      * Older SB models don't support higher speeds than 22050.
 348    */
 349 
 350   if (sbc_major < 2 ||
 351       (sbc_major == 2 && sbc_minor == 0))
 352     max_speed = 22050;
 353 
 354   /*
 355      * SB models earlier than SB Pro have low limit for the input speed.
 356    */
 357   if (open_mode != OPEN_WRITE)  /* Recording is possible */
 358     if (sbc_major < 3)          /* Limited input speed with these cards */
 359       if (sbc_major == 2 && sbc_minor > 0)
 360         max_speed = 15000;
 361       else
 362         max_speed = 13000;
 363 
 364   if (speed > max_speed)
 365     speed = max_speed;          /*
 366                                  * Invalid speed
 367                                  */
 368 
 369   /* Logitech SoundMan Games and Jazz16 cards can support 44.1kHz stereo */
 370 #if !defined (SM_GAMES)
 371   /*
 372    * Max. stereo speed is 22050
 373    */
 374   if (dsp_stereo && speed > 22050 && Jazz16_detected == 0 && AudioDrive == 0)
 375     speed = 22050;
 376 #endif
 377 
 378   if ((speed > 22050) && sb_midi_busy)
 379     {
 380       printk ("SB Warning: High speed DSP not possible simultaneously with MIDI output\n");
 381       speed = 22050;
 382     }
 383 
 384   if (dsp_stereo)
 385     speed *= 2;
 386 
 387   /*
 388    * Now the speed should be valid
 389    */
 390 
 391   if (speed > 22050)
 392     {                           /*
 393                                  * High speed mode
 394                                  */
 395       int             tmp;
 396 
 397       tconst = (unsigned char) ((65536 -
 398                                  ((256000000 + speed / 2) / speed)) >> 8);
 399       sb_dsp_highspeed = 1;
 400 
 401       save_flags (flags);
 402       cli ();
 403       if (sb_dsp_command (0x40))
 404         sb_dsp_command (tconst);
 405       restore_flags (flags);
 406 
 407       tmp = 65536 - (tconst << 8);
 408       speed = (256000000 + tmp / 2) / tmp;
 409     }
 410   else
 411     {
 412       int             tmp;
 413 
 414       sb_dsp_highspeed = 0;
 415       tconst = (256 - ((1000000 + speed / 2) / speed)) & 0xff;
 416 
 417       save_flags (flags);
 418       cli ();
 419       if (sb_dsp_command (0x40))        /*
 420                                          * Set time constant
 421                                          */
 422         sb_dsp_command (tconst);
 423       restore_flags (flags);
 424 
 425       tmp = 256 - tconst;
 426       speed = (1000000 + tmp / 2) / tmp;
 427     }
 428 
 429   if (dsp_stereo)
 430     speed /= 2;
 431 
 432   dsp_current_speed = speed;
 433   return speed;
 434 }
 435 
 436 static int
 437 dsp_set_stereo (int mode)
     /* [previous][next][first][last][top][bottom][index][help] */
 438 {
 439   dsp_stereo = 0;
 440 
 441   if (sbc_major < 3 || sb16)
 442     return 0;                   /*
 443                                  * Sorry no stereo
 444                                  */
 445 
 446   if (mode && sb_midi_busy)
 447     {
 448       printk ("SB Warning: Stereo DSP not possible simultaneously with MIDI output\n");
 449       return 0;
 450     }
 451 
 452   dsp_stereo = !!mode;
 453   dsp_speed (dsp_requested_speed);
 454   return dsp_stereo;
 455 }
 456 
 457 static unsigned long trg_buf;
 458 static int      trg_bytes;
 459 static int      trg_intrflag;
 460 static int      trg_restart;
 461 
 462 static void
 463 sb_dsp_output_block (int dev, unsigned long buf, int nr_bytes,
     /* [previous][next][first][last][top][bottom][index][help] */
 464                      int intrflag, int restart_dma)
 465 {
 466   trg_buf = buf;
 467   trg_bytes = nr_bytes;
 468   trg_intrflag = intrflag;
 469   trg_restart = restart_dma;
 470   sb_irq_mode = IMODE_OUTPUT;
 471 }
 472 
 473 static void
 474 actually_output_block (int dev, unsigned long buf, int nr_bytes,
     /* [previous][next][first][last][top][bottom][index][help] */
 475                        int intrflag, int restart_dma)
 476 {
 477   unsigned long   flags;
 478   int             count = nr_bytes;
 479 
 480   DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE);
 481 
 482   sb_irq_mode = 0;
 483 
 484   if (audio_devs[dev]->dmachan1 > 3)
 485     count >>= 1;
 486   count--;
 487   dsp_count = count;
 488 
 489   sb_irq_mode = IMODE_OUTPUT;
 490 
 491   if (AudioDrive)
 492     {
 493       short           c = -nr_bytes;
 494 
 495       ess_write (0xa4, (unsigned char) ((unsigned short) c & 0xff));
 496       ess_write (0xa5, (unsigned char) (((unsigned short) c >> 8) & 0xff));
 497 
 498       ess_write (0xb8, ess_read (0xb8) | 0x01);         /* Go */
 499     }
 500   else if (sb_dsp_highspeed)
 501     {
 502       save_flags (flags);
 503       cli ();
 504       if (sb_dsp_command (0x48))        /*
 505                                            * High speed size
 506                                          */
 507         {
 508           sb_dsp_command ((unsigned char) (dsp_count & 0xff));
 509           sb_dsp_command ((unsigned char) ((dsp_count >> 8) & 0xff));
 510           sb_dsp_command (0x91);        /*
 511                                            * High speed 8 bit DAC
 512                                          */
 513         }
 514       else
 515         printk ("SB Error: Unable to start (high speed) DAC\n");
 516       restore_flags (flags);
 517     }
 518   else
 519     {
 520       save_flags (flags);
 521       cli ();
 522       if (sb_dsp_command (0x14))        /*
 523                                            * 8-bit DAC (DMA)
 524                                          */
 525         {
 526           sb_dsp_command ((unsigned char) (dsp_count & 0xff));
 527           sb_dsp_command ((unsigned char) ((dsp_count >> 8) & 0xff));
 528         }
 529       else
 530         printk ("SB Error: Unable to start DAC\n");
 531       restore_flags (flags);
 532     }
 533   sb_intr_active = 1;
 534 }
 535 
 536 static void
 537 sb_dsp_start_input (int dev, unsigned long buf, int count, int intrflag,
     /* [previous][next][first][last][top][bottom][index][help] */
 538                     int restart_dma)
 539 {
 540   if (sb_no_recording)
 541     {
 542       return;
 543     }
 544 
 545   trg_buf = buf;
 546   trg_bytes = count;
 547   trg_intrflag = intrflag;
 548   trg_restart = restart_dma;
 549   sb_irq_mode = IMODE_INPUT;
 550 }
 551 
 552 static void
 553 actually_start_input (int dev, unsigned long buf, int nr_bytes, int intrflag,
     /* [previous][next][first][last][top][bottom][index][help] */
 554                       int restart_dma)
 555 {
 556   unsigned long   flags;
 557   int             count = nr_bytes;
 558 
 559   if (sb_no_recording)
 560     {
 561       return;
 562     }
 563 
 564   /*
 565    * Start a DMA input to the buffer pointed by dmaqtail
 566    */
 567 
 568   DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ);
 569   sb_irq_mode = 0;
 570 
 571   if (audio_devs[dev]->dmachan1 > 3)
 572     count >>= 1;
 573   count--;
 574   dsp_count = count;
 575 
 576   sb_irq_mode = IMODE_INPUT;
 577 
 578   if (AudioDrive)
 579     {
 580       short           c = -nr_bytes;
 581 
 582       ess_write (0xa4, (unsigned char) ((unsigned short) c & 0xff));
 583       ess_write (0xa5, (unsigned char) (((unsigned short) c >> 8) & 0xff));
 584 
 585       ess_write (0xb8, ess_read (0xb8) | 0x01);         /* Go */
 586     }
 587   else if (sb_dsp_highspeed)
 588     {
 589       save_flags (flags);
 590       cli ();
 591       if (sb_dsp_command (0x48))        /*
 592                                            * High speed size
 593                                          */
 594         {
 595           sb_dsp_command ((unsigned char) (dsp_count & 0xff));
 596           sb_dsp_command ((unsigned char) ((dsp_count >> 8) & 0xff));
 597           sb_dsp_command (0x99);        /*
 598                                            * High speed 8 bit ADC
 599                                          */
 600         }
 601       else
 602         printk ("SB Error: Unable to start (high speed) ADC\n");
 603       restore_flags (flags);
 604     }
 605   else
 606     {
 607       save_flags (flags);
 608       cli ();
 609       if (sb_dsp_command (0x24))        /*
 610                                            * 8-bit ADC (DMA)
 611                                          */
 612         {
 613           sb_dsp_command ((unsigned char) (dsp_count & 0xff));
 614           sb_dsp_command ((unsigned char) ((dsp_count >> 8) & 0xff));
 615         }
 616       else
 617         printk ("SB Error: Unable to start ADC\n");
 618       restore_flags (flags);
 619     }
 620 
 621   sb_intr_active = 1;
 622 }
 623 
 624 static void
 625 sb_dsp_trigger (int dev, int bits)
     /* [previous][next][first][last][top][bottom][index][help] */
 626 {
 627 
 628   if (!bits)
 629     sb_dsp_command (0xd0);      /* Halt DMA */
 630   else if (bits & sb_irq_mode)
 631     {
 632       switch (sb_irq_mode)
 633         {
 634         case IMODE_INPUT:
 635           actually_start_input (my_dev, trg_buf, trg_bytes,
 636                                 trg_intrflag, trg_restart);
 637           break;
 638 
 639         case IMODE_OUTPUT:
 640           actually_output_block (my_dev, trg_buf, trg_bytes,
 641                                  trg_intrflag, trg_restart);
 642           break;
 643         }
 644     }
 645 
 646   trigger_bits = bits;
 647 }
 648 
 649 static void
 650 dsp_cleanup (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 651 {
 652   sb_intr_active = 0;
 653 }
 654 
 655 static int
 656 sb_dsp_prepare_for_input (int dev, int bsize, int bcount)
     /* [previous][next][first][last][top][bottom][index][help] */
 657 {
 658   if (sb_no_recording)
 659     {
 660       printk ("SB Error: This device doesn't support recording\n");
 661       return 0;
 662     }
 663 
 664   dsp_cleanup ();
 665   dsp_speaker (OFF);
 666   dsp_speed (dsp_requested_speed);
 667 
 668   if (sbc_major == 3)           /*
 669                                  * SB Pro
 670                                  */
 671     {
 672       if (AudioDrive)
 673         {
 674 
 675           ess_write (0xb8, 0x0e);       /* Auto init DMA mode */
 676           ess_write (0xa8, (ess_read (0xa8) & ~0x04) |
 677                      (2 - dsp_stereo));         /* Mono/stereo */
 678           ess_write (0xb9, 2);  /* Demand mode (2 bytes/xfer) */
 679 
 680           if (!dsp_stereo)
 681             {
 682               if (dsp_16bit == 0)
 683                 {               /* 8 bit mono */
 684                   ess_write (0xb7, 0x51);
 685                   ess_write (0xb7, 0xd0);
 686                 }
 687               else
 688                 {               /* 16 bit mono */
 689                   ess_write (0xb7, 0x71);
 690                   ess_write (0xb7, 0xf4);
 691                 }
 692             }
 693           else
 694             {                   /* Stereo */
 695               if (!dsp_16bit)
 696                 {               /* 8 bit stereo */
 697                   ess_write (0xb7, 0x51);
 698                   ess_write (0xb7, 0x98);
 699                 }
 700               else
 701                 {               /* 16 bit stereo */
 702                   ess_write (0xb7, 0x71);
 703                   ess_write (0xb7, 0xbc);
 704                 }
 705             }
 706 
 707           ess_write (0xb1, (ess_read (0xb1) & 0x0f) | 0x50);
 708           ess_write (0xb2, (ess_read (0xb2) & 0x0f) | 0x50);
 709         }
 710       else
 711         {                       /* !AudioDrive */
 712 
 713           /* Select correct dma channel
 714              * for 16/8 bit acccess
 715            */
 716           audio_devs[my_dev]->dmachan1 =
 717             audio_devs[my_dev]->dmachan2 =
 718             dsp_16bit ? dma16 : dma8;
 719           if (dsp_stereo)
 720             sb_dsp_command (dsp_16bit ? 0xac : 0xa8);
 721           else
 722             sb_dsp_command (dsp_16bit ? 0xa4 : 0xa0);
 723 
 724         }                       /* !AudioDrive */
 725     }
 726   trigger_bits = 0;
 727   return 0;
 728 }
 729 
 730 static int
 731 sb_dsp_prepare_for_output (int dev, int bsize, int bcount)
     /* [previous][next][first][last][top][bottom][index][help] */
 732 {
 733   dsp_cleanup ();
 734   dsp_speaker (OFF);
 735   dsp_speed (dsp_requested_speed);
 736 
 737   if (sbc_major == 3)           /* SB Pro (at least ) */
 738     {
 739 
 740       if (AudioDrive)
 741         {
 742 
 743           ess_write (0xb8, 4);  /* Auto init DMA mode */
 744           ess_write (0xa8, ess_read (0xa8) |
 745                      (2 - dsp_stereo));         /* Mono/stereo */
 746           ess_write (0xb9, 2);  /* Demand mode (2 bytes/xfer) */
 747 
 748           if (!dsp_stereo)
 749             {
 750               if (dsp_16bit == 0)
 751                 {               /* 8 bit mono */
 752                   ess_write (0xb6, 0x80);
 753                   ess_write (0xb7, 0x51);
 754                   ess_write (0xb7, 0xd0);
 755                 }
 756               else
 757                 {               /* 16 bit mono */
 758                   ess_write (0xb6, 0x00);
 759                   ess_write (0xb7, 0x71);
 760                   ess_write (0xb7, 0xf4);
 761                 }
 762             }
 763           else
 764             {                   /* Stereo */
 765               if (!dsp_16bit)
 766                 {               /* 8 bit stereo */
 767                   ess_write (0xb6, 0x80);
 768                   ess_write (0xb7, 0x51);
 769                   ess_write (0xb7, 0x98);
 770                 }
 771               else
 772                 {               /* 16 bit stereo */
 773                   ess_write (0xb6, 0x00);
 774                   ess_write (0xb7, 0x71);
 775                   ess_write (0xb7, 0xbc);
 776                 }
 777             }
 778 
 779           ess_write (0xb1, (ess_read (0xb1) & 0x0f) | 0x50);
 780           ess_write (0xb2, (ess_read (0xb2) & 0x0f) | 0x50);
 781         }
 782       else
 783         {                       /* !AudioDrive */
 784 
 785           /* 16 bit specific instructions (Jazz16)
 786            */
 787           audio_devs[my_dev]->dmachan1 =
 788             audio_devs[my_dev]->dmachan2 =
 789             dsp_16bit ? dma16 : dma8;
 790           if (Jazz16_detected != 2)     /* SM Wave */
 791             sb_mixer_set_stereo (dsp_stereo);
 792           if (dsp_stereo)
 793             sb_dsp_command (dsp_16bit ? 0xac : 0xa8);
 794           else
 795             sb_dsp_command (dsp_16bit ? 0xa4 : 0xa0);
 796         }                       /* !AudioDrive */
 797 
 798     }
 799 
 800   trigger_bits = 0;
 801   dsp_speaker (ON);
 802   return 0;
 803 }
 804 
 805 static void
 806 sb_dsp_halt_xfer (int dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 807 {
 808   if (AudioDrive)
 809     sb_reset_dsp ();
 810 }
 811 
 812 static int
 813 verify_irq (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 814 {
 815   irq_ok = 1;
 816   return irq_ok;
 817 }
 818 
 819 static int
 820 sb_dsp_open (int dev, int mode)
     /* [previous][next][first][last][top][bottom][index][help] */
 821 {
 822   int             retval;
 823 
 824   if (!sb_dsp_ok)
 825     {
 826       printk ("SB Error: SoundBlaster board not installed\n");
 827       return -ENXIO;
 828     }
 829 
 830   if (sb_no_recording && mode & OPEN_READ)
 831     {
 832       printk ("SB Warning: Recording not supported by this device\n");
 833     }
 834 
 835   if (sb_intr_active || (sb_midi_busy && sb_midi_mode == UART_MIDI))
 836     {
 837       printk ("SB: Audio device or MIDI already in use\n");
 838       return -EBUSY;
 839     }
 840 
 841   if (!sb_midi_busy)
 842     sb_reset_dsp ();
 843 
 844   if (!irq_verified)
 845     {
 846       verify_irq ();
 847       irq_verified = 1;
 848     }
 849   else if (!irq_ok)
 850     printk ("SB Warning: Incorrect IRQ setting %d\n",
 851             sbc_irq);
 852 
 853   retval = sb_get_irq ();
 854   if (retval)
 855     return retval;
 856 
 857   /* Allocate 8 bit dma
 858    */
 859   audio_devs[my_dev]->dmachan1 =
 860     audio_devs[my_dev]->dmachan2 =
 861     dma8;
 862 
 863   /* Allocate 16 bit dma (jazz16)
 864    */
 865   if (Jazz16_detected != 0)
 866     if (dma16 != dma8)
 867       {
 868         if (sound_open_dma (dma16, "Jazz16 16 bit"))
 869           {
 870             sb_free_irq ();
 871             /* DMAbuf_close_dma (dev); */
 872             return -EBUSY;
 873           }
 874       }
 875 
 876   sb_irq_mode = IMODE_NONE;
 877 
 878   sb_dsp_busy = 1;
 879   open_mode = mode;
 880 
 881   return 0;
 882 }
 883 
 884 static void
 885 sb_dsp_close (int dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 886 {
 887   /* Release 16 bit dma channel
 888    */
 889   if (Jazz16_detected)
 890     {
 891       audio_devs[my_dev]->dmachan1 =
 892         audio_devs[my_dev]->dmachan2 =
 893         dma8;
 894 
 895       if (dma16 != dma8)
 896         sound_close_dma (dma16);
 897     }
 898 
 899   if (AudioDrive)
 900     sb_reset_dsp ();
 901 
 902   /* DMAbuf_close_dma (dev); */
 903   sb_free_irq ();
 904   /* sb_dsp_command (0xd4); */
 905   dsp_cleanup ();
 906   dsp_speaker (OFF);
 907   sb_dsp_busy = 0;
 908   sb_dsp_highspeed = 0;
 909   open_mode = 0;
 910 }
 911 
 912 static int
 913 dsp_set_bits (int arg)
     /* [previous][next][first][last][top][bottom][index][help] */
 914 {
 915   if (arg)
 916     if (Jazz16_detected == 0 && AudioDrive == 0)
 917       dsp_16bit = 0;
 918     else
 919       switch (arg)
 920         {
 921         case 8:
 922           dsp_16bit = 0;
 923           break;
 924         case 16:
 925           dsp_16bit = 1;
 926           break;
 927         default:
 928           dsp_16bit = 0;
 929         }
 930 
 931   return dsp_16bit ? 16 : 8;
 932 }
 933 
 934 static int
 935 sb_dsp_ioctl (int dev, unsigned int cmd, caddr_t arg, int local)
     /* [previous][next][first][last][top][bottom][index][help] */
 936 {
 937   switch (cmd)
 938     {
 939     case SOUND_PCM_WRITE_RATE:
 940       if (local)
 941         return dsp_speed ((int) arg);
 942       return snd_ioctl_return ((int *) arg, dsp_speed (get_fs_long ((long *) arg)));
 943       break;
 944 
 945     case SOUND_PCM_READ_RATE:
 946       if (local)
 947         return dsp_current_speed;
 948       return snd_ioctl_return ((int *) arg, dsp_current_speed);
 949       break;
 950 
 951     case SOUND_PCM_WRITE_CHANNELS:
 952       if (local)
 953         return dsp_set_stereo ((int) arg - 1) + 1;
 954       return snd_ioctl_return ((int *) arg, dsp_set_stereo (get_fs_long ((long *) arg) - 1) + 1);
 955       break;
 956 
 957     case SOUND_PCM_READ_CHANNELS:
 958       if (local)
 959         return dsp_stereo + 1;
 960       return snd_ioctl_return ((int *) arg, dsp_stereo + 1);
 961       break;
 962 
 963     case SNDCTL_DSP_STEREO:
 964       if (local)
 965         return dsp_set_stereo ((int) arg);
 966       return snd_ioctl_return ((int *) arg, dsp_set_stereo (get_fs_long ((long *) arg)));
 967       break;
 968 
 969       /* Word size specific cases here.
 970          * SNDCTL_DSP_SETFMT=SOUND_PCM_WRITE_BITS
 971        */
 972     case SNDCTL_DSP_SETFMT:
 973       if (local)
 974         return dsp_set_bits ((int) arg);
 975       return snd_ioctl_return ((int *) arg, dsp_set_bits (get_fs_long ((long *) arg)));
 976       break;
 977 
 978     case SOUND_PCM_READ_BITS:
 979       if (local)
 980         return dsp_16bit ? 16 : 8;
 981       return snd_ioctl_return ((int *) arg, dsp_16bit ? 16 : 8);
 982       break;
 983 
 984     case SOUND_PCM_WRITE_FILTER:
 985     case SOUND_PCM_READ_FILTER:
 986       return -EINVAL;
 987       break;
 988 
 989     default:;
 990     }
 991 
 992   return -EINVAL;
 993 }
 994 
 995 static void
 996 sb_dsp_reset (int dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 997 {
 998   unsigned long   flags;
 999 
1000   save_flags (flags);
1001   cli ();
1002 
1003   sb_reset_dsp ();
1004   dsp_speed (dsp_current_speed);
1005   dsp_cleanup ();
1006 
1007   restore_flags (flags);
1008 }
1009 
1010 #endif
1011 
1012 
1013 /*
1014  * Initialization of a Media Vision ProSonic 16 Soundcard.
1015  * The function initializes a ProSonic 16 like PROS.EXE does for DOS. It sets
1016  * the base address, the DMA-channels, interrupts and enables the joystickport.
1017  *
1018  * Also used by Jazz 16 (same card, different name)
1019  *
1020  * written 1994 by Rainer Vranken
1021  * E-Mail: rvranken@polaris.informatik.uni-essen.de
1022  */
1023 
1024 unsigned int
1025 get_sb_byte (void)
     /* [previous][next][first][last][top][bottom][index][help] */
1026 {
1027   int             i;
1028 
1029   for (i = 1000; i; i--)
1030     if (inb (DSP_DATA_AVAIL) & 0x80)
1031       {
1032         return inb (DSP_READ);
1033       }
1034 
1035   return 0xffff;
1036 }
1037 
1038 /*
1039  * Logitech Soundman Wave detection and initialization by Hannu Savolainen.
1040  *
1041  * There is a microcontroller (8031) in the SM Wave card for MIDI emulation.
1042  * it's located at address MPU_BASE+4.  MPU_BASE+7 is a SM Wave specific
1043  * control register for MC reset, SCSI, OPL4 and DSP (future expansion)
1044  * address decoding. Otherwise the SM Wave is just a ordinary MV Jazz16
1045  * based soundcard.
1046  */
1047 
1048 static void
1049 smw_putmem (int base, int addr, unsigned char val)
     /* [previous][next][first][last][top][bottom][index][help] */
1050 {
1051   unsigned long   flags;
1052 
1053   save_flags (flags);
1054   cli ();
1055 
1056   outb (addr & 0xff, base + 1); /* Low address bits */
1057   outb (addr >> 8, base + 2);   /* High address bits */
1058   outb (val, base);             /* Data */
1059 
1060   restore_flags (flags);
1061 }
1062 
1063 static unsigned char
1064 smw_getmem (int base, int addr)
     /* [previous][next][first][last][top][bottom][index][help] */
1065 {
1066   unsigned long   flags;
1067   unsigned char   val;
1068 
1069   save_flags (flags);
1070   cli ();
1071 
1072   outb (addr & 0xff, base + 1); /* Low address bits */
1073   outb (addr >> 8, base + 2);   /* High address bits */
1074   val = inb (base);             /* Data */
1075 
1076   restore_flags (flags);
1077   return val;
1078 }
1079 
1080 #ifdef SMW_MIDI0001_INCLUDED
1081 #include "smw-midi0001.h"
1082 #else
1083 unsigned char  *smw_ucode = NULL;
1084 int             smw_ucodeLen = 0;
1085 
1086 #endif
1087 
1088 static int
1089 initialize_smw (int mpu_base)
     /* [previous][next][first][last][top][bottom][index][help] */
1090 {
1091 
1092   int             mp_base = mpu_base + 4;       /* Microcontroller base */
1093   int             i;
1094   unsigned char   control;
1095 
1096 
1097   /*
1098      *  Reset the microcontroller so that the RAM can be accessed
1099    */
1100 
1101   control = inb (mpu_base + 7);
1102   outb (control | 3, mpu_base + 7);     /* Set last two bits to 1 (?) */
1103   outb ((control & 0xfe) | 2, mpu_base + 7);    /* xxxxxxx0 resets the mc */
1104 
1105   for (i = 0; i < 300; i++)     /* Wait at least 1ms */
1106     tenmicrosec (sb_osp);
1107 
1108   outb (control & 0xfc, mpu_base + 7);  /* xxxxxx00 enables RAM */
1109 
1110   /*
1111      *  Detect microcontroller by probing the 8k RAM area
1112    */
1113   smw_putmem (mp_base, 0, 0x00);
1114   smw_putmem (mp_base, 1, 0xff);
1115   tenmicrosec (sb_osp);
1116 
1117   if (smw_getmem (mp_base, 0) != 0x00 || smw_getmem (mp_base, 1) != 0xff)
1118     {
1119       printk ("\nSM Wave: No microcontroller RAM detected (%02x, %02x)\n",
1120               smw_getmem (mp_base, 0), smw_getmem (mp_base, 1));
1121       return 0;                 /* No RAM */
1122     }
1123 
1124   /*
1125      *  There is RAM so assume it's really a SM Wave
1126    */
1127 
1128   if (smw_ucodeLen > 0)
1129     {
1130       if (smw_ucodeLen != 8192)
1131         {
1132           printk ("\nSM Wave: Invalid microcode (MIDI0001.BIN) length\n");
1133           return 1;
1134         }
1135 
1136       /*
1137          *  Download microcode
1138        */
1139 
1140       for (i = 0; i < 8192; i++)
1141         smw_putmem (mp_base, i, smw_ucode[i]);
1142 
1143       /*
1144          *  Verify microcode
1145        */
1146 
1147       for (i = 0; i < 8192; i++)
1148         if (smw_getmem (mp_base, i) != smw_ucode[i])
1149           {
1150             printk ("SM Wave: Microcode verification failed\n");
1151             return 0;
1152           }
1153     }
1154 
1155   control = 0;
1156 #ifdef SMW_SCSI_IRQ
1157   /*
1158      * Set the SCSI interrupt (IRQ2/9, IRQ3 or IRQ10). The SCSI interrupt
1159      * is disabled by default.
1160      *
1161      * Btw the Zilog 5380 SCSI controller is located at MPU base + 0x10.
1162    */
1163   {
1164     static unsigned char scsi_irq_bits[] =
1165     {0, 0, 3, 1, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0};
1166 
1167     control |= scsi_irq_bits[SMW_SCSI_IRQ] << 6;
1168   }
1169 #endif
1170 
1171 #ifdef SMW_OPL4_ENABLE
1172   /*
1173      *  Make the OPL4 chip visible on the PC bus at 0x380.
1174      *
1175      *  There is no need to enable this feature since this driver
1176      *  doesn't support OPL4 yet. Also there is no RAM in SM Wave so
1177      *  enabling OPL4 is pretty useless.
1178    */
1179   control |= 0x10;              /* Uses IRQ12 if bit 0x20 == 0 */
1180   /* control |= 0x20;      Uncomment this if you want to use IRQ7 */
1181 #endif
1182 
1183   outb (control | 0x03, mpu_base + 7);  /* xxxxxx11 restarts */
1184   return 1;
1185 }
1186 
1187 static int
1188 initialize_ProSonic16 (void)
     /* [previous][next][first][last][top][bottom][index][help] */
1189 {
1190   int             x;
1191   static unsigned char int_translat[16] =
1192   {0, 0, 2, 3, 0, 1, 0, 4, 0, 2, 5, 0, 0, 0, 0, 6}, dma_translat[8] =
1193   {0, 1, 0, 2, 0, 3, 0, 4};
1194 
1195   outb (0xAF, 0x201);           /* ProSonic/Jazz16 wakeup */
1196   for (x = 0; x < 1000; ++x)    /* wait 10 milliseconds */
1197     tenmicrosec (sb_osp);
1198   outb (0x50, 0x201);
1199   outb ((sbc_base & 0x70) | ((mpu_base & 0x30) >> 4), 0x201);
1200 
1201   if (sb_reset_dsp ())
1202     {                           /* OK. We have at least a SB */
1203 
1204       /* Check the version number of ProSonic (I guess) */
1205 
1206       if (!sb_dsp_command (0xFA))
1207         return 1;
1208       if (get_sb_byte () != 0x12)
1209         return 1;
1210 
1211       if (sb_dsp_command (0xFB) &&      /* set DMA-channels and Interrupts */
1212           sb_dsp_command ((dma_translat[dma16] << 4) | dma_translat[dma8]) &&
1213       sb_dsp_command ((int_translat[mpu_irq] << 4) | int_translat[sbc_irq]))
1214         {
1215           Jazz16_detected = 1;
1216 
1217           if (mpu_base != 0)
1218             if (initialize_smw (mpu_base))
1219               Jazz16_detected = 2;
1220 
1221           sb_dsp_disable_midi ();
1222         }
1223 
1224       return 1;                 /* There was at least a SB */
1225     }
1226   return 0;                     /* No SB or ProSonic16 detected */
1227 }
1228 
1229 int
1230 sb_dsp_detect (struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
1231 {
1232   if (sb_dsp_ok)
1233     return 0;                   /*
1234                                  * Already initialized
1235                                  */
1236 
1237   sbc_base = hw_config->io_base;
1238   sbc_irq = hw_config->irq;
1239   sbc_dma = hw_config->dma;
1240   sb_osp = hw_config->osp;
1241   dma8 = dma16 = hw_config->dma;
1242 
1243   if (sb_reset_dsp ())
1244     dsp_get_vers (hw_config);
1245   else
1246     sbc_major = 0;
1247 
1248   if (sbc_major == 3 || sbc_major == 0)
1249     if (initialize_ProSonic16 ())
1250       return 1;
1251 
1252   if (!sb_reset_dsp ())
1253     return 0;
1254 
1255   return 1;                     /*
1256                                  * Detected
1257                                  */
1258 }
1259 
1260 #ifdef CONFIG_AUDIO
1261 static struct audio_operations sb_dsp_operations =
1262 {
1263   "SoundBlaster",
1264   NOTHING_SPECIAL,
1265   AFMT_U8,                      /* Just 8 bits. Poor old SB */
1266   NULL,
1267   sb_dsp_open,
1268   sb_dsp_close,
1269   sb_dsp_output_block,
1270   sb_dsp_start_input,
1271   sb_dsp_ioctl,
1272   sb_dsp_prepare_for_input,
1273   sb_dsp_prepare_for_output,
1274   sb_dsp_reset,
1275   sb_dsp_halt_xfer,
1276   NULL,                         /* local_qlen */
1277   NULL,                         /* copy_from_user */
1278   NULL,
1279   NULL,
1280   sb_dsp_trigger
1281 };
1282 
1283 #endif
1284 
1285 static void
1286 ess_init (int ess_minor)        /* ESS1688 Initialization */
     /* [previous][next][first][last][top][bottom][index][help] */
1287 {
1288   unsigned char   cfg, irq_bits = 0, dma_bits = 0;
1289 
1290   AudioDrive = 1;
1291 
1292   if (ess_minor >= 8)           /* ESS1688 doesn't support SB MIDI */
1293     midi_disabled = 1;
1294 
1295   sb_reset_dsp ();              /* Turn on extended mode */
1296 
1297 /*
1298  *    Set IRQ configuration register
1299  */
1300 
1301   cfg = 0x50;                   /* Enable only DMA counter interrupt */
1302 
1303   switch (sbc_irq)
1304     {
1305     case 2:
1306     case 9:
1307       irq_bits = 0;
1308       break;
1309 
1310     case 5:
1311       irq_bits = 1;
1312       break;
1313 
1314     case 7:
1315       irq_bits = 2;
1316       break;
1317 
1318     case 10:
1319       irq_bits = 3;
1320       break;
1321 
1322     default:
1323       irq_bits = 0;
1324       cfg = 0x10;               /* Disable all interrupts */
1325       printk ("\nESS1688: Invalid IRQ %d\n", sbc_irq);
1326     }
1327 
1328   if (!ess_write (0xb1, cfg | (irq_bits << 2)))
1329     printk ("\nESS1688: Failed to write to IRQ config register\n");
1330 
1331 /*
1332  *    Set DMA configuration register
1333  */
1334 
1335   cfg = 0x50;                   /* Extended mode DMA ebable */
1336 
1337   if (sbc_dma > 3 || sbc_dma < 0 || sbc_dma == 2)
1338     {
1339       dma_bits = 0;
1340       cfg = 0x00;               /* Disable all DMA */
1341       printk ("\nESS1688: Invalid DMA %d\n", sbc_dma);
1342     }
1343   else
1344     {
1345       if (sbc_dma == 3)
1346         dma_bits = 3;
1347       else
1348         dma_bits = sbc_dma + 1;
1349     }
1350 
1351   if (!ess_write (0xb2, cfg | (dma_bits << 2)))
1352     printk ("\nESS1688: Failed to write to DMA config register\n");
1353 
1354 /*
1355  * Enable joystick and OPL3
1356  */
1357 
1358   cfg = sb_getmixer (0x40);
1359   sb_setmixer (0x40, cfg | 0x03);
1360 }
1361 
1362 #ifdef CONFIG_MIDI
1363 void
1364 ess_midi_init (struct address_info *hw_config)  /* called from sb16_midi.c */
     /* [previous][next][first][last][top][bottom][index][help] */
1365 {
1366   unsigned char   cfg, tmp;
1367 
1368   cfg = sb_getmixer (0x40) & 0x03;
1369 
1370   tmp = (hw_config->io_base & 0x0f0) >> 4;
1371 
1372   if (tmp > 3)
1373     {
1374       sb_setmixer (0x40, cfg);
1375       return;
1376     }
1377 
1378   cfg |= tmp << 3;
1379 
1380   tmp = 1;                      /* MPU enabled without interrupts */
1381 
1382   switch (hw_config->irq)
1383     {
1384     case 9:
1385       tmp = 0x4;
1386       break;
1387     case 5:
1388       tmp = 0x5;
1389       break;
1390     case 7:
1391       tmp = 0x6;
1392       break;
1393     case 10:
1394       tmp = 0x7;
1395       break;
1396     }
1397 
1398   cfg |= tmp << 5;
1399 
1400   if (tmp != 1)
1401     {
1402       ess_mpu_irq = hw_config->irq;
1403 
1404       if (snd_set_irq_handler (ess_mpu_irq, sbmidiintr, "ES1688 MIDI", sb_osp) < 0)
1405         printk ("ES1688: Can't allocate IRQ%d\n", ess_mpu_irq);
1406     }
1407 
1408   sb_setmixer (0x40, cfg);
1409 }
1410 #endif
1411 
1412 void
1413 Jazz16_midi_init (struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
1414 {
1415   extern void     smw_mixer_init (void);
1416   extern void     sb_mixer_reset (void);
1417 
1418   mpu_base = hw_config->io_base;
1419   mpu_irq = hw_config->irq;
1420 
1421   initialize_ProSonic16 ();
1422 
1423   smw_mixer_init ();
1424   sb_mixer_reset ();
1425 }
1426 
1427 void
1428 Jazz16_set_dma16 (int dma)
     /* [previous][next][first][last][top][bottom][index][help] */
1429 {
1430   dma16 = dma;
1431 
1432 /* Allocate 16 bit dma (Jazz16)
1433  */
1434   if (dma16 != dma8)
1435     {
1436       if (sound_alloc_dma (dma16, "Jazz16 16 bit"))
1437         {
1438           printk ("Jazz16: Can't allocate 16 bit DMA channel\n");
1439           Jazz16_detected = 0;
1440           return;
1441         }
1442     }
1443   initialize_ProSonic16 ();
1444 }
1445 
1446 static void
1447 dsp_get_vers (struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
1448 {
1449   int             i;
1450 
1451   unsigned long   flags;
1452 
1453   save_flags (flags);
1454   cli ();
1455   sb_osp = hw_config->osp;
1456   sbc_major = sbc_minor = 0;
1457   sb_dsp_command (0xe1);        /* Get version */
1458 
1459   for (i = 100000; i; i--)
1460     {
1461       if (inb (DSP_DATA_AVAIL) & 0x80)
1462         {
1463           if (sbc_major == 0)
1464             sbc_major = inb (DSP_READ);
1465           else
1466             {
1467               sbc_minor = inb (DSP_READ);
1468               break;
1469             }
1470         }
1471     }
1472   restore_flags (flags);
1473 }
1474 
1475 long
1476 sb_dsp_init (long mem_start, struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
1477 {
1478   int             i;
1479   int             ess_major = 0, ess_minor = 0;
1480 
1481   int             mixer_type = 0;
1482 
1483   if (sbc_major == 0)
1484     dsp_get_vers (hw_config);
1485 
1486   if (sbc_major == 0)
1487     {
1488       sb_reset_dsp ();
1489       dsp_get_vers (hw_config);
1490     }
1491 
1492   if (sbc_major == 0)
1493     {
1494       printk ("\n\nFailed to get SB version (%x) - possible I/O conflict?\n\n",
1495               inb (DSP_DATA_AVAIL));
1496       sbc_major = 1;
1497     }
1498 
1499   if (sbc_major == 2 || sbc_major == 3)
1500     sb_duplex_midi = 1;
1501 
1502   if (sbc_major == 4)
1503     sb16 = 1;
1504 
1505   if (sbc_major == 3 && sbc_minor == 1)
1506     {
1507 
1508 /*
1509  * Try to detect ESS chips.
1510  */
1511 
1512       sb_dsp_command (0xe7);    /*
1513                                  * Return identification bytes.
1514                                  */
1515 
1516       for (i = 1000; i; i--)
1517         {
1518           if (inb (DSP_DATA_AVAIL) & 0x80)
1519             {                   /*
1520                                  * wait for Data Ready
1521                                  */
1522               if (ess_major == 0)
1523                 ess_major = inb (DSP_READ);
1524               else
1525                 {
1526                   ess_minor = inb (DSP_READ);
1527                   break;
1528                 }
1529             }
1530         }
1531     }
1532 
1533   if (snd_set_irq_handler (sbc_irq, sbintr, "SoundBlaster", sb_osp) < 0)
1534     printk ("sb_dsp: Can't allocate IRQ\n");;
1535 
1536 #ifdef CONFIG_AUDIO
1537   if (sbc_major >= 3)
1538     {
1539       if (Jazz16_detected)
1540         {
1541           if (Jazz16_detected == 2)
1542             sprintf (sb_dsp_operations.name, "SoundMan Wave %d.%d", sbc_major, sbc_minor);
1543           else
1544             sprintf (sb_dsp_operations.name, "MV Jazz16 %d.%d", sbc_major, sbc_minor);
1545           sb_dsp_operations.format_mask |= AFMT_S16_LE;         /* Hurrah, 16 bits          */
1546         }
1547       else
1548 #ifdef __SGNXPRO__
1549       if (mixer_type == 2)
1550         {
1551           sprintf (sb_dsp_operations.name, "Sound Galaxy NX Pro %d.%d", sbc_major, sbc_minor);
1552         }
1553       else
1554 #endif
1555 
1556       if (sbc_major == 4)
1557         {
1558           sprintf (sb_dsp_operations.name, "SoundBlaster 16 %d.%d", sbc_major, sbc_minor);
1559         }
1560       else if (ess_major != 0)
1561         {
1562           if (ess_major == 0x48 && (ess_minor & 0xf0) == 0x80)
1563             sprintf (sb_dsp_operations.name, "ESS ES488 AudioDrive (rev %d)",
1564                      ess_minor & 0x0f);
1565           else if (ess_major == 0x68 && (ess_minor & 0xf0) == 0x80)
1566             {
1567               sprintf (sb_dsp_operations.name,
1568                        "ESS ES1688 AudioDrive (rev %d)",
1569                        ess_minor & 0x0f);
1570               sb_dsp_operations.format_mask |= AFMT_S16_LE;
1571               ess_init (ess_minor);
1572             }
1573         }
1574       else
1575         {
1576           sprintf (sb_dsp_operations.name, "SoundBlaster Pro %d.%d", sbc_major, sbc_minor);
1577         }
1578     }
1579   else
1580     {
1581       sprintf (sb_dsp_operations.name, "SoundBlaster %d.%d", sbc_major, sbc_minor);
1582     }
1583 
1584   conf_printf (sb_dsp_operations.name, hw_config);
1585 
1586   if (sbc_major >= 3)
1587     mixer_type = sb_mixer_init (sbc_major);
1588 
1589   if (!sb16)
1590     if (num_audiodevs < MAX_AUDIO_DEV)
1591       {
1592         audio_devs[my_dev = num_audiodevs++] = &sb_dsp_operations;
1593 
1594         if (AudioDrive)
1595           audio_devs[my_dev]->flags |= DMA_AUTOMODE;
1596 
1597         audio_devs[my_dev]->buffsize = DSP_BUFFSIZE;
1598         dma8 = audio_devs[my_dev]->dmachan1 = hw_config->dma;
1599         dma16 = audio_devs[my_dev]->dmachan2 = hw_config->dma;
1600         if (sound_alloc_dma (hw_config->dma, "SoundBlaster"))
1601           printk ("sb_dsp.c: Can't allocate DMA channel\n");
1602       }
1603     else
1604       printk ("SB: Too many DSP devices available\n");
1605 #else
1606   conf_printf ("SoundBlaster (configured without audio support)", hw_config);
1607 #endif
1608 
1609 #ifdef CONFIG_MIDI
1610   if (!midi_disabled && !sb16)  /*
1611                                  * Midi don't work in the SB emulation mode *
1612                                  * of PAS, SB16 has better midi interface
1613                                  */
1614     sb_midi_init (sbc_major);
1615 #endif
1616 
1617   sb_dsp_ok = 1;
1618   sb_reset_dsp ();
1619 
1620   if (sb16 || hw_config->dma2 >= 0)
1621     {
1622       if (sb16_dsp_detect (hw_config))
1623         {
1624           sb16_inited = 1;
1625           return sb16_dsp_init (mem_start, hw_config);
1626         }
1627     }
1628   return mem_start;
1629 }
1630 
1631 void
1632 sb_dsp_unload (struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
1633 {
1634   sound_free_dma (dma8);
1635 
1636   /* Free 16 bit dma (Jazz16)
1637    */
1638   if (Jazz16_detected != 0)
1639     if (dma16 != dma8)
1640       {
1641         sound_free_dma (dma16);
1642       }
1643   snd_release_irq (sbc_irq);
1644 
1645   if (AudioDrive && ess_mpu_irq)
1646     {
1647       snd_release_irq (ess_mpu_irq);
1648     }
1649 
1650   if (sb16_inited)
1651     unload_sb16 (hw_config);
1652 }
1653 
1654 void
1655 sb_dsp_disable_midi (void)
     /* [previous][next][first][last][top][bottom][index][help] */
1656 {
1657   midi_disabled = 1;
1658 }
1659 
1660 
1661 #endif

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