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

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