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

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