OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [drivers/] [sound/] [sb_common.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 * sound/sb_common.c
3
 *
4
 * Common routines for Sound Blaster compatible cards.
5
 */
6
/*
7
 * Copyright (C) by Hannu Savolainen 1993-1996
8
 *
9
 * USS/Lite for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10
 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11
 * for more info.
12
 */
13
#include <linux/config.h>
14
 
15
 
16
#include "sound_config.h"
17
 
18
#if defined(CONFIG_SBDSP)
19
 
20
#ifndef CONFIG_AUDIO
21
#error You will need to configure the sound driver with CONFIG_AUDIO option.
22
#endif
23
 
24
#include "sb_mixer.h"
25
#include "sb.h"
26
 
27
static sb_devc *detected_devc = NULL;   /* For communication from probe to init */
28
static sb_devc *last_devc = NULL;       /* For MPU401 initialization */
29
static sb_devc *irq2devc[16] =
30
{NULL};
31
static unsigned char jazz_irq_bits[] =
32
{0, 0, 2, 3, 0, 1, 0, 4, 0, 2, 5, 0, 0, 0, 0, 6};
33
static unsigned char jazz_dma_bits[] =
34
{0, 1, 0, 2, 0, 3, 0, 4};
35
 
36
/*
37
 * Jazz16 chipset specific control variables
38
 */
39
 
40
static int      jazz16_base = 0; /* Not detected */
41
static unsigned char jazz16_bits = 0;    /* I/O relocation bits */
42
 
43
/*
44
 * Logitech SoundMan Wave specific initialization code
45
 */
46
 
47
#ifdef SMW_MIDI0001_INCLUDED
48
#include "smw-midi0001.h"
49
#else
50
unsigned char  *smw_ucode = NULL;
51
int             smw_ucodeLen = 0;
52
 
53
#endif
54
 
55
int
56
sb_dsp_command (sb_devc * devc, unsigned char val)
57
{
58
  int             i;
59
  unsigned long   limit;
60
 
61
  limit = jiffies + HZ / 10;    /*
62
                                   * The timeout is 0.1 seconds
63
                                 */
64
 
65
  /*
66
   * Note! the i<500000 is an emergency exit. The sb_dsp_command() is sometimes
67
   * called while interrupts are disabled. This means that the timer is
68
   * disabled also. However the timeout situation is a abnormal condition.
69
   * Normally the DSP should be ready to accept commands after just couple of
70
   * loops.
71
   */
72
 
73
  for (i = 0; i < 500000 && jiffies < limit; i++)
74
    {
75
      if ((inb (DSP_STATUS) & 0x80) == 0)
76
        {
77
          outb (val, DSP_COMMAND);
78
          return 1;
79
        }
80
    }
81
 
82
  printk ("Sound Blaster: DSP Command(%x) Timeout.\n", val);
83
  return 0;
84
}
85
 
86
int
87
sb_dsp_get_byte (sb_devc * devc)
88
{
89
  int             i;
90
 
91
  for (i = 1000; i; i--)
92
    if (inb (DSP_DATA_AVAIL) & 0x80)
93
      {
94
        return inb (DSP_READ);
95
      }
96
 
97
  return 0xffff;
98
}
99
 
100
int
101
ess_write (sb_devc * devc, unsigned char reg, unsigned char data)
102
{
103
  /* Write a byte to an extended mode register of ES1688 */
104
 
105
  if (!sb_dsp_command (devc, reg))
106
    return 0;
107
 
108
  return sb_dsp_command (devc, data);
109
}
110
 
111
int
112
ess_read (sb_devc * devc, unsigned char reg)
113
{
114
/* Read a byte from an extended mode register of ES1688 */
115
 
116
  if (!sb_dsp_command (devc, 0xc0))     /* Read register command */
117
    return -1;
118
 
119
  if (!sb_dsp_command (devc, reg))
120
    return -1;
121
 
122
  return sb_dsp_get_byte (devc);
123
}
124
 
125
void
126
sbintr (int irq, void *dev_id, struct pt_regs *dummy)
127
{
128
  int             status;
129
  unsigned char   src = 0xff;
130
 
131
  sb_devc        *devc = irq2devc[irq];
132
 
133
  if (devc == NULL || devc->irq != irq)
134
    {
135
      DEB (printk ("sbintr: Bogus interrupt IRQ%d\n", irq));
136
      return;
137
    }
138
 
139
  devc->irq_ok = 1;
140
 
141
  if (devc->model == MDL_SB16)
142
    {
143
 
144
      src = sb_getmixer (devc, IRQ_STAT);       /* Interrupt source register */
145
 
146
#if defined(CONFIG_MIDI) && defined(CONFIG_UART401)
147
      if (src & 4)
148
        uart401intr (devc->irq, NULL, NULL);    /* MPU401 interrupt */
149
#endif
150
 
151
      if (!(src & 3))
152
        return;                 /* Not a DSP interrupt */
153
    }
154
 
155
  if (devc->intr_active)
156
    switch (devc->irq_mode)
157
      {
158
      case IMODE_OUTPUT:
159
        DMAbuf_outputintr (devc->dev, 1);
160
        break;
161
 
162
      case IMODE_INPUT:
163
        DMAbuf_inputintr (devc->dev);
164
        break;
165
 
166
      case IMODE_INIT:
167
        break;
168
 
169
      case IMODE_MIDI:
170
#ifdef CONFIG_MIDI
171
        sb_midi_interrupt (devc);
172
#endif
173
        break;
174
 
175
      default:
176
        printk ("Sound Blaster: Unexpected interrupt\n");
177
      }
178
/*
179
 * Acknowledge interrupts
180
 */
181
 
182
  if (src & 0x01)
183
    status = inb (DSP_DATA_AVAIL);
184
 
185
  if (devc->model == MDL_SB16 && src & 0x02)
186
    status = inb (DSP_DATA_AVL16);
187
}
188
 
189
int
190
sb_dsp_reset (sb_devc * devc)
191
{
192
  int             loopc;
193
 
194
  if (devc->model == MDL_ESS)
195
    outb (3, DSP_RESET);        /* Reset FIFO too */
196
  else
197
    outb (1, DSP_RESET);
198
 
199
  tenmicrosec (devc->osp);
200
  outb (0, DSP_RESET);
201
  tenmicrosec (devc->osp);
202
  tenmicrosec (devc->osp);
203
  tenmicrosec (devc->osp);
204
 
205
  for (loopc = 0; loopc < 1000 && !(inb (DSP_DATA_AVAIL) & 0x80); loopc++);
206
 
207
  if (inb (DSP_READ) != 0xAA)
208
    return 0;                    /* Sorry */
209
 
210
  if (devc->model == MDL_ESS)
211
    sb_dsp_command (devc, 0xc6);        /* Enable extended mode */
212
 
213
  return 1;
214
}
215
 
216
static void
217
dsp_get_vers (sb_devc * devc)
218
{
219
  int             i;
220
 
221
  unsigned long   flags;
222
 
223
  save_flags (flags);
224
  cli ();
225
  devc->major = devc->minor = 0;
226
  sb_dsp_command (devc, 0xe1);  /* Get version */
227
 
228
  for (i = 100000; i; i--)
229
    {
230
      if (inb (DSP_DATA_AVAIL) & 0x80)
231
        {
232
          if (devc->major == 0)
233
            devc->major = inb (DSP_READ);
234
          else
235
            {
236
              devc->minor = inb (DSP_READ);
237
              break;
238
            }
239
        }
240
    }
241
  restore_flags (flags);
242
}
243
 
244
static int
245
sb16_set_dma_hw (sb_devc * devc)
246
{
247
  int             bits;
248
 
249
  if (devc->dma8 != 0 && devc->dma8 != 1 && devc->dma8 != 3)
250
    {
251
      printk ("SB16: Invalid 8 bit DMA (%d)\n", devc->dma8);
252
      return 0;
253
    }
254
 
255
  bits = (1 << devc->dma8);
256
 
257
  if (devc->dma16 >= 5 && devc->dma16 <= 7)
258
    bits |= (1 << devc->dma16);
259
 
260
  sb_setmixer (devc, DMA_NR, bits);
261
  return 1;
262
}
263
 
264
#if defined(CONFIG_MIDI) && defined(CONFIG_UART401)
265
static void
266
sb16_set_mpu_port(sb_devc *devc, struct address_info *hw_config)
267
{
268
/*
269
 * This routine initializes new MIDI port setup register of SB Vibra.
270
 */
271
        unsigned char bits = sb_getmixer(devc, 0x84) & ~0x06;
272
        switch (hw_config->io_base)
273
        {
274
        case 0x300:
275
                sb_setmixer (devc, 0x84, bits | 0x04);
276
                break;
277
 
278
        case 0x330:
279
                sb_setmixer (devc, 0x84, bits | 0x00);
280
                break;
281
 
282
        default:
283
                sb_setmixer (devc, 0x84, bits | 0x02); /* Disable MPU */
284
                printk("SB16: Invalid MIDI I/O port %x\n", hw_config->io_base);
285
        }
286
}
287
#endif
288
 
289
static int
290
sb16_set_irq_hw (sb_devc * devc, int level)
291
{
292
  int             ival;
293
 
294
  switch (level)
295
    {
296
    case 5:
297
      ival = 2;
298
      break;
299
    case 7:
300
      ival = 4;
301
      break;
302
    case 9:
303
      ival = 1;
304
      break;
305
    case 10:
306
      ival = 8;
307
      break;
308
    default:
309
      printk ("SB16 IRQ%d is not possible\n", level);
310
      return 0;
311
    }
312
  sb_setmixer (devc, IRQ_NR, ival);
313
  return 1;
314
}
315
 
316
static void
317
relocate_Jazz16 (sb_devc * devc, struct address_info *hw_config)
318
{
319
  unsigned char   bits = 0;
320
  unsigned long   flags;
321
 
322
  if (jazz16_base != 0 && jazz16_base != hw_config->io_base)
323
    return;
324
 
325
  switch (hw_config->io_base)
326
    {
327
    case 0x220:
328
      bits = 1;
329
      break;
330
    case 0x240:
331
      bits = 2;
332
      break;
333
    case 0x260:
334
      bits = 3;
335
      break;
336
 
337
    default:
338
      return;
339
    }
340
 
341
  bits = jazz16_bits = bits << 5;
342
 
343
  jazz16_base = hw_config->io_base;
344
 
345
/*
346
 * Magic wake up sequence by writing to 0x201 (aka Joystick port)
347
 */
348
  save_flags (flags);
349
  cli ();
350
  outb (0xAF, 0x201);
351
  outb (0x50, 0x201);
352
  outb (bits, 0x201);
353
  restore_flags (flags);
354
}
355
 
356
static int
357
init_Jazz16 (sb_devc * devc, struct address_info *hw_config)
358
{
359
  char            name[100];
360
 
361
/*
362
 * First try to check that the card has Jazz16 chip. It identifies itself
363
 * by returning 0x12 as response to DSP command 0xfa.
364
 */
365
 
366
  if (!sb_dsp_command (devc, 0xfa))
367
    return 0;
368
 
369
  if (sb_dsp_get_byte (devc) != 0x12)
370
    return 0;
371
 
372
/*
373
 * OK so far. Now configure the IRQ and DMA channel used by the card.
374
 */
375
  if (hw_config->irq < 1 || hw_config->irq > 15 ||
376
      jazz_irq_bits[hw_config->irq] == 0)
377
    {
378
      printk ("Jazz16: Invalid interrupt (IRQ%d)\n", hw_config->irq);
379
      return 0;
380
    }
381
 
382
  if (hw_config->dma < 0 || hw_config->dma > 3 ||
383
      jazz_dma_bits[hw_config->dma] == 0)
384
    {
385
      printk ("Jazz16: Invalid 8 bit DMA (DMA%d)\n", hw_config->dma);
386
      return 0;
387
    }
388
 
389
  if (hw_config->dma2 < 0)
390
    {
391
      printk ("Jazz16: No 16 bit DMA channel defined\n");
392
      return 0;
393
    }
394
 
395
  if (hw_config->dma2 < 5 || hw_config->dma2 > 7 ||
396
      jazz_dma_bits[hw_config->dma2] == 0)
397
    {
398
      printk ("Jazz16: Invalid 16 bit DMA (DMA%d)\n", hw_config->dma2);
399
      return 0;
400
    }
401
 
402
  devc->dma16 = hw_config->dma2;
403
 
404
  if (!sb_dsp_command (devc, 0xfb))
405
    return 0;
406
 
407
  if (!sb_dsp_command (devc, jazz_dma_bits[hw_config->dma] |
408
                       (jazz_dma_bits[hw_config->dma2] << 4)))
409
    return 0;
410
 
411
  if (!sb_dsp_command (devc, jazz_irq_bits[hw_config->irq]))
412
    return 0;
413
 
414
/*
415
 * Now we have configured a standard Jazz16 device.
416
 */
417
  devc->model = MDL_JAZZ;
418
  strcpy (name, "Jazz16");
419
 
420
 
421
  hw_config->name = (char *) (sound_mem_blocks[sound_nblocks] = vmalloc (strlen (name + 1)));
422
  if (sound_nblocks < 1024)
423
    sound_nblocks++;;
424
  if (hw_config->name != NULL)
425
    strcpy (hw_config->name, name);
426
  devc->caps |= SB_NO_MIDI;
427
  return 1;
428
}
429
 
430
static int
431
ess_init (sb_devc * devc, struct address_info *hw_config)
432
{
433
  unsigned char   cfg, irq_bits = 0, dma_bits = 0;
434
  int             ess_major = 0, ess_minor = 0;
435
  int             i;
436
  char            name[100];
437
 
438
/*
439
 * Try to detect ESS chips.
440
 */
441
 
442
  sb_dsp_command (devc, 0xe7);  /* Return identification */
443
 
444
  for (i = 1000; i; i--)
445
    {
446
      if (inb (DSP_DATA_AVAIL) & 0x80)
447
        {
448
          if (ess_major == 0)
449
            ess_major = inb (DSP_READ);
450
          else
451
            {
452
              ess_minor = inb (DSP_READ);
453
              break;
454
            }
455
        }
456
    }
457
 
458
  if (ess_major == 0)
459
    return 0;
460
 
461
  if (ess_major == 0x48 && (ess_minor & 0xf0) == 0x80)
462
    {
463
      sprintf (name, "ESS ES488 AudioDrive (rev %d)",
464
               ess_minor & 0x0f);
465
      hw_config->name = name;
466
      devc->model = MDL_SBPRO;
467
      return 1;
468
    }
469
  else if (ess_major == 0x68 && (ess_minor & 0xf0) == 0x80)
470
    {
471
      sprintf (name,
472
               "ESS ES1688 AudioDrive (rev %d)",
473
               ess_minor & 0x0f);
474
    }
475
  else
476
    strcpy (name, "Jazz16");
477
 
478
  devc->model = MDL_ESS;
479
  devc->submodel = ess_minor & 0x0f;
480
 
481
  hw_config->name = (char *) (sound_mem_blocks[sound_nblocks] = vmalloc (strlen (name + 1)));
482
  if (sound_nblocks < 1024)
483
    sound_nblocks++;;
484
  if (hw_config->name != NULL)
485
    strcpy (hw_config->name, name);
486
 
487
 
488
  sb_dsp_reset (devc);          /* Turn on extended mode */
489
 
490
/*
491
 *    Set IRQ configuration register
492
 */
493
 
494
  cfg = 0x50;                   /* Enable only DMA counter interrupt */
495
 
496
  switch (devc->irq)
497
    {
498
    case 2:
499
    case 9:
500
      irq_bits = 0;
501
      break;
502
 
503
    case 5:
504
      irq_bits = 1;
505
      break;
506
 
507
    case 7:
508
      irq_bits = 2;
509
      break;
510
 
511
    case 10:
512
      irq_bits = 3;
513
      break;
514
 
515
    default:
516
      irq_bits = 0;
517
      cfg = 0x10;               /* Disable all interrupts */
518
      printk ("\nESS1688: Invalid IRQ %d\n", devc->irq);
519
      return 0;
520
    }
521
 
522
  if (!ess_write (devc, 0xb1, cfg | (irq_bits << 2)))
523
    printk ("\nESS1688: Failed to write to IRQ config register\n");
524
 
525
/*
526
 *    Set DMA configuration register
527
 */
528
 
529
  cfg = 0x50;                   /* Extended mode DMA enable */
530
 
531
  if (devc->dma8 > 3 || devc->dma8 < 0 || devc->dma8 == 2)
532
    {
533
      dma_bits = 0;
534
      cfg = 0x00;               /* Disable all DMA */
535
      printk ("\nESS1688: Invalid DMA %d\n", devc->dma8);
536
    }
537
  else
538
    {
539
      if (devc->dma8 == 3)
540
        dma_bits = 3;
541
      else
542
        dma_bits = devc->dma8 + 1;
543
    }
544
 
545
  if (!ess_write (devc, 0xb2, cfg | (dma_bits << 2)))
546
    printk ("\nESS1688: Failed to write to DMA config register\n");
547
 
548
/*
549
 * Enable joystick and OPL3
550
 */
551
 
552
  cfg = sb_getmixer (devc, 0x40);
553
  sb_setmixer (devc, 0x40, cfg | 0x03);
554
  if (devc->submodel >= 8)      /* ES1688 */
555
    devc->caps |= SB_NO_MIDI;   /* ES1688 uses MPU401 MIDI mode */
556
  sb_dsp_reset (devc);
557
  return 1;
558
}
559
 
560
int
561
sb_dsp_detect (struct address_info *hw_config)
562
{
563
  sb_devc         sb_info;
564
  sb_devc        *devc = &sb_info;
565
 
566
/*
567
 * Initialize variables
568
 */
569
  DDB (printk ("sb_dsp_detect(%x) entered\n", hw_config->io_base));
570
  if (check_region (hw_config->io_base, 16))
571
    return 0;
572
 
573
  memset ((char *) &sb_info, 0, sizeof (sb_info));       /* Zero everything */
574
 
575
  devc->osp = hw_config->osp;
576
  devc->type = hw_config->card_subtype;
577
 
578
  devc->base = hw_config->io_base;
579
  devc->irq = hw_config->irq;
580
  devc->dma8 = hw_config->dma;
581
 
582
  devc->dma16 = -1;
583
 
584
/*
585
 * Detect the device
586
 */
587
 
588
  cli();                        /* Some ESS1688 cards need this */
589
  inb (devc->base + 0x9);
590
  inb (devc->base + 0x9);
591
  inb (devc->base + 0x9);
592
  inb (devc->base + 0xb);
593
  inb (devc->base + 0x9);
594
  inb (devc->base + 0xb);
595
  inb (devc->base + 0x9);
596
  inb (devc->base + 0x9);
597
  inb (devc->base + 0xb);
598
  inb (devc->base + 0x9);
599
  inb (devc->base);
600
  sti();
601
 
602
  if (sb_dsp_reset (devc))
603
    dsp_get_vers (devc);
604
  else
605
    devc->major = 0;
606
 
607
  if (devc->type == 0 || devc->type == MDL_JAZZ || devc->type == MDL_SMW)
608
    if (devc->major == 0 || (devc->major == 3 && devc->minor == 1))
609
      relocate_Jazz16 (devc, hw_config);
610
 
611
  if (!sb_dsp_reset (devc))
612
    {
613
      DDB (printk ("SB reset failed\n"));
614
      return 0;
615
    }
616
 
617
  if (devc->major == 0)
618
    dsp_get_vers (devc);
619
 
620
  if (devc->major == 3 && devc->minor == 1)
621
    if (devc->type == MDL_AZTECH)       /* SG Washington? */
622
      {
623
        if (sb_dsp_command (devc, 0x09))
624
          if (sb_dsp_command (devc, 0x00))      /* Enter WSS mode */
625
            {
626
              int             i;
627
 
628
              /* Have some delay */
629
              for (i = 0; i < 10000; i++)
630
                inb (DSP_DATA_AVAIL);
631
              devc->caps = SB_NO_AUDIO | SB_NO_MIDI;    /* Mixer only */
632
            }
633
      }
634
 
635
/*
636
 * Save device information for sb_dsp_init()
637
 */
638
 
639
 
640
  detected_devc = (sb_devc *) (sound_mem_blocks[sound_nblocks] = vmalloc (sizeof (sb_devc)));
641
  if (sound_nblocks < 1024)
642
    sound_nblocks++;;
643
 
644
  if (detected_devc == NULL)
645
    {
646
      printk ("sb: Can't allocate memory for device information\n");
647
      return 0;
648
    }
649
 
650
  memcpy ((char *) detected_devc, (char *) devc, sizeof (sb_devc));
651
 
652
  DDB (printk ("SB %d.%d detected OK (%x)\n", devc->major, devc->minor,
653
               hw_config->io_base));
654
  return 1;
655
}
656
 
657
void
658
sb_dsp_init (struct address_info *hw_config)
659
{
660
  sb_devc        *devc;
661
  char            name[100];
662
 
663
#ifndef NO_SB_IRQ_TEST
664
  int             n;
665
#endif
666
 
667
/*
668
 * Check if we had detected a SB device earlier
669
 */
670
  DDB (printk ("sb_dsp_init(%x) entered\n", hw_config->io_base));
671
 
672
  if (detected_devc == NULL)
673
    {
674
      DDB (printk ("No detected device\n"));
675
      return;
676
    }
677
 
678
  devc = detected_devc;
679
  detected_devc = NULL;
680
 
681
  if (devc->base != hw_config->io_base)
682
    {
683
      DDB (printk ("I/O port mismatch\n"));
684
      return;
685
    }
686
 
687
/*
688
 * Now continue initialization of the device
689
 */
690
  devc->dev = num_audiodevs;
691
  devc->caps = hw_config->driver_use_1;
692
 
693
  if (snd_set_irq_handler (hw_config->irq,
694
                           sbintr, "sound blaster", devc->osp) < 0)
695
    {
696
      printk ("SB: Can't allocate IRQ%d\n", hw_config->irq);
697
      irq2devc[hw_config->irq] = NULL;
698
      return;
699
    }
700
 
701
  irq2devc[hw_config->irq] = devc;
702
  devc->irq_ok = 0;
703
 
704
  if (devc->major == 4)
705
    if (!sb16_set_irq_hw (devc, devc->irq))     /* Unsupported IRQ */
706
      {
707
        snd_release_irq (devc->irq);
708
        return;
709
      }
710
 
711
  if ((devc->type == 0 || devc->type == MDL_ESS) &&
712
      devc->major == 3 && devc->minor == 1)
713
    {                           /* Handle various chipsets which claim they are SB Pro compatible */
714
      if ((devc->type != 0 && devc->type != MDL_ESS) ||
715
          !ess_init (devc, hw_config))
716
        if ((devc->type != 0 && devc->type != MDL_JAZZ &&
717
             devc->type != MDL_SMW) || !init_Jazz16 (devc, hw_config))
718
          {
719
            DDB (printk ("This is a genuine SB Pro\n"));
720
          }
721
    }
722
 
723
#ifndef NO_SB_IRQ_TEST
724
  if (devc->major != 4 || devc->minor > 11) /* Not Sb16 v4.5 or v4.11 */
725
  {
726
    for (n = 0; n < 3 && devc->irq_ok == 0; n++)
727
    if (sb_dsp_command (devc, 0xf2))    /* Cause interrupt immediately */
728
      {
729
        int             i;
730
 
731
        for (i = 0; !devc->irq_ok && i < 10000; i++);
732
      }
733
 
734
  if (!devc->irq_ok)
735
    {
736
      printk ("sb: Interrupt test on IRQ%d failed - device disabled\n", devc->irq);
737
      snd_release_irq (devc->irq);
738
      return;
739
    }
740
  else
741
    {
742
      DDB (printk ("IRQ test OK (IRQ%d)\n", devc->irq));
743
    }
744
  }
745
#endif
746
 
747
  request_region (hw_config->io_base, 16, "sound blaster");
748
 
749
  switch (devc->major)
750
    {
751
    case 1:                     /* SB 1.0 or 1.5 */
752
      devc->model = hw_config->card_subtype = MDL_SB1;
753
      break;
754
 
755
    case 2:                     /* SB 2.x */
756
      if (devc->minor == 0)
757
        devc->model = hw_config->card_subtype = MDL_SB2;
758
      else
759
        devc->model = hw_config->card_subtype = MDL_SB201;
760
      break;
761
 
762
    case 3:                     /* SB Pro and most clones */
763
      if (devc->model == 0)
764
        {
765
          devc->model = hw_config->card_subtype = MDL_SBPRO;
766
          if (hw_config->name == NULL)
767
            hw_config->name = "Sound Blaster Pro";
768
        }
769
      break;
770
 
771
    case 4:
772
      devc->model = hw_config->card_subtype = MDL_SB16;
773
      if (hw_config->name == NULL)
774
        hw_config->name = "Sound Blaster 16";
775
 
776
      if (hw_config->dma2 == -1)
777
        devc->dma16 = devc->dma8;
778
      else if (hw_config->dma2 < 5 || hw_config->dma2 > 7)
779
        {
780
          printk ("SB16: Bad or missing 16 bit DMA channel\n");
781
          devc->dma16 = devc->dma8;
782
        }
783
      else
784
        devc->dma16 = hw_config->dma2;
785
 
786
      sb16_set_dma_hw (devc);
787
      devc->caps |= SB_NO_MIDI;
788
    }
789
 
790
  if (!(devc->caps & SB_NO_MIXER))
791
    if (devc->major == 3 || devc->major == 4)
792
      sb_mixer_init (devc);
793
 
794
#ifdef CONFIG_MIDI
795
  if (!(devc->caps & SB_NO_MIDI))
796
    sb_dsp_midi_init (devc);
797
#endif
798
 
799
  if (hw_config->name == NULL)
800
    hw_config->name = "Sound Blaster";
801
 
802
  sprintf (name, "%s (%d.%d)", hw_config->name, devc->major, devc->minor);
803
  conf_printf (name, hw_config);
804
  hw_config->card_subtype = devc->model;
805
  last_devc = devc;             /* For SB MPU detection */
806
 
807
  if (!(devc->caps & SB_NO_AUDIO))
808
    {
809
      if (sound_alloc_dma (devc->dma8, "Sound Blaster8"))
810
        {
811
          printk ("SB: Can't allocate 8 bit DMA channel %d\n", devc->dma8);
812
        }
813
      if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)
814
        if (sound_alloc_dma (devc->dma16, "Sound Blaster16"))
815
          {
816
            printk ("SB: Can't allocate 16 bit DMA channel %d\n", devc->dma16);
817
          }
818
      sb_audio_init (devc, name);
819
    }
820
}
821
 
822
void
823
sb_dsp_disable_midi (int io_base)
824
{
825
}
826
 
827
void
828
sb_dsp_disable_recording (int io_base)
829
{
830
}
831
 
832
void
833
sb_dsp_unload (struct address_info *hw_config)
834
{
835
  sb_devc        *devc;
836
  int             irq = hw_config->irq;
837
 
838
  if (irq < 0)
839
    irq *= -1;
840
 
841
  devc = irq2devc[irq];
842
 
843
  if (devc && devc->base == hw_config->io_base)
844
    {
845
      release_region (devc->base, 16);
846
      if (!(devc->caps & SB_NO_AUDIO))
847
        {
848
          sound_free_dma (devc->dma8);
849
 
850
          if (devc->dma16 >= 0)
851
            sound_free_dma (devc->dma16);
852
        }
853
 
854
      snd_release_irq (devc->irq);
855
      irq2devc[devc->irq] = NULL;
856
    }
857
}
858
 
859
/*
860
 * Mixer access routines
861
 */
862
 
863
void
864
sb_setmixer (sb_devc * devc, unsigned int port, unsigned int value)
865
{
866
  unsigned long   flags;
867
 
868
  save_flags (flags);
869
  cli ();
870
  outb ((unsigned char) (port & 0xff), MIXER_ADDR);
871
 
872
  tenmicrosec (devc->osp);
873
  outb ((unsigned char) (value & 0xff), MIXER_DATA);
874
  tenmicrosec (devc->osp);
875
  restore_flags (flags);
876
}
877
 
878
unsigned int
879
sb_getmixer (sb_devc * devc, unsigned int port)
880
{
881
  unsigned int    val;
882
  unsigned long   flags;
883
 
884
  save_flags (flags);
885
  cli ();
886
  outb ((unsigned char) (port & 0xff), MIXER_ADDR);
887
 
888
  tenmicrosec (devc->osp);
889
  val = inb (MIXER_DATA);
890
  tenmicrosec (devc->osp);
891
  restore_flags (flags);
892
 
893
  return val;
894
}
895
 
896
#ifdef CONFIG_MIDI
897
/*
898
 * MPU401 MIDI initialization.
899
 */
900
 
901
static void
902
smw_putmem (sb_devc * devc, int base, int addr, unsigned char val)
903
{
904
  unsigned long   flags;
905
 
906
  save_flags (flags);
907
  cli ();
908
 
909
  outb (addr & 0xff, base + 1); /* Low address bits */
910
  outb (addr >> 8, base + 2);   /* High address bits */
911
  outb (val, base);             /* Data */
912
 
913
  restore_flags (flags);
914
}
915
 
916
static unsigned char
917
smw_getmem (sb_devc * devc, int base, int addr)
918
{
919
  unsigned long   flags;
920
  unsigned char   val;
921
 
922
  save_flags (flags);
923
  cli ();
924
 
925
  outb (addr & 0xff, base + 1); /* Low address bits */
926
  outb (addr >> 8, base + 2);   /* High address bits */
927
  val = inb (base);             /* Data */
928
 
929
  restore_flags (flags);
930
  return val;
931
}
932
 
933
static int
934
smw_midi_init (sb_devc * devc, struct address_info *hw_config)
935
{
936
  int             mpu_base = hw_config->io_base;
937
  int             mp_base = mpu_base + 4;       /* Microcontroller base */
938
  int             i;
939
  unsigned char   control;
940
 
941
 
942
  /*
943
     *  Reset the microcontroller so that the RAM can be accessed
944
   */
945
 
946
  control = inb (mpu_base + 7);
947
  outb (control | 3, mpu_base + 7);     /* Set last two bits to 1 (?) */
948
  outb ((control & 0xfe) | 2, mpu_base + 7);    /* xxxxxxx0 resets the mc */
949
 
950
  for (i = 0; i < 300; i++)      /* Wait at least 1ms */
951
    tenmicrosec (devc->osp);
952
 
953
  outb (control & 0xfc, mpu_base + 7);  /* xxxxxx00 enables RAM */
954
 
955
  /*
956
     *  Detect microcontroller by probing the 8k RAM area
957
   */
958
  smw_putmem (devc, mp_base, 0, 0x00);
959
  smw_putmem (devc, mp_base, 1, 0xff);
960
  tenmicrosec (devc->osp);
961
 
962
  if (smw_getmem (devc, mp_base, 0) != 0x00 || smw_getmem (devc, mp_base, 1) != 0xff)
963
    {
964
      DDB (printk ("\nSM Wave: No microcontroller RAM detected (%02x, %02x)\n",
965
             smw_getmem (devc, mp_base, 0), smw_getmem (devc, mp_base, 1)));
966
      return 0;                  /* No RAM */
967
    }
968
 
969
  /*
970
     *  There is RAM so assume it's really a SM Wave
971
   */
972
 
973
  devc->model = MDL_SMW;
974
  smw_mixer_init (devc);
975
 
976
  if (smw_ucodeLen > 0)
977
    {
978
      if (smw_ucodeLen != 8192)
979
        {
980
          printk ("\nSM Wave: Invalid microcode (MIDI0001.BIN) length\n");
981
          return 1;
982
        }
983
 
984
      /*
985
       *  Download microcode
986
       */
987
 
988
      for (i = 0; i < 8192; i++)
989
        smw_putmem (devc, mp_base, i, smw_ucode[i]);
990
 
991
      /*
992
       *  Verify microcode
993
       */
994
 
995
      for (i = 0; i < 8192; i++)
996
        if (smw_getmem (devc, mp_base, i) != smw_ucode[i])
997
          {
998
            printk ("SM Wave: Microcode verification failed\n");
999
            return 0;
1000
          }
1001
    }
1002
 
1003
  control = 0;
1004
#ifdef SMW_SCSI_IRQ
1005
  /*
1006
     * Set the SCSI interrupt (IRQ2/9, IRQ3 or IRQ10). The SCSI interrupt
1007
     * is disabled by default.
1008
     *
1009
     * BTW the Zilog 5380 SCSI controller is located at MPU base + 0x10.
1010
   */
1011
  {
1012
    static unsigned char scsi_irq_bits[] =
1013
    {0, 0, 3, 1, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0};
1014
 
1015
    control |= scsi_irq_bits[SMW_SCSI_IRQ] << 6;
1016
  }
1017
#endif
1018
 
1019
#ifdef SMW_OPL4_ENABLE
1020
  /*
1021
     *  Make the OPL4 chip visible on the PC bus at 0x380.
1022
     *
1023
     *  There is no need to enable this feature since this driver
1024
     *  doesn't support OPL4 yet. Also there is no RAM in SM Wave so
1025
     *  enabling OPL4 is pretty useless.
1026
   */
1027
  control |= 0x10;              /* Uses IRQ12 if bit 0x20 == 0 */
1028
  /* control |= 0x20;      Uncomment this if you want to use IRQ7 */
1029
#endif
1030
 
1031
  outb (control | 0x03, mpu_base + 7);  /* xxxxxx11 restarts */
1032
  hw_config->name = "SoundMan Wave";
1033
  return 1;
1034
}
1035
 
1036
static int
1037
ess_midi_init (sb_devc * devc, struct address_info *hw_config)
1038
{
1039
  unsigned char   cfg, tmp;
1040
 
1041
  cfg = sb_getmixer (devc, 0x40) & 0x03;
1042
 
1043
  if (devc->submodel < 8)
1044
    {
1045
      sb_setmixer (devc, 0x40, cfg | 0x03);     /* Enable OPL3 & joystick */
1046
      return 0;                  /* ES688 doesn't support MPU401 mode */
1047
    }
1048
 
1049
  tmp = (hw_config->io_base & 0x0f0) >> 4;
1050
 
1051
  if (tmp > 3)
1052
    {
1053
      sb_setmixer (devc, 0x40, cfg);
1054
      return 0;
1055
    }
1056
 
1057
  cfg |= tmp << 3;
1058
 
1059
  tmp = 1;                      /* MPU enabled without interrupts */
1060
 
1061
  switch (hw_config->irq)
1062
    {
1063
    case 9:
1064
      tmp = 0x4;
1065
      break;
1066
    case 5:
1067
      tmp = 0x5;
1068
      break;
1069
    case 7:
1070
      tmp = 0x6;
1071
      break;
1072
    case 10:
1073
      tmp = 0x7;
1074
      break;
1075
    default:
1076
      return 0;
1077
    }
1078
 
1079
  cfg |= tmp << 5;
1080
 
1081
  sb_setmixer (devc, 0x40, cfg | 0x03);
1082
  return 1;
1083
}
1084
 
1085
static int
1086
init_Jazz16_midi (sb_devc * devc, struct address_info *hw_config)
1087
{
1088
  int             mpu_base = hw_config->io_base;
1089
  int             sb_base = devc->base;
1090
  int             irq = hw_config->irq;
1091
 
1092
  unsigned char   bits = 0;
1093
  unsigned long   flags;
1094
 
1095
  if (irq < 0)
1096
    irq *= -1;
1097
 
1098
  if (irq < 1 || irq > 15 ||
1099
      jazz_irq_bits[irq] == 0)
1100
    {
1101
      printk ("Jazz16: Invalid MIDI interrupt (IRQ%d)\n", irq);
1102
      return 0;
1103
    }
1104
 
1105
  switch (sb_base)
1106
    {
1107
    case 0x220:
1108
      bits = 1;
1109
      break;
1110
    case 0x240:
1111
      bits = 2;
1112
      break;
1113
    case 0x260:
1114
      bits = 3;
1115
      break;
1116
 
1117
    default:
1118
      return 0;
1119
    }
1120
 
1121
  bits = jazz16_bits = bits << 5;
1122
 
1123
  switch (mpu_base)
1124
    {
1125
    case 0x310:
1126
      bits |= 1;
1127
      break;
1128
    case 0x320:
1129
      bits |= 2;
1130
      break;
1131
    case 0x330:
1132
      bits |= 3;
1133
      break;
1134
 
1135
    default:
1136
      printk ("Jazz16: Invalid MIDI I/O port %x\n", mpu_base);
1137
      return 0;
1138
    }
1139
/*
1140
 * Magic wake up sequence by writing to 0x201 (aka Joystick port)
1141
 */
1142
  save_flags (flags);
1143
  cli ();
1144
  outb (0xAF, 0x201);
1145
  outb (0x50, 0x201);
1146
  outb (bits, 0x201);
1147
  restore_flags (flags);
1148
 
1149
  hw_config->name = "Jazz16";
1150
  smw_midi_init (devc, hw_config);
1151
 
1152
  if (!sb_dsp_command (devc, 0xfb))
1153
    return 0;
1154
 
1155
  if (!sb_dsp_command (devc, jazz_dma_bits[devc->dma8] |
1156
                       (jazz_dma_bits[devc->dma16] << 4)))
1157
    return 0;
1158
 
1159
  if (!sb_dsp_command (devc, jazz_irq_bits[devc->irq] |
1160
                       (jazz_irq_bits[irq] << 4)))
1161
    return 0;
1162
 
1163
  return 1;
1164
}
1165
 
1166
void
1167
attach_sbmpu (struct address_info *hw_config)
1168
{
1169
#if defined(CONFIG_MIDI) && defined(CONFIG_UART401)
1170
  attach_uart401 (hw_config);
1171
#endif
1172
}
1173
 
1174
int
1175
probe_sbmpu (struct address_info *hw_config)
1176
{
1177
#if defined(CONFIG_MIDI) && defined(CONFIG_UART401)
1178
  sb_devc        *devc = last_devc;
1179
 
1180
  if (last_devc == NULL)
1181
    return 0;
1182
 
1183
  last_devc = 0;
1184
 
1185
  if (hw_config->io_base <= 0)
1186
     return 0;
1187
 
1188
  if (check_region (hw_config->io_base, 4))
1189
    {
1190
      printk ("sbmpu: I/O port conflict (%x)\n", hw_config->io_base);
1191
      return 0;
1192
    }
1193
 
1194
  switch (devc->model)
1195
    {
1196
    case MDL_SB16:
1197
      if (hw_config->io_base != 0x300 && hw_config->io_base != 0x330)
1198
        {
1199
          printk ("SB16: Invalid MIDI port %x\n", hw_config->io_base);
1200
          return 0;
1201
        }
1202
      hw_config->name = "Sound Blaster 16";
1203
      hw_config->irq = -devc->irq;
1204
      hw_config->dma = -1;
1205
      hw_config->dma2 = -1;
1206
      sb16_set_mpu_port(devc, hw_config);
1207
      break;
1208
 
1209
    case MDL_ESS:
1210
      if (hw_config->irq < 3 || hw_config->irq == devc->irq)
1211
        hw_config->irq = -devc->irq;
1212
      if (!ess_midi_init (devc, hw_config))
1213
        return 0;
1214
      hw_config->name = "ESS ES1688";
1215
      break;
1216
 
1217
    case MDL_JAZZ:
1218
      if (hw_config->irq < 3 || hw_config->irq == devc->irq)
1219
        hw_config->irq = -devc->irq;
1220
      if (!init_Jazz16_midi (devc, hw_config))
1221
        return 0;
1222
      break;
1223
 
1224
    default:
1225
      return 0;
1226
    }
1227
 
1228
  return probe_uart401 (hw_config);
1229
#else
1230
  return 0;
1231
#endif
1232
}
1233
 
1234
void
1235
unload_sbmpu (struct address_info *hw_config)
1236
{
1237
#if defined(CONFIG_MIDI) && defined(CONFIG_UART401)
1238
  unload_uart401 (hw_config);
1239
#endif
1240
}
1241
#else /* !CONFIG_MIDI */
1242
 
1243
void
1244
unload_sbmpu (struct address_info *hw_config)
1245
{
1246
}
1247
 
1248
int
1249
probe_sbmpu (struct address_info *hw_config)
1250
{
1251
  return 0;
1252
}
1253
 
1254
void
1255
attach_sbmpu (struct address_info *hw_config)
1256
{
1257
}
1258
#endif
1259
 
1260
 
1261
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.