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

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