1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
|
/*
* sound/pss.c
*
* The low level driver for the Personal Sound System (ECHO ESC614).
*/
/*
* Copyright (C) by Hannu Savolainen 1993-1997
*
* OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
* Version 2 (June 1991). See the "COPYING" file distributed with this software
* for more info.
*/
#include <linux/config.h>
#include "sound_config.h"
#if defined(CONFIG_PSS) && defined(CONFIG_AUDIO)
/*
* PSS registers.
*/
#define REG(x) (devc->base+x)
#define PSS_DATA 0
#define PSS_STATUS 2
#define PSS_CONTROL 2
#define PSS_ID 4
#define PSS_IRQACK 4
#define PSS_PIO 0x1a
/*
* Config registers
*/
#define CONF_PSS 0x10
#define CONF_WSS 0x12
#define CONF_SB 0x13
#define CONF_CDROM 0x16
#define CONF_MIDI 0x18
/*
* Status bits.
*/
#define PSS_FLAG3 0x0800
#define PSS_FLAG2 0x0400
#define PSS_FLAG1 0x1000
#define PSS_FLAG0 0x0800
#define PSS_WRITE_EMPTY 0x8000
#define PSS_READ_FULL 0x4000
#include "coproc.h"
#ifdef PSS_HAVE_LD
#include "synth-ld.h"
#else
static int pss_synthLen = 0;
static unsigned char *pss_synth =
NULL;
#endif
typedef struct pss_confdata
{
int base;
int irq;
int dma;
int *osp;
}
pss_confdata;
static pss_confdata pss_data;
static pss_confdata *devc = &pss_data;
static int pss_initialized = 0;
static int nonstandard_microcode = 0;
static void
pss_write (int data)
{
int i, limit;
limit = jiffies + 10; /* The timeout is 0.1 seconds */
/*
* Note! the i<5000000 is an emergency exit. The dsp_command() is sometimes
* called while interrupts are disabled. This means that the timer is
* disabled also. However the timeout situation is a abnormal condition.
* Normally the DSP should be ready to accept commands after just couple of
* loops.
*/
for (i = 0; i < 5000000 && jiffies < limit; i++)
{
if (inw (devc->base + PSS_STATUS) & PSS_WRITE_EMPTY)
{
outw (devc->base + PSS_DATA, data);
return;
}
}
printk ("PSS: DSP Command (%04x) Timeout.\n", data);
}
int
probe_pss (struct address_info *hw_config)
{
unsigned short id;
int irq, dma;
devc->base = hw_config->io_base;
irq = devc->irq = hw_config->irq;
dma = devc->dma = hw_config->dma;
devc->osp = hw_config->osp;
if (devc->base != 0x220 && devc->base != 0x240)
if (devc->base != 0x230 && devc->base != 0x250) /* Some cards use these */
return 0;
if (check_region (devc->base, 16))
{
printk ("PSS: I/O port conflict\n");
return 0;
}
id = inw (REG (PSS_ID));
if ((id >> 8) != 'E')
{
/* printk ("No PSS signature detected at 0x%x (0x%x)\n", devc->base, id); */
return 0;
}
return 1;
}
static int
set_irq (pss_confdata * devc, int dev, int irq)
{
static unsigned short irq_bits[16] =
{
0x0000, 0x0000, 0x0000, 0x0008,
0x0000, 0x0010, 0x0000, 0x0018,
0x0000, 0x0020, 0x0028, 0x0030,
0x0038, 0x0000, 0x0000, 0x0000
};
unsigned short tmp, bits;
if (irq < 0 || irq > 15)
return 0;
tmp = inw (REG (dev)) & ~0x38; /* Load confreg, mask IRQ bits out */
if ((bits = irq_bits[irq]) == 0 && irq != 0)
{
printk ("PSS: Invalid IRQ %d\n", irq);
return 0;
}
outw (tmp | bits, REG (dev));
return 1;
}
static int
set_io_base (pss_confdata * devc, int dev, int base)
{
unsigned short tmp = inw (REG (dev)) & 0x003f;
unsigned short bits = (base & 0x0ffc) << 4;
outw (bits | tmp, REG (dev));
return 1;
}
static int
set_dma (pss_confdata * devc, int dev, int dma)
{
static unsigned short dma_bits[8] =
{
0x0001, 0x0002, 0x0000, 0x0003,
0x0000, 0x0005, 0x0006, 0x0007
};
unsigned short tmp, bits;
if (dma < 0 || dma > 7)
return 0;
tmp = inw (REG (dev)) & ~0x07; /* Load confreg, mask DMA bits out */
if ((bits = dma_bits[dma]) == 0 && dma != 4)
{
printk ("PSS: Invalid DMA %d\n", dma);
return 0;
}
outw (tmp | bits, REG (dev));
return 1;
}
static int
pss_reset_dsp (pss_confdata * devc)
{
unsigned long i, limit = jiffies + 10;
outw (0x2000, REG (PSS_CONTROL));
for (i = 0; i < 32768 && jiffies < limit; i++)
inw (REG (PSS_CONTROL));
outw (0x0000, REG (PSS_CONTROL));
return 1;
}
static int
pss_put_dspword (pss_confdata * devc, unsigned short word)
{
int i, val;
for (i = 0; i < 327680; i++)
{
val = inw (REG (PSS_STATUS));
if (val & PSS_WRITE_EMPTY)
{
outw (word, REG (PSS_DATA));
return 1;
}
}
return 0;
}
static int
pss_get_dspword (pss_confdata * devc, unsigned short *word)
{
int i, val;
for (i = 0; i < 327680; i++)
{
val = inw (REG (PSS_STATUS));
if (val & PSS_READ_FULL)
{
*word = inw (REG (PSS_DATA));
return 1;
}
}
return 0;
}
static int
pss_download_boot (pss_confdata * devc, unsigned char *block, int size, int flags)
{
int i, limit, val, count;
if (flags & CPF_FIRST)
{
/*_____ Warn DSP software that a boot is coming */
outw (0x00fe, REG (PSS_DATA));
limit = jiffies + 10;
for (i = 0; i < 32768 && jiffies < limit; i++)
if (inw (REG (PSS_DATA)) == 0x5500)
break;
outw (*block++, REG (PSS_DATA));
pss_reset_dsp (devc);
}
count = 1;
while (1)
{
int j;
for (j = 0; j < 327670; j++)
{
/*_____ Wait for BG to appear */
if (inw (REG (PSS_STATUS)) & PSS_FLAG3)
break;
}
if (j == 327670)
{
/* It's ok we timed out when the file was empty */
if (count >= size && flags & CPF_LAST)
break;
else
{
printk ("\nPSS: Download timeout problems, byte %d=%d\n",
count, size);
return 0;
}
}
/*_____ Send the next byte */
outw (*block++, REG (PSS_DATA));
count++;
}
if (flags & CPF_LAST)
{
/*_____ Why */
outw (0, REG (PSS_DATA));
limit = jiffies + 10;
for (i = 0; i < 32768 && jiffies < limit; i++)
val = inw (REG (PSS_STATUS));
limit = jiffies + 10;
for (i = 0; i < 32768 && jiffies < limit; i++)
{
val = inw (REG (PSS_STATUS));
if (val & 0x4000)
break;
}
/* now read the version */
for (i = 0; i < 32000; i++)
{
val = inw (REG (PSS_STATUS));
if (val & PSS_READ_FULL)
break;
}
if (i == 32000)
return 0;
val = inw (REG (PSS_DATA));
/* printk("<PSS: microcode version %d.%d loaded>", val/16, val % 16); */
}
return 1;
}
void
attach_pss (struct address_info *hw_config)
{
unsigned short id;
char tmp[100];
devc->base = hw_config->io_base;
devc->irq = hw_config->irq;
devc->dma = hw_config->dma;
devc->osp = hw_config->osp;
if (!probe_pss (hw_config))
return;
id = inw (REG (PSS_ID)) & 0x00ff;
/*
* Disable all emulations. Will be enabled later (if required).
*/
outw (0x0000, REG (CONF_PSS)); /* 0x0400 enables joystick */
outw (0x0000, REG (CONF_WSS));
outw (0x0000, REG (CONF_SB));
outw (0x0000, REG (CONF_MIDI));
outw (0x0000, REG (CONF_CDROM));
#if YOU_REALLY_WANT_TO_ALLOCATE_THESE_RESOURCES
if (sound_alloc_dma (hw_config->dma, "PSS"))
{
printk ("pss.c: Can't allocate DMA channel\n");
return;
}
if (!set_irq (devc, CONF_PSS, devc->irq))
{
printk ("PSS: IRQ error\n");
return;
}
if (!set_dma (devc, CONF_PSS, devc->dma))
{
printk ("PSS: DRQ error\n");
return;
}
#endif
pss_initialized = 1;
sprintf (tmp, "ECHO-PSS Rev. %d", id);
conf_printf (tmp, hw_config);
}
static void
pss_init_speaker (void)
{
/* Don't ask what are these commands. I really don't know */
pss_write (0x0010);
pss_write (0x0000 | 252); /* Left master volume */
pss_write (0x0010);
pss_write (0x0100 | 252); /* Right master volume */
pss_write (0x0010);
pss_write (0x0200 | 246); /* Bass */
pss_write (0x0010);
pss_write (0x0300 | 246); /* Treble */
pss_write (0x0010);
pss_write (0x0800 | 0x00ce); /* Stereo switch? */
}
int
probe_pss_mpu (struct address_info *hw_config)
{
int timeout;
if (!pss_initialized)
return 0;
if (check_region (hw_config->io_base, 2))
{
printk ("PSS: MPU I/O port conflict\n");
return 0;
}
if (!set_io_base (devc, CONF_MIDI, hw_config->io_base))
{
printk ("PSS: MIDI base error.\n");
return 0;
}
if (!set_irq (devc, CONF_MIDI, hw_config->irq))
{
printk ("PSS: MIDI IRQ error.\n");
return 0;
}
if (!pss_synthLen)
{
printk ("PSS: Can't enable MPU. MIDI synth microcode not available.\n");
return 0;
}
if (!pss_download_boot (devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
{
printk ("PSS: Unable to load MIDI synth microcode to DSP.\n");
return 0;
}
pss_init_speaker ();
/*
* Finally wait until the DSP algorithm has initialized itself and
* deactivates receive interrupt.
*/
for (timeout = 900000; timeout > 0; timeout--)
{
if ((inb (hw_config->io_base + 1) & 0x80) == 0) /* Input data avail */
inb (hw_config->io_base); /* Discard it */
else
break; /* No more input */
}
#if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
return probe_mpu401 (hw_config);
#else
return 0;
#endif
}
static int
pss_coproc_open (void *dev_info, int sub_device)
{
switch (sub_device)
{
case COPR_MIDI:
if (pss_synthLen == 0)
{
printk ("PSS: MIDI synth microcode not available.\n");
return -EIO;
}
if (nonstandard_microcode)
if (!pss_download_boot (devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
{
printk ("PSS: Unable to load MIDI synth microcode to DSP.\n");
return -EIO;
}
nonstandard_microcode = 0;
break;
default:;
}
return 0;
}
static void
pss_coproc_close (void *dev_info, int sub_device)
{
return;
}
static void
pss_coproc_reset (void *dev_info)
{
if (pss_synthLen)
if (!pss_download_boot (devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
{
printk ("PSS: Unable to load MIDI synth microcode to DSP.\n");
}
nonstandard_microcode = 0;
}
static int
download_boot_block (void *dev_info, copr_buffer * buf)
{
if (buf->len <= 0 || buf->len > sizeof (buf->data))
return -EINVAL;
if (!pss_download_boot (devc, buf->data, buf->len, buf->flags))
{
printk ("PSS: Unable to load microcode block to DSP.\n");
return -EIO;
}
nonstandard_microcode = 1; /* The MIDI microcode has been overwritten */
return 0;
}
static int
pss_coproc_ioctl (void *dev_info, unsigned int cmd, caddr_t arg, int local)
{
/* printk("PSS coproc ioctl %x %x %d\n", cmd, arg, local); */
switch (cmd)
{
case SNDCTL_COPR_RESET:
pss_coproc_reset (dev_info);
return 0;
break;
case SNDCTL_COPR_LOAD:
{
copr_buffer *buf;
int err;
buf = (copr_buffer *) vmalloc (sizeof (copr_buffer));
if (buf == NULL)
return -ENOSPC;
memcpy ((char *) buf, (&((char *) arg)[0]), sizeof (*buf));
err = download_boot_block (dev_info, buf);
vfree (buf);
return err;
}
break;
case SNDCTL_COPR_SENDMSG:
{
copr_msg *buf;
unsigned long flags;
unsigned short *data;
int i;
buf = (copr_msg *) vmalloc (sizeof (copr_msg));
if (buf == NULL)
return -ENOSPC;
memcpy ((char *) buf, (&((char *) arg)[0]), sizeof (*buf));
data = (unsigned short *) (buf->data);
save_flags (flags);
cli ();
for (i = 0; i < buf->len; i++)
{
if (!pss_put_dspword (devc, *data++))
{
restore_flags (flags);
buf->len = i; /* feed back number of WORDs sent */
memcpy ((&((char *) arg)[0]), (char *) buf, sizeof (*buf));
vfree (buf);
return -EIO;
}
}
restore_flags (flags);
vfree (buf);
return 0;
}
break;
case SNDCTL_COPR_RCVMSG:
{
copr_msg *buf;
unsigned long flags;
unsigned short *data;
unsigned int i;
int err = 0;
buf = (copr_msg *) vmalloc (sizeof (copr_msg));
if (buf == NULL)
return -ENOSPC;
data = (unsigned short *) buf->data;
save_flags (flags);
cli ();
for (i = 0; i < buf->len; i++)
{
buf->len = i; /* feed back number of WORDs read */
if (!pss_get_dspword (devc, data++))
{
if (i == 0)
err = -EIO;
break;
}
}
restore_flags (flags);
memcpy ((&((char *) arg)[0]), (char *) buf, sizeof (*buf));
vfree (buf);
return err;
}
break;
case SNDCTL_COPR_RDATA:
{
copr_debug_buf buf;
unsigned long flags;
unsigned short tmp;
memcpy ((char *) &buf, (&((char *) arg)[0]), sizeof (buf));
save_flags (flags);
cli ();
if (!pss_put_dspword (devc, 0x00d0))
{
restore_flags (flags);
return -EIO;
}
if (!pss_put_dspword (devc, (unsigned short) (buf.parm1 & 0xffff)))
{
restore_flags (flags);
return -EIO;
}
if (!pss_get_dspword (devc, &tmp))
{
restore_flags (flags);
return -EIO;
}
buf.parm1 = tmp;
restore_flags (flags);
memcpy ((&((char *) arg)[0]), (char *) &buf, sizeof (buf));
return 0;
}
break;
case SNDCTL_COPR_WDATA:
{
copr_debug_buf buf;
unsigned long flags;
unsigned short tmp;
memcpy ((char *) &buf, (&((char *) arg)[0]), sizeof (buf));
save_flags (flags);
cli ();
if (!pss_put_dspword (devc, 0x00d1))
{
restore_flags (flags);
return -EIO;
}
if (!pss_put_dspword (devc, (unsigned short) (buf.parm1 & 0xffff)))
{
restore_flags (flags);
return -EIO;
}
tmp = (unsigned int) buf.parm2 & 0xffff;
if (!pss_put_dspword (devc, tmp))
{
restore_flags (flags);
return -EIO;
}
restore_flags (flags);
return 0;
}
break;
case SNDCTL_COPR_WCODE:
{
copr_debug_buf buf;
unsigned long flags;
unsigned short tmp;
memcpy ((char *) &buf, (&((char *) arg)[0]), sizeof (buf));
save_flags (flags);
cli ();
if (!pss_put_dspword (devc, 0x00d3))
{
restore_flags (flags);
return -EIO;
}
if (!pss_put_dspword (devc, (unsigned short) (buf.parm1 & 0xffff)))
{
restore_flags (flags);
return -EIO;
}
tmp = (unsigned int) buf.parm2 & 0x00ff;
if (!pss_put_dspword (devc, tmp))
{
restore_flags (flags);
return -EIO;
}
tmp = ((unsigned int) buf.parm2 >> 8) & 0xffff;
if (!pss_put_dspword (devc, tmp))
{
restore_flags (flags);
return -EIO;
}
restore_flags (flags);
return 0;
}
break;
case SNDCTL_COPR_RCODE:
{
copr_debug_buf buf;
unsigned long flags;
unsigned short tmp;
memcpy ((char *) &buf, (&((char *) arg)[0]), sizeof (buf));
save_flags (flags);
cli ();
if (!pss_put_dspword (devc, 0x00d2))
{
restore_flags (flags);
return -EIO;
}
if (!pss_put_dspword (devc, (unsigned short) (buf.parm1 & 0xffff)))
{
restore_flags (flags);
return -EIO;
}
if (!pss_get_dspword (devc, &tmp)) /* Read MSB */
{
restore_flags (flags);
return -EIO;
}
buf.parm1 = tmp << 8;
if (!pss_get_dspword (devc, &tmp)) /* Read LSB */
{
restore_flags (flags);
return -EIO;
}
buf.parm1 |= tmp & 0x00ff;
restore_flags (flags);
memcpy ((&((char *) arg)[0]), (char *) &buf, sizeof (buf));
return 0;
}
break;
default:
return -EINVAL;
}
return -EINVAL;
}
static coproc_operations pss_coproc_operations =
{
"ADSP-2115",
pss_coproc_open,
pss_coproc_close,
pss_coproc_ioctl,
pss_coproc_reset,
&pss_data
};
void
attach_pss_mpu (struct address_info *hw_config)
{
#if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
{
int prev_devs;
prev_devs = num_midis;
attach_mpu401 (hw_config);
if (num_midis == (prev_devs + 1)) /* The MPU driver installed itself */
midi_devs[prev_devs]->coproc = &pss_coproc_operations;
}
#endif
}
int
probe_pss_mss (struct address_info *hw_config)
{
volatile int timeout;
if (!pss_initialized)
return 0;
if (check_region (hw_config->io_base, 8))
{
printk ("PSS: WSS I/O port conflict\n");
return 0;
}
if (!set_io_base (devc, CONF_WSS, hw_config->io_base))
{
printk ("PSS: WSS base error.\n");
return 0;
}
if (!set_irq (devc, CONF_WSS, hw_config->irq))
{
printk ("PSS: WSS IRQ error.\n");
return 0;
}
if (!set_dma (devc, CONF_WSS, hw_config->dma))
{
printk ("PSS: WSS DRQ error\n");
return 0;
}
/*
* For some reason the card returns 0xff in the WSS status register
* immediately after boot. Probably MIDI+SB emulation algorithm
* downloaded to the ADSP2115 spends some time initializing the card.
* Let's try to wait until it finishes this task.
*/
for (timeout = 0;
timeout < 100000 && (inb (hw_config->io_base + 3) & 0x3f) != 0x04;
timeout++);
outb ((0x0b), hw_config->io_base + 4); /* Required by some cards */
for (timeout = 0;
timeout < 100000;
timeout++);
return probe_ms_sound (hw_config);
}
void
attach_pss_mss (struct address_info *hw_config)
{
int prev_devs;
prev_devs = num_audiodevs;
attach_ms_sound (hw_config);
if (num_audiodevs == (prev_devs + 1)) /* The MSS driver installed itself */
audio_devs[prev_devs]->coproc = &pss_coproc_operations;
}
void
unload_pss (struct address_info *hw_config)
{
}
void
unload_pss_mpu (struct address_info *hw_config)
{
#if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
unload_mpu401 (hw_config);
#endif
}
void
unload_pss_mss (struct address_info *hw_config)
{
unload_ms_sound (hw_config);
}
#endif
|