4 * The low level driver for the Personal Sound System (ECHO ESC614).
6 * Copyright by Hannu Savolainen 1993
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.
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
30 #include <i386/isa/sound/sound_config.h>
32 #if defined(CONFIG_PSS) && defined(CONFIG_AUDIO)
37 #define REG(x) (devc->base+x)
51 #define CONF_CDROM 0x16
52 #define CONF_MIDI 0x18
57 #define PSS_FLAG3 0x0800
58 #define PSS_FLAG2 0x0400
59 #define PSS_FLAG1 0x1000
60 #define PSS_FLAG0 0x0800
61 #define PSS_WRITE_EMPTY 0x8000
62 #define PSS_READ_FULL 0x4000
69 static int pss_synthLen = 0;
70 static u_char pss_synth[1] =
75 typedef struct pss_config {
82 static pss_config pss_data;
83 static pss_config *devc = &pss_data;
85 static int pss_initialized = 0;
86 static int nonstandard_microcode = 0;
89 probe_pss(struct address_info * hw_config)
94 devc->base = hw_config->io_base;
95 irq = devc->irq = hw_config->irq;
96 dma = devc->dma = hw_config->dma;
97 devc->osp = hw_config->osp;
99 /* these are the possible addresses */
100 if (devc->base != 0x220 && devc->base != 0x240 &&
101 devc->base != 0x230 && devc->base != 0x250)
104 /* these are the possible irqs */
105 if (irq != 3 && irq != 5 && irq != 7 && irq != 9 &&
106 irq != 10 && irq != 11 && irq != 12)
109 /* and these are the possible dmas */
110 if (dma != 5 && dma != 6 && dma != 7)
113 id = inb(REG(PSS_ID));
115 /* XXX the following test cannot possibly succeed! - lr970714 */
116 if ((id >> 8) != 'E') {
118 * printf ("No PSS signature detected at 0x%x (0x%x)\n",
127 set_irq(pss_config * devc, int dev, int irq)
129 static u_short irq_bits[16] =
131 0x0000, 0x0000, 0x0000, 0x0008,
132 0x0000, 0x0010, 0x0000, 0x0018,
133 0x0000, 0x0020, 0x0028, 0x0030,
134 0x0038, 0x0000, 0x0000, 0x0000
139 if (irq < 0 || irq > 15)
142 tmp = inb(REG(dev)) & ~0x38; /* Load confreg, mask IRQ bits out */
144 if ((bits = irq_bits[irq]) == 0 && irq != 0) {
145 printf("PSS: Invalid IRQ %d\n", irq);
148 outw(REG(dev), tmp | bits);
153 set_io_base(pss_config * devc, int dev, int base)
155 u_short tmp = inb(REG(dev)) & 0x003f;
156 u_short bits = (base & 0x0ffc) << 4;
158 outw(REG(dev), bits | tmp);
164 set_dma(pss_config * devc, int dev, int dma)
166 static u_short dma_bits[8] =
168 0x0001, 0x0002, 0x0000, 0x0003,
169 0x0000, 0x0005, 0x0006, 0x0007
174 if (dma < 0 || dma > 7)
177 tmp = inb(REG(dev)) & ~0x07; /* Load confreg, mask DMA bits out */
179 if ((bits = dma_bits[dma]) == 0 && dma != 4) {
180 printf("PSS: Invalid DMA %d\n", dma);
183 outw(REG(dev), tmp | bits);
188 pss_reset_dsp(pss_config * devc)
190 u_long i, limit = get_time() + 10;
192 outw(REG(PSS_CONTROL), 0x2000);
194 for (i = 0; i < 32768 && get_time() < limit; i++)
195 inb(REG(PSS_CONTROL));
197 outw(REG(PSS_CONTROL), 0x0000);
203 pss_put_dspword(pss_config * devc, u_short word)
207 for (i = 0; i < 327680; i++) {
208 val = inb(REG(PSS_STATUS));
209 if (val & PSS_WRITE_EMPTY) {
210 outw(REG(PSS_DATA), word);
218 pss_get_dspword(pss_config * devc, u_short *word)
222 for (i = 0; i < 327680; i++) {
223 val = inb(REG(PSS_STATUS));
224 if (val & PSS_READ_FULL) {
225 *word = inb(REG(PSS_DATA));
234 pss_download_boot(pss_config * devc, u_char *block, int size, int flags)
236 int i, limit, val, count;
238 if (flags & CPF_FIRST) {
239 /* _____ Warn DSP software that a boot is coming */
240 outw(REG(PSS_DATA), 0x00fe);
242 limit = get_time() + 10;
244 for (i = 0; i < 32768 && get_time() < limit; i++)
245 if (inb(REG(PSS_DATA)) == 0x5500)
248 outw(REG(PSS_DATA), *block++);
256 for (j = 0; j < 327670; j++) {
257 /* _____ Wait for BG to appear */
258 if (inb(REG(PSS_STATUS)) & PSS_FLAG3)
263 /* It's ok we timed out when the file was empty */
264 if (count >= size && flags & CPF_LAST)
267 printf("\nPSS: DownLoad timeout problems, byte %d=%d\n",
272 /* _____ Send the next byte */
273 outw(REG(PSS_DATA), *block++);
277 if (flags & CPF_LAST) {
279 outw(REG(PSS_DATA), 0);
281 limit = get_time() + 10;
282 for (i = 0; i < 32768 && get_time() < limit; i++)
283 val = inb(REG(PSS_STATUS));
285 limit = get_time() + 10;
286 for (i = 0; i < 32768 && get_time() < limit; i++) {
287 val = inb(REG(PSS_STATUS));
292 /* now read the version */
293 for (i = 0; i < 32000; i++) {
294 val = inb(REG(PSS_STATUS));
295 if (val & PSS_READ_FULL)
301 val = inb(REG(PSS_DATA));
303 * printf("<PSS: microcode version %d.%d loaded>", val/16,
311 attach_pss(struct address_info * hw_config)
316 devc->base = hw_config->io_base;
317 devc->irq = hw_config->irq;
318 devc->dma = hw_config->dma;
319 devc->osp = hw_config->osp;
321 if (!probe_pss(hw_config))
324 id = inb(REG(PSS_ID)) & 0x00ff;
327 * Disable all emulations. Will be enabled later (if required).
329 outw(REG(CONF_PSS), 0x0000);
330 outw(REG(CONF_WSS), 0x0000);
331 outw(REG(CONF_SB), 0x0000);
332 outw(REG(CONF_MIDI), 0x0000);
333 outw(REG(CONF_CDROM), 0x0000);
335 #if YOU_REALLY_WANT_TO_ALLOCATE_THESE_RESOURCES
337 printf("pss.c: Can't allocate DMA channel\n");
340 if (!set_irq(devc, CONF_PSS, devc->irq)) {
341 printf("PSS: IRQ error\n");
344 if (!set_dma(devc, CONF_PSS, devc->dma)) {
345 printf("PSS: DRQ error\n");
351 snprintf(tmp, sizeof(tmp), "ECHO-PSS Rev. %d", id);
352 conf_printf(tmp, hw_config);
358 probe_pss_mpu(struct address_info * hw_config)
362 if (!pss_initialized)
366 printf("PSS: MPU I/O port conflict\n");
369 if (!set_io_base(devc, CONF_MIDI, hw_config->io_base)) {
370 printf("PSS: MIDI base error.\n");
373 if (!set_irq(devc, CONF_MIDI, hw_config->irq)) {
374 printf("PSS: MIDI IRQ error.\n");
378 printf("PSS: Can't enable MPU. MIDI synth microcode not available.\n");
381 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST)) {
382 printf("PSS: Unable to load MIDI synth microcode to DSP.\n");
386 * Finally wait until the DSP algorithm has initialized itself and
387 * deactivates receive interrupt.
390 for (timeout = 900000; timeout > 0; timeout--) {
391 if ((inb(hw_config->io_base + 1) & 0x80) == 0) /* Input data avail */
392 inb(hw_config->io_base); /* Discard it */
394 break; /* No more input */
397 #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
398 return probe_mpu401(hw_config);
405 pss_coproc_open(void *dev_info, int sub_device)
407 switch (sub_device) {
410 if (pss_synthLen == 0) {
411 printf("PSS: MIDI synth microcode not available.\n");
414 if (nonstandard_microcode)
415 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST)) {
416 printf("PSS: Unable to load MIDI synth microcode to DSP.\n");
419 nonstandard_microcode = 0;
428 pss_coproc_close(void *dev_info, int sub_device)
434 pss_coproc_reset(void *dev_info)
437 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST)) {
438 printf("PSS: Unable to load MIDI synth microcode to DSP.\n");
440 nonstandard_microcode = 0;
444 download_boot_block(void *dev_info, copr_buffer * buf)
446 if (buf->len <= 0 || buf->len > sizeof(buf->data))
449 if (!pss_download_boot(devc, buf->data, buf->len, buf->flags)) {
450 printf("PSS: Unable to load microcode block to DSP.\n");
453 nonstandard_microcode = 1; /* The MIDI microcode has been
460 pss_coproc_ioctl(void *dev_info, u_int cmd, ioctl_arg arg, int local)
462 /* printf("PSS coproc ioctl %x %x %d\n", cmd, arg, local); */
465 case SNDCTL_COPR_RESET:
466 pss_coproc_reset(dev_info);
470 case SNDCTL_COPR_LOAD:
475 buf = (copr_buffer *) malloc(sizeof(copr_buffer), M_TEMP, M_WAITOK);
479 bcopy(&(((char *) arg)[0]), (char *) buf, sizeof(*buf));
480 err = download_boot_block(dev_info, buf);
486 case SNDCTL_COPR_RDATA:
492 bcopy(&(((char *) arg)[0]), (char *) &buf, sizeof(buf));
495 if (!pss_put_dspword(devc, 0x00d0)) {
499 if (!pss_put_dspword(devc, (u_short) (buf.parm1 & 0xffff))) {
503 if (!pss_get_dspword(devc, &tmp)) {
510 bcopy(&buf, &(((char *) arg)[0]), sizeof(buf));
515 case SNDCTL_COPR_WDATA:
521 bcopy(&(((char *) arg)[0]), (char *) &buf, sizeof(buf));
524 if (!pss_put_dspword(devc, 0x00d1)) {
528 if (!pss_put_dspword(devc, (u_short) (buf.parm1 & 0xffff))) {
532 tmp = (u_int) buf.parm2 & 0xffff;
533 if (!pss_put_dspword(devc, tmp)) {
542 case SNDCTL_COPR_WCODE:
548 bcopy(&(((char *) arg)[0]), (char *) &buf, sizeof(buf));
551 if (!pss_put_dspword(devc, 0x00d3)) {
555 if (!pss_put_dspword(devc, (u_short) (buf.parm1 & 0xffff))) {
559 tmp = ((u_int) buf.parm2 >> 8) & 0xffff;
560 if (!pss_put_dspword(devc, tmp)) {
564 tmp = (u_int) buf.parm2 & 0x00ff;
565 if (!pss_put_dspword(devc, tmp)) {
574 case SNDCTL_COPR_RCODE:
580 bcopy(&(((char *) arg)[0]), (char *) &buf, sizeof(buf));
583 if (!pss_put_dspword(devc, 0x00d2)) {
587 if (!pss_put_dspword(devc, (u_short) (buf.parm1 & 0xffff))) {
591 if (!pss_get_dspword(devc, &tmp)) { /* Read msb */
595 buf.parm1 = tmp << 8;
597 if (!pss_get_dspword(devc, &tmp)) { /* Read lsb */
601 buf.parm1 |= tmp & 0x00ff;
605 bcopy(&buf, &(((char *) arg)[0]), sizeof(buf));
617 static coproc_operations pss_coproc_operations =
628 attach_pss_mpu(struct address_info * hw_config)
632 #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
633 prev_devs = num_midis;
634 attach_mpu401(hw_config);
636 if (num_midis == (prev_devs + 1)) /* The MPU driver installed
638 midi_devs[prev_devs]->coproc = &pss_coproc_operations;
643 probe_pss_mss(struct address_info * hw_config)
647 if (!pss_initialized)
651 printf("PSS: WSS I/O port conflict\n");
654 if (!set_io_base(devc, CONF_WSS, hw_config->io_base)) {
655 printf("PSS: WSS base error.\n");
658 if (!set_irq(devc, CONF_WSS, hw_config->irq)) {
659 printf("PSS: WSS IRQ error.\n");
662 if (!set_dma(devc, CONF_WSS, hw_config->dma)) {
663 printf("PSS: WSS DRQ error\n");
667 * For some reason the card returns 0xff in the WSS status register
668 * immediately after boot. Propably MIDI+SB emulation algorithm
669 * downloaded to the ADSP2115 spends some time initializing the card.
670 * Let's try to wait until it finishes this task.
673 timeout < 100000 && (inb(hw_config->io_base + 3) & 0x3f) != 0x04;
676 return probe_mss(hw_config);
680 attach_pss_mss(struct address_info * hw_config)
685 prev_devs = num_audiodevs;
686 attach_mss(hw_config);
688 /* Check if The MSS driver installed itself */
689 if (num_audiodevs == (prev_devs + 1))
690 audio_devs[prev_devs]->coproc = &pss_coproc_operations;