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_audio.c] - Blame information for rev 199

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 * sound/sb_audio.c
3
 *
4
 * Audio 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
#include "sb_mixer.h"
21
#include "sb.h"
22
 
23
static int
24
sb_audio_open (int dev, int mode)
25
{
26
  sb_devc        *devc = audio_devs[dev]->devc;
27
  unsigned long   flags;
28
 
29
  if (devc == NULL)
30
    {
31
      printk ("SB: Incomplete initialization\n");
32
      return -(ENXIO);
33
    }
34
 
35
  if (devc->caps & SB_NO_RECORDING && mode & OPEN_READ)
36
    {
37
      printk ("SB: Recording is not possible with this device\n");
38
      return -(EPERM);
39
    }
40
 
41
  save_flags (flags);
42
  cli ();
43
  if (devc->opened)
44
    {
45
      restore_flags (flags);
46
      return -(EBUSY);
47
    }
48
 
49
  if (devc->dma16 != -1 && devc->dma16 != devc->dma8)
50
    {
51
      if (sound_open_dma (devc->dma16, "Sound Blaster 16 bit"))
52
        {
53
          return -(EBUSY);
54
        }
55
    }
56
  devc->opened = mode;
57
  restore_flags (flags);
58
 
59
  devc->irq_mode = IMODE_NONE;
60
  sb_dsp_reset (devc);
61
 
62
  return 0;
63
}
64
 
65
static void
66
sb_audio_close (int dev)
67
{
68
  sb_devc        *devc = audio_devs[dev]->devc;
69
 
70
  audio_devs[dev]->dmachan1 =
71
    audio_devs[dev]->dmachan2 =
72
    devc->dma8;
73
 
74
  if (devc->dma16 != -1 && devc->dma16 != devc->dma8)
75
    sound_close_dma (devc->dma16);
76
 
77
  devc->opened = 0;
78
}
79
 
80
static void
81
sb_set_output_parms (int dev, unsigned long buf, int nr_bytes,
82
                     int intrflag, int restart_dma)
83
{
84
  sb_devc        *devc = audio_devs[dev]->devc;
85
 
86
  devc->trg_buf = buf;
87
  devc->trg_bytes = nr_bytes;
88
  devc->trg_intrflag = intrflag;
89
  devc->trg_restart = restart_dma;
90
  devc->irq_mode = IMODE_OUTPUT;
91
}
92
 
93
static void
94
sb_set_input_parms (int dev, unsigned long buf, int count, int intrflag,
95
                    int restart_dma)
96
{
97
  sb_devc        *devc = audio_devs[dev]->devc;
98
 
99
  devc->trg_buf = buf;
100
  devc->trg_bytes = count;
101
  devc->trg_intrflag = intrflag;
102
  devc->trg_restart = restart_dma;
103
  devc->irq_mode = IMODE_INPUT;
104
}
105
 
106
/*
107
 * SB1.x compatible routines
108
 */
109
 
110
static void
111
sb1_audio_output_block (int dev, unsigned long buf, int nr_bytes,
112
                        int intrflag, int restart_dma)
113
{
114
  unsigned long   flags;
115
  int             count = nr_bytes;
116
  sb_devc        *devc = audio_devs[dev]->devc;
117
 
118
  DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE);
119
 
120
  if (audio_devs[dev]->dmachan1 > 3)
121
    count >>= 1;
122
  count--;
123
 
124
  devc->irq_mode = IMODE_OUTPUT;
125
 
126
  save_flags (flags);
127
  cli ();
128
  if (sb_dsp_command (devc, 0x14))      /* 8 bit DAC using DMA */
129
    {
130
      sb_dsp_command (devc, (unsigned char) (count & 0xff));
131
      sb_dsp_command (devc, (unsigned char) ((count >> 8) & 0xff));
132
    }
133
  else
134
    printk ("SB: Unable to start DAC\n");
135
  restore_flags (flags);
136
  devc->intr_active = 1;
137
}
138
 
139
static void
140
sb1_audio_start_input (int dev, unsigned long buf, int nr_bytes, int intrflag,
141
                       int restart_dma)
142
{
143
  unsigned long   flags;
144
  int             count = nr_bytes;
145
  sb_devc        *devc = audio_devs[dev]->devc;
146
 
147
  /*
148
   * Start a DMA input to the buffer pointed by dmaqtail
149
   */
150
 
151
  DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ);
152
 
153
  if (audio_devs[dev]->dmachan1 > 3)
154
    count >>= 1;
155
  count--;
156
 
157
  devc->irq_mode = IMODE_INPUT;
158
 
159
  save_flags (flags);
160
  cli ();
161
  if (sb_dsp_command (devc, 0x24))      /* 8 bit ADC using DMA */
162
    {
163
      sb_dsp_command (devc, (unsigned char) (count & 0xff));
164
      sb_dsp_command (devc, (unsigned char) ((count >> 8) & 0xff));
165
    }
166
  else
167
    printk ("SB Error: Unable to start ADC\n");
168
  restore_flags (flags);
169
 
170
  devc->intr_active = 1;
171
}
172
 
173
static void
174
sb1_audio_trigger (int dev, int bits)
175
{
176
  sb_devc        *devc = audio_devs[dev]->devc;
177
 
178
  bits &= devc->irq_mode;
179
 
180
  if (!bits)
181
    sb_dsp_command (devc, 0xd0);        /* Halt DMA */
182
  else
183
    {
184
      switch (devc->irq_mode)
185
        {
186
        case IMODE_INPUT:
187
          sb1_audio_start_input (dev, devc->trg_buf, devc->trg_bytes,
188
                                 devc->trg_intrflag, devc->trg_restart);
189
          break;
190
 
191
        case IMODE_OUTPUT:
192
          sb1_audio_output_block (dev, devc->trg_buf, devc->trg_bytes,
193
                                  devc->trg_intrflag, devc->trg_restart);
194
          break;
195
        }
196
    }
197
 
198
  devc->trigger_bits = bits;
199
}
200
 
201
static int
202
sb1_audio_prepare_for_input (int dev, int bsize, int bcount)
203
{
204
  sb_devc        *devc = audio_devs[dev]->devc;
205
  unsigned long   flags;
206
 
207
  save_flags (flags);
208
  cli ();
209
  if (sb_dsp_command (devc, 0x40))
210
    sb_dsp_command (devc, devc->tconst);
211
  sb_dsp_command (devc, DSP_CMD_SPKOFF);
212
  restore_flags (flags);
213
 
214
  devc->trigger_bits = 0;
215
  return 0;
216
}
217
 
218
static int
219
sb1_audio_prepare_for_output (int dev, int bsize, int bcount)
220
{
221
  sb_devc        *devc = audio_devs[dev]->devc;
222
  unsigned long   flags;
223
 
224
  save_flags (flags);
225
  cli ();
226
  if (sb_dsp_command (devc, 0x40))
227
    sb_dsp_command (devc, devc->tconst);
228
  sb_dsp_command (devc, DSP_CMD_SPKON);
229
  restore_flags (flags);
230
  devc->trigger_bits = 0;
231
  return 0;
232
}
233
 
234
static int
235
sb1_audio_set_speed (int dev, int speed)
236
{
237
  int             max_speed = 23000;
238
  sb_devc        *devc = audio_devs[dev]->devc;
239
  int             tmp;
240
 
241
  if (devc->opened & OPEN_READ)
242
    max_speed = 13000;
243
 
244
  if (speed > 0)
245
    {
246
      if (speed < 4000)
247
        speed = 4000;
248
 
249
      if (speed > max_speed)
250
        speed = max_speed;
251
 
252
      devc->tconst = (256 - ((1000000 + speed / 2) / speed)) & 0xff;
253
 
254
      tmp = 256 - devc->tconst;
255
      speed = (1000000 + tmp / 2) / tmp;
256
 
257
      devc->speed = speed;
258
    }
259
 
260
  return devc->speed;
261
}
262
 
263
static short
264
sb1_audio_set_channels (int dev, short channels)
265
{
266
  sb_devc        *devc = audio_devs[dev]->devc;
267
 
268
  return devc->channels = 1;
269
}
270
 
271
static unsigned int
272
sb1_audio_set_bits (int dev, unsigned int bits)
273
{
274
  sb_devc        *devc = audio_devs[dev]->devc;
275
 
276
  return devc->bits = 8;
277
}
278
 
279
static void
280
sb1_audio_halt_xfer (int dev)
281
{
282
  sb_devc        *devc = audio_devs[dev]->devc;
283
 
284
  sb_dsp_reset (devc);
285
}
286
 
287
/*
288
 * SB 2.0 and SB 2.01 compatible routines
289
 */
290
 
291
static void
292
sb20_audio_output_block (int dev, unsigned long buf, int nr_bytes,
293
                         int intrflag, int restart_dma)
294
{
295
  unsigned long   flags;
296
  int             count = nr_bytes;
297
  sb_devc        *devc = audio_devs[dev]->devc;
298
  unsigned char   cmd;
299
 
300
  DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE);
301
 
302
  if (audio_devs[dev]->dmachan1 > 3)
303
    count >>= 1;
304
  count--;
305
 
306
  devc->irq_mode = IMODE_OUTPUT;
307
 
308
  save_flags (flags);
309
  cli ();
310
  if (sb_dsp_command (devc, 0x48))      /* DSP Block size */
311
    {
312
      sb_dsp_command (devc, (unsigned char) (count & 0xff));
313
      sb_dsp_command (devc, (unsigned char) ((count >> 8) & 0xff));
314
 
315
      if (devc->speed * devc->channels <= 23000)
316
        cmd = 0x1c;             /* 8 bit PCM output */
317
      else
318
        cmd = 0x90;             /* 8 bit high speed PCM output (SB2.01/Pro) */
319
 
320
      if (!sb_dsp_command (devc, cmd))
321
        printk ("SB: Unable to start DAC\n");
322
 
323
    }
324
  else
325
    printk ("SB: Unable to start DAC\n");
326
  restore_flags (flags);
327
  devc->intr_active = 1;
328
}
329
 
330
static void
331
sb20_audio_start_input (int dev, unsigned long buf, int nr_bytes, int intrflag,
332
                        int restart_dma)
333
{
334
  unsigned long   flags;
335
  int             count = nr_bytes;
336
  sb_devc        *devc = audio_devs[dev]->devc;
337
  unsigned char   cmd;
338
 
339
  /*
340
   * Start a DMA input to the buffer pointed by dmaqtail
341
   */
342
 
343
  DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ);
344
 
345
  if (audio_devs[dev]->dmachan1 > 3)
346
    count >>= 1;
347
  count--;
348
 
349
  devc->irq_mode = IMODE_INPUT;
350
 
351
  save_flags (flags);
352
  cli ();
353
  if (sb_dsp_command (devc, 0x48))      /* DSP Block size */
354
    {
355
      sb_dsp_command (devc, (unsigned char) (count & 0xff));
356
      sb_dsp_command (devc, (unsigned char) ((count >> 8) & 0xff));
357
 
358
      if (devc->speed * devc->channels <= (devc->major == 3 ? 23000 : 13000))
359
        cmd = 0x2c;             /* 8 bit PCM input */
360
      else
361
        cmd = 0x98;             /* 8 bit high speed PCM input (SB2.01/Pro) */
362
 
363
      if (!sb_dsp_command (devc, cmd))
364
        printk ("SB: Unable to start ADC\n");
365
    }
366
  else
367
    printk ("SB Error: Unable to start ADC\n");
368
  restore_flags (flags);
369
 
370
  devc->intr_active = 1;
371
}
372
 
373
static void
374
sb20_audio_trigger (int dev, int bits)
375
{
376
  sb_devc        *devc = audio_devs[dev]->devc;
377
 
378
  bits &= devc->irq_mode;
379
 
380
  if (!bits)
381
    sb_dsp_command (devc, 0xd0);        /* Halt DMA */
382
  else
383
    {
384
      switch (devc->irq_mode)
385
        {
386
        case IMODE_INPUT:
387
          sb20_audio_start_input (dev, devc->trg_buf, devc->trg_bytes,
388
                                  devc->trg_intrflag, devc->trg_restart);
389
          break;
390
 
391
        case IMODE_OUTPUT:
392
          sb20_audio_output_block (dev, devc->trg_buf, devc->trg_bytes,
393
                                   devc->trg_intrflag, devc->trg_restart);
394
          break;
395
        }
396
    }
397
 
398
  devc->trigger_bits = bits;
399
}
400
 
401
/*
402
 * SB2.01 specific speed setup
403
 */
404
 
405
static int
406
sb201_audio_set_speed (int dev, int speed)
407
{
408
  sb_devc        *devc = audio_devs[dev]->devc;
409
  int             tmp;
410
  int             s = speed * devc->channels;
411
 
412
  if (speed > 0)
413
    {
414
      if (speed < 4000)
415
        speed = 4000;
416
 
417
      if (speed > 44100)
418
        speed = 44100;
419
 
420
      if (devc->opened & OPEN_READ && speed > 15000)
421
        speed = 15000;
422
 
423
      devc->tconst = ((65536 - ((256000000 + s / 2) /
424
                                s)) >> 8) & 0xff;
425
 
426
      tmp = 256 - devc->tconst;
427
      speed = ((1000000 + tmp / 2) / tmp) / devc->channels;
428
 
429
      devc->speed = speed;
430
    }
431
 
432
  return devc->speed;
433
}
434
 
435
/*
436
 * SB Pro specific routines
437
 */
438
 
439
static int
440
sbpro_audio_prepare_for_input (int dev, int bsize, int bcount)
441
{                               /* For SB Pro and Jazz16 */
442
  sb_devc        *devc = audio_devs[dev]->devc;
443
  unsigned long   flags;
444
  unsigned char   bits = 0;
445
 
446
  if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)
447
    audio_devs[dev]->dmachan1 =
448
      audio_devs[dev]->dmachan2 =
449
      devc->bits == 16 ? devc->dma16 : devc->dma8;
450
 
451
  if (devc->model == MDL_JAZZ || devc->model == MDL_SMW)
452
    if (devc->bits == AFMT_S16_LE)
453
      bits = 0x04;              /* 16 bit mode */
454
 
455
  save_flags (flags);
456
  cli ();
457
  if (sb_dsp_command (devc, 0x40))
458
    sb_dsp_command (devc, devc->tconst);
459
  sb_dsp_command (devc, DSP_CMD_SPKOFF);
460
  if (devc->channels == 1)
461
    sb_dsp_command (devc, 0xa0 | bits);         /* Mono input */
462
  else
463
    sb_dsp_command (devc, 0xa8 | bits);         /* Stereo input */
464
  restore_flags (flags);
465
 
466
  devc->trigger_bits = 0;
467
  return 0;
468
}
469
 
470
static int
471
sbpro_audio_prepare_for_output (int dev, int bsize, int bcount)
472
{                               /* For SB Pro and Jazz16 */
473
  sb_devc        *devc = audio_devs[dev]->devc;
474
  unsigned long   flags;
475
  unsigned char   tmp;
476
  unsigned char   bits = 0;
477
 
478
  if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)
479
    audio_devs[dev]->dmachan1 =
480
      audio_devs[dev]->dmachan2 =
481
      devc->bits == 16 ? devc->dma16 : devc->dma8;
482
 
483
  save_flags (flags);
484
  cli ();
485
  if (sb_dsp_command (devc, 0x40))
486
    sb_dsp_command (devc, devc->tconst);
487
  sb_dsp_command (devc, DSP_CMD_SPKON);
488
 
489
  if (devc->model == MDL_JAZZ || devc->model == MDL_SMW)
490
    {
491
      if (devc->bits == AFMT_S16_LE)
492
        bits = 0x04;            /* 16 bit mode */
493
 
494
      if (devc->channels == 1)
495
        sb_dsp_command (devc, 0xa0 | bits);     /* Mono output */
496
      else
497
        sb_dsp_command (devc, 0xa8 | bits);     /* Stereo output */
498
    }
499
  else
500
    {
501
      tmp = sb_getmixer (devc, 0x0e);
502
      if (devc->channels == 1)
503
        tmp &= ~0x02;
504
      else
505
        tmp |= 0x02;
506
      sb_setmixer (devc, 0x0e, tmp);
507
    }
508
  restore_flags (flags);
509
  devc->trigger_bits = 0;
510
  return 0;
511
}
512
 
513
static int
514
sbpro_audio_set_speed (int dev, int speed)
515
{
516
  sb_devc        *devc = audio_devs[dev]->devc;
517
 
518
  if (speed > 0)
519
    {
520
      if (speed < 4000)
521
        speed = 4000;
522
 
523
      if (speed > 44100)
524
        speed = 44100;
525
 
526
      if (devc->channels > 1 && speed > 22050)
527
        speed = 22050;
528
 
529
      sb201_audio_set_speed (dev, speed);
530
    }
531
 
532
  return devc->speed;
533
}
534
 
535
static short
536
sbpro_audio_set_channels (int dev, short channels)
537
{
538
  sb_devc        *devc = audio_devs[dev]->devc;
539
 
540
  if (channels == 1 || channels == 2)
541
    if (channels != devc->channels)
542
      {
543
        devc->channels = channels;
544
        sbpro_audio_set_speed (dev, devc->speed);
545
      }
546
  return devc->channels;
547
}
548
 
549
static int
550
jazz16_audio_set_speed (int dev, int speed)
551
{
552
  sb_devc        *devc = audio_devs[dev]->devc;
553
 
554
  if (speed > 0)
555
    {
556
      int             tmp;
557
      int             s = speed * devc->channels;
558
 
559
      if (speed < 5000)
560
        speed = 4000;
561
 
562
      if (speed > 44100)
563
        speed = 44100;
564
 
565
      devc->tconst = ((65536 - ((256000000 + s / 2) /
566
                                s)) >> 8) & 0xff;
567
 
568
      tmp = 256 - devc->tconst;
569
      speed = ((1000000 + tmp / 2) / tmp) / devc->channels;
570
 
571
      devc->speed = speed;
572
    }
573
 
574
  return devc->speed;
575
}
576
 
577
/*
578
 * ESS specific routines
579
 */
580
 
581
static void
582
ess_speed (sb_devc * devc)
583
{
584
  int             divider;
585
  unsigned char   bits = 0;
586
  int             speed = devc->speed;
587
 
588
  if (speed < 4000)
589
    speed = 4000;
590
  else if (speed > 48000)
591
    speed = 48000;
592
 
593
  if (speed > 22000)
594
    {
595
      bits = 0x80;
596
      divider = 256 - (795500 + speed / 2) / speed;
597
    }
598
  else
599
    {
600
      divider = 128 - (397700 + speed / 2) / speed;
601
    }
602
 
603
  bits |= (unsigned char) divider;
604
  ess_write (devc, 0xa1, bits);
605
 
606
/*
607
 * Set filter divider register
608
 */
609
 
610
  speed = (speed * 9) / 20;     /* Set filter roll-off to 90% of speed/2 */
611
  divider = 256 - 7160000 / (speed * 82);
612
  ess_write (devc, 0xa2, divider);
613
 
614
  return;
615
}
616
 
617
static int
618
ess_audio_prepare_for_input (int dev, int bsize, int bcount)
619
{
620
  sb_devc        *devc = audio_devs[dev]->devc;
621
 
622
  ess_speed (devc);
623
  sb_dsp_command (devc, DSP_CMD_SPKOFF);
624
 
625
  ess_write (devc, 0xb8, 0x0e); /* Auto init DMA mode */
626
  ess_write (devc, 0xa8, (ess_read (devc, 0xa8) & ~0x03) |
627
             (3 - devc->channels));     /* Mono/stereo */
628
  ess_write (devc, 0xb9, 2);    /* Demand mode (4 bytes/DMA request) */
629
 
630
  if (devc->channels == 1)
631
    {
632
      if (devc->bits == AFMT_U8)
633
        {                       /* 8 bit mono */
634
          ess_write (devc, 0xb7, 0x51);
635
          ess_write (devc, 0xb7, 0xd0);
636
        }
637
      else
638
        {                       /* 16 bit mono */
639
          ess_write (devc, 0xb7, 0x71);
640
          ess_write (devc, 0xb7, 0xf4);
641
        }
642
    }
643
  else
644
    {                           /* Stereo */
645
      if (devc->bits == AFMT_U8)
646
        {                       /* 8 bit stereo */
647
          ess_write (devc, 0xb7, 0x51);
648
          ess_write (devc, 0xb7, 0x98);
649
        }
650
      else
651
        {                       /* 16 bit stereo */
652
          ess_write (devc, 0xb7, 0x71);
653
          ess_write (devc, 0xb7, 0xbc);
654
        }
655
    }
656
 
657
  ess_write (devc, 0xb1, (ess_read (devc, 0xb1) & 0x0f) | 0x50);
658
  ess_write (devc, 0xb2, (ess_read (devc, 0xb2) & 0x0f) | 0x50);
659
 
660
  devc->trigger_bits = 0;
661
  return 0;
662
}
663
 
664
static int
665
ess_audio_prepare_for_output (int dev, int bsize, int bcount)
666
{
667
  sb_devc        *devc = audio_devs[dev]->devc;
668
 
669
  sb_dsp_reset (devc);
670
  ess_speed (devc);
671
 
672
  ess_write (devc, 0xb8, 4);    /* Auto init DMA mode */
673
  ess_write (devc, 0xa8, (ess_read (devc, 0xa8) & ~0x03) |
674
             (3 - devc->channels));     /* Mono/stereo */
675
  ess_write (devc, 0xb9, 2);    /* Demand mode (4 bytes/request) */
676
 
677
  if (devc->channels == 1)
678
    {
679
      if (devc->bits == AFMT_U8)
680
        {                       /* 8 bit mono */
681
          ess_write (devc, 0xb6, 0x80);
682
          ess_write (devc, 0xb7, 0x51);
683
          ess_write (devc, 0xb7, 0xd0);
684
        }
685
      else
686
        {                       /* 16 bit mono */
687
          ess_write (devc, 0xb6, 0x00);
688
          ess_write (devc, 0xb7, 0x71);
689
          ess_write (devc, 0xb7, 0xf4);
690
        }
691
    }
692
  else
693
    {                           /* Stereo */
694
      if (devc->bits == AFMT_U8)
695
        {                       /* 8 bit stereo */
696
          ess_write (devc, 0xb6, 0x80);
697
          ess_write (devc, 0xb7, 0x51);
698
          ess_write (devc, 0xb7, 0x98);
699
        }
700
      else
701
        {                       /* 16 bit stereo */
702
          ess_write (devc, 0xb6, 0x00);
703
          ess_write (devc, 0xb7, 0x71);
704
          ess_write (devc, 0xb7, 0xbc);
705
        }
706
    }
707
 
708
  ess_write (devc, 0xb1, (ess_read (devc, 0xb1) & 0x0f) | 0x50);
709
  ess_write (devc, 0xb2, (ess_read (devc, 0xb2) & 0x0f) | 0x50);
710
  sb_dsp_command (devc, DSP_CMD_SPKON);
711
 
712
  devc->trigger_bits = 0;
713
  return 0;
714
}
715
 
716
static void
717
ess_audio_output_block (int dev, unsigned long buf, int nr_bytes,
718
                        int intrflag, int restart_dma)
719
{
720
  int             count = nr_bytes;
721
  sb_devc        *devc = audio_devs[dev]->devc;
722
  short           c = -nr_bytes;
723
 
724
  if (!restart_dma)
725
    return;
726
 
727
  DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE);
728
 
729
  if (audio_devs[dev]->dmachan1 > 3)
730
    count >>= 1;
731
  count--;
732
 
733
  devc->irq_mode = IMODE_OUTPUT;
734
 
735
  ess_write (devc, 0xa4, (unsigned char) ((unsigned short) c & 0xff));
736
  ess_write (devc, 0xa5, (unsigned char) (((unsigned short) c >> 8) & 0xff));
737
 
738
  ess_write (devc, 0xb8, ess_read (devc, 0xb8) | 0x05);         /* Go */
739
  devc->intr_active = 1;
740
}
741
 
742
static void
743
ess_audio_start_input (int dev, unsigned long buf, int nr_bytes, int intrflag,
744
                       int restart_dma)
745
{
746
  int             count = nr_bytes;
747
  sb_devc        *devc = audio_devs[dev]->devc;
748
  short           c = -nr_bytes;
749
 
750
  if (!restart_dma)
751
    return;
752
 
753
  /*
754
   * Start a DMA input to the buffer pointed by dmaqtail
755
   */
756
 
757
  DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ);
758
 
759
  if (audio_devs[dev]->dmachan1 > 3)
760
    count >>= 1;
761
  count--;
762
 
763
  devc->irq_mode = IMODE_INPUT;
764
 
765
  ess_write (devc, 0xa4, (unsigned char) ((unsigned short) c & 0xff));
766
  ess_write (devc, 0xa5, (unsigned char) (((unsigned short) c >> 8) & 0xff));
767
 
768
  ess_write (devc, 0xb8, ess_read (devc, 0xb8) | 0x0f);         /* Go */
769
  devc->intr_active = 1;
770
}
771
 
772
static void
773
ess_audio_trigger (int dev, int bits)
774
{
775
  sb_devc        *devc = audio_devs[dev]->devc;
776
 
777
  bits &= devc->irq_mode;
778
 
779
  if (!bits)
780
    sb_dsp_command (devc, 0xd0);        /* Halt DMA */
781
  else
782
    {
783
      switch (devc->irq_mode)
784
        {
785
        case IMODE_INPUT:
786
          ess_audio_start_input (dev, devc->trg_buf, devc->trg_bytes,
787
                                 devc->trg_intrflag, devc->trg_restart);
788
          break;
789
 
790
        case IMODE_OUTPUT:
791
          ess_audio_output_block (dev, devc->trg_buf, devc->trg_bytes,
792
                                  devc->trg_intrflag, devc->trg_restart);
793
          break;
794
        }
795
    }
796
 
797
  devc->trigger_bits = bits;
798
}
799
 
800
/*
801
 * SB16 specific routines
802
 */
803
 
804
static int
805
sb16_audio_set_speed (int dev, int speed)
806
{
807
  sb_devc        *devc = audio_devs[dev]->devc;
808
 
809
  if (speed > 0)
810
    {
811
      if (speed < 5000)
812
        speed = 4000;
813
 
814
      if (speed > 44100)
815
        speed = 44100;
816
 
817
      devc->speed = speed;
818
    }
819
 
820
  return devc->speed;
821
}
822
 
823
static unsigned int
824
sb16_audio_set_bits (int dev, unsigned int bits)
825
{
826
  sb_devc        *devc = audio_devs[dev]->devc;
827
 
828
  if (bits != 0)
829
    if (devc->bits == AFMT_U8 || bits == AFMT_S16_LE)
830
      devc->bits = bits;
831
    else
832
      devc->bits = AFMT_U8;
833
 
834
  return devc->bits;
835
}
836
 
837
static int
838
sb16_audio_prepare_for_input (int dev, int bsize, int bcount)
839
{
840
  sb_devc        *devc = audio_devs[dev]->devc;
841
 
842
  audio_devs[dev]->dmachan1 =
843
    audio_devs[dev]->dmachan2 =
844
    devc->bits == AFMT_S16_LE ? devc->dma16 : devc->dma8;
845
 
846
  devc->trigger_bits = 0;
847
  return 0;
848
}
849
 
850
static int
851
sb16_audio_prepare_for_output (int dev, int bsize, int bcount)
852
{
853
  sb_devc        *devc = audio_devs[dev]->devc;
854
 
855
  audio_devs[dev]->dmachan1 =
856
    audio_devs[dev]->dmachan2 =
857
    devc->bits == AFMT_S16_LE ? devc->dma16 : devc->dma8;
858
 
859
  devc->trigger_bits = 0;
860
  return 0;
861
}
862
 
863
static void
864
sb16_audio_output_block (int dev, unsigned long buf, int count,
865
                         int intrflag, int restart_dma)
866
{
867
  unsigned long   flags, cnt;
868
  sb_devc        *devc = audio_devs[dev]->devc;
869
 
870
  devc->irq_mode = IMODE_OUTPUT;
871
  devc->intr_active = 1;
872
 
873
  if (!restart_dma)
874
    return;
875
 
876
  cnt = count;
877
  if (devc->bits == AFMT_S16_LE)
878
    cnt >>= 1;
879
  cnt--;
880
 
881
  save_flags (flags);
882
  cli ();
883
 
884
  if (restart_dma)
885
    DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE);
886
 
887
  sb_dsp_command (devc, 0x41);
888
  sb_dsp_command (devc, (unsigned char) ((devc->speed >> 8) & 0xff));
889
  sb_dsp_command (devc, (unsigned char) (devc->speed & 0xff));
890
 
891
  sb_dsp_command (devc, (devc->bits == AFMT_S16_LE ? 0xb6 : 0xc6));
892
  sb_dsp_command (devc, ((devc->channels == 2 ? 0x20 : 0) +
893
                         (devc->bits == AFMT_S16_LE ? 0x10 : 0)));
894
  sb_dsp_command (devc, (unsigned char) (cnt & 0xff));
895
  sb_dsp_command (devc, (unsigned char) (cnt >> 8));
896
 
897
  restore_flags (flags);
898
}
899
 
900
static void
901
sb16_audio_start_input (int dev, unsigned long buf, int count, int intrflag,
902
                        int restart_dma)
903
{
904
  unsigned long   flags, cnt;
905
  sb_devc        *devc = audio_devs[dev]->devc;
906
 
907
  devc->irq_mode = IMODE_INPUT;
908
  devc->intr_active = 1;
909
 
910
  if (!restart_dma)
911
    return;
912
 
913
  cnt = count;
914
  if (devc->bits == AFMT_S16_LE)
915
    cnt >>= 1;
916
  cnt--;
917
 
918
  save_flags (flags);
919
  cli ();
920
 
921
  if (restart_dma)
922
    DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ);
923
 
924
  sb_dsp_command (devc, 0x42);
925
  sb_dsp_command (devc, (unsigned char) ((devc->speed >> 8) & 0xff));
926
  sb_dsp_command (devc, (unsigned char) (devc->speed & 0xff));
927
 
928
  sb_dsp_command (devc, (devc->bits == AFMT_S16_LE ? 0xbe : 0xce));
929
  sb_dsp_command (devc, ((devc->channels == 2 ? 0x20 : 0) +
930
                         (devc->bits == AFMT_S16_LE ? 0x10 : 0)));
931
  sb_dsp_command (devc, (unsigned char) (cnt & 0xff));
932
  sb_dsp_command (devc, (unsigned char) (cnt >> 8));
933
 
934
  restore_flags (flags);
935
}
936
 
937
static void
938
sb16_audio_trigger (int dev, int bits)
939
{
940
  sb_devc        *devc = audio_devs[dev]->devc;
941
 
942
  bits &= devc->irq_mode;
943
 
944
  if (!bits)
945
    sb_dsp_command (devc, 0xd0);        /* Halt DMA */
946
  else
947
    {
948
      switch (devc->irq_mode)
949
        {
950
        case IMODE_INPUT:
951
          sb16_audio_start_input (dev, devc->trg_buf, devc->trg_bytes,
952
                                  devc->trg_intrflag, devc->trg_restart);
953
          break;
954
 
955
        case IMODE_OUTPUT:
956
          sb16_audio_output_block (dev, devc->trg_buf, devc->trg_bytes,
957
                                   devc->trg_intrflag, devc->trg_restart);
958
          break;
959
        }
960
    }
961
 
962
  devc->trigger_bits = bits;
963
}
964
 
965
static int
966
sb_audio_ioctl (int dev, unsigned int cmd, caddr_t arg, int local)
967
{
968
  return -(EINVAL);
969
}
970
 
971
static void
972
sb_audio_reset (int dev)
973
{
974
  unsigned long   flags;
975
  sb_devc        *devc = audio_devs[dev]->devc;
976
 
977
  save_flags (flags);
978
  cli ();
979
  sb_dsp_reset (devc);
980
  restore_flags (flags);
981
}
982
 
983
static struct audio_driver sb1_audio_driver =   /* SB1.x */
984
{
985
  sb_audio_open,
986
  sb_audio_close,
987
  sb_set_output_parms,
988
  sb_set_input_parms,
989
  sb_audio_ioctl,
990
  sb1_audio_prepare_for_input,
991
  sb1_audio_prepare_for_output,
992
  sb_audio_reset,
993
  sb1_audio_halt_xfer,
994
  NULL,                         /* local_qlen */
995
  NULL,                         /* copy_from_user */
996
  NULL,
997
  NULL,
998
  sb1_audio_trigger,
999
  sb1_audio_set_speed,
1000
  sb1_audio_set_bits,
1001
  sb1_audio_set_channels
1002
};
1003
 
1004
static struct audio_driver sb20_audio_driver =  /* SB2.0 */
1005
{
1006
  sb_audio_open,
1007
  sb_audio_close,
1008
  sb_set_output_parms,
1009
  sb_set_input_parms,
1010
  sb_audio_ioctl,
1011
  sb1_audio_prepare_for_input,
1012
  sb1_audio_prepare_for_output,
1013
  sb_audio_reset,
1014
  sb1_audio_halt_xfer,
1015
  NULL,                         /* local_qlen */
1016
  NULL,                         /* copy_from_user */
1017
  NULL,
1018
  NULL,
1019
  sb20_audio_trigger,
1020
  sb1_audio_set_speed,
1021
  sb1_audio_set_bits,
1022
  sb1_audio_set_channels
1023
};
1024
 
1025
static struct audio_driver sb201_audio_driver =         /* SB2.01 */
1026
{
1027
  sb_audio_open,
1028
  sb_audio_close,
1029
  sb_set_output_parms,
1030
  sb_set_input_parms,
1031
  sb_audio_ioctl,
1032
  sb1_audio_prepare_for_input,
1033
  sb1_audio_prepare_for_output,
1034
  sb_audio_reset,
1035
  sb1_audio_halt_xfer,
1036
  NULL,                         /* local_qlen */
1037
  NULL,                         /* copy_from_user */
1038
  NULL,
1039
  NULL,
1040
  sb20_audio_trigger,
1041
  sb201_audio_set_speed,
1042
  sb1_audio_set_bits,
1043
  sb1_audio_set_channels
1044
};
1045
 
1046
static struct audio_driver sbpro_audio_driver =         /* SB Pro */
1047
{
1048
  sb_audio_open,
1049
  sb_audio_close,
1050
  sb_set_output_parms,
1051
  sb_set_input_parms,
1052
  sb_audio_ioctl,
1053
  sbpro_audio_prepare_for_input,
1054
  sbpro_audio_prepare_for_output,
1055
  sb_audio_reset,
1056
  sb1_audio_halt_xfer,
1057
  NULL,                         /* local_qlen */
1058
  NULL,                         /* copy_from_user */
1059
  NULL,
1060
  NULL,
1061
  sb20_audio_trigger,
1062
  sbpro_audio_set_speed,
1063
  sb1_audio_set_bits,
1064
  sbpro_audio_set_channels
1065
};
1066
 
1067
static struct audio_driver jazz16_audio_driver =        /* Jazz16 and SM Wave */
1068
{
1069
  sb_audio_open,
1070
  sb_audio_close,
1071
  sb_set_output_parms,
1072
  sb_set_input_parms,
1073
  sb_audio_ioctl,
1074
  sbpro_audio_prepare_for_input,
1075
  sbpro_audio_prepare_for_output,
1076
  sb_audio_reset,
1077
  sb1_audio_halt_xfer,
1078
  NULL,                         /* local_qlen */
1079
  NULL,                         /* copy_from_user */
1080
  NULL,
1081
  NULL,
1082
  sb20_audio_trigger,
1083
  jazz16_audio_set_speed,
1084
  sb16_audio_set_bits,
1085
  sbpro_audio_set_channels
1086
};
1087
 
1088
static struct audio_driver sb16_audio_driver =  /* SB16 */
1089
{
1090
  sb_audio_open,
1091
  sb_audio_close,
1092
  sb_set_output_parms,
1093
  sb_set_input_parms,
1094
  sb_audio_ioctl,
1095
  sb16_audio_prepare_for_input,
1096
  sb16_audio_prepare_for_output,
1097
  sb_audio_reset,
1098
  sb1_audio_halt_xfer,
1099
  NULL,                         /* local_qlen */
1100
  NULL,                         /* copy_from_user */
1101
  NULL,
1102
  NULL,
1103
  sb16_audio_trigger,
1104
  sb16_audio_set_speed,
1105
  sb16_audio_set_bits,
1106
  sbpro_audio_set_channels
1107
};
1108
 
1109
static struct audio_driver ess_audio_driver =   /* ESS ES688/1688 */
1110
{
1111
  sb_audio_open,
1112
  sb_audio_close,
1113
  sb_set_output_parms,
1114
  sb_set_input_parms,
1115
  sb_audio_ioctl,
1116
  ess_audio_prepare_for_input,
1117
  ess_audio_prepare_for_output,
1118
  sb_audio_reset,
1119
  sb1_audio_halt_xfer,
1120
  NULL,                         /* local_qlen */
1121
  NULL,                         /* copy_from_user */
1122
  NULL,
1123
  NULL,
1124
  ess_audio_trigger,
1125
  sb16_audio_set_speed,
1126
  sb16_audio_set_bits,
1127
  sbpro_audio_set_channels
1128
};
1129
 
1130
void
1131
sb_audio_init (sb_devc * devc, char *name)
1132
{
1133
  int             audio_flags = 0;
1134
  int             format_mask = AFMT_U8;
1135
 
1136
  struct audio_driver *driver = &sb1_audio_driver;
1137
 
1138
  switch (devc->model)
1139
    {
1140
    case MDL_SB1:               /* SB1.0 or SB 1.5 */
1141
      DDB (printk ("Will use standard SB1.x driver\n"));
1142
      audio_flags = DMA_HARDSTOP;
1143
      break;
1144
 
1145
    case MDL_SB2:
1146
      DDB (printk ("Will use SB2.0 driver\n"));
1147
      audio_flags = DMA_AUTOMODE;
1148
      driver = &sb20_audio_driver;
1149
      break;
1150
 
1151
    case MDL_SB201:
1152
      DDB (printk ("Will use SB2.01 (high speed) driver\n"));
1153
      audio_flags = DMA_AUTOMODE;
1154
      driver = &sb201_audio_driver;
1155
      break;
1156
 
1157
    case MDL_JAZZ:
1158
    case MDL_SMW:
1159
      DDB (printk ("Will use Jazz16 driver\n"));
1160
      audio_flags = DMA_AUTOMODE;
1161
      format_mask |= AFMT_S16_LE;
1162
      driver = &jazz16_audio_driver;
1163
      break;
1164
 
1165
    case MDL_ESS:
1166
      DDB (printk ("Will use ESS ES688/1688 driver\n"));
1167
      audio_flags = DMA_AUTOMODE;
1168
      format_mask |= AFMT_S16_LE;
1169
      driver = &ess_audio_driver;
1170
      break;
1171
 
1172
    case MDL_SB16:
1173
      DDB (printk ("Will use SB16 driver\n"));
1174
      audio_flags = DMA_AUTOMODE;
1175
      format_mask |= AFMT_S16_LE;
1176
      driver = &sb16_audio_driver;
1177
      break;
1178
 
1179
    default:
1180
      DDB (printk ("Will use SB Pro driver\n"));
1181
      audio_flags = DMA_AUTOMODE;
1182
      driver = &sbpro_audio_driver;
1183
    }
1184
 
1185
  if ((devc->my_dev = sound_install_audiodrv (AUDIO_DRIVER_VERSION,
1186
                                              name,
1187
                                              driver,
1188
                                              sizeof (struct audio_driver),
1189
                                              audio_flags,
1190
                                              format_mask,
1191
                                              devc,
1192
                                              devc->dma8,
1193
                                              devc->dma8)) < 0)
1194
    {
1195
      return;
1196
    }
1197
 
1198
  audio_devs[devc->my_dev]->mixer_dev = devc->my_mixerdev;
1199
  audio_devs[devc->my_dev]->min_fragment = 5;
1200
}
1201
 
1202
#endif

powered by: WebSVN 2.1.0

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