4 * Low level driver for Ensoniq Soundscape
6 * Copyright by Hannu Savolainen 1994
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>
34 #include <i386/isa/sound/coproc.h>
36 #define EXCLUDE_NATIVE_PCM
53 #define GA_INTSTAT_REG 0
54 #define GA_INTENA_REG 1
57 #define GA_INTCFG_REG 4
58 #define GA_DMACFG_REG 5
59 #define GA_CDCFG_REG 6
60 #define GA_SMCFGA_REG 7
61 #define GA_SMCFGB_REG 8
62 #define GA_HMCTL_REG 9
65 * DMA channel identifiers (A and B)
67 #define SSCAPE_DMA_A 0
68 #define SSCAPE_DMA_B 1
70 #define PORT(name) (devc->base+name)
73 * Host commands recognized by the OBP microcode
75 #define CMD_GEN_HOST_ACK 0x80
76 #define CMD_GEN_MPU_ACK 0x81
77 #define CMD_GET_BOARD_TYPE 0x82
78 #define CMD_SET_CONTROL 0x88
79 #define CMD_GET_CONTROL 0x89
80 #define CTL_MASTER_VOL 0
81 #define CTL_MIC_MODE 2
82 #define CTL_SYNTH_VOL 4
83 #define CTL_WAVE_VOL 7
84 #define CMD_SET_MT32 0x96
85 #define CMD_GET_MT32 0x97
86 #define CMD_SET_EXTMIDI 0x9b
87 #define CMD_GET_EXTMIDI 0x9c
91 typedef struct sscape_info {
93 int ok; /* Properly detected */
102 static struct sscape_info dev_info =
104 static struct sscape_info *devc = &dev_info;
106 static int *sscape_sleeper = NULL;
107 static volatile struct snd_wait sscape_sleep_flag =
110 /* Some older cards have assigned interrupt bits differently than new ones */
111 static char valid_interrupts_old[] =
114 static char valid_interrupts_new[] =
117 static char *valid_interrupts = valid_interrupts_new;
120 static char old_hardware = 1;
123 static char old_hardware = 0;
128 sscape_read(struct sscape_info * devc, int reg)
134 outb(PORT(ODIE_ADDR), reg);
135 val = inb(PORT(ODIE_DATA));
141 sscape_write(struct sscape_info * devc, int reg, int data)
146 outb(PORT(ODIE_ADDR), reg);
147 outb(PORT(ODIE_DATA), data);
152 host_open(struct sscape_info * devc)
154 outb(PORT(HOST_CTRL), 0x00); /* Put the board to the host mode */
158 host_close(struct sscape_info * devc)
160 outb(PORT(HOST_CTRL), 0x03); /* Put the board to the MIDI mode */
164 host_write(struct sscape_info * devc, u_char *data, int count)
172 * Send the command and data bytes
175 for (i = 0; i < count; i++) {
176 for (timeout_val = 10000; timeout_val > 0; timeout_val--)
177 if (inb(PORT(HOST_CTRL)) & TX_READY)
180 if (timeout_val <= 0) {
184 outb(PORT(HOST_DATA), data[i]);
194 host_read(struct sscape_info * devc)
206 for (timeout_val = 10000; timeout_val > 0; timeout_val--)
207 if (inb(PORT(HOST_CTRL)) & RX_READY)
210 if (timeout_val <= 0) {
214 data = inb(PORT(HOST_DATA));
222 host_command1(struct sscape_info * devc, int cmd)
226 buf[0] = (u_char) (cmd & 0xff);
228 return host_write(devc, buf, 1);
232 host_command2(struct sscape_info * devc, int cmd, int parm1)
236 buf[0] = (u_char) (cmd & 0xff);
237 buf[1] = (u_char) (parm1 & 0xff);
239 return host_write(devc, buf, 2);
243 host_command3(struct sscape_info * devc, int cmd, int parm1, int parm2)
247 buf[0] = (u_char) (cmd & 0xff);
248 buf[1] = (u_char) (parm1 & 0xff);
249 buf[2] = (u_char) (parm2 & 0xff);
251 return host_write(devc, buf, 3);
255 set_mt32(struct sscape_info * devc, int value)
258 host_command2(devc, CMD_SET_MT32,
260 if (host_read(devc) != CMD_ACK) {
261 printf("SNDSCAPE: Setting MT32 mode failed\n");
267 set_control(struct sscape_info * devc, int ctrl, int value)
270 host_command3(devc, CMD_SET_CONTROL, ctrl, value);
271 if (host_read(devc) != CMD_ACK) {
272 printf("SNDSCAPE: Setting control (%d) failed\n", ctrl);
278 get_board_type(struct sscape_info * devc)
283 if (!host_command1(devc, CMD_GET_BOARD_TYPE))
286 tmp = host_read(devc);
296 bits = sscape_read(devc, GA_INTSTAT_REG);
297 DEB(printf("sscapeintr(0x%02x)\n", bits));
298 if ((sscape_sleep_flag.mode & WK_SLEEP)) {
299 sscape_sleep_flag.mode = WK_WAKEUP;
300 wakeup(sscape_sleeper);
302 if (bits & 0x02) { /* Host interface interrupt */
303 printf("SSCAPE: Host interrupt, data=%02x\n", host_read(devc));
305 #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
307 static int debug = 0;
310 if (debug++ > 10) { /* Temporary debugging hack */
311 sscape_write(devc, GA_INTENA_REG, 0x00); /* Disable all interr. */
317 * Acknowledge interrupts (toggle the interrupt bits)
320 tmp = sscape_read(devc, GA_INTENA_REG);
321 sscape_write(devc, GA_INTENA_REG, (~bits & 0x0e) | (tmp & 0xf1));
326 do_dma(struct sscape_info * devc, int dma_chan, u_long buf, int blk_size, int mode)
330 if (dma_chan != SSCAPE_DMA_A) {
331 printf("SSCAPE: Tried to use DMA channel != A. Why?\n");
334 DMAbuf_start_dma(devc->my_audiodev, buf, blk_size, mode);
336 temp = devc->dma << 4; /* Setup DMA channel select bits */
338 temp |= 0x80; /* 8 bit DMA channel */
340 temp |= 1; /* Trigger DMA */
341 sscape_write(devc, GA_DMAA_REG, temp);
342 temp &= 0xfe; /* Clear DMA trigger */
343 sscape_write(devc, GA_DMAA_REG, temp);
347 verify_mpu(struct sscape_info * devc)
350 * The SoundScape board could be in three modes (MPU, 8250 and host).
351 * If the card is not in the MPU mode, enabling the MPU driver will
352 * cause infinite loop (the driver believes that there is always some
353 * received data in the buffer.
355 * Detect this by looking if there are more than 10 received MIDI bytes
356 * (0x00) in the buffer.
361 for (i = 0; i < 10; i++) {
362 if (inb(devc->base + HOST_CTRL) & 0x80)
365 if (inb(devc->base) != 0x00)
369 printf("SoundScape: The device is not in the MPU-401 mode\n");
374 sscape_coproc_open(void *dev_info, int sub_device)
376 if (sub_device == COPR_MIDI) {
378 if (!verify_mpu(devc))
381 sscape_sleep_flag.aborting = 0;
382 sscape_sleep_flag.mode = WK_NONE;
387 sscape_coproc_close(void *dev_info, int sub_device)
389 struct sscape_info *devc = dev_info;
393 if (devc->dma_allocated) {
394 sscape_write(devc, GA_DMAA_REG, 0x20); /* DMA channel disabled */
395 #ifdef CONFIG_NATIVE_PCM
397 devc->dma_allocated = 0;
399 sscape_sleep_flag.aborting = 0;
400 sscape_sleep_flag.mode = WK_NONE;
407 sscape_coproc_reset(void *dev_info)
412 sscape_download_boot(struct sscape_info * devc, u_char *block, int size, int flag)
416 int done, timeout_val;
418 if (flag & CPF_FIRST) {
420 * First block. Have to allocate DMA and to reset the board
425 if (devc->dma_allocated == 0) {
426 devc->dma_allocated = 1;
430 sscape_write(devc, GA_HMCTL_REG,
431 (temp = sscape_read(devc, GA_HMCTL_REG)) & 0x3f); /* Reset */
433 for (timeout_val = 10000; timeout_val > 0; timeout_val--)
434 sscape_read(devc, GA_HMCTL_REG); /* Delay */
436 /* Take board out of reset */
437 sscape_write(devc, GA_HMCTL_REG,
438 (temp = sscape_read(devc, GA_HMCTL_REG)) | 0x80);
441 * Transfer one code block using DMA
443 bcopy(block, audio_devs[devc->my_audiodev]->dmap_out->raw_buf, size);
446 /******** INTERRUPTS DISABLED NOW ********/
447 do_dma(devc, SSCAPE_DMA_A,
448 audio_devs[devc->my_audiodev]->dmap_out->raw_buf_phys,
452 * Wait until transfer completes.
454 sscape_sleep_flag.aborting = 0;
455 sscape_sleep_flag.mode = WK_NONE;
458 while (!done && timeout_val-- > 0) {
460 sscape_sleeper = &chn;
461 DO_SLEEP(chn, sscape_sleep_flag, 1);
470 if (flag & CPF_LAST) {
472 * Take the board out of reset
474 outb(PORT(HOST_CTRL), 0x00);
475 outb(PORT(MIDI_CTRL), 0x00);
477 temp = sscape_read(devc, GA_HMCTL_REG);
479 sscape_write(devc, GA_HMCTL_REG, temp); /* Kickstart the board */
482 * Wait until the ODB wakes up
487 timeout_val = 5 * hz;
488 while (!done && timeout_val-- > 0) {
491 sscape_sleeper = &chn;
492 DO_SLEEP(chn, sscape_sleep_flag, 1);
494 if (inb(PORT(HOST_DATA)) == 0xff) /* OBP startup acknowledge */
499 printf("SoundScape: The OBP didn't respond after code download\n");
504 timeout_val = 5 * hz;
505 while (!done && timeout_val-- > 0) {
508 sscape_sleeper = &chn;
509 DO_SLEEP(chn, sscape_sleep_flag, 1);
511 if (inb(PORT(HOST_DATA)) == 0xfe) /* Host startup acknowledge */
516 printf("SoundScape: OBP Initialization failed.\n");
519 printf("SoundScape board of type %d initialized OK\n",
520 get_board_type(devc));
522 set_control(devc, CTL_MASTER_VOL, 100);
523 set_control(devc, CTL_SYNTH_VOL, 100);
527 * Temporary debugging aid. Print contents of the registers
528 * after downloading the code.
533 for (i = 0; i < 13; i++)
534 printf("I%d = %02x (new value)\n", i, sscape_read(devc, i));
543 download_boot_block(void *dev_info, copr_buffer * buf)
545 if (buf->len <= 0 || buf->len > sizeof(buf->data))
548 if (!sscape_download_boot(devc, buf->data, buf->len, buf->flags)) {
549 printf("SSCAPE: Unable to load microcode block to the OBP.\n");
556 sscape_coproc_ioctl(void *dev_info, u_int cmd, ioctl_arg arg, int local)
560 case SNDCTL_COPR_RESET:
561 sscape_coproc_reset(dev_info);
565 case SNDCTL_COPR_LOAD:
570 buf = (copr_buffer *) malloc(sizeof(copr_buffer), M_TEMP, M_WAITOK);
573 bcopy(&(((char *) arg)[0]), (char *) buf, sizeof(*buf));
574 err = download_boot_block(dev_info, buf);
586 static coproc_operations sscape_coproc_operations =
597 sscape_audio_open(int dev, int mode)
600 sscape_info *devc = (sscape_info *) audio_devs[dev]->devc;
611 * Temporary debugging aid. Print contents of the registers when the
617 for (i = 0; i < 13; i++)
618 printf("I%d = %02x\n", i, sscape_read(devc, i));
626 sscape_audio_close(int dev)
629 sscape_info *devc = (sscape_info *) audio_devs[dev]->devc;
631 DEB(printf("sscape_audio_close(void)\n"));
641 set_speed(sscape_info * devc, int arg)
647 set_channels(sscape_info * devc, int arg)
653 set_format(sscape_info * devc, int arg)
659 sscape_audio_ioctl(int dev, u_int cmd, ioctl_arg arg, int local)
661 sscape_info *devc = (sscape_info *) audio_devs[dev]->devc;
664 case SOUND_PCM_WRITE_RATE:
666 return set_speed(devc, (int) arg);
667 return *(int *) arg = set_speed(devc, (*(int *) arg));
669 case SOUND_PCM_READ_RATE:
672 return *(int *) arg = 8000;
674 case SNDCTL_DSP_STEREO:
676 return set_channels(devc, (int) arg + 1) - 1;
677 return *(int *) arg = set_channels(devc, (*(int *) arg) + 1) - 1;
679 case SOUND_PCM_WRITE_CHANNELS:
681 return set_channels(devc, (int) arg);
682 return *(int *) arg = set_channels(devc, (*(int *) arg));
684 case SOUND_PCM_READ_CHANNELS:
687 return *(int *) arg = 1;
689 case SNDCTL_DSP_SAMPLESIZE:
691 return set_format(devc, (int) arg);
692 return *(int *) arg = set_format(devc, (*(int *) arg));
694 case SOUND_PCM_READ_BITS:
697 return *(int *) arg = 8;
705 sscape_audio_output_block(int dev, u_long buf, int count, int intrflag, int dma_restart)
710 sscape_audio_start_input(int dev, u_long buf, int count, int intrflag, int dma_restart)
715 sscape_audio_prepare_for_input(int dev, int bsize, int bcount)
721 sscape_audio_prepare_for_output(int dev, int bsize, int bcount)
727 sscape_audio_halt(int dev)
732 sscape_audio_reset(int dev)
734 sscape_audio_halt(dev);
738 #if !defined(EXCLUDE_NATIVE_PCM) && defined(CONFIG_AUDIO)
739 static struct audio_operations sscape_audio_operations =
743 AFMT_U8 | AFMT_S16_LE,
747 sscape_audio_output_block,
748 sscape_audio_start_input,
750 sscape_audio_prepare_for_input,
751 sscape_audio_prepare_for_output,
757 #endif /* !defined(EXCLUDE_NATIVE_PCM) && defined(CONFIG_AUDIO) */
759 static int sscape_detected = 0;
762 attach_sscape(struct address_info * hw_config)
766 * Config register values for Spea/V7 Media FX and Ensoniq S-2000.
767 * These values are card dependent. If you have another SoundScape
768 * based card, you have to find the correct values. Do the following:
769 * - Compile this driver with SSCAPE_DEBUG1 defined. - Shut down and
770 * power off your machine. - Boot with DOS so that the SSINIT.EXE
771 * program is run. - Warm boot to {Linux|SYSV|BSD} and write down the
772 * lines displayed when detecting the SoundScape. - Modify the
773 * following list to use the values printed during boot. Undefine the
776 #define SSCAPE_REGS { \
778 0xf0, /* Note! Ignored. Set always to 0xf0 */ \
779 0x20, /* Note! Ignored. Set always to 0x20 */ \
780 0x20, /* Note! Ignored. Set always to 0x20 */ \
781 0xf5, /* Ignored */ \
784 0x2e, /* I7 MEM config A. Likely to vary between models */ \
785 0x00, /* I8 MEM config B. Likely to vary between models */ \
786 /* I9 */ 0x40 /* Ignored */ \
791 static u_char regs[10] = SSCAPE_REGS;
793 int i, irq_bits = 0xff;
795 if (sscape_detected != hw_config->io_base)
799 valid_interrupts = valid_interrupts_old;
800 conf_printf("Ensoniq Soundscape (old)", hw_config);
802 conf_printf("Ensoniq Soundscape", hw_config);
804 for (i = 0; i < sizeof(valid_interrupts); i++)
805 if (hw_config->irq == valid_interrupts[i]) {
809 if (hw_config->irq > 15 || (regs[4] = irq_bits == 0xff)) {
810 printf("Invalid IRQ%d\n", hw_config->irq);
815 for (i = 1; i < 10; i++)
817 case 1: /* Host interrupt enable */
818 sscape_write(devc, i, 0xf0); /* All interrupts enabled */
821 case 2: /* DMA A status/trigger register */
822 case 3: /* DMA B status/trigger register */
823 sscape_write(devc, i, 0x20); /* DMA channel disabled */
826 case 4: /* Host interrupt config reg */
827 sscape_write(devc, i, 0xf0 | (irq_bits << 2) | irq_bits);
830 case 5: /* Don't destroy CD-ROM DMA config bits (0xc0) */
831 sscape_write(devc, i, (regs[i] & 0x3f) |
832 (sscape_read(devc, i) & 0xc0));
835 case 6: /* CD-ROM config. Don't touch. */
838 case 9: /* Master control reg. Don't modify CR-ROM
839 * bits. Disable SB emul */
840 sscape_write(devc, i, (sscape_read(devc, i) & 0xf0) | 0x00);
844 sscape_write(devc, i, regs[i]);
851 * Temporary debugging aid. Print contents of the registers after
857 for (i = 0; i < 13; i++)
858 printf("I%d = %02x (new value)\n", i, sscape_read(devc, i));
862 #if defined(CONFIG_MIDI) && defined(CONFIG_MPU_EMU)
863 if (probe_mpu401(hw_config))
864 hw_config->always_detect = 1;
868 prev_devs = num_midis;
869 attach_mpu401(hw_config);
871 if (num_midis == (prev_devs + 1)) /* The MPU driver
872 * installed itself */
873 midi_devs[prev_devs]->coproc = &sscape_coproc_operations;
877 #ifndef EXCLUDE_NATIVE_PCM
878 /* Not supported yet */
881 if (num_audiodevs < MAX_AUDIO_DEV) {
884 audio_devs[my_dev = num_audiodevs++] = &sscape_audio_operations;
885 audio_devs[my_dev]->dmachan1 = hw_config->dma;
886 audio_devs[my_dev]->buffsize = DSP_BUFFSIZE;
887 audio_devs[my_dev]->devc = devc;
888 devc->my_audiodev = my_dev;
890 audio_devs[my_dev]->coproc = &sscape_coproc_operations;
891 if (snd_set_irq_handler(hw_config->irq, sscapeintr, devc->osp) < 0)
892 printf("Error: Can't allocate IRQ for SoundScape\n");
893 sscape_write(devc, GA_INTENA_REG, 0x80); /* Master IRQ enable */
895 printf("SoundScape: More than enough audio devices detected\n");
904 probe_sscape(struct address_info * hw_config)
909 devc->base = hw_config->io_base;
910 devc->irq = hw_config->irq;
911 devc->dma = hw_config->dma;
912 devc->osp = hw_config->osp;
914 if (sscape_detected != 0 && sscape_detected != hw_config->io_base)
918 * First check that the address register of "ODIE" is there and that
919 * it has exactly 4 writeable bits. First 4 bits
921 if ((save = inb(PORT(ODIE_ADDR))) & 0xf0)
924 outb(PORT(ODIE_ADDR), 0x00);
925 if (inb(PORT(ODIE_ADDR)) != 0x00)
928 outb(PORT(ODIE_ADDR), 0xff);
929 if (inb(PORT(ODIE_ADDR)) != 0x0f)
932 outb(PORT(ODIE_ADDR), save);
935 * Now verify that some indirect registers return zero on some bits.
936 * This may break the driver with some future revisions of "ODIE"
940 if (sscape_read(devc, 0) & 0x0c)
943 if (sscape_read(devc, 1) & 0x0f)
946 if (sscape_read(devc, 5) & 0x0f)
951 * Temporary debugging aid. Print contents of the registers before
957 for (i = 0; i < 13; i++)
958 printf("I%d = %02x (old value)\n", i, sscape_read(devc, i));
962 if (old_hardware) { /* Check that it's really an old Spea/Reveal card. */
966 if (!((tmp = sscape_read(devc, GA_HMCTL_REG)) & 0xc0)) {
967 sscape_write(devc, GA_HMCTL_REG, tmp | 0x80);
968 for (cc = 0; cc < 200000; ++cc)
969 inb(devc->base + ODIE_ADDR);
974 printf("sscape.c: Can't allocate DMA channel\n");
977 sscape_detected = hw_config->io_base;
983 probe_ss_mss(struct address_info * hw_config)
985 int i, irq_bits = 0xff;
991 printf("SoundScape: Invalid initialization order.\n");
994 for (i = 0; i < sizeof(valid_interrupts); i++)
995 if (hw_config->irq == valid_interrupts[i]) {
999 if (hw_config->irq > 15 || irq_bits == 0xff) {
1000 printf("SoundScape: Invalid MSS IRQ%d\n", hw_config->irq);
1003 return ad1848_detect(hw_config->io_base, NULL, hw_config->osp);
1007 attach_ss_mss(struct address_info * hw_config)
1010 * This routine configures the SoundScape card for use with the Win
1011 * Sound System driver. The AD1848 codec interface uses the CD-ROM
1012 * config registers of the "ODIE".
1015 int i, irq_bits = 0xff;
1017 #ifndef CONFIG_NATIVE_PCM
1018 int prev_devs = num_audiodevs;
1022 * Setup the DMA polarity.
1024 sscape_write(devc, GA_DMACFG_REG, 0x50);
1027 * Take the gate-arry off of the DMA channel.
1029 sscape_write(devc, GA_DMAB_REG, 0x20);
1032 * Init the AD1848 (CD-ROM) config reg.
1035 for (i = 0; i < sizeof(valid_interrupts); i++)
1036 if (hw_config->irq == valid_interrupts[i]) {
1040 sscape_write(devc, GA_CDCFG_REG, 0x89 | (hw_config->dma << 4) |
1043 if (hw_config->irq == devc->irq)
1044 printf("SoundScape: Warning! WSS mode can't share IRQ with MIDI\n");
1046 ad1848_init("SoundScape", hw_config->io_base,
1053 #ifndef CONFIG_NATIVE_PCM
1054 /* Check if the AD1848 driver installed itself */
1055 if (num_audiodevs == (prev_devs + 1))
1056 audio_devs[prev_devs]->coproc = &sscape_coproc_operations;